Search in sources :

Example 1 with Decl

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

the class ModulePathTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Set up ABS nature
    natureMock = mock(AbsNature.class, Mockito.RETURNS_DEEP_STUBS);
    MainBlock main = mock(MainBlock.class, Mockito.RETURNS_DEEP_STUBS);
    natureMock.modelLock = new Object();
    // Set up mocks with @Mock annotation
    MockitoAnnotations.initMocks(this);
    declArray = new ModuleDecl[] { modDeclA, modDeclAAA, modDeclAAB, modDeclAAC, modDeclAAD, modDeclAAE };
    // Set up module paths
    modPathEmpty = new ModulePath(natureMock, "");
    modPathA = new ModulePath(natureMock, "A");
    modPathAA = new ModulePath(natureMock, "A.A");
    modPathAAA = new ModulePath(natureMock, "A.A.A");
    modPathAAB = new ModulePath(natureMock, "A.A.B");
    modPathAAC = new ModulePath(natureMock, "A.A.C");
    modPathAAD = new ModulePath(natureMock, "A.A.D");
    modPathAAE = new ModulePath(natureMock, "A.A.E");
    // Return "fake" module names.
    when(modDeclA.getName()).thenReturn("A");
    when(modDeclAAA.getName()).thenReturn("A.A.A");
    when(modDeclAAB.getName()).thenReturn("A.A.B");
    when(modDeclAAC.getName()).thenReturn("A.A.C");
    when(modDeclAAD.getName()).thenReturn("A.A.D");
    when(modDeclAAE.getName()).thenReturn("A.A.E");
    // Setting up child nodes of ModuleDecls
    // moduleDeclA and moduleDeclAAA are empty
    // moduleDeclAAB has a main block
    when(declArray[2].hasBlock()).thenReturn(true);
    when(declArray[2].getBlock()).thenReturn(main);
    // moduleDeclAAC has a decl (class declaration)
    when(declArray[3].getNumDecl()).thenReturn(1);
    abs.frontend.ast.List<Decl> declList = new abs.frontend.ast.List<Decl>();
    declList.add((Decl) mock(ClassDecl.class));
    when(declArray[3].getDeclList()).thenReturn(declList);
    // moduleDeclAAD has an Export
    when(declArray[4].getNumExport()).thenReturn(1);
    // moduleDeclAAD has an Import
    when(declArray[5].getNumImport()).thenReturn(2);
    decls = Arrays.asList(declArray);
    when(model.getModuleDecls()).thenReturn(decls);
    when(natureMock.getCompleteModel()).thenReturn(model);
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) ModuleDecl(abs.frontend.ast.ModuleDecl) Decl(abs.frontend.ast.Decl) ClassDecl(abs.frontend.ast.ClassDecl) ArrayList(java.util.ArrayList) List(java.util.List) MainBlock(abs.frontend.ast.MainBlock) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) Before(org.junit.Before)

Example 2 with Decl

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

the class WizardUtilsTests method testValidateClass.

