use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XnodeUtilTest method xpathIntersectTest.
@Test
public void xpathIntersectTest() {
Context context = new TestContext();
assertTrue(Files.exists(TestConstant.TEST_PROGRAM));
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PROGRAM, context);
assertNotNull(xcodeml);
List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(4, pragmas.size());
Xnode loopHoistStart = new Xnode(pragmas.get(1).element());
assertNotNull(loopHoistStart);
assertTrue(loopHoistStart.value().contains("loop-hoist"));
Xnode loopHoistEnd = new Xnode(pragmas.get(2).element());
assertNotNull(loopHoistEnd);
assertTrue(loopHoistEnd.value().contains("end loop-hoist"));
List<HoistedNestedDoStatement> stmts = XnodeUtil.findDoStatementForHoisting(loopHoistStart, loopHoistEnd, Arrays.asList("j", "i"));
assertEquals(3, stmts.size());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class FbasicTypeTest method addDimensionTest.
@Test
public void addDimensionTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.NONE);
assertEquals(0, bt.getDimensions());
assertFalse(bt.isArray());
assertFalse(bt.isAllAssumedShape());
Xnode d1 = xcodeml.createEmptyAssumedShaped();
bt.addDimension(d1);
assertEquals(1, bt.getDimensions());
Xnode d2 = xcodeml.createEmptyAssumedShaped();
bt.addDimension(d2);
assertEquals(2, bt.getDimensions());
assertTrue(bt.isAllAssumedShape());
Xnode arrayIndex = xcodeml.createNode(Xcode.ARRAY_INDEX);
arrayIndex.append(xcodeml.createIntConstant(10));
bt.addDimension(arrayIndex, 0);
assertEquals(3, bt.getDimensions());
assertEquals(Xcode.ARRAY_INDEX, bt.getDimensions(0).opcode());
assertEquals(Xcode.INDEX_RANGE, bt.getDimensions(1).opcode());
assertEquals(Xcode.INDEX_RANGE, bt.getDimensions(2).opcode());
assertTrue(bt.getDimensions(1).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
assertTrue(bt.getDimensions(2).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
assertFalse(bt.isAllAssumedShape());
assertTrue(bt.isArray());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class FfunctionTypeTest method simpleFctTypeTest.
/**
* Test simple fct type
*
* function foo(a,b) integer a, b
*/
@Test
public void simpleFctTypeTest() {
Context context = new TestContext();
FfunctionType f = XmlHelper.createXfctTypeFromString(fctType1);
assertFunctionType(f);
FfunctionType clone = f.cloneNode();
assertNotEquals(clone.element(), f.element());
assertFunctionType(clone);
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
FfunctionType emptyFctType = xcodeml.createFunctionType(null);
assertFalse(emptyFctType.hasParam("a"));
Xnode paramA = xcodeml.createName("a", FortranType.INTEGER.toString());
Xnode paramB = xcodeml.createName("b", FortranType.INTEGER.toString());
Xnode paramC = xcodeml.createName("c", FortranType.INTEGER.toString());
Xnode paramD = xcodeml.createName("d", FortranType.INTEGER.toString());
emptyFctType.addParameters(paramB);
assertEquals(1, emptyFctType.getParameters().size());
emptyFctType.addParameters(paramB, paramA);
assertEquals(2, emptyFctType.getParameters().size());
emptyFctType.addParameters(paramD, paramC);
assertEquals(3, emptyFctType.getParameters().size());
emptyFctType.addParameters(null);
assertEquals(3, emptyFctType.getParameters().size());
emptyFctType.addParameters(null, null);
assertEquals(3, emptyFctType.getParameters().size());
assertEquals("a", emptyFctType.getParameters().get(0).value());
assertEquals("b", emptyFctType.getParameters().get(1).value());
assertEquals("c", emptyFctType.getParameters().get(2).value());
emptyFctType.addParameters(null, paramD);
assertEquals(4, emptyFctType.getParameters().size());
assertEquals("d", emptyFctType.getParameters().get(3).value());
List<String> names = emptyFctType.getParamsNames();
assertEquals(4, names.size());
assertEquals("a", names.get(0));
assertEquals("b", names.get(1));
assertEquals("c", names.get(2));
assertEquals("d", names.get(3));
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XnodeTest method hasBodyTest.
@Test
public void hasBodyTest() {
Context context = new TestContext();
List<Xcode> expectedNodeWithBody = new ArrayList<>(Arrays.asList(Xcode.ASSOCIATE_STATEMENT, Xcode.BLOCK_STATEMENT, Xcode.CRITICAL_STATEMENT, Xcode.ELSE, Xcode.F_CASE_LABEL, Xcode.F_DO_CONCURRENT_STATEMENT, Xcode.F_DO_STATEMENT, Xcode.F_DO_WHILE_STATEMENT, Xcode.F_FUNCTION_DEFINITION, Xcode.FOR_ALL_STATEMENT, Xcode.THEN, Xcode.TYPE_GUARD));
for (Xcode x : expectedNodeWithBody) {
assertTrue(x.hasBody());
}
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
for (Xcode opcode : Xcode.values()) {
Xnode n = xcodeml.createNode(opcode);
if (expectedNodeWithBody.contains(n.opcode())) {
assertTrue(n.opcode().hasBody());
assertTrue(n.hasBody());
} else {
assertFalse(n.opcode().hasBody());
assertFalse(n.hasBody());
}
}
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XnodeTest method deletedTest.
@Test
public void deletedTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
Xnode n1 = xcodeml.createNode(Xcode.F_BASIC_TYPE);
assertFalse(n1.isDeleted());
n1.delete();
assertTrue(n1.isDeleted());
}
Aggregations