use of abs.frontend.ast.VarDeclStmt 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.ast.VarDeclStmt 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.ast.VarDeclStmt in project abstools by abstools.
the class LocationTypeTests method assertInfer.
private Model assertInfer(String code, LocationType expected, boolean fails) {
Model m = assertParse(code, WITH_STD_LIB);
// m.setLocationTypingEnabled(true);
LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
m.registerTypeSystemExtension(ltie);
SemanticConditionList e = m.typeCheck();
// System.out.println(ltie.getConstraints());
assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage(), fails, e.containsErrors());
// assertEquals(fails, generated == null);
if (expected != null) {
VarDeclStmt vds = ((VarDeclStmt) m.getMainBlock().getStmt(0));
LocationType t = ltie.getResults().get(LocationTypeInferrerExtension.getLV(vds.getVarDecl().getType()));
assertTrue(t.toString(), expected == LocationType.FAR ? t == LocationType.FAR || t.isParametricFar() : expected == t);
}
return m;
}
use of abs.frontend.ast.VarDeclStmt in project abstools by abstools.
the class AnnotationTests method testVarDecl.
@Test
public void testVarDecl() {
Model m = assertParseOkAnn("{ [Near] I i; }");
VarDeclStmt v = ((VarDeclStmt) m.getMainBlock().getStmt(0));
assertHasLocAnnotation(v.getVarDecl().getType(), "Near");
}
use of abs.frontend.ast.VarDeclStmt in project abstools by abstools.
the class ASTBasedABSTestRunnerGenerator method generateMainBlockAST.
private MainBlock generateMainBlockAST(List<Import> list) {
final MainBlock block = new MainBlock();
DataConstructorExp empty = new DataConstructorExp("EmptySet", new List<>());
VarDeclStmt futsStatement = getVarDecl(futs, getType("Set", getFutUnitType()), empty);
block.addStmtNoTransform(futsStatement);
VarDeclStmt futStatement = getVarDecl(fut, getFutUnitType(), null);
block.addStmtNoTransform(futStatement);
Set<TypeUse> use = new HashSet<>();
for (InterfaceDecl key : tests.keySet()) {
for (ClassDecl clazz : tests.get(key)) {
use.addAll(generateTestClassImplAST(key, clazz, block));
}
}
block.addStmtNoTransform(generateWaitSyncAST());
return block;
}
Aggregations