@Test
public void testValidateClass() {
    ModuleDecl mockDecl = mock(ModuleDecl.class);
    List<Decl> list = new List<Decl>();
    ClassDecl m1 = mock(ClassDecl.class);
    ClassDecl m2 = mock(ClassDecl.class);
    when(m1.getName()).thenReturn("Class1");
    when(m2.getName()).thenReturn("Class2");
    list.add(m1);
    list.add(m2);
    when(mockDecl.getDecls()).thenReturn(list);
    String valid1 = "A";
    String valid2 = "Abc3";
    String valid3 = "ABC3";
    String invalid1 = "";
    String invalid2 = "a";
    String invalid3 = "a.b";
    String invalid4 = ";";
    String invalid5 = "module";
    String invalid6 = "Class1";
    String invalid7 = "Class2";
    assertTrue(validateClass(valid1, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(valid2, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(valid3, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(invalid1, mockDecl).equals(ErrorType.ERROR_NO_NAME));
    assertTrue(validateClass(invalid2, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateClass(invalid3, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateClass(invalid4, mockDecl).equals(ErrorType.ERROR_INVALID_NAME));
    assertTrue(validateClass(invalid5, mockDecl).equals(ErrorType.ERROR_KEYWORD));
    assertTrue(validateClass(invalid6, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
    assertTrue(validateClass(invalid7, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) List(abs.frontend.ast.List) Test(org.junit.Test)

Example 3 with Decl

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

the class ParFnAppTest method sameAnonTwiceTwoExpansions.

@Test
public void sameAnonTwiceTwoExpansions() {
    Model m = testExpand(parse("apply((Int i) => i)(1);" + "apply((Int i) => i)(1);", applyFunction()));
    ModuleDecl module = m.lookupModule("UnitTest");
    int foundExpansions = 0;
    for (Decl decl : module.getDecls()) {
        if (decl instanceof FunctionDecl) {
            FunctionDecl fun = (FunctionDecl) decl;
            if (fun.getName().startsWith("Apply_")) {
                ++foundExpansions;
            }
        }
    }
    assertEquals(2, foundExpansions);
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 4 with Decl

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

the class PureExpressionBuilder method createPureExpression.

/**
 * @param currentHeapReference
 * @param initialisationsOrders
 * @param heapNames
 * @param dataValue
 * @return
 */
PureExp createPureExpression(String currentHeapReference, List<String> initialisationsOrders, String testName, Set<String> heapNames, ABSData dataValue) {
    String type = getABSDataType(dataValue);
    String value = getABSDataValue(dataValue);
    if (type.contains("(") && dataValue instanceof ABSTerm) {
        ABSTerm term = (ABSTerm) dataValue;
        type = getABSTermTypeName(term);
    }
    // import type
    Decl decl = getDecl(model, Decl.class, namePred(type));
    importType(decl);
    if (dataValue instanceof ABSTerm) {
        ABSTerm term = (ABSTerm) dataValue;
        return makeDataTermValue(currentHeapReference, initialisationsOrders, testName, heapNames, term, decl);
    } else if (dataValue instanceof ABSRef) {
        if (heapNames.contains(value)) {
            String ref = heapRefBuilder.heapReferenceForTest(testName, value);
            if (currentHeapReference != null) {
                // we need to consider initialisation order!
                updateInitialisationOrder(initialisationsOrders, currentHeapReference, ref);
            }
            return new VarUse(ref);
        } else {
            return new NullExp();
        }
    } else {
        throw new IllegalStateException("Cannot handle ABSData that is not " + "either a ABSRef or a ABSTerm");
    }
}
Also used : ABSTerm(apet.testCases.ABSTerm) ABSRef(apet.testCases.ABSRef) NullExp(abs.frontend.ast.NullExp) AbsASTBuilderUtil.getDecl(abs.backend.tests.AbsASTBuilderUtil.getDecl) DataTypeDecl(abs.frontend.ast.DataTypeDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Decl(abs.frontend.ast.Decl) TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) VarUse(abs.frontend.ast.VarUse)

Example 5 with Decl

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

the class PureExpressionBuilder method resolveTypeSynonym.

/**
 * Resolve the type synonyms to its raw type (interface or data type)
 * @param d
 * @return
 */
Decl resolveTypeSynonym(TypeSynDecl d) {
    TypeUse use = d.getValue();
    Decl decl = getDecl(model, Decl.class, namePred(use.getName()));
    if (decl instanceof TypeSynDecl) {
        return resolveTypeSynonym((TypeSynDecl) decl);
    }
    return decl;
}
Also used : TypeUse(abs.frontend.ast.TypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) AbsASTBuilderUtil.getDecl(abs.backend.tests.AbsASTBuilderUtil.getDecl) DataTypeDecl(abs.frontend.ast.DataTypeDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Decl(abs.frontend.ast.Decl) TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl)

Aggregations

Decl (abs.frontend.ast.Decl)17 ClassDecl (abs.frontend.ast.ClassDecl)9 InterfaceDecl (abs.frontend.ast.InterfaceDecl)8 ModuleDecl (abs.frontend.ast.ModuleDecl)7 DataTypeDecl (abs.frontend.ast.DataTypeDecl)6 ParametricDataTypeDecl (abs.frontend.ast.ParametricDataTypeDecl)6 TypeSynDecl (abs.frontend.ast.TypeSynDecl)6 Test (org.junit.Test)6 FunctionDecl (abs.frontend.ast.FunctionDecl)5 Model (abs.frontend.ast.Model)4 AbsASTBuilderUtil.getDecl (abs.backend.tests.AbsASTBuilderUtil.getDecl)3 DeltaDecl (abs.frontend.ast.DeltaDecl)3 TypeParameterDecl (abs.frontend.ast.TypeParameterDecl)3 List (abs.frontend.ast.List)2 MainBlock (abs.frontend.ast.MainBlock)2 HasCogs (abs.frontend.analyser.HasCogs)1 Annotation (abs.frontend.ast.Annotation)1 Block (abs.frontend.ast.Block)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 DataTypeUse (abs.frontend.ast.DataTypeUse)1