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);
}
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));
}
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);
}
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");
}
}
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;
}
Aggregations