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));
}
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);
}
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;
}
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);
}
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;
}
Aggregations