use of claw.tatsu.xcodeml.xnode.common.Xnode 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.Xnode in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method analyze.
/**
* Execute the parsing on the raw string and return a ClawPragma object if
* successful.
*
* @param raw Raw directive.
* @param directive Expected directive.
* @return ClawPragma object with information extracted from parsing.
*/
private ClawPragma analyze(String raw, ClawDirective directive) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
ClawPragma l = ClawPragma.analyze(p);
assertEquals(directive, l.getDirective());
return l;
} catch (IllegalDirectiveException idex) {
fail();
}
return null;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method analyzeInvalidClawLanguage.
/**
* Assert any invalid claw raw input
*
* @param raw Raw string value of the CLAW directive to be analyzed.
*/
private void analyzeInvalidClawLanguage(String raw) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
cfg.init(CompilerDirective.OPENACC, Target.GPU);
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
ClawPragma.analyze(p);
fail();
} catch (IllegalDirectiveException pex) {
assertNotNull(pex);
assertNotNull(pex.getMessage());
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode 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.Xnode 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));
}
Aggregations