Search in sources :

Example 1 with Member

use of ast.Expression.ClassB.Member in project L42 by ElvisResearchGroup.

the class InjectionOnSugar method visit.

@Override
public Expression visit(ClassB s) {
    Doc doc1 = s.getDoc1();
    Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
    List<Type> supertypes = s.getSupertypes();
    List<Member> members = new ArrayList<>();
    for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
        members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
            Doc idoc = mwt.getDoc();
            MethodSelector is = mwt.getMs();
            MethodType mt = mwt.getMt();
            return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
        }));
    }
    return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
Also used : VarDecXE(ast.Ast.VarDecXE) UpdateVar(ast.ExpCore.UpdateVar) Ast(ast.Ast) Header(ast.Ast.Header) MCall(ast.ExpCore.MCall) Type(ast.Ast.Type) Member(ast.Expression.ClassB.Member) WellFormedness(auxiliaryGrammar.WellFormedness) MethodType(ast.Ast.MethodType) Loop(ast.ExpCore.Loop) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Visitor(coreVisitors.Visitor) ClassB(ast.ExpCore.ClassB) WalkBy(ast.ExpCore.WalkBy) Mdf(ast.Ast.Mdf) X(ast.ExpCore.X) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) Signal(ast.ExpCore.Signal) Match(tools.Match) Doc(ast.Ast.Doc) ExpCore._void(ast.ExpCore._void) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Expression(ast.Expression) List(java.util.List) Position(ast.Ast.Position) Using(ast.ExpCore.Using) Optional(java.util.Optional) Collections(java.util.Collections) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Header(ast.Ast.Header) Expression(ast.Expression) Doc(ast.Ast.Doc) Member(ast.Expression.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 2 with Member

use of ast.Expression.ClassB.Member 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 3 with Member

use of ast.Expression.ClassB.Member in project L42 by ElvisResearchGroup.

the class CheckVarUsedAreInScope method visit.

public Expression visit(ClassB s) {
    for (Member m : s.getMs()) {
        m.match(nc -> {
            CheckVarUsedAreInScope.of(nc.getInner(), Collections.emptyList());
            return null;
        }, mi -> {
            List<String> names = new ArrayList<>(mi.getS().getNames());
            names.add("this");
            CheckVarUsedAreInScope.of(mi.getInner(), names);
            return null;
        }, mt -> {
            if (mt.getInner().isPresent()) {
                List<String> names = new ArrayList<>(mt.getMs().getNames());
                names.add("this");
                CheckVarUsedAreInScope.of(mt.getInner().get(), names);
            }
            ;
            return null;
        });
    }
    return s;
}
Also used : ArrayList(java.util.ArrayList) Member(ast.Expression.ClassB.Member)

Example 4 with Member

use of ast.Expression.ClassB.Member 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)

Example 5 with Member

use of ast.Expression.ClassB.Member in project L42 by ElvisResearchGroup.

the class Desugar method visit.

public Expression visit(ClassReuse s) {
    ClassB res = lift(s.getInner());
    //ClassB reused2=OnLineCode.getCode(s.getUrl());
    ExpCore.ClassB _reused = this.importedLibs.get(s.getUrl());
    assert _reused != null : s.getUrl() + " " + this.importedLibs.keySet() + this.importedLibs.get(s.getUrl()) + this.importedLibs;
    ExpCore.ClassB reused = RefreshUniqueNames.refreshTopLevel(_reused);
    for (Member m2 : res.getMs()) {
        m2.match(nc2 -> {
            for (ast.ExpCore.ClassB.NestedClass nc1 : reused.ns()) {
                if (nc1.getName().equals(nc2.getName())) {
                    throw new ast.ErrorMessage.NotWellFormedMsk(s, s, "Nested class \"" + nc1.getName() + "\" already present in reused library " + s.getUrl());
                }
            }
            return null;
        }, mi -> {
            return null;
        }, mwt2 -> {
            for (ast.ExpCore.ClassB.MethodWithType mwt1 : reused.mwts()) {
                if (mwt1.getMs().equals(mwt2.getMs())) {
                    throw new ast.ErrorMessage.NotWellFormedMsk(s, s, "Method with type \"" + mwt1.getMs() + "\" already present in reused library " + s.getUrl());
                }
            }
            return null;
        });
    }
    return new ClassReuse(res, s.getUrl(), reused);
}
Also used : ExpCore(ast.ExpCore) ClassReuse(ast.Expression.ClassReuse) Member(ast.Expression.ClassB.Member) ClassB(ast.Expression.ClassB)

Aggregations

Member (ast.Expression.ClassB.Member)7 ClassB (ast.Expression.ClassB)4 Header (ast.Ast.Header)3 MethodType (ast.Ast.MethodType)3 Type (ast.Ast.Type)3 ExpCore (ast.ExpCore)3 ArrayList (java.util.ArrayList)3 Ast (ast.Ast)2 ConcreteHeader (ast.Ast.ConcreteHeader)2 Doc (ast.Ast.Doc)2 FieldDec (ast.Ast.FieldDec)2 Mdf (ast.Ast.Mdf)2 MethodSelector (ast.Ast.MethodSelector)2 Path (ast.Ast.Path)2 Position (ast.Ast.Position)2 VarDec (ast.Ast.VarDec)2 VarDecXE (ast.Ast.VarDecXE)2 Expression (ast.Expression)2 ClassReuse (ast.Expression.ClassReuse)2 Visitor (coreVisitors.Visitor)2