use of abs.frontend.typechecker.Type in project abstools by abstools.
the class FrontendTest method getTypeOfNthAssignment.
protected Type getTypeOfNthAssignment(Model m, int n) {
int count = 0;
for (Stmt s : m.getMainBlock().getStmts()) {
Type t = null;
if (s instanceof AssignStmt) {
AssignStmt as = (AssignStmt) s;
t = as.getValue().getType();
} else if (s instanceof VarDeclStmt) {
VarDeclStmt vd = (VarDeclStmt) s;
if (vd.getVarDecl().hasInitExp()) {
t = vd.getVarDecl().getInitExp().getType();
}
}
if (t != null) {
count++;
if (count == n) {
return t;
}
}
}
return null;
}
use of abs.frontend.typechecker.Type in project abstools by abstools.
the class OtherAnalysisTests method awaitRewriteModule1.
@Test
public void awaitRewriteModule1() {
Model.doAACrewrite = false;
Model m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}");
ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
ReturnStmt ret = (ReturnStmt) c.getMethod(0).getBlock().getStmt(0);
assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
Model.doAACrewrite = true;
m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.WITH_STD_LIB);
c = (ClassDecl) m.lookupModule("C").getDecl(0);
Stmt s = c.getMethod(0).getBlock().getStmt(0);
VarDeclStmt b = (VarDeclStmt) s;
Type t = ((DataTypeType) b.getVarDecl().getType()).getTypeArg(0);
assertEquals("A.X", t.getQualifiedName());
}
use of abs.frontend.typechecker.Type in project abstools by abstools.
the class JavaGeneratorHelper method generateTaskInitMethod.
private static void generateTaskInitMethod(PrintStream stream, final java.util.List<Type> paramTypes) {
int i;
stream.print("public " + abs.backend.java.lib.runtime.AsyncCall.class.getName() + "<?> init(");
i = 0;
for (Type t : paramTypes) {
if (i > 0)
stream.print(",");
stream.print(JavaBackend.getQualifiedString(t) + " _arg" + i);
i++;
}
stream.println(") {");
for (i = 0; i < paramTypes.size(); i++) {
stream.println("arg" + i + " = _arg" + i + ";");
}
stream.println("return this;");
stream.println("}");
}
use of abs.frontend.typechecker.Type in project abstools by abstools.
the class TypeExtensionHelper method checkAssignable.
public void checkAssignable(Type callee, HasParams params, ASTNode<?> n) {
java.util.List<Type> paramsTypes = params.getTypes();
for (int i = 0; i < paramsTypes.size(); i++) {
Type argType = paramsTypes.get(i);
PureExp exp = ((HasActualParams) n).getParams().getChild(i);
checkAssignable(callee, AdaptDirection.TO, exp.getType(), argType, n);
}
}
use of abs.frontend.typechecker.Type in project abstools by abstools.
the class TypeExtensionHelper method annotateType.
public void annotateType(Type t, ASTNode<?> originatingNode, ASTNode<?> typeNode) {
if (t.isDataType()) {
DataTypeType dt = (DataTypeType) t;
if (dt.hasTypeArgs()) {
ParametricDataTypeUse pu = null;
// typeNode maybe a type synonym
if (typeNode instanceof ParametricDataTypeUse)
pu = (ParametricDataTypeUse) typeNode;
int i = 0;
for (Type ta : dt.getTypeArgs()) {
ASTNode<?> childTypeNode = null;
if (pu != null)
childTypeNode = pu.getParam(i);
annotateType(ta, originatingNode, childTypeNode);
i++;
}
}
}
if (t.isReferenceType() || t.isNullType()) {
for (TypeSystemExtension tse : obs) {
tse.annotateType(t, originatingNode, typeNode);
}
}
}
Aggregations