/* some straightforward attribute - accessor/mutator checks */ public void testAccessors() { testSetValidDefinitions(); assertTrue(!dvar.isScopeHolder()); assertTrue(dfn.isScopeHolder()); // assert (dvar.isDefining ()); assertTrue(dvar.getUnqualifiedName().equals(VARID)); }
/* very simple test of valid use of 'setDefinition' */ public void testSetValidDefinitions() { dvar.setDefinition(dvar); dfn.setDefinition(shfn); dtype.setDefinition(shclass); }
protected void setUp() { // d.on (); // Create a time manager to synchronize back tracking BTTimeManager timeMan = new BTTimeManager(); // Create the symbol table rt_symtab = new RT_Symbol_Table(timeMan); // Create a virtual machine state . vms = new VMState( timeMan, boStatic, toStatic, boHeap, toHeap, boStack, toStack, boScratch, toScratch, rt_symtab); Cpp_StatementManager sm = new Cpp_StatementManager(); if (dm == null) dm = new Cpp_DeclarationManager(cem, sm, vms); // Prepare the VMState vms.setProperty("ASTUtilities", new Cpp_ASTUtilities()); vms.setProperty("DatumUtilities", new DatumUtilities()); // create the expression for 5 five = new ConstInt(ctyInt, "5", 5); // create the expression for 1 one = new ConstInt(ctyInt, "1", 1); // create the expression for x String xid = "x"; x_sn = new Cpp_ScopedName(xid); x = new ExpId(new TyRef(tyInt), xid, x_sn); // create the expression for 5.0 ffive = new ConstFloat(ctyFloat, "5.0", 5.0); // create the expression for 1.0 fone = new ConstFloat(ctyFloat, "1.0", 1.0); // create the expression for y String yid = "y"; y_sn = new Cpp_ScopedName(yid); y = new ExpId(new TyRef(tyFloat), yid, y_sn); tyPointer = new TyPointer(); tyPointer.addToEnd(tyInt); // create the expression for p String pid = "p"; p = new ExpId(new TyRef(tyPointer), pid, new Cpp_ScopedName(pid)); tyArray = new TyArray(); tyArray.addToEnd(tyInt); // create the expression for a String aid = "a"; a = new ExpId(new TyRef(tyArray), aid, new Cpp_ScopedName(aid)); String idC = "C"; sn_C = new Cpp_ScopedName(idC); tyClass = new TyClass(idC, sn_C, null); // create the expression for c String cid = "c"; c_sn = new Cpp_ScopedName(cid); c = new ExpId(new TyRef(tyClass), cid, c_sn); String bid = "b"; b = new ExpId(new TyRef(tyBool), bid, new Cpp_ScopedName(bid)); _true = new ConstInt(tyBool, "true", 1); // create a string constant str_const = (ConstStr) Literals.make_string_const("\"blah\"", vms); // array of char tyArrayChar = new TyArray(); tyArrayChar.addToEnd(tyChar); // create the expression for a String acid = "ac"; ac = new ExpId(new TyRef(tyArrayChar), acid, new Cpp_ScopedName(acid)); // reference to int tyRefInt = new TyRef(tyInt); // create the id expression for rint String riid = "ri"; r_sn = new Cpp_ScopedName(riid); rint = new ExpId(new TyRef(tyRefInt), riid, r_sn); // constant reference to int ctyRefInt = new TyRef(ctyInt); ctyRefInt.setAttributes(Cpp_Specifiers.CVQ_CONST); // create the id expression for rint String criid = "cri"; crint = new ExpId(new TyRef(ctyRefInt), criid, new Cpp_ScopedName(criid)); // function taking no parameters and returning int tyFun = new TyFun(new Vector(), false); tyFun.addToEnd(tyInt); // create the following scope and declaration space // int x; // int &r; // int foo (); // class C { // float y; // int bar (); // }; // C c; // C *pc; Cpp_SpecifierSet sps = new Cpp_SpecifierSet(); NodeList nl = new NodeList(); Declaration decl; // int x decl = new Declaration(VARIABLE_LF, x_sn, null, sps, tyInt); decl.setDefinition(decl); decl.getCategory().set(dm.type_extractor.categorizeType(tyInt)); st.addDeclaration(decl); // int &r decl = new Declaration(VARIABLE_LF, r_sn, null, sps, tyRefInt); decl.setDefinition(decl); decl.getCategory().set(dm.type_extractor.categorizeType(tyRefInt)); st.addDeclaration(decl); // int foo () foo_sn = new Cpp_ScopedName("foo"); st.addDefiningDeclaration(foo_sn, REG_FN_LF, tyFun); // class C ClassHead chc = new ClassHead(ClassHead.CLASS, sn_C, new Vector()); Declaration c_decl = st.addDefiningDeclaration(chc); st.enterScope(c_decl); // float y decl = new Declaration(VARIABLE_LF, y_sn, null, sps, tyFloat); decl.setDefinition(decl); decl.getCategory().set(dm.type_extractor.categorizeType(tyFloat)); st.addDeclaration(decl); // int bar () bar_sn = new Cpp_ScopedName("bar"); st.addDefiningDeclaration(bar_sn, MEM_FN_LF, tyFun); st.exitScope(); // C c decl = new Declaration(VARIABLE_LF, c_sn, null, sps, tyClass); decl.setDefinition(c_decl); decl.getCategory().set(dm.type_extractor.categorizeClass(decl)); st.addDeclaration(decl); tyPointerClass = new TyPointer(); tyPointerClass.addToEnd(tyClass); // C *pc String pcid = "pc"; pc_sn = new Cpp_ScopedName(pcid); pc = new ExpId(new TyRef(tyPointer), pcid, pc_sn); decl = new Declaration(VARIABLE_LF, pc_sn, null, sps, tyPointerClass); decl.setDefinition(decl); decl.getCategory().set(dm.type_extractor.categorizeType(tyPointerClass)); st.addDeclaration(decl); }