use of org.abs_models.frontend.ast.Stmt in project abstools by abstools.
the class TreeUtilsTest method findChildrenListNotNull.
@Test
public void findChildrenListNotNull() {
Model model = assertParse("def Int test(Int i) = test(1);");
FunctionDecl functionDecl = getLastFunctionDecl(model);
assertEquals("test", functionDecl.getName());
List<Stmt> children = functionDecl.getFunctionDef().findChildren(Stmt.class);
assertNotNull(children);
assertTrue(children.isEmpty());
}
use of org.abs_models.frontend.ast.Stmt in project abstools by abstools.
the class FreeVarTest method fieldUse.
@Test
public void fieldUse() {
ClassDecl clazz = getFirstClassDecl(assertParse("class C {" + "Int i = 0;" + "Int m() {" + "return i + 1;" + "}" + "}"));
MethodImpl method = clazz.lookupMethod("m");
assertNotNull(method);
Stmt stmt = method.getBlock().getStmt(0);
assertTrue(stmt instanceof ReturnStmt);
ReturnStmt returnStmt = (ReturnStmt) stmt;
Exp exp = returnStmt.getRetExp();
assertEquals(exp.getFreeVars(), "i");
}
use of org.abs_models.frontend.ast.Stmt 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 org.abs_models.frontend.ast.Stmt in project abstools by abstools.
the class AnnotationUtil method annotateCall.
/**
* <p>Annotates the parent Statement or Function node with an ExpansionCall annotation.</p>
*
* <p>If said node already has an annotation with the ExpansionCall type, the expansionIndex will be added to the
* existing annotation.</p>
*
* @param call the call to use as a starting point to look for a Stmt or FunctionDecl parent
* @param expansionId the ID of the called Expansion
* @throws IllegalArgumentException if there is no Stmt or FunctionDecl parent
*/
public static void annotateCall(FnApp call, int expansionId) {
Stmt parent = call.closestParent(Stmt.class);
if (parent == null) {
FunctionDecl parentFunction = call.closestParent(FunctionDecl.class);
if (parentFunction == null) {
throw new IllegalArgumentException("Function call has no parent Statement or FunctionDecl: " + call);
}
addToAnnotations(parentFunction.getAnnotations(), expansionCallType(), expansionId);
} else {
addToAnnotations(parent.getAnnotations(), expansionCallType(), expansionId);
}
}
use of org.abs_models.frontend.ast.Stmt in project abstools by abstools.
the class SchedulerChecker method checkNewExp.
@Override
public void checkNewExp(NewExp e) {
Stmt stmt = CompilerUtils.findStmtForExpression(e);
PureExp sched = AnnotationHelper.getAnnotationValueFromName(stmt.getAnnotations(), "ABS.Scheduler.Scheduler");
if (sched != null) {
ClassDecl decl = (ClassDecl) (e.lookup(new KindedName(KindedName.Kind.CLASS, e.getClassName())));
checkScheduleExp(sched, decl, stmt);
}
}
Aggregations