void Driver<Sage>::addPointerToTopParentDeclaration(SgSymbol * symbol, unsigned file_id) { SgSymbol * parent = symbol; std::map<SgSymbol *, SgSymbol *>::const_iterator it_parent = p_parent_map.find(symbol); assert(it_parent != p_parent_map.end()); while (it_parent->second != NULL) { parent = it_parent->second; it_parent = p_parent_map.find(parent); assert(it_parent != p_parent_map.end()); } assert(parent != NULL); SgDeclarationStatement * decl_to_add = NULL; SgVariableSymbol * var_sym = isSgVariableSymbol(parent); if (var_sym != NULL) { assert(var_sym == symbol); SgInitializedName * init_name = isSgInitializedName(var_sym->get_symbol_basis()); assert(init_name != NULL); // TODO } else decl_to_add = isSgDeclarationStatement(parent->get_symbol_basis()); assert(decl_to_add != NULL); std::map<unsigned, SgSourceFile *>::iterator it_file = id_to_file_map.find(file_id); assert(it_file != id_to_file_map.end()); SgSourceFile * file = it_file->second; assert(file != NULL); SgGlobal * global_scope = file->get_globalScope(); assert(global_scope != NULL); const std::vector<SgDeclarationStatement *> & declaration_list = global_scope->getDeclarationList(); if (find(declaration_list.begin(), declaration_list.end(), decl_to_add) == declaration_list.end()) SageInterface::prependStatement(decl_to_add, global_scope); }
void instr(SgProject* project, Rose_STL_Container<SgType*> types) { SgGlobal* global = SI::getFirstGlobalScope(project); std::string prefix("rtc_ti_"); //struct prefix std::string ti_type_str("struct rtc_typeinfo*"); SgType* ti_type = SB::buildOpaqueType(ti_type_str,global); //Insert declarations from the typechecking library. //void minalloc_check(unsigned long long addr) SgFunctionDeclaration* minalloc_check_decl = SB::buildNondefiningFunctionDeclaration( SgName("minalloc_check"), SgTypeVoid::createType(), SB::buildFunctionParameterList( SB::buildInitializedName("addr",SB::buildUnsignedLongLongType())), global,NULL); SI::prependStatement(minalloc_check_decl,global); //void typetracker_add(unsigned long long addr, struct rtc_typeinfo* ti); SgFunctionDeclaration* typetracker_add_decl = SB::buildNondefiningFunctionDeclaration( SgName("typetracker_add"), SgTypeVoid::createType(), SB::buildFunctionParameterList( SB::buildInitializedName("addr",SB::buildUnsignedLongLongType()), SB::buildInitializedName("ti",ti_type)), global,NULL); SI::prependStatement(typetracker_add_decl,global); //void setBaseType(rtc_typeinfo* ti, rtc_typeinfo* base) SgFunctionDeclaration* setBaseType_decl = SB::buildNondefiningFunctionDeclaration( SgName("setBaseType"), SgTypeVoid::createType(), SB::buildFunctionParameterList( SB::buildInitializedName("ti",ti_type), SB::buildInitializedName("base",ti_type)), global,NULL); SI::prependStatement(setBaseType_decl,global); //struct rtc_typeinfo* ti_init(const char* a, size_t sz, int c) SgFunctionDeclaration* ti_init_decl = SB::buildNondefiningFunctionDeclaration( SgName("ti_init"), ti_type, SB::buildFunctionParameterList( // SB::buildInitializedName("a",SB::buildPointerType(SB::buildConstType(SB::buildCharType()))), SB::buildInitializedName("a",SB::buildPointerType(SB::buildCharType())), // SB::buildInitializedName("sz", SB::buildOpaqueType("size_t",global)), SB::buildInitializedName("sz", SB::buildLongLongType()), SB::buildInitializedName("c", SB::buildIntType())), global,NULL); SI::prependStatement(ti_init_decl,global); //void traverseAndPrint() SgFunctionDeclaration* traverseAndPrint_decl = SB::buildNondefiningFunctionDeclaration( SgName("traverseAndPrint"),SgTypeVoid::createType(),SB::buildFunctionParameterList(),global,NULL); SI::prependStatement(traverseAndPrint_decl,global); //non-defining declaration of rtc_init_typeinfo SgName init_name("rtc_init_typeinfo"); SgFunctionDeclaration* init_nondef = SB::buildNondefiningFunctionDeclaration(init_name,SgTypeVoid::createType(),SB::buildFunctionParameterList(),global,NULL); SI::prependStatement(init_nondef,global); //call to rtc_init_typeinfo placed in main function. SgFunctionDeclaration* maindecl = SI::findMain(project); SgExprStatement* initcall = SB::buildFunctionCallStmt(init_name,SgTypeVoid::createType(),NULL,maindecl->get_definition()); maindecl->get_definition()->prepend_statement(initcall); //defining declaration of rtc_init_typeinfo SgFunctionDeclaration* init_definingDecl = new SgFunctionDeclaration(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),init_name,init_nondef->get_type(),NULL); init_definingDecl->set_firstNondefiningDeclaration(init_nondef); SgFunctionDefinition* init_definition = new SgFunctionDefinition(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),init_definingDecl,SB::buildBasicBlock()); init_definingDecl->set_definition(init_definition); SI::appendStatement(init_definingDecl,global); std::vector<std::string> lst; for(unsigned int index = 0; index < types.size(); index++) { SgType* ptr = types[index]; ptr = ptr->stripTypedefsAndModifiers(); if(!shouldInstrumentType(ptr)) continue; std::string nameStr = prefix + Util::getNameForType(ptr).getString(); if(!contains(lst,nameStr)) { SgVariableDeclaration* decl = SB::buildVariableDeclaration(nameStr,ti_type,NULL,global); SI::prependStatement(decl,global); lst.push_back(nameStr); } } for(unsigned int index = 0; index < types.size(); index++) { SgType* ptr = types[index]; ptr = ptr->stripTypedefsAndModifiers(); if(!shouldInstrumentType(ptr)) continue; std::string typeNameStr = Util::getNameForType(ptr).getString(); std::string structNameStr = prefix + Util::getNameForType(ptr).getString(); if(contains(lst,structNameStr)) { SgExpression* lhs; SgExpression* rhs; //In case of an anonymous struct or union, we create a local, named version of the declaration so we can know its size. SgClassDeclaration* altDecl = NULL; if(isSgNamedType(ptr) && isSgClassDeclaration(isSgNamedType(ptr)->get_declaration()) && isSgClassDeclaration(isSgNamedType(ptr)->get_declaration())->get_isUnNamed()) { SgClassDeclaration* originalDecl = isSgClassDeclaration(isSgNamedType(ptr)->get_declaration()->get_definingDeclaration()); SgName altDecl_name(typeNameStr + "_def"); altDecl = new SgClassDeclaration(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),altDecl_name,originalDecl->get_class_type()); SgClassDefinition* altDecl_definition = SB::buildClassDefinition(altDecl); SgDeclarationStatementPtrList originalMembers = originalDecl->get_definition()->get_members(); for(SgDeclarationStatementPtrList::iterator it = originalMembers.begin(); it != originalMembers.end(); it++) { SgDeclarationStatement* member = *it; SgDeclarationStatement* membercpy = isSgDeclarationStatement(SI::copyStatement(member)); altDecl_definition->append_member(membercpy); } SgClassDeclaration* altDecl_nondef = new SgClassDeclaration(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),altDecl_name,originalDecl->get_class_type()); altDecl_nondef->set_scope(global); altDecl->set_scope(global); altDecl->set_firstNondefiningDeclaration(altDecl_nondef); altDecl_nondef->set_firstNondefiningDeclaration(altDecl_nondef); altDecl->set_definingDeclaration(altDecl); altDecl_nondef->set_definingDeclaration(altDecl); SgClassType* altDecl_ct = SgClassType::createType(altDecl_nondef); altDecl->set_type(altDecl_ct); altDecl_nondef->set_type(altDecl_ct); altDecl->set_isUnNamed(false); altDecl_nondef->set_isUnNamed(false); altDecl_nondef->set_forward(true); SgSymbol* sym = new SgClassSymbol(altDecl_nondef); global->insert_symbol(altDecl_name, sym); altDecl->set_linkage("C"); altDecl_nondef->set_linkage("C"); ROSE_ASSERT(sym && sym->get_symbol_basis() == altDecl_nondef); ROSE_ASSERT(altDecl->get_definingDeclaration() == altDecl); ROSE_ASSERT(altDecl->get_firstNondefiningDeclaration() == altDecl_nondef); ROSE_ASSERT(altDecl->search_for_symbol_from_symbol_table() == sym); ROSE_ASSERT(altDecl->get_definition() == altDecl_definition); ROSE_ASSERT(altDecl->get_scope() == global && altDecl->get_scope() == altDecl_nondef->get_scope()); ROSE_ASSERT(altDecl_ct->get_declaration() == altDecl_nondef); //For some reason, this is not working... //global->append_statement(altDecl); //global->prepend_statement(altDecl_nondef); //SI::setOneSourcePositionForTransformation(altDecl); //SI::setOneSourcePositionForTransformation(altDecl_nondef); } SgType* baseType; if(isSgPointerType(ptr)) baseType = ptr->dereference(); else baseType = ptr->findBaseType(); baseType = baseType->stripTypedefsAndModifiers(); if(baseType == NULL || baseType == ptr) { //In this case, there is no base type. rhs = SB::buildFunctionCallExp(SgName("ti_init"),SgTypeVoid::createType(),SB::buildExprListExp( SB::buildStringVal(ptr->unparseToString()), ((altDecl == NULL && !isSgTypeVoid(ptr)) ? (SgExpression*) SB::buildSizeOfOp(types[index]) : (SgExpression*) SB::buildIntVal(-1)), SB::buildIntVal(getClassification(ptr)) ),init_definition); } else { //The type has a base type. std::string baseStructNameStr = prefix + Util::getNameForType(baseType).getString(); rhs = SB::buildFunctionCallExp(SgName("ti_init"),ti_type,SB::buildExprListExp( SB::buildStringVal(ptr->unparseToString()), ((altDecl == NULL && !isSgTypeVoid(ptr)) ? (SgExpression*) SB::buildSizeOfOp(types[index]) : (SgExpression*) SB::buildIntVal(-1)), SB::buildIntVal(getClassification(ptr)) ),init_definition); SgExprStatement* set_BT = SB::buildFunctionCallStmt(SgName("setBaseType"),ti_type,SB::buildExprListExp( SB::buildVarRefExp(structNameStr), SB::buildVarRefExp(baseStructNameStr)), init_definition); init_definition->append_statement(set_BT); } lhs = SB::buildVarRefExp(structNameStr); SgExprStatement* assignstmt = SB::buildAssignStatement(lhs,rhs); init_definition->prepend_statement(assignstmt); std::remove(lst.begin(),lst.end(),structNameStr); } } }
// DQ (8/23/2011): Made this a static function so that I could call it from the Java support. void FixupAstSymbolTablesToSupportAliasedSymbols::injectSymbolsFromReferencedScopeIntoCurrentScope ( SgScopeStatement* referencedScope, SgScopeStatement* currentScope, SgNode* causalNode, SgAccessModifier::access_modifier_enum accessLevel ) { ROSE_ASSERT(referencedScope != NULL); ROSE_ASSERT(currentScope != NULL); #if ALIAS_SYMBOL_DEBUGGING || 0 printf ("In injectSymbolsFromReferencedScopeIntoCurrentScope(): referencedScope = %p = %s currentScope = %p = %s accessLevel = %d \n",referencedScope,referencedScope->class_name().c_str(),currentScope,currentScope->class_name().c_str(),accessLevel); #endif SgSymbolTable* symbolTable = referencedScope->get_symbol_table(); ROSE_ASSERT(symbolTable != NULL); #if 0 printf ("AST Fixup: Building Symbol Table for %p = %s at: \n",scope,scope->sage_class_name()); referencedScope->get_file_info()->display("Symbol Table Location"); #endif SgClassDefinition* classDefinition = isSgClassDefinition(referencedScope); if (classDefinition != NULL) { // If this is a class definition, then we need to make sure that we only for alias symbols for those declarations. #if ALIAS_SYMBOL_DEBUGGING printf ("Injection of symbols from a class definition needs to respect access priviledge (private, protected, public) declarations \n"); #endif } SgSymbolTable::BaseHashType* internalTable = symbolTable->get_table(); ROSE_ASSERT(internalTable != NULL); int counter = 0; SgSymbolTable::hash_iterator i = internalTable->begin(); while (i != internalTable->end()) { // DQ: removed SgName casting operator to char* // cout << "[" << idx << "] " << (*i).first.str(); ROSE_ASSERT ( (*i).first.str() != NULL ); ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL ); #if ALIAS_SYMBOL_DEBUGGING printf ("Symbol number: %d (pair.first (SgName) = %s) pair.second (SgSymbol) class_name() = %s \n",counter,(*i).first.str(),(*i).second->class_name().c_str()); #endif SgName name = (*i).first; SgSymbol* symbol = (*i).second; ROSE_ASSERT ( symbol != NULL ); // Make sure that this is not a SgLabelSymbol, I think these should not be aliased // (if only because I don't think that C++ support name qualification for labels). ROSE_ASSERT ( isSgLabelSymbol(symbol) == NULL ); // DQ (6/22/2011): For now skip the handling of alias symbol from other scopes. // ROSE_ASSERT(isSgAliasSymbol(symbol) == NULL); if (isSgAliasSymbol(symbol) != NULL) { #if ALIAS_SYMBOL_DEBUGGING printf ("WARNING: Not clear if we want to nest SgAliasSymbol inside of SgAliasSymbol \n"); #endif // DQ (9/22/2012): We need to avoid building chains of SgAliasSymbol (to simplify the representation in the AST). while (isSgAliasSymbol(symbol) != NULL) { #if ALIAS_SYMBOL_DEBUGGING printf (" --- Iterating to root of alias: symbol = %p = %s \n",symbol,symbol->class_name().c_str()); #endif symbol = isSgAliasSymbol(symbol)->get_alias(); ROSE_ASSERT(symbol != NULL); } #if ALIAS_SYMBOL_DEBUGGING printf ("Resolved aliased symbol to root symbol: symbol = %p = %s \n",symbol,symbol->class_name().c_str()); #endif } SgNode* symbolBasis = symbol->get_symbol_basis(); ROSE_ASSERT(symbolBasis != NULL); #if ALIAS_SYMBOL_DEBUGGING printf ("symbolBasis = %p = %s \n",symbolBasis,symbolBasis->class_name().c_str()); #endif // SgDeclarationStatement* declarationFromSymbol = symbol->get_declaration(); SgDeclarationStatement* declarationFromSymbol = isSgDeclarationStatement(symbolBasis); SgAccessModifier::access_modifier_enum declarationAccessLevel = SgAccessModifier::e_unknown; // ROSE_ASSERT(declarationFromSymbol != NULL); if (declarationFromSymbol != NULL) { // DQ (6/22/2011): Can I, or should I, do relational operations on enum values (note that the values are designed to allow this). declarationAccessLevel = declarationFromSymbol->get_declarationModifier().get_accessModifier().get_modifier(); } else { SgInitializedName* initializedNameFromSymbol = isSgInitializedName(symbolBasis); ROSE_ASSERT(initializedNameFromSymbol != NULL); // DQ (9/8/2014): This fails for test2013_234, 235, 240, 241, 242, 246.C. // ROSE_ASSERT(initializedNameFromSymbol->get_declptr() != NULL); // declarationAccessLevel = initializedNameFromSymbol->get_declptr()->get_declarationModifier().get_accessModifier().get_modifier(); if (initializedNameFromSymbol->get_declptr() != NULL) { declarationAccessLevel = initializedNameFromSymbol->get_declptr()->get_declarationModifier().get_accessModifier().get_modifier(); } else { mprintf ("WARNING: In injectSymbolsFromReferencedScopeIntoCurrentScope(): initializedNameFromSymbol->get_declptr() == NULL: initializedNameFromSymbol->get_name() = %s \n",initializedNameFromSymbol->get_name().str()); } } #if ALIAS_SYMBOL_DEBUGGING || 0 printf ("declarationAccessLevel = %d accessLevel = %d \n",declarationAccessLevel,accessLevel); #endif #if 0 // DQ (12/23/2015): Is this only supporting the SgBaseClass IR nodes? No, another example is the case of a SgUsingDirectiveStatement. ROSE_ASSERT(causalNode != NULL); if (isSgBaseClass(causalNode) == NULL) { printf ("ERROR: This is not a SgBaseClass: causalNode = %p = %s \n",causalNode,causalNode->class_name().c_str()); ROSE_ASSERT(false); } #endif // DQ (12/23/2015): See test2015_140.C for where even private base classes will require representations // of it's symbols in the derived class (to support correct name qualification). // if (declarationAccessLevel >= accessLevel) if ( (declarationAccessLevel >= accessLevel) || isSgBaseClass(causalNode) != NULL) { // This declaration is visible, so build an alias. // DQ (7/24/2011): Need to make sure that the symbol is not already present in the symbol table // (else injection would be redundant. This is a likely key to the problem we are having with // symbol table explosions for some codes. This should be refactored to a member function of // the symbol table support. // Note that this change improves the performance from 15 minutes to 5 seconds for the outlining example. bool alreadyExists = currentScope->symbol_exists(name); if (alreadyExists == true) { // Just because the names match is not strong enough. // SgSymbol* symbol currentScope->symbol_exists(name); switch (symbol->variantT()) { case V_SgAliasSymbol: { // not clear what to do here... // I think we need more symbol table support for detecting matching symbols. // I think we also need more alias symbol specific query support. break; } // DQ (11/10/2014): Added support for templated typedef symbols. case V_SgTemplateTypedefSymbol: case V_SgEnumSymbol: case V_SgVariableSymbol: case V_SgTemplateClassSymbol: case V_SgClassSymbol: case V_SgTemplateFunctionSymbol: case V_SgTemplateMemberFunctionSymbol: case V_SgFunctionSymbol: case V_SgMemberFunctionSymbol: case V_SgTypedefSymbol: case V_SgEnumFieldSymbol: case V_SgNamespaceSymbol: case V_SgTemplateSymbol: case V_SgLabelSymbol: { // Liao, 10/31/2012. // Using lookup_function_symbol () etc. is not good enough since it returns the first match only. // There might be multiple hits. We have to go through them all instead of checking only the first hit alreadyExists = false; // reset to be false // using less expensive equal_range(), which can be O(logN) instead of O(N) // This matters since this function is called inside another loop with complexity of O(N) already. rose_hash_multimap * internal_table = currentScope->get_symbol_table()->get_table(); ROSE_ASSERT (internal_table != NULL); std::pair<rose_hash_multimap::iterator, rose_hash_multimap::iterator> range = internal_table ->equal_range (name); for (rose_hash_multimap::iterator i = range.first; i != range.second; ++i) { SgSymbol * orig_current_symbol = i->second; ROSE_ASSERT (orig_current_symbol != NULL); // strip off alias symbols SgSymbol * non_alias_symbol = orig_current_symbol; while (isSgAliasSymbol(non_alias_symbol)) { non_alias_symbol = isSgAliasSymbol(non_alias_symbol) ->get_alias(); ROSE_ASSERT (non_alias_symbol != NULL); } SgNode* associatedDeclaration = i->second->get_symbol_basis(); assert(associatedDeclaration != NULL); // same basis and same symbol type // The assumption is that no two symbols can share the same basis declaration TODO double check this! if (associatedDeclaration == symbolBasis && (non_alias_symbol->variantT() == symbol->variantT())) { alreadyExists = true; break; } } // end for break; } #if 0 // uniform handling by code above now case V_SgEnumSymbol: { // alreadyExists = (currentScope->lookup_enum_symbol(name) != NULL); SgEnumSymbol* tmpSymbol = currentScope->lookup_enum_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } case V_SgVariableSymbol: { // alreadyExists = (currentScope->lookup_variable_symbol(name) != NULL); SgVariableSymbol* tmpSymbol = currentScope->lookup_variable_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } // DQ (2/12/2012): Not clear if this is the best way to add this support. case V_SgTemplateClassSymbol: case V_SgClassSymbol: { // alreadyExists = (currentScope->lookup_class_symbol(name) != NULL); SgClassSymbol* tmpSymbol = currentScope->lookup_class_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } #if 0 // DQ (2/12/2012): Added support for SgTemplateFunctionSymbol. case V_SgTemplateFunctionSymbol: { SgTemplateFunctionSymbol* tmpSymbol = currentScope->lookup_template_function_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } // DQ (2/12/2012): Added support for SgTemplateMemberFunctionSymbol. case V_SgTemplateMemberFunctionSymbol: { SgTemplateMemberFunctionSymbol* tmpSymbol = currentScope->lookup_template_member_function_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } #else // DQ (2/12/2012): Not clear if this is the best way to add this support. case V_SgTemplateFunctionSymbol: case V_SgTemplateMemberFunctionSymbol: #endif case V_SgFunctionSymbol: case V_SgMemberFunctionSymbol: { // alreadyExists = (currentScope->lookup_function_symbol(name) != NULL); SgFunctionSymbol* tmpSymbol = currentScope->lookup_function_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } case V_SgTypedefSymbol: { // alreadyExists = (currentScope->lookup_typedef_symbol(name) != NULL); SgTypedefSymbol* tmpSymbol = currentScope->lookup_typedef_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } case V_SgEnumFieldSymbol: { // alreadyExists = (currentScope->lookup_enum_field_symbol(name) != NULL); SgEnumFieldSymbol* tmpSymbol = currentScope->lookup_enum_field_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } case V_SgNamespaceSymbol: { // alreadyExists = (currentScope->lookup_namespace_symbol(name) != NULL); SgNamespaceSymbol* tmpSymbol = currentScope->lookup_namespace_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } case V_SgTemplateSymbol: { // alreadyExists = (currentScope->lookup_template_symbol(name) != NULL); SgTemplateSymbol* tmpSymbol = currentScope->lookup_template_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } case V_SgLabelSymbol: { // alreadyExists = (currentScope->lookup_label_symbol(name) != NULL); SgLabelSymbol* tmpSymbol = currentScope->lookup_label_symbol(name); if (tmpSymbol != NULL) { SgNode* tmpSymbolBasis = tmpSymbol->get_symbol_basis(); ROSE_ASSERT(tmpSymbolBasis != NULL); alreadyExists = (tmpSymbolBasis == symbolBasis); } break; } #endif default: printf ("Error: default reached in switch symbol = %p = %s \n",symbol,symbol->class_name().c_str()); ROSE_ASSERT(false); break; } } if ( alreadyExists == false) { #if 0 printf ("Building a SgAliasSymbol \n"); #endif // DQ: The parameter to a SgAliasSymbol is a SgSymbol (but should not be another SgAliasSymbol). SgAliasSymbol* aliasSymbol = new SgAliasSymbol(symbol); ROSE_ASSERT(aliasSymbol != NULL); // DQ (7/12/2014): Added support to trace back the SgAliasSymbol to the declarations that caused it to be added. ROSE_ASSERT(causalNode != NULL); aliasSymbol->get_causal_nodes().push_back(causalNode); #if ALIAS_SYMBOL_DEBUGGING // printf ("In injectSymbolsFromReferencedScopeIntoCurrentScope(): Adding symbol to new scope as a SgAliasSymbol = %p causalNode = %p = %s \n",aliasSymbol,causalNode,causalNode->class_name().c_str()); printf ("In injectSymbolsFromReferencedScopeIntoCurrentScope(): Adding symbol to new scope (currentScope = %p = %s) as a SgAliasSymbol = %p causalNode = %p = %s \n",currentScope,currentScope->class_name().c_str(),aliasSymbol,causalNode,causalNode->class_name().c_str()); #endif // Use the current name and the alias to the symbol currentScope->insert_symbol(name, aliasSymbol); #if ALIAS_SYMBOL_DEBUGGING printf ("In injectSymbolsFromReferencedScopeIntoCurrentScope(): DONE: Adding symbol to new scope (currentScope = %p = %s) as a SgAliasSymbol = %p causalNode = %p = %s \n",currentScope,currentScope->class_name().c_str(),aliasSymbol,causalNode,causalNode->class_name().c_str()); #endif } } else { #if ALIAS_SYMBOL_DEBUGGING printf ("NO SgAliasSymbol ADDED (wrong permissions): declarationFromSymbol = %p \n",declarationFromSymbol); #endif } #if 0 // Older version of code... // SgAliasSymbol* aliasSymbol = new SgAliasSymbol (SgSymbol *alias=NULL, bool isRenamed=false, SgName new_name="") SgAliasSymbol* aliasSymbol = new SgAliasSymbol (symbol); // Use the current name and the alias to the symbol currentScope->insert_symbol(name, aliasSymbol); #endif // Increment iterator and counter i++; counter++; } #if 0 // debugging symbolTable->print("In injectSymbolsFromReferencedScopeIntoCurrentScope(): printing out the symbol tables"); #endif #if ALIAS_SYMBOL_DEBUGGING printf ("In injectSymbolsFromReferencedScopeIntoCurrentScope(): referencedScope = %p = %s currentScope = %p = %s accessLevel = %d \n",referencedScope,referencedScope->class_name().c_str(),currentScope,currentScope->class_name().c_str(),accessLevel); #endif }