Search in sources :

Example 41 with Xnode

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());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 42 with Xnode

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;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) ClawPragma(claw.wani.language.ClawPragma)

Example 43 with Xnode

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());
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException)

Example 44 with Xnode

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());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 45 with Xnode

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));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Aggregations

Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)124 Context (claw.tatsu.common.Context)29 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)24 Test (org.junit.Test)24 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)20 TestContext (helper.Utils.TestContext)20 ArrayList (java.util.ArrayList)18 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)17 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)9 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)8 Xid (claw.tatsu.xcodeml.xnode.common.Xid)8 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)8 HashSet (java.util.HashSet)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)6 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)6 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)5 ClawPragma (claw.wani.language.ClawPragma)5 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)5 NodeList (org.w3c.dom.NodeList)5 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)4