use of claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition in project claw-compiler by C2SM-RCM.
the class XdeclTableTest method allKindOfDeclTest.
@Test
public void allKindOfDeclTest() {
Context context = new TestContext();
XcodeProgram xcodeml = createFromFile(context);
XglobalDeclTable global = xcodeml.getGlobalDeclarationsTable();
assertNotNull(global);
assertNull(global.getFunctionDefinition("unknown"));
assertNull(global.getModuleDefinition("unknown"));
List<Xnode> modules = xcodeml.matchAll(Xcode.F_MODULE_DEFINITION);
assertEquals(1, modules.size());
FmoduleDefinition mod = new FmoduleDefinition(modules.get(0));
XdeclTable modDecl = mod.getDeclarationTable();
assertNotNull(modDecl);
List<Xnode> modDeclarations = modDecl.values();
assertEquals(2, modDeclarations.size());
assertEquals(Xcode.F_STRUCT_DECL, modDeclarations.get(0).opcode());
assertEquals(Xcode.F_INTERFACE_DECL, modDeclarations.get(1).opcode());
Xnode interface1 = modDecl.get("dummy");
assertNotNull(interface1);
assertEquals(Xcode.F_INTERFACE_DECL, interface1.opcode());
assertEquals(1, modDecl.values(Xcode.F_INTERFACE_DECL).size());
List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(1, functions.size());
FfunctionDefinition fctDef = new FfunctionDefinition(functions.get(0));
XdeclTable fctDecl = fctDef.getDeclarationTable();
assertNotNull(fctDecl);
List<Xnode> fctDeclarations = fctDecl.values();
assertEquals(10, fctDeclarations.size());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(0).opcode());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(1).opcode());
assertEquals(Xcode.F_NAMELIST_DECL, fctDeclarations.get(2).opcode());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(3).opcode());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(4).opcode());
assertEquals(Xcode.F_COMMON_DECL, fctDeclarations.get(5).opcode());
assertEquals(Xcode.F_USE_DECL, fctDeclarations.get(6).opcode());
assertEquals(Xcode.F_USE_ONLY_DECL, fctDeclarations.get(7).opcode());
assertEquals(Xcode.F_EQUIVALENCE_DECL, fctDeclarations.get(8).opcode());
assertEquals(Xcode.EXTERN_DECL, fctDeclarations.get(9).opcode());
Xnode varDecl1 = fctDecl.get("sub1");
assertNotNull(varDecl1);
assertEquals(Xcode.VAR_DECL, varDecl1.opcode());
Xnode namelist = fctDecl.get("case");
assertNotNull(namelist);
assertEquals(Xcode.F_NAMELIST_DECL, namelist.opcode());
Xnode useDecl = fctDecl.get("mod4");
assertNotNull(useDecl);
assertEquals(Xcode.F_USE_DECL, useDecl.opcode());
Xnode useOnlyDecl = fctDecl.get("mod5");
assertNotNull(useOnlyDecl);
assertEquals(Xcode.F_USE_ONLY_DECL, useOnlyDecl.opcode());
Xnode externDecl = fctDecl.get("interface_sub");
assertNotNull(externDecl);
assertEquals(Xcode.EXTERN_DECL, externDecl.opcode());
assertEquals(4, fctDecl.values(Xcode.VAR_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_USE_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_USE_ONLY_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_NAMELIST_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_EQUIVALENCE_DECL).size());
assertEquals(1, fctDecl.values(Xcode.EXTERN_DECL).size());
}
use of claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition in project claw-compiler by C2SM-RCM.
the class XglobalDeclTest method simpleGlobalDeclarationTest.
@Test
public void simpleGlobalDeclarationTest() {
XglobalDeclTable gdTable = XmlHelper.createGlobalDeclTable(SIMPLE_GLOB_DECL);
assertNotNull(gdTable);
assertEquals(2, gdTable.size());
assertTrue(gdTable.hasDefinition("fct1"));
assertTrue(gdTable.hasFunctionDefinition("fct1"));
assertFalse(gdTable.hasModuleDefinition("fct1"));
FfunctionDefinition fDef = gdTable.getFunctionDefinition("fct1");
assertNotNull(fDef);
assertEquals("fct1", fDef.getName());
assertNotNull(fDef.body());
assertNotNull(fDef.getDeclarationTable());
assertNull(fDef.getParams());
assertNotNull(fDef.getSymbolTable());
assertEquals(917, fDef.lineNo());
assertEquals("./src/module.f90", fDef.filename());
assertTrue(gdTable.hasDefinition("module"));
assertFalse(gdTable.hasFunctionDefinition("module"));
assertTrue(gdTable.hasModuleDefinition("module"));
FmoduleDefinition mDef = gdTable.getModuleDefinition("module");
assertNotNull(mDef);
assertEquals("module", mDef.getName());
assertEquals(4, mDef.lineNo());
assertEquals("./src/module.f90", mDef.filename());
}
Aggregations