// SgScopeStatement* SgNode* SourceLocationInheritedAttribute::getParentScope() const { SgScopeStatement* scope = NULL; int numberOfScopes = scopeList.size(); // ROSE_ASSERT (numberOfScopes > 0); // printf ("In SourceLocationInheritedAttribute::getParentScope(): numberOfScopes = %d \n",numberOfScopes); if (numberOfScopes > 1) { scope = scopeList[numberOfScopes-2]; // We don't want to return a for loop statement as a parent scope statement since insert_statement // is not well defined for such scope statements. // if (scope->variantT() == V_SgForStatement) int i = 1; while (scope->variantT() == V_SgForStatement) { ROSE_ASSERT (numberOfScopes-(2+i) >= 0); scope = scopeList[numberOfScopes-(2+i)]; i++; } } else { scope = isSgGlobal( getGlobalScope() ); } printf ("In SourceLocationInheritedAttribute::getParentScope(): parent scope is %s \n",scope->sage_class_name()); ROSE_ASSERT (scope->variantT() != V_SgForStatement); ROSE_ASSERT (scope != NULL); return scope; }
/* * The function * findScope() * takes as a parameter a SgNode* which is a SgStatement*. It returns a SgNodePtrVector of all * preceding scopes the SgStatement is in. * */ SgNodePtrVector findScopes (SgNode * astNode) { ROSE_ASSERT (isSgStatement (astNode)); SgNodePtrVector returnVector; SgScopeStatement *currentScope; if (isSgScopeStatement (astNode)) { currentScope = isSgScopeStatement (astNode); ROSE_ASSERT (currentScope != NULL); returnVector.push_back (astNode); } else { SgStatement *sageStatement = isSgStatement (astNode); ROSE_ASSERT (sageStatement != NULL); currentScope = sageStatement->get_scope (); ROSE_ASSERT (currentScope != NULL); returnVector.push_back (currentScope); } while (currentScope->variantT () != V_SgGlobal) { currentScope = currentScope->get_scope (); ROSE_ASSERT (currentScope != NULL); returnVector.push_back (currentScope); } //Must also include the Global Scopes of the other files in the project if (currentScope->variantT () == V_SgGlobal) { SgFile *sageFile = isSgFile ((currentScope)->get_parent ()); ROSE_ASSERT (sageFile != NULL); SgProject *sageProject = isSgProject (sageFile->get_parent ()); ROSE_ASSERT (sageProject != NULL); //Get a list of all files in the current project const SgFilePtrList& sageFilePtrList = sageProject->get_fileList (); //Iterate over the list of files to find all Global Scopes SgNodePtrVector globalScopes; for (unsigned int i = 0; i < sageFilePtrList.size (); i += 1) { const SgSourceFile *sageFile = isSgSourceFile (sageFilePtrList[i]); ROSE_ASSERT (sageFile != NULL); SgGlobal *sageGlobal = sageFile->get_globalScope(); ROSE_ASSERT (sageGlobal != NULL); returnVector.push_back (sageGlobal); } } return returnVector; };
void FunctionCallNormalization::visit( SgNode *astNode ) { SgStatement *stm = isSgStatement( astNode ); // visiting all statements which may contain function calls; // Note 1: we do not look at the body of loops, or sequences of statements, but only // at statements which may contain directly function calls; all other statements will have their component parts visited in turn if ( isSgEnumDeclaration( astNode ) || isSgVariableDeclaration( astNode ) || isSgVariableDefinition( astNode ) || isSgExprStatement( astNode ) || isSgForStatement( astNode ) || isSgReturnStmt( astNode ) || isSgSwitchStatement( astNode ) ) { // maintain the mappings from function calls to expressions (variables or dereferenced variables) map<SgFunctionCallExp *, SgExpression *> fct2Var; // list of Declaration structures, one structure per function call DeclarationPtrList declarations; bool variablesDefined = false; // list of function calls, in correnspondence with the inForTest list below list<SgNode*> functionCallExpList; list<bool> inForTest; SgForStatement *forStm = isSgForStatement( stm ); SgSwitchStatement *swStm = isSgSwitchStatement( stm ); list<SgNode*> temp1, temp2; // for-loops and Switch statements have conditions ( and increment ) expressed as expressions // and not as standalone statements; this will change in future Sage versions // TODO: when for-loops and switch statements have conditions expressed via SgStatements // these cases won't be treated separately; however, do-while will have condition expressed via expression // so that will be the only exceptional case to be treated separately if (forStm != NULL) { // create a list of function calls in the condition and increment expression // the order is important, the condition is evaluated after the increment expression // temp1 = FEOQueryForNodes( forStm->get_increment_expr_root(), V_SgFunctionCallExp ); // temp2 = FEOQueryForNodes( forStm->get_test_expr_root(), V_SgFunctionCallExp ); temp1 = FEOQueryForNodes( forStm->get_increment(), V_SgFunctionCallExp ); temp2 = FEOQueryForNodes( forStm->get_test_expr(), V_SgFunctionCallExp ); functionCallExpList = temp1; functionCallExpList.splice( functionCallExpList.end(), temp2 ); } else { if (swStm != NULL) { // create a list of function calls in the condition in the order of function evaluation // DQ (11/23/2005): Fixed SgSwitchStmt to have SgStatement for conditional. // list<SgNode*> temp1 = FEOQueryForNodes( swStm->get_item_selector_root(), V_SgFunctionCallExp ); list<SgNode*> temp1 = FEOQueryForNodes( swStm->get_item_selector(), V_SgFunctionCallExp ); functionCallExpList = temp1; } else { // create a list of function calls in the statement in the order of function evaluation functionCallExpList = FEOQueryForNodes( stm, V_SgFunctionCallExp ); } } // all function calls get replaced: this is because they can occur in expressions (e.g. for-loops) // which makes it difficult to build control flow graphs if ( functionCallExpList.size() > 0 ) { cout << "--------------------------------------\nStatement "; cout << stm->unparseToString() << "\n";; // traverse the list of function calls in the current statement, generate a structure Declaration for each call // put these structures in a list to be inserted in the code later for ( list<SgNode *>::iterator i = functionCallExpList.begin(); i != functionCallExpList.end(); i++ ) { variablesDefined = true; // get function call exp SgFunctionCallExp *exp = isSgFunctionCallExp( *i ); ROSE_ASSERT ( exp ); // get type of expression, generate unique variable name SgType *expType = exp->get_type(); ROSE_ASSERT ( expType ); Sg_File_Info *location = Sg_File_Info::generateDefaultFileInfoForTransformationNode(); ROSE_ASSERT ( location ); ostringstream os; os << "__tempVar__" << location; SgName name = os.str().c_str(); // replace previous variable bindings in the AST SgExprListExp *paramsList = exp->get_args(); SgExpression *function = exp->get_function(); ROSE_ASSERT ( paramsList && function ); replaceFunctionCallsInExpression( paramsList, fct2Var ); replaceFunctionCallsInExpression( function, fct2Var ); // duplicate function call expression, for the initialization declaration and the assignment SgTreeCopy treeCopy; SgFunctionCallExp *newExpInit = isSgFunctionCallExp( exp->copy( treeCopy ) ); ROSE_ASSERT ( newExpInit ); SgFunctionCallExp *newExpAssign = isSgFunctionCallExp( exp->copy( treeCopy ) ); ROSE_ASSERT ( newExpAssign ); // variables Sg_File_Info *initLoc = Sg_File_Info::generateDefaultFileInfoForTransformationNode(), *nonInitLoc = Sg_File_Info::generateDefaultFileInfoForTransformationNode(), *assignLoc = Sg_File_Info::generateDefaultFileInfoForTransformationNode(); Declaration *newDecl = new Declaration(); SgStatement *nonInitVarDeclaration, *initVarDeclaration, *assignStmt; SgExpression *varRefExp; SgVariableSymbol *varSymbol; SgAssignOp *assignOp; SgInitializedName *initName; bool pointerTypeNeeded = false; // mark whether to replace inside or outside of ForStatement due to the // function call being inside the test or the increment for a for-loop statement // the 'inForTest' list is in 1:1 ordered correpondence with the 'declarations' list if ( forStm ) { // SgExpressionRoot // *testExp = isSgForStatement( astNode )->get_test_expr_root(), // *incrExp = isSgForStatement( astNode )->get_increment_expr_root(); SgExpression *testExp = isSgForStatement( astNode )->get_test_expr(), *incrExp = isSgForStatement( astNode )->get_increment(); SgNode *up = exp; while ( up && up != testExp && up != incrExp ) up = up->get_parent(); ROSE_ASSERT ( up ); // function call is in the condition of the for-loop if ( up == testExp ) inForTest.push_back( true ); // function call is in the increment expression else { inForTest.push_back( false ); // for increment expressions we need to be able to reassign the return value // of the function; if the ret value is a reference, we need to generate a // pointer of that type (to be able to reassign it later) if ( isSgReferenceType( expType ) ) pointerTypeNeeded = true; } } // for do-while statements: we need to generate declaration of type pointer to be able to have // non-assigned references when looping and assign them at the end of the body of the loop if ( isSgDoWhileStmt( stm->get_parent() ) && isSgReferenceType( expType ) ) pointerTypeNeeded = true; // we have a function call returning a reference and we can't initialize the variable // at the point of declaration; we need to define the variable as a pointer if ( pointerTypeNeeded ) { // create 'address of' term for function expression, so we can assign it to the pointer SgAddressOfOp *addressOp = new SgAddressOfOp( assignLoc, newExpAssign, expType ); // create noninitialized declaration SgType *base = isSgReferenceType( expType )->get_base_type(); ROSE_ASSERT( base ); SgPointerType *ptrType = SgPointerType::createType( isSgReferenceType( expType )->get_base_type() ); ROSE_ASSERT ( ptrType ); nonInitVarDeclaration = new SgVariableDeclaration ( nonInitLoc, name, ptrType ); // create assignment (symbol, varRefExp, assignment) initName = isSgVariableDeclaration( nonInitVarDeclaration )->get_decl_item( name ); ROSE_ASSERT ( initName ); varSymbol = new SgVariableSymbol( initName ); ROSE_ASSERT ( varSymbol ); varRefExp = new SgVarRefExp( assignLoc, varSymbol ); SgPointerDerefExp *ptrDeref= new SgPointerDerefExp( assignLoc, varRefExp, expType ); ROSE_ASSERT ( isSgExpression( varRefExp ) && ptrDeref ); assignOp = new SgAssignOp( assignLoc, varRefExp, addressOp, ptrType ); assignStmt = new SgExprStatement( assignLoc, assignOp ); ROSE_ASSERT ( assignStmt && nonInitVarDeclaration ); // we don't need initialized declarations in this case initVarDeclaration = NULL; // save new mapping fct2Var.insert( Fct2Var( exp, ptrDeref ) ); } else { // create (non- &)initialized declarations, initialized name & symbol SgAssignInitializer *declInit = new SgAssignInitializer( initLoc, newExpInit, expType ); ROSE_ASSERT ( declInit ); initVarDeclaration = new SgVariableDeclaration ( initLoc, name, expType, declInit ); nonInitVarDeclaration = new SgVariableDeclaration ( nonInitLoc, name, expType ); ROSE_ASSERT ( initVarDeclaration && nonInitVarDeclaration ); initName = isSgVariableDeclaration( nonInitVarDeclaration )->get_decl_item( name ); ROSE_ASSERT ( initName ); newExpInit->set_parent( initName ); varSymbol = new SgVariableSymbol( initName ); ROSE_ASSERT ( varSymbol ); // create variable ref exp varRefExp = new SgVarRefExp( assignLoc, varSymbol ); ROSE_ASSERT ( isSgVarRefExp( varRefExp ) ); // create the assignment assignOp = new SgAssignOp( assignLoc, varRefExp, newExpAssign, expType ); assignStmt = new SgExprStatement( assignLoc, assignOp ); ROSE_ASSERT ( assignStmt ); initVarDeclaration->set_parent( stm->get_parent() ); isSgVariableDeclaration( initVarDeclaration )->set_definingDeclaration( isSgDeclarationStatement( initVarDeclaration ) ); // save new mapping fct2Var.insert( Fct2Var( exp, varRefExp ) ); } // save the 'declaration' structure, with all 3 statements and the variable name newDecl->nonInitVarDeclaration = nonInitVarDeclaration; newDecl->initVarDeclaration = initVarDeclaration; newDecl->assignment = assignStmt; newDecl->name = name; nonInitVarDeclaration->set_parent( stm->get_parent() ); isSgVariableDeclaration( nonInitVarDeclaration )->set_definingDeclaration( isSgVariableDeclaration( nonInitVarDeclaration ) ); assignStmt->set_parent( stm->get_parent() ); declarations.push_back( newDecl ); } // end for } // end if fct calls in crt stmt > 1 SgScopeStatement *scope = stm->get_scope(); ROSE_ASSERT ( scope ); // insert function bindings to variables; each 'declaration' structure in the list // corresponds to one function call for ( DeclarationPtrList::iterator i = declarations.begin(); i != declarations.end(); i++ ) { Declaration *d = *i; ROSE_ASSERT ( d && d->assignment && d->nonInitVarDeclaration ); // if the current statement is a for-loop, we insert Declarations before & in the loop body, depending on the case if ( forStm ) { SgStatement *parentScope = isSgStatement( stm->get_scope() ); SgBasicBlock *body = SageInterface::ensureBasicBlockAsBodyOfFor(forStm); ROSE_ASSERT ( !inForTest.empty() && body && parentScope ); // SgStatementPtrList &list = body->get_statements(); // if function call is in loop condition, we add initialized variable before the loop and at its end // hoist initialized variable declarations outside the loop if ( inForTest.front() ) { ROSE_ASSERT ( d->initVarDeclaration ); parentScope->insert_statement( stm, d->initVarDeclaration ); // set the scope of the initializedName SgInitializedName *initName = isSgVariableDeclaration( d->initVarDeclaration )->get_decl_item( d->name ); ROSE_ASSERT ( initName ); initName->set_scope( isSgScopeStatement( parentScope ) ); ROSE_ASSERT ( initName->get_scope() ); } // function call is in loop post increment so add noninitialized variable decls above the loop else { parentScope->insert_statement( stm, d->nonInitVarDeclaration ); // set the scope of the initializedName SgInitializedName *initName = isSgVariableDeclaration( d->nonInitVarDeclaration )->get_decl_item( d->name ); ROSE_ASSERT ( initName ); initName->set_scope( isSgScopeStatement( parentScope ) ); ROSE_ASSERT ( initName->get_scope() ); } // in a for-loop, always insert assignments at the end of the loop body->get_statements().push_back( d->assignment ); d->assignment->set_parent( body ); // remove marker inForTest.pop_front(); } else { // look at the type of the enclosing scope switch ( scope->variantT() ) { // while stmts have to repeat the function calls at the end of the loop; // note there is no "break" statement, since we want to also add initialized // declarations before the while-loop case V_SgWhileStmt: { // assignments need to be inserted at the end of each while loop SgBasicBlock *body = SageInterface::ensureBasicBlockAsBodyOfWhile(isSgWhileStmt( scope ) ); ROSE_ASSERT ( body ); d->assignment->set_parent( body ); body->get_statements().push_back( d->assignment ); } // SgForInitStatement has scope SgForStatement, move declarations before the for loop; // same thing if the enclosing scope is an If, or Switch statement case V_SgForStatement: case V_SgIfStmt: case V_SgSwitchStatement: { // adding bindings (initialized variable declarations only, not assignments) // outside the statement, in the parent scope SgStatement *parentScope = isSgStatement( scope->get_parent() ); ROSE_ASSERT ( parentScope ); parentScope->insert_statement( scope, d->initVarDeclaration, true );\ // setting the scope of the initializedName SgInitializedName *initName = isSgVariableDeclaration( d->initVarDeclaration )->get_decl_item( d->name ); ROSE_ASSERT ( initName ); initName->set_scope( scope->get_scope() ); ROSE_ASSERT ( initName->get_scope() ); } break; // do-while needs noninitialized declarations before the loop, with assignments inside the loop case V_SgDoWhileStmt: { // adding noninitialized variable declarations before the body of the loop SgStatement *parentScope = isSgStatement( scope->get_parent() ); ROSE_ASSERT ( parentScope ); parentScope->insert_statement( scope, d->nonInitVarDeclaration, true ); // initialized name scope setting SgInitializedName *initName = isSgVariableDeclaration( d->nonInitVarDeclaration )->get_decl_item( d->name ); ROSE_ASSERT ( initName ); initName->set_scope( scope->get_scope() ); ROSE_ASSERT ( initName->get_scope() ); // adding assignemts at the end of the do-while loop SgBasicBlock *body = SageInterface::ensureBasicBlockAsBodyOfDoWhile( isSgDoWhileStmt(scope) ); ROSE_ASSERT ( body ); body->get_statements().push_back( d->assignment ); d->assignment->set_parent(body); } break; // for all other scopes, add bindings ( initialized declarations ) before the statement, in the same scope default: scope->insert_statement( stm, d->initVarDeclaration, true ); // initialized name scope setting SgInitializedName *initName = isSgVariableDeclaration( d->initVarDeclaration )->get_decl_item( d->name ); ROSE_ASSERT ( initName ); initName->set_scope( scope->get_scope() ); ROSE_ASSERT ( initName->get_scope() ); } } } // once we have inserted all variable declarations, we need to replace top-level calls in the original statement if ( variablesDefined ) { cout << "\tReplacing in the expression " << stm->unparseToString() << "\n"; // for ForStatements, replace expressions in condition and increment expressions, // not in the body, since those get replace later if ( forStm ) { // SgExpressionRoot *testExp = forStm->get_test_expr_root(), *incrExp = forStm->get_increment_expr_root(); SgExpression *testExp = forStm->get_test_expr(), *incrExp = forStm->get_increment(); replaceFunctionCallsInExpression( incrExp, fct2Var ); replaceFunctionCallsInExpression( testExp, fct2Var ); } else if ( swStm ) { // DQ (11/23/2005): Fixed SgSwitch to permit use of declaration for conditional // replaceFunctionCallsInExpression( swStm->get_item_selector_root(), fct2Var ); replaceFunctionCallsInExpression( swStm->get_item_selector(), fct2Var ); } else replaceFunctionCallsInExpression( stm, fct2Var ); } } // end if isSgStatement block }
bool FixupTemplateArguments::contains_private_type (SgType* type, SgScopeStatement* targetScope) { // DQ (4/2/2018): Note that this function now addresses requirements of supporting both private and protected types. #if DEBUGGING_USING_RECURSIVE_DEPTH // For debugging, keep track of the recursive depth. static size_t depth = 0; printf ("In contains_private_type(SgType*): depth = %zu \n",depth); ROSE_ASSERT(depth < 500); printf ("In contains_private_type(SgType*): global_depth = %zu \n",global_depth); ROSE_ASSERT(global_depth < 55); #endif // Note this is the recursive function. bool returnValue = false; #if DEBUG_PRIVATE_TYPE || 0 // DQ (1/7/2016): It is a problem to do this for some files (failing about 35 files in Cxx_tests). // The issues appears to be in the unparsing of the template arguments of the qualified names for the types. // printf ("In contains_private_type(SgType*): type = %p = %s = %s \n",type,type->class_name().c_str(),type->unparseToString().c_str()); printf ("In contains_private_type(SgType*): type = %p = %s \n",type,type->class_name().c_str()); #endif SgTypedefType* typedefType = isSgTypedefType(type); if (typedefType != NULL) { // Get the associated declaration. SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(typedefType->get_declaration()); ROSE_ASSERT(typedefDeclaration != NULL); #if 0 bool isPrivate = typedefDeclaration->get_declarationModifier().get_accessModifier().isPrivate(); #else // DQ (4/2/2018): Fix this to address requirements of both private and protected class members (see Cxx11_tests/test2018_71.C). bool isPrivate = typedefDeclaration->get_declarationModifier().get_accessModifier().isPrivate() || typedefDeclaration->get_declarationModifier().get_accessModifier().isProtected(); #endif #if DEBUG_PRIVATE_TYPE || 0 printf ("typedefDeclaration isPrivate = %s \n",isPrivate ? "true" : "false"); #endif // First we need to know if this is a visable type. bool isVisable = false; #if 0 printf ("targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str()); // printf ("typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->class_name().c_str()); printf ("typedefDeclaration->get_scope() = %p = %s \n",typedefDeclaration->get_scope(),typedefDeclaration->get_scope()->class_name().c_str()); #endif #if 0 printf ("SageInterface::whereAmI(targetScope): \n"); SageInterface::whereAmI(targetScope); printf ("SageInterface::whereAmI(typedefDeclaration): \n"); SageInterface::whereAmI(typedefDeclaration); #endif #if 0 printf ("\ntargetScope symbol table: \n"); targetScope->get_symbol_table()->print("targetScope"); printf ("end of symbol table \n"); printf ("\ntypedefDeclaration->get_scope() symbol table: \n"); typedefDeclaration->get_scope()->get_symbol_table()->print("typedefDeclaration->get_scope()"); printf ("end of symbol table \n\n"); #endif // Test for the trivial case of matching scope (an even better test (below) is be to make sure that the targetScope is nested in the typedef scope). if (typedefDeclaration->get_scope() == targetScope) { #if 0 printf ("In contains_private_type(SgType*): This is a typedef type from the same scope as the target declaration \n"); #endif // ROSE_ASSERT(false); // return false; isVisable = true; } else { // SgTypedefSymbol* lookupTypedefSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL); SgTypedefSymbol* typedefSymbol = SageInterface::lookupTypedefSymbolInParentScopes (typedefDeclaration->get_name(),targetScope); if (typedefSymbol != NULL) { #if 0 printf ("In contains_private_type(SgType*): This is not in the current scope but can be reached from the current scope \n"); #endif // ROSE_ASSERT(false); // return false; isVisable = true; } else { #if 0 printf ("Symbol for typedef name = %s not found in parent scopes \n",typedefDeclaration->get_name().str()); #endif // ROSE_ASSERT(false); } } #if 0 // Testing codes because it seems that "BitSet" shuld be visiable and so we need to debug this first. if (typedefDeclaration->get_name() == "BitSet") { printf ("Exiting as a test! \n"); ROSE_ASSERT(false); } #endif // If this is not private, then we are looking at what would be possbile template arguments used in a possible name qualification. // if (isPrivate == false) // if (isPrivate == false && isVisable == false) if (isVisable == false) { if (isPrivate == true) { return true; } else { // Get the scope and see if it is a template instantiation. SgScopeStatement* scope = typedefDeclaration->get_scope(); #if DEBUG_PRIVATE_TYPE || 0 printf ("++++++++++++++ Looking in parent scope for template arguments: scope = %p = %s \n",scope,scope->class_name().c_str()); #endif // Get the associated declaration. switch (scope->variantT()) { case V_SgTemplateInstantiationDefn: { SgTemplateInstantiationDefn* templateInstantiationDefinition = isSgTemplateInstantiationDefn(scope); ROSE_ASSERT(templateInstantiationDefinition != NULL); SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(templateInstantiationDefinition->get_declaration()); ROSE_ASSERT(templateInstantiationDeclaration != NULL); SgTemplateArgumentPtrList & templateArgumentPtrList = templateInstantiationDeclaration->get_templateArguments(); for (SgTemplateArgumentPtrList::iterator i = templateArgumentPtrList.begin(); i != templateArgumentPtrList.end(); i++) { #if DEBUG_PRIVATE_TYPE printf ("recursive call to contains_private_type(%p): name = %s = %s \n",*i,(*i)->class_name().c_str(),(*i)->unparseToString().c_str()); #endif #if DEBUGGING_USING_RECURSIVE_DEPTH global_depth++; #endif bool isPrivateType = contains_private_type(*i,targetScope); #if DEBUGGING_USING_RECURSIVE_DEPTH global_depth--; #endif returnValue |= isPrivateType; } break; } default: { #if DEBUG_PRIVATE_TYPE printf ("Ignoring non-SgTemplateInstantiationDefn \n"); #endif } } } } else { // If it is visible then it need not be qualified and we don't care about if it was private. ROSE_ASSERT(isVisable == true); // returnValue = true; returnValue = false; } } else { #if DEBUG_PRIVATE_TYPE || 0 printf ("could be a wrapped type: type = %p = %s (not a template class instantiaton) \n",type,type->class_name().c_str()); if (isSgModifierType(type) != NULL) { SgModifierType* modifierType = isSgModifierType(type); SgType* base_type = modifierType->get_base_type(); printf ("--- base_type = %p = %s \n",base_type,base_type->class_name().c_str()); SgNamedType* namedType = isSgNamedType(base_type); if (namedType != NULL) { printf ("--- base_type: name = %s \n",namedType->get_name().str()); } } #endif // If this is a default SgModifierType then unwrap it. #if 0 SgModifierType* modifierType = isSgModifierType(type); if (modifierType != NULL) { #error "DEAD CODE!" // What kind of modifier is this? printf ("What kind of type modifier: %s \n",modifierType->get_typeModifier().displayString().c_str()); if (modifierType->get_typeModifier().isDefault() == true) { // This is a default mode modifier (acting as a wrapper type). type = modifierType->get_base_type(); } else { printf ("Not a default modifierType wrapper (need to handle this case) \n"); ROSE_ASSERT(false); } } #else // Strip past pointers and other wrapping modifiers (but not the typedef types, since the whole point is to detect private instatances). type = type->stripType(SgType::STRIP_MODIFIER_TYPE|SgType::STRIP_REFERENCE_TYPE|SgType::STRIP_RVALUE_REFERENCE_TYPE|SgType::STRIP_POINTER_TYPE|SgType::STRIP_ARRAY_TYPE); #endif #if 0 printf ("After stripType(): type = %p = %s \n",type,type->class_name().c_str()); SgNamedType* namedType = isSgNamedType(type); if (namedType != NULL) { printf ("--- stripType: name = %s \n",namedType->get_name().str()); } #endif ROSE_ASSERT(type != NULL); // Make sure this is not a simple template type (else we will have infinite recursion). // if (type != NULL && type->isIntegerType() == false && type->isFloatType() == false) // if (type != NULL) SgTemplateType* templateType = isSgTemplateType(type); SgClassType* classType = isSgClassType(type); SgTypeVoid* voidType = isSgTypeVoid(type); SgRvalueReferenceType* rvalueReferenceType = isSgRvalueReferenceType(type); SgFunctionType* functionType = isSgFunctionType(type); SgDeclType* declType = isSgDeclType(type); // DQ (12/7/2016): An enum type needs to be handled since the declaration might be private (but still debugging this for now). SgEnumType* enumType = isSgEnumType(type); // DQ (2/12/2017): Added specific type (causing infinite recursion for CompileTests/RoseExample_tests/testRoseHeaders_03.C. SgTypeEllipse* typeEllipse = isSgTypeEllipse(type); SgTypeUnknown* typeUnknown = isSgTypeUnknown(type); SgTypeComplex* typeComplex = isSgTypeComplex(type); // DQ (2/16/2017): This is a case causeing many C codes to fail. SgTypeOfType* typeOfType = isSgTypeOfType(type); if (type != NULL && templateType == NULL && classType == NULL && voidType == NULL && rvalueReferenceType == NULL && functionType == NULL && declType == NULL && enumType == NULL && typeEllipse == NULL && typeUnknown == NULL && typeComplex == NULL && typeOfType == NULL) { #if DEBUG_PRIVATE_TYPE || 0 printf ("found unwrapped type = %p = %s = %s (not a template class instantiaton) \n",type,type->class_name().c_str(),type->unparseToString().c_str()); #endif // if (type->isIntegerType() == false && type->isFloatType() == false) // if (type->isIntegerType() == false && type->isFloatType() == false) if (type->isIntegerType() == false && type->isFloatType() == false) { #if DEBUG_PRIVATE_TYPE || 0 printf ("Making a recursive call to contains_private_type(type): not integer or float type: type = %p = %s \n",type,type->class_name().c_str()); #endif #if DEBUGGING_USING_RECURSIVE_DEPTH depth++; global_depth++; #endif bool isPrivateType = contains_private_type(type,targetScope); #if DEBUGGING_USING_RECURSIVE_DEPTH depth--; global_depth--; #endif returnValue = isPrivateType; } else { // This can't be a private type. #if DEBUG_PRIVATE_TYPE printf ("This is an integer or float type (of some sort): type = %p = %s = %s \n",type,type->class_name().c_str(),type->unparseToString().c_str()); #endif returnValue = false; } } else { // This is where we need to resolve is any types that are associated with declarations might be private (e.g. SgEnumType). if (classType != NULL) { // Check if this is associated with a template class instantiation. #if 0 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration()); ROSE_ASSERT(classDeclaration != NULL); printf ("--------- classDeclaration = %p = %s = %s \n",classDeclaration,classDeclaration->class_name().c_str(),classDeclaration->get_name().str()); #endif SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(classType->get_declaration()); if (templateInstantiationDeclaration != NULL) { #if DEBUGGING_USING_RECURSIVE_DEPTH global_depth++; #endif #if 0 printf ("Calling contains_private_type(SgTemplateArgumentPtrList): templateInstantiationDeclaration = %p = %s \n", templateInstantiationDeclaration,templateInstantiationDeclaration->get_name().str()); #endif returnValue = contains_private_type(templateInstantiationDeclaration->get_templateArguments(),targetScope); #if DEBUGGING_USING_RECURSIVE_DEPTH global_depth--; #endif #if 0 printf ("DONE: Calling contains_private_type(SgTemplateArgumentPtrList): templateInstantiationDeclaration = %p = %s \n", templateInstantiationDeclaration,templateInstantiationDeclaration->get_name().str()); #endif } #if 0 printf ("DONE: --- classDeclaration = %p = %s = %s \n",classDeclaration,classDeclaration->class_name().c_str(),classDeclaration->get_name().str()); #endif } } } #if DEBUG_PRIVATE_TYPE || 0 printf ("Leaving contains_private_type(SgType*): type = %p = %s = %s returnValue = %s \n",type,type->class_name().c_str(),type->unparseToString().c_str(),returnValue ? "true" : "false"); #endif return returnValue; }
string nodeColor( SgStatement* statement ) { /* color: colorCode:red:on color: colorCode:orange:on color: colorCode:yellow:on color: colorCode:blue:on color: colorCode:green:on color: colorCode:violet:on color: colorCode:brown:on color: colorCode:purple:on color: colorCode:lightblue:on color: colorCode:lightgreen:on color: colorCode:lightred:on color: colorCode:black:on color: colorCode:darkblue:on color: colorCode:grey:on color: colorCode:darkgrey:on color: colorCode:olivegreen:on color: colorCode:darkgreen:on */ string returnString; SgDeclarationStatement* declarationStatement = isSgDeclarationStatement(statement); if (declarationStatement != NULL) { switch (declarationStatement->variantT()) { case V_SgFunctionDeclaration: case V_SgMemberFunctionDeclaration: case V_SgTemplateInstantiationFunctionDecl: case V_SgTemplateInstantiationMemberFunctionDecl: returnString = "orange"; break; case V_SgClassDeclaration: case V_SgTemplateInstantiationDecl: returnString = "yellow"; break; case V_SgAsmStmt: case V_SgCtorInitializerList: case V_SgEnumDeclaration: case V_SgFunctionParameterList: case V_SgNamespaceAliasDeclarationStatement: case V_SgNamespaceDeclarationStatement: case V_SgPragmaDeclaration: case V_SgTemplateDeclaration: case V_SgTemplateInstantiationDirectiveStatement: case V_SgTypedefDeclaration: case V_SgUsingDeclarationStatement: case V_SgUsingDirectiveStatement: case V_SgVariableDeclaration: case V_SgVariableDefinition: returnString = "lightred"; break; // DQ (11/11/2012): Added support for newer IR nodes in edg4x work. case V_SgTemplateMemberFunctionDeclaration: case V_SgTemplateClassDeclaration: case V_SgTemplateFunctionDeclaration: case V_SgTemplateVariableDeclaration: returnString = "red"; break; default: returnString = "ERROR DEFAULT REACHED"; printf ("Default reached in nodeColor() exiting ... (%s) \n",declarationStatement->class_name().c_str()); ROSE_ASSERT(false); break; } } SgScopeStatement* scopeStatement = isSgScopeStatement(statement); if (scopeStatement != NULL) { switch (scopeStatement->variantT()) { case V_SgBasicBlock: returnString = "lightblue"; break; case V_SgClassDefinition: returnString = "lightblue"; break; case V_SgTemplateInstantiationDefn: case V_SgFunctionDefinition: returnString = "lightblue"; break; case V_SgWhileStmt: case V_SgDoWhileStmt: case V_SgForStatement: returnString = "darkblue"; break; case V_SgGlobal: case V_SgIfStmt: case V_SgNamespaceDefinitionStatement: case V_SgSwitchStatement: case V_SgCatchOptionStmt: returnString = "black"; break; // DQ (11/11/2012): Added support for newer IR nodes in edg4x work. case V_SgTemplateClassDefinition: case V_SgTemplateFunctionDefinition: returnString = "red"; break; default: returnString = "ERROR DEFAULT REACHED"; printf ("Default reached in nodeColor() exiting ... (%s) \n",scopeStatement->class_name().c_str()); ROSE_ASSERT(false); break; } } if (scopeStatement == NULL && declarationStatement == NULL) { switch (statement->variantT()) { case V_SgExprStatement: returnString = "violet"; break; case V_SgBreakStmt: case V_SgCaseOptionStmt: case V_SgCatchStatementSeq: case V_SgContinueStmt: case V_SgDefaultOptionStmt: case V_SgClinkageStartStatement: case V_SgForInitStatement: case V_SgFunctionTypeTable: case V_SgGotoStatement: case V_SgLabelStatement: case V_SgNullStatement: case V_SgReturnStmt: case V_SgSpawnStmt: case V_SgTryStmt: case V_SgVariantStatement: returnString = "brown"; break; default: returnString = "ERROR DEFAULT REACHED"; printf ("Default reached in nodeColor() exiting ... (%s) \n",statement->class_name().c_str()); ROSE_ASSERT(false); break; } } return returnString; }