use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class XmlHelper method getDummyXcodeProgram.
public static XcodeProgram getDummyXcodeProgram(Context context) {
assertTrue(Files.exists(TestConstant.TEST_DATA));
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DATA, context);
assertNotNull(xcodeml);
return xcodeml;
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class FmoduleDefinitionTest method simpleModuleDefinitionTest.
@Test
public void simpleModuleDefinitionTest() {
Context context = new TestContext();
Xnode node = XmlHelper.createXnode(module1);
FmoduleDefinition mod = new FmoduleDefinition(node);
assertNotNull(mod);
assertEquals("module", mod.getName());
assertEquals(4, mod.lineNo());
assertEquals("./src/module.f90", mod.filename());
assertNull(mod.getSymbolTable());
assertNull(mod.getDeclarationTable());
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DECLARATIONS, context);
assertNotNull(xcodeml);
List<Xnode> nodes = xcodeml.matchAll(Xcode.F_MODULE_DEFINITION);
assertFalse(nodes.isEmpty());
FmoduleDefinition modDef = new FmoduleDefinition(nodes.get(0));
assertEquals("mod1", modDef.getName());
assertFalse(modDef.getFunctionDefinition(null).isPresent());
assertFalse(modDef.getFunctionDefinition("").isPresent());
assertTrue(modDef.getFunctionDefinition("sub1").isPresent());
assertNotNull(modDef.cloneNode());
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram 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 claw.tatsu.xcodeml.xnode.common.XcodeProgram 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 claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class FfunctionDefinitionTest method findContainingXmodTest.
@Test
public void findContainingXmodTest() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
assertTrue(Files.exists(TestConstant.TEST_DECLARATIONS));
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DECLARATIONS, context);
assertNotNull(xcodeml);
List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
for (FfunctionDefinition fctDef : fctDefs) {
// Search paths is not set so module cannot be found.
assertNull(fctDef.findContainingXmod(context));
}
}
Aggregations