Search in sources :

Example 51 with Model

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

the class TypingTest method functionTypeArgs5.

@Test
public void functionTypeArgs5() {
    Model m = assertParseOkStdLib("def B nth<B>(List<B> list, Int n) = nth(tail(list), n-1) ; ");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    TypeParameterDecl typeParameter = d.getTypeParameter(0);
    TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    assertEquals(typeParameter.getName(), type.getDecl().getName());
}
Also used : TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) TypeParameter(abs.frontend.typechecker.TypeParameter) Model(abs.frontend.ast.Model) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 52 with Model

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

the class TypingTest method testSyncCall.

@Test
public void testSyncCall() {
    Model m = assertParseOkStdLib(" interface I { Bool m(); } { I i; i.m(); }");
    assertEquals(m.getBoolType(), getSecondExp(m).getType());
}
Also used : Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 53 with Model

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

the class TypingTest method testThisTyping.

@Test
public void testThisTyping() {
    Model m = assertParseOk("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());
}
Also used : UnionType(abs.frontend.typechecker.UnionType) ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 54 with Model

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

the class TreeUtilsTest method findChildrenList.

@Test
public void findChildrenList() {
    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);
    assertEquals(2, children.size());
}
Also used : Model(abs.frontend.ast.Model) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 55 with Model

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

the class TreeUtilsTest method findChildrenMultipleTypes.

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

Aggregations

Model (abs.frontend.ast.Model)224 Test (org.junit.Test)170 FrontendTest (abs.frontend.FrontendTest)93 ClassDecl (abs.frontend.ast.ClassDecl)57 DeltaDecl (abs.frontend.ast.DeltaDecl)30 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)24 FunctionDecl (abs.frontend.ast.FunctionDecl)15 PrintStream (java.io.PrintStream)14 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)11 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 CompilationUnit (abs.frontend.ast.CompilationUnit)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)7 PureExp (abs.frontend.ast.PureExp)7 TraitExpr (abs.frontend.ast.TraitExpr)7 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)6