Search in sources :

Example 76 with Type

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

the class ToAst method visitClassB.

@Override
public Expression visitClassB(ClassBContext ctx) {
    //the number 1 if present is ignored
    Doc doc1 = parseDoc(ctx.docsOpt().get(0));
    Header h = parseHeader(ctx.header());
    List<Type> supertypes = new ArrayList<>();
    ImplsContext impl = ctx.impls();
    if (impl != null) {
        {
            int i = -1;
            for (TerminalNode p : impl.Path()) {
                i += 1;
                supertypes.add(Path.sugarParse(nameU(p)).toImmNT().withDoc(parseDoc(impl.docsOpt().get(0))));
            }
        }
    }
    List<Member> ms = visitMembers(ctx.member());
    List<Ast.FieldDec> fs = new ArrayList<>();
    for (FieldDecContext f : ctx.fieldDec()) {
        fs.add(parseFieldDec(f));
    }
    return new Expression.ClassB(doc1, h, fs, supertypes, ms, position(ctx));
}
Also used : Type(ast.Ast.Type) FieldDec(ast.Ast.FieldDec) Header(ast.Ast.Header) ConcreteHeader(ast.Ast.ConcreteHeader) InterfaceHeader(ast.Ast.InterfaceHeader) TraitHeader(ast.Ast.TraitHeader) Doc(ast.Ast.Doc) ClassB(ast.Expression.ClassB)

Example 77 with Type

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

the class ToAst method parseRealVDec.

private VarDecXE parseRealVDec(VarDecContext vd) {
    TContext tt = vd.t();
    Optional<Type> t = (tt == null) ? Optional.<Type>empty() : Optional.of(parseType(tt));
    Expression inner = vd.eTop().accept(this);
    return new Ast.VarDecXE(vd.Var() != null, t, nameL(vd.x()), inner);
}
Also used : Type(ast.Ast.Type) Expression(ast.Expression) VarDecXE(ast.Ast.VarDecXE)

Example 78 with Type

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

the class ExtractInfo method isParTypeOk.

/*
  static java.util.Map<Path,List<MethodSelector>> implementedInterfacesMethods(Program p,Path path){
    java.util.Map<Path,List<MethodSelector>> accumulator=new HashMap<>();
    fillImplementedInterfacesMethods(accumulator,p,path);
    return accumulator;
  }
  static void fillImplementedInterfacesMethods(java.util.Map<Path,List<MethodSelector>> accumulator,Program p,Path path){
    //assume p have all the cb present,we do not use ct here
    ClassB cb=p.extractCb(path);
    if(cb.isInterface()){accumulateCb(accumulator,path,cb);}
    for(Path pi:cb.getSupertypes()){
      pi=From.fromP(pi,path);
      fillImplementedInterfacesMethods(accumulator, p, pi);
    }
  }
*/
static List<Integer> isParTypeOk(MethodWithType mta, MethodWithType mtb) {
    List<Integer> res = new ArrayList<>();
    int maxLen = Math.max(mta.getMt().getTs().size(), mtb.getMt().getTs().size());
    for (int i = 0; i < maxLen; i++) {
        Type ta;
        Type tb;
        try {
            ta = mta.getMt().getTs().get(i);
            tb = mtb.getMt().getTs().get(i);
        } catch (ArrayIndexOutOfBoundsException out) {
            res.add(i);
            continue;
        }
        if (!ta.equals(tb)) {
            res.add(i);
        }
    }
    return res;
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList)

Example 79 with Type

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

the class MakeKs method prototypeK.

//can not reuse the desugar one, here we create ExpCore stuff, also , the sugar one may disappear
private static MethodWithType prototypeK(Doc doc, List<String> fieldNames, List<Type> fieldTypes, Position pos) {
    MethodSelector ms = MethodSelector.of("", fieldNames);
    Type resT = Type.mutThis0;
    MethodType mt = new MethodType(false, ast.Ast.Mdf.Class, fieldTypes, resT, Collections.emptyList());
    return new MethodWithType(doc, ms, mt, Optional.empty(), pos);
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType)

Example 80 with Type

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

the class MethodPathCloneVisitor method getVarEnvOf.

private HashMap<String, Ast.Type> getVarEnvOf(Program p, MethodSelector s, ClassB cb) {
    assert p.top() == cb;
    Ast.MethodType mt = getMt(p, s, cb);
    HashMap<String, Ast.Type> result = new HashMap<>();
    {
        int i = -1;
        for (String n : s.getNames()) {
            i += 1;
            //NormType nt=Norm.of(p,mt.getTs().get(i));
            result.put(n, mt.getTs().get(i));
        }
    }
    result.put("this", new Type(mt.getMdf(), Path.outer(0), Doc.empty()));
    return result;
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Ast(ast.Ast) HashMap(java.util.HashMap)

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