Search in sources :

Example 11 with PureExp

use of abs.frontend.ast.PureExp in project abstools by abstools.

the class TreeUtilsTest method findChildrenIncludeOnlySelf.

@Test
public void findChildrenIncludeOnlySelf() {
    Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    ExpFunctionDef def = (ExpFunctionDef) functionDecl.getFunctionDef();
    PureExp exp = def.getRhs();
    Stream<PureExp> children = def.findChildren(cast(PureExp.class), n -> false);
    assertNotNull(children);
    List<PureExp> result = children.distinct().collect(Collectors.toList());
    assertEquals(1, result.size());
    assertTrue(result.contains(exp));
}
Also used : Model(abs.frontend.ast.Model) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 12 with PureExp

use of abs.frontend.ast.PureExp in project abstools by abstools.

the class TreeUtilsTest method closestParent.

@Test
public void closestParent() {
    Model model = assertParseOkStdLib("def Int test() = 1;");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    PureExp exp = ((ExpFunctionDef) functionDecl.getFunctionDef()).getRhs();
    assertSame(functionDecl, exp.closestParent(Decl.class));
    assertSame(functionDecl, exp.closestParent(FunctionDecl.class));
}
Also used : Model(abs.frontend.ast.Model) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 13 with PureExp

use of abs.frontend.ast.PureExp in project abstools by abstools.

the class TreeUtilsTest method findChildrenListLazy.

@Test
public void findChildrenListLazy() {
    Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    List<PureExp> children = functionDecl.getFunctionDef().findChildren(PureExp.class, true);
    assertEquals(1, children.size());
    assertTrue(children.get(0) instanceof FnApp);
}
Also used : FnApp(abs.frontend.ast.FnApp) Model(abs.frontend.ast.Model) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 14 with PureExp

use of abs.frontend.ast.PureExp in project abstools by abstools.

the class TreeUtilsTest method findChildrenIncludeSelf.

@Test
public void findChildrenIncludeSelf() {
    Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    ExpFunctionDef def = (ExpFunctionDef) functionDecl.getFunctionDef();
    PureExp exp = def.getRhs();
    Stream<PureExp> children = def.findChildren(cast(PureExp.class), n -> true);
    assertNotNull(children);
    List<PureExp> result = children.distinct().collect(Collectors.toList());
    assertEquals(2, result.size());
    assertTrue(result.contains(exp));
}
Also used : Model(abs.frontend.ast.Model) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 15 with PureExp

use of abs.frontend.ast.PureExp in project abstools by abstools.

the class JavaGeneratorHelper method generateExprGuard.

public static void generateExprGuard(ExpGuard expGuard, PrintStream beforeAwaitStream, PrintStream stream) {
    PureExp expr = expGuard.getPureExp();
    replaceLocalVariables((PureExp) expr.copy(), beforeAwaitStream);
    stream.print("new " + JavaBackendConstants.EXPGUARD + "() { public " + ABSBool.class.getName() + " evaluateExp() { return ");
    expGuard.getPureExp().generateJava(stream);
    stream.print("; }}");
}
Also used : ABSBool(abs.backend.java.lib.types.ABSBool) PureExp(abs.frontend.ast.PureExp)

Aggregations

PureExp (abs.frontend.ast.PureExp)26 FunctionDecl (abs.frontend.ast.FunctionDecl)8 FrontendTest (abs.frontend.FrontendTest)7 Model (abs.frontend.ast.Model)7 Test (org.junit.Test)7 VarUse (abs.frontend.ast.VarUse)6 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)5 ABSData (apet.testCases.ABSData)5 Annotation (abs.frontend.ast.Annotation)4 FnApp (abs.frontend.ast.FnApp)4 IntLiteral (abs.frontend.ast.IntLiteral)4 ABSRef (apet.testCases.ABSRef)3 PreviousCall (apet.testCases.PreviousCall)3 ABSBool (abs.backend.java.lib.types.ABSBool)2 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)2 AbsASTBuilderUtil.getCall (abs.backend.tests.AbsASTBuilderUtil.getCall)2 Call (abs.frontend.ast.Call)2 ClassDecl (abs.frontend.ast.ClassDecl)2 DataTypeUse (abs.frontend.ast.DataTypeUse)2 EqExp (abs.frontend.ast.EqExp)2