Search in sources :

Example 11 with Type

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

the class Desugar method visit.

public Expression visit(ClassB s) {
    Position pos = s.getP();
    assert !(s.getH() instanceof ConcreteHeader);
    if (!s.getFields().isEmpty()) {
        List<Member> ms = s.getFields().stream().flatMap(f -> Desugar.field(pos, f)).collect(Collectors.toList());
        ms.addAll(s.getMs());
        s = s.withMs(ms).withH(new Ast.TraitHeader());
    }
    Set<String> oldUsedVars = this.usedVars;
    HashMap<String, Type> oldVarEnv = this.varEnv;
    try {
        s = (ClassB) super.visit(s);
        s = FlatFirstLevelLocalNestedClasses.of(s, this);
        s = DesugarCatchDefault.of(s);
        return s;
    } finally {
        this.usedVars = oldUsedVars;
        this.varEnv = oldVarEnv;
    }
}
Also used : Stage(ast.Ast.Stage) VarDecXE(ast.Ast.VarDecXE) X(ast.Expression.X) Ast(ast.Ast) FieldDec(ast.Ast.FieldDec) Parameters(ast.Ast.Parameters) Catch1(ast.Expression.Catch1) Catch(ast.Expression.Catch) SquareWithCall(ast.Expression.SquareWithCall) ErrorMessage(ast.ErrorMessage) Type(ast.Ast.Type) Configuration(facade.Configuration) FCall(ast.Expression.FCall) SquareCall(ast.Expression.SquareCall) ConcreteHeader(ast.Ast.ConcreteHeader) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) Visitor(coreVisitors.Visitor) BinOp(ast.Expression.BinOp) InjectionOnSugar(coreVisitors.InjectionOnSugar) Op(ast.Ast.Op) SignalKind(ast.Ast.SignalKind) Loop(ast.Expression.Loop) OnLineCode(platformSpecific.fakeInternet.OnLineCode) RoundBlock(ast.Expression.RoundBlock) TypeManipulation(newTypeSystem.TypeManipulation) Set(java.util.Set) MethodSelectorX(ast.Ast.MethodSelectorX) With(ast.Expression.With) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) UseSquare(ast.Expression.UseSquare) While(ast.Expression.While) ClassReuse(ast.Expression.ClassReuse) VarDecCE(ast.Ast.VarDecCE) EncodingHelper(auxiliaryGrammar.EncodingHelper) Optional(java.util.Optional) Timer(profiling.Timer) L42(facade.L42) Expression._void(ast.Expression._void) Program(programReduction.Program) Header(ast.Ast.Header) Using(ast.Expression.Using) Member(ast.Expression.ClassB.Member) HashMap(java.util.HashMap) Assertions(tools.Assertions) MethodType(ast.Ast.MethodType) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PathMxMx(ast.Util.PathMxMx) RefreshUniqueNames(privateMangling.RefreshUniqueNames) MCall(ast.Expression.MCall) If(ast.Expression.If) Literal(ast.Expression.Literal) UnOp(ast.Expression.UnOp) IsCompiled(coreVisitors.IsCompiled) Mdf(ast.Ast.Mdf) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) DocE(ast.Expression.DocE) Doc(ast.Ast.Doc) VarDecE(ast.Ast.VarDecE) ExpCore(ast.ExpCore) Expression(ast.Expression) ClassB(ast.Expression.ClassB) Functions(auxiliaryGrammar.Functions) CatchMany(ast.Expression.CatchMany) CurlyBlock(ast.Expression.CurlyBlock) Position(ast.Ast.Position) MethodImplemented(ast.Expression.ClassB.MethodImplemented) PathAux(ast.PathAux) Collections(java.util.Collections) NestedClass(ast.Expression.ClassB.NestedClass) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Position(ast.Ast.Position) Member(ast.Expression.ClassB.Member) ConcreteHeader(ast.Ast.ConcreteHeader)

Example 12 with Type

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

the class Desugar method visit.

