Beispiel #1
0
 virtual void visit(SgNode* n) {
     SgLabelStatement* l = isSgLabelStatement(n);
     if (l) {
         SgName name = l->get_label();
         // The label is in some inner scope, and needs to be moved to the
         // enclosing function definition
         SgSymbolTable* st = l->get_scope()->get_symbol_table();
         ROSE_ASSERT (st);
         ROSE_ASSERT (st->find_label(name));
         st->remove(st->find_label(name));
         name << "__" << ++labelRenameCounter;
         // cout << "Found label " << l->get_label().getString() << " to rename to " << name.getString() << endl;
         l->set_label(name);
         l->set_scope(newScope);
         SgLabelSymbol* lSym = new SgLabelSymbol(l);
         lSym->set_parent(symtab);
         symtab->insert(name, lSym);
     }
 }
Beispiel #2
0
    virtual void visit(SgNode* n)
    {
        if (isSgFunctionDefinition(n)) {
            renameLabels(isSgFunctionDefinition(n), isSgFunctionDefinition(n));
        } else if (isSgInitializedName(n))
        {
            SgInitializedName* n2 = isSgInitializedName(n);

            ROSE_ASSERT(n2->get_file_info() != NULL);

            if (isMemberVariable(*n2)) return;

            // JW (7/16/2004): Added patch
            if (isSgVariableDeclaration(n2->get_parent()))
            {
                SgVariableDeclaration* decl = isSgVariableDeclaration(n2->get_parent());
                if (isSgGlobal(decl->get_parent())) return;
                if (isSgNamespaceDefinitionStatement(decl->get_parent())) return;
            }

            if (isSgCtorInitializerList(n2->get_parent())) return;
            if (n2->get_name().getString() == "") return;
            SgName name(n2->get_name());
            SgSymbolTable* symtab = n2->get_scope()->get_symbol_table();
            SgSymbol* sym = symtab->find(n2);
            if (sym) {
                symtab->remove(sym);
            }
            name << "__" << counter++;

            n2->set_name(name);
            SgVariableSymbol* n2symbol = new SgVariableSymbol(n2);
            n2symbol->set_parent(symtab);
            symtab->insert(name, n2symbol);

            // printf ("RenameVariablesVisitor(): name = %s scope = %p = %s \n",name.str(),savedScope,savedScope->class_name().c_str());
            ROSE_ASSERT(n2->get_parent() != NULL);
            ROSE_ASSERT(n2->get_file_info() != NULL);
        }
    }
TEST(SymbolTableTest, InsertNameWithNullSymbolAborts){
  SgSymbolTable *p = new SgSymbolTable();
  const SgName foo("foo");
  EXPECT_EQ(p->size(), 0);
  EXPECT_DEATH(p->insert(foo, NULL), "");
}