Search in sources :

Example 6 with Position

use of ast.Ast.Position in project L42 by ElvisResearchGroup.

the class L42 method runSlow.

public static ErrorMessage.FinalResult runSlow(String fileName, String code) {
    try {
        L42.setExecutionStage(ExecutionStage.Parsing);
        Expression code1 = Parser.parse(fileName, code);
        assert code1 instanceof Expression.ClassB || code1 instanceof Expression.ClassReuse;
        L42.setExecutionStage(ExecutionStage.CheckingWellFormedness);
        auxiliaryGrammar.WellFormedness.checkAll(code1);
        L42.setExecutionStage(ExecutionStage.Desugaring);
        Expression code2 = Desugar.of(code1);
        assert auxiliaryGrammar.WellFormedness.checkAll(code2);
        ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
        assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
        // L42.usedNames.addAll(CollectDeclaredVarsAndCheckNoDeclaredTwice.of(code2));
        //L42.usedNames.addAll(CollectDeclaredClassNamesAndMethodNames.of(code2));
        L42.setExecutionStage(ExecutionStage.MetaExecution);
        //ClassB result= (ClassB)Executor.stepStar(exe,code3);
        //Refresh of position identities, it is used to generate correct Java code.
        code3 = (ClassB) code3.accept(new CloneVisitor() {

            @Override
            public ExpCore visit(ClassB cb) {
                Position p = cb.getP();
                cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
                return super.visit(cb);
            }
        });
        //ClassB result= Configuration.reduction.of(code3);
        ClassB result = ProgramReduction.allSteps(code3);
        //System.out.println("--------------------------");
        return checkFinalError(result);
    } finally {
        L42.setExecutionStage(ExecutionStage.None);
    }
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) Position(ast.Ast.Position) CloneVisitor(coreVisitors.CloneVisitor) ClassB(ast.ExpCore.ClassB) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 7 with Position

use of ast.Ast.Position in project L42 by ElvisResearchGroup.

the class InjectionOnSugar method visit.

@Override
public Expression visit(MCall s) {
    ast.Expression receiver = lift(s.getInner());
    String name = s.getS().nameToS();
    Doc docs = s.getDoc();
    List<String> xs = s.getS().getNames();
    List<ast.ExpCore> es1 = s.getEs();
    List<ast.Expression> es = new ArrayList<ast.Expression>();
    for (ast.ExpCore e : es1) {
        es.add(lift(e));
    }
    ast.Ast.Parameters ps = new ast.Ast.Parameters(Optional.<ast.Expression>empty(), xs, es);
    Position pos = s.getP();
    return new Expression.MCall(receiver, name, docs, ps, pos);
}
Also used : ExpCore(ast.ExpCore) Ast(ast.Ast) Position(ast.Ast.Position) ArrayList(java.util.ArrayList) ExpCore(ast.ExpCore) Expression(ast.Expression) Expression(ast.Expression) MCall(ast.ExpCore.MCall) Doc(ast.Ast.Doc)

Example 8 with Position

use of ast.Ast.Position in project L42 by ElvisResearchGroup.

the class DesugarVars method getDecForVar.

private VarDecXE getDecForVar(Ast.C cName, VarDecXE varDec) {
    Type nt = new Type(Mdf.Mutable, Path.outer(0).pushC(cName), Doc.empty());
    Position pos = Desugar.getPosition(varDec.getInner());
    MCall right = new MCall(new Expression.EPath(pos, nt.getPath()), "#apply", Doc.empty(), Desugar.getPs("inner", new X(pos, varDec.getX())), pos);
    String nameZ = Functions.freshName(nt.getPath(), usedVars);
    //usedVars.add(nameZ);
    return new VarDecXE(false, Optional.of(nt), nameZ, right);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Position(ast.Ast.Position) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) VarDecXE(ast.Ast.VarDecXE)

Example 9 with Position

use of ast.Ast.Position in project L42 by ElvisResearchGroup.

the class Resources method nameOf.

public static String nameOf(int level, List<Ast.C> cs) {
    Program p = Resources.getP();
    Position pos = p.get(level).getP();
    assert pos != null;
    assert pos != Position.noInfo;
    //ok, all relevant positions existed together at the same moment.
    int hc = System.identityHashCode(pos);
    assert !pos.equals(Position.noInfo);
    String res = "This" + hc;
    //String res="This"+level;
    for (Ast.C s : cs) {
        res += "." + s;
    }
    return nameOf(res);
}
Also used : Program(programReduction.Program) CloneVisitorWithProgram(coreVisitors.CloneVisitorWithProgram) Ast(ast.Ast) Position(ast.Ast.Position) C(ast.Ast.C)

Example 10 with Position

use of ast.Ast.Position in project L42 by ElvisResearchGroup.

the class CollapsePositions method accumulateSinglePos.

public static Position accumulateSinglePos(Position p) {
    if (p.get_next() == null) {
        return p;
    }
    Position p2 = accumulateSinglePos(p.get_next());
    assert p2.get_next() == null;
    Position res = accumulatePos(p.with_next(null), p2);
    assert res.get_next() == null;
    return res;
}
Also used : Position(ast.Ast.Position)

Aggregations

Position (ast.Ast.Position)14 Expression (ast.Expression)9 ErrorMessage (ast.ErrorMessage)5 ExpCore (ast.ExpCore)5 ArrayList (java.util.ArrayList)5 Ast (ast.Ast)4 ClassB (ast.ExpCore.ClassB)3 ClassB (ast.Expression.ClassB)3 ClassReuse (ast.Expression.ClassReuse)3 C (ast.Ast.C)2 Doc (ast.Ast.Doc)2 MethodSelectorX (ast.Ast.MethodSelectorX)2 Path (ast.Ast.Path)2 Type (ast.Ast.Type)2 VarDec (ast.Ast.VarDec)2 VarDecXE (ast.Ast.VarDecXE)2 Catch (ast.Expression.Catch)2 MethodWithType (ast.Expression.ClassB.MethodWithType)2 MCall (ast.Expression.MCall)2 RoundBlock (ast.Expression.RoundBlock)2