public MethodImplemented visit(MethodImplemented mi) {
    this.usedVars = new HashSet<String>();
    this.varEnv = new HashMap<String, Type>();
    String mName = desugarName(mi.getS().nameToS());
    mi = mi.withS(mi.getS().withName(mName));
    for (String name : mi.getS().getNames()) {
        usedVars.add(name);
        List<Ast.MethodSelectorX> msxsi = new ArrayList<>();
        msxsi.add(new Ast.MethodSelectorX(mi.getS(), name));
        varEnv.put(name, null);
    }
    usedVars.add("this");
    List<Ast.MethodSelectorX> msxsi = new ArrayList<>();
    msxsi.add(new Ast.MethodSelectorX(mi.getS(), "this"));
    //varEnv.put("this",new Ast.HistoricType(Path.outer(0),msxsi,Doc.empty()));
    List<Ast.MethodSelectorX> msxs = new ArrayList<>();
    msxs.add(new Ast.MethodSelectorX(mi.getS(), ""));
    usedVars.addAll(CollectDeclaredVars.of(mi.getInner()));
    //final restrictions
    final MethodImplemented mi2 = mi;
    return withExpectedType(null, () -> super.visit(mi2));
//well... this is an issue> method desugaring for method implemented does not know its return type?
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodImplemented(ast.Expression.ClassB.MethodImplemented) Ast(ast.Ast) MethodSelectorX(ast.Ast.MethodSelectorX) ArrayList(java.util.ArrayList) MethodSelectorX(ast.Ast.MethodSelectorX)

Example 13 with Type

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

the class DesugarW method castT.

private VarDecXE castT(Position pos, Type t, String y, String x) {
    assert t instanceof Type;
    Type nt = t;
    String z = Functions.freshName("casted", usedVars);
    List<Catch> ks = new ArrayList<>();
    Type t2 = new Type(nt.getMdf(), Path.Any(), Doc.empty());
    ks.add(new //case return captured
    Expression.Catch1(//case return captured
    pos, //case return captured
    SignalKind.Return, //case return captured
    t, //case return captured
    z, //return it
    new X(pos, z)));
    ks.add(new //else
    Expression.Catch1(//else
    pos, //else
    SignalKind.Return, //else
    t2, //else
    z, // exception void
    new Signal(SignalKind.Exception, Expression._void.instance)));
    RoundBlock block = Desugar.getBlock(pos, new Signal(SignalKind.Return, new X(pos, x)), ks, Desugar.errorMsg("CastT-Should be unreachable code"));
    return new VarDecXE(false, Optional.of(t), y, block);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Signal(ast.Expression.Signal) Expression(ast.Expression) Catch(ast.Expression.Catch) ArrayList(java.util.ArrayList) X(ast.Expression.X) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Example 14 with Type

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

the class DesugarW method withDesugarGetDefaultCatch.

private Catch withDesugarGetDefaultCatch(Position pos, SignalKind kind, Expression eClose) {
    String propagated1 = Functions.freshName("propagated", usedVars);
    Expression blockPropagate1 = Desugar.getBlock(pos, eClose, new Signal(kind, new X(pos, propagated1)));
    Type t = Type.immAny;
    Expression.Catch1 k1 = new Expression.Catch1(pos, kind, t, propagated1, blockPropagate1);
    return new DesugarCatchDefault.CatchToComplete(k1);
}
Also used : Signal(ast.Expression.Signal) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Expression(ast.Expression) Catch1(ast.Expression.Catch1) X(ast.Expression.X) Catch1(ast.Expression.Catch1)

Example 15 with Type

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

the class CloneVisitor method visit.

public Expression visit(ClassB s) {
    Header h = liftH(s.getH());
    List<FieldDec> fs = Map.of(this::liftF, s.getFields());
    List<Type> superT = Map.of(this::liftT, s.getSupertypes());
    List<Member> ms = Map.of(this::liftM, s.getMs());
    return new ClassB(liftDoc(s.getDoc1()), h, fs, superT, ms, s.getP());
}
Also used : FieldDec(ast.Ast.FieldDec) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Header(ast.Ast.Header) ConcreteHeader(ast.Ast.ConcreteHeader) Member(ast.Expression.ClassB.Member) ClassB(ast.Expression.ClassB)

Aggregations

Type (ast.Ast.Type)81 MethodType (ast.Ast.MethodType)50 MethodWithType (ast.ExpCore.ClassB.MethodWithType)28 MethodWithType (ast.Expression.ClassB.MethodWithType)24 ArrayList (java.util.ArrayList)24 Mdf (ast.Ast.Mdf)16 Expression (ast.Expression)15 Path (ast.Ast.Path)13 Doc (ast.Ast.Doc)11 Ast (ast.Ast)10 MethodSelector (ast.Ast.MethodSelector)10 HashMap (java.util.HashMap)10 MethodSelectorX (ast.Ast.MethodSelectorX)8 VarDecXE (ast.Ast.VarDecXE)8 ExpCore (ast.ExpCore)8 Catch (ast.Expression.Catch)8 X (ast.Expression.X)8 VarDec (ast.Ast.VarDec)7 Block (ast.ExpCore.Block)7 List (java.util.List)7