use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.
the class ReachabilityInformation method isReachable.
/**
* checks if the method is reachable. It looks at the class name
* and all the interface names that are directly or indirectly
* implemented by the method's class
* @param method
* @return true if method is reachable, false otherwise
*/
public boolean isReachable(MethodImpl method) {
ClassDecl clazz = obtainOwnerClass(method);
boolean reachable = false;
if (clazz != null) {
List<InterfaceTypeUse> interfaces = clazz.getImplementedInterfaceUseList();
Iterator<InterfaceTypeUse> it = interfaces.iterator();
// checks if the method is reachable with its class name
reachable = reachableMethods.contains(getMethodId(clazz, method.getMethodSig()));
// implemented by its class
while (!reachable && it.hasNext()) reachable = isReachable(it.next(), method.getMethodSig());
return reachable;
} else
return false;
}
use of org.abs_models.frontend.ast.ClassDecl 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;
}
use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.
the class OtherAnalysisTests method awaitRewriteModule1.
@Test
public void awaitRewriteModule1() {
Model m = assertParse("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.TYPE_CHECK, Config.WITHOUT_DESUGARING_AFTER_TYPECHECK);
ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
Stmt stmt = c.getMethod(0).getBlock().getStmt(0);
ReturnStmt ret = (ReturnStmt) stmt;
assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
m = assertParse("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.TYPE_CHECK);
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 org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.
the class TypingTest method testThisTyping.
@Test
public void testThisTyping() {
Model m = assertParse("class C implements I { I m() { return this; } } interface I { }");
ClassDecl d = (ClassDecl) m.lookupModule("UnitTest").getDecl(0);
ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
assertEquals(m.lookupModule("UnitTest").getDecl(1), ((UnionType) s.getRetExp().getType()).getType(0).getDecl());
}
use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.
the class TypeCheckerTest method classParamsMethodShadowsField.
@Test
public void classParamsMethodShadowsField() {
Model m = assertParse("class C(Bool b) { Bool m(Bool b) { return b; } }");
ModuleDecl u = m.lookupModule("UnitTest");
ClassDecl c = (ClassDecl) u.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
MethodImpl me = c.lookupMethod("m");
ReturnStmt r = (ReturnStmt) me.getBlock().getStmt(0);
VarOrFieldUse vu = (VarOrFieldUse) r.getRetExp();
ParamDecl d = (ParamDecl) vu.getDecl();
assertThat(d.getParent().getParent(), instanceOf(MethodSig.class));
assertThat(vu.getClass().getName(), vu, instanceOf(VarUse.class));
}
Aggregations