/* * The function * queryNodeAnonymousTypedefClassDeclaration() * is a NodeQuery which finds all Anonymous Typedefs is the scope. */ NodeQuerySynthesizedAttributeType NodeQuery::queryNodeAnonymousTypedefClassDeclaration(SgNode* node) { NodeQuerySynthesizedAttributeType returnList; ROSE_ASSERT( node != NULL ); SgTypedefDeclaration* sageTypedefDeclaration = isSgTypedefDeclaration(node); if (sageTypedefDeclaration != NULL) if(isSgClassType(sageTypedefDeclaration->get_base_type())) { SgClassType* sageClassType = isSgClassType(sageTypedefDeclaration->get_base_type()); SgClassDeclaration* sageClassDeclaration = isSgClassDeclaration(sageClassType->get_declaration()); ROSE_ASSERT(sageClassDeclaration != NULL); returnList.push_back(sageClassDeclaration); } return returnList; } /* End function:queryNodeCLassDeclarationFromName() */
/** * class: SgClassType * term: class_type(name,type,scope) * arg name: name of the class * arg type: type enum of the class (class/struct/union) * arg scope: name of the scope */ PrologCompTerm* RoseToTerm::getClassTypeSpecific(SgType* mtype) { /*make sure we are actually dealing with a class type*/ SgClassType* ctype = isSgClassType(mtype); ROSE_ASSERT(ctype != NULL); SgClassDeclaration* d = isSgClassDeclaration(ctype->get_declaration()); ROSE_ASSERT(d != NULL); return new PrologCompTerm ("class_type", //3, /*add base type*/ new PrologAtom(ctype->get_name().str()), /* what kind of class is this?*/ getEnum(d->get_class_type(), re.class_types), /* add qualified name of scope*/ new PrologAtom (d->get_scope()->get_scope()->get_qualified_name().getString())); }
PrologCompTerm* RoseToTerm::getVariableDeclarationSpecific(SgVariableDeclaration* d) { ROSE_ASSERT(d != NULL); /* add base type forward declaration */ SgNode *baseTypeDecl = NULL; if (d->get_variableDeclarationContainsBaseTypeDefiningDeclaration()) { baseTypeDecl = d->get_baseTypeDefiningDeclaration(); } else { /* The complication is that in the AST, the type declaration member is * only set if it is a type definition, not if it is a forward * declaration. So we need to check whether the base type (possibly * below layers of pointers) is a class type, and whether its first * declaration appears to be hidden here in the variable declaration. */ SgClassType *ctype = isSgClassType(d->get_variables().front() ->get_type()->findBaseType()); if (ctype) { /* See if the type is declared in the scope where it belongs. If no, * then the declaration is apparently inside this variable * declaration, so we add it as a subterm. */ SgDeclarationStatement *cdecl = ctype->get_declaration(); SgSymbol *symbol = cdecl->get_symbol_from_symbol_table(); if (!typeWasDeclaredBefore( getTypeSpecific(symbol->get_type())->getRepresentation())) { baseTypeDecl = cdecl; } } } return new PrologCompTerm ("variable_declaration_specific", //3, getDeclarationModifierSpecific(&(d->get_declarationModifier())), (baseTypeDecl != NULL ? traverseSingleNode(baseTypeDecl) : new PrologAtom("null")), PPI(d)); }
StencilEvaluation_SynthesizedAttribute StencilEvaluationTraversal::evaluateSynthesizedAttribute (SgNode* astNode, StencilEvaluation_InheritedAttribute inheritedAttribute, SubTreeSynthesizedAttributes synthesizedAttributeList ) { StencilEvaluation_SynthesizedAttribute return_synthesizedAttribute; #if 0 printf ("In StencilEvaluationTraversal::evaluateSynthesizedAttribute(): astNode = %p = %s \n",astNode,astNode->class_name().c_str()); #endif bool foundStencilOffsetFSM = false; SgConstructorInitializer* constructorInitializer = isSgConstructorInitializer(astNode); if (constructorInitializer != NULL && inheritedAttribute.stencilOffsetFSM != NULL) { #if 0 printf ("Found pair<Shift,double>(x,y): set then in the synthesizedAttribute: astNode = %p = %s \n",astNode,astNode->class_name().c_str()); #endif return_synthesizedAttribute.stencilOffsetFSM = inheritedAttribute.stencilOffsetFSM; return_synthesizedAttribute.stencilCoeficientValue = inheritedAttribute.stencilCoeficientValue; #if 0 printf ("return_synthesizedAttribute.stencilCoeficientValue = %f \n",return_synthesizedAttribute.stencilCoeficientValue); #endif foundStencilOffsetFSM = true; } // There should only be a single child set with a pair<Shift,double>(x,y) object. for (size_t i = 0; i < synthesizedAttributeList.size(); i++) { if (synthesizedAttributeList[i].stencilOffsetFSM != NULL) { // Check that the return_synthesizedAttribute.stencilOffsetFSM has not already been set. // This could happend if we allows nesting of pair<Shift,double>(x,y) within itself (not allowed). #if 0 printf ("synthesizedAttributeList[i].stencilOffsetFSM != NULL \n"); #endif // ROSE_ASSERT(foundStencilOffsetFSM == false); if (foundStencilOffsetFSM == false) { #if 0 printf ("foundStencilOffsetFSM == false \n"); #endif // ROSE_ASSERT(return_synthesizedAttribute.stencilOffsetFSM == NULL); if (return_synthesizedAttribute.stencilOffsetFSM == NULL) { #if 0 printf ("return_synthesizedAttribute.stencilOffsetFSM != NULL \n"); #endif return_synthesizedAttribute.stencilOffsetFSM = synthesizedAttributeList[i].stencilOffsetFSM; return_synthesizedAttribute.stencilCoeficientValue = synthesizedAttributeList[i].stencilCoeficientValue; } foundStencilOffsetFSM = true; } } } // This allows us to find the variables of type vector<Point> and vector<double> used as an alternative way // to specify a stencil (using the Stencil constructor that takes these variables as input arguments). // It relies upon a previous traversal to have identified the inputs to Stencil constructor. // This support is incomplete while I focus on the alternative approach to the specification of the stencil // using intremental union of a stencil with a pair<Shift,double>() template instantiation. SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(astNode); if (variableDeclaration != NULL) { // Get the SgInitializedName from the SgVariableDeclaration. SgInitializedName* initializedName = SageInterface::getFirstInitializedName(variableDeclaration); #if 0 printf ("In evaluateInheritedAttribute(): case SgInitializedName from variable declaration: initializedName = %p name = %s \n",initializedName,initializedName->get_name().str()); #endif bool foundStencilDeclaration = false; if (find(stencilInputInitializedNameList.begin(),stencilInputInitializedNameList.end(),initializedName) != stencilInputInitializedNameList.end()) { #if 0 printf ("Found declaration associated with stencil input: initializedName = %p = %s name = %s \n",initializedName,initializedName->class_name().c_str(),initializedName->get_name().str()); #endif // Build the finite state machine for the stencil and add it to the map using the name (in SgInitializedName) as a key. // For now we assume that the stencil specification is using the default construction. if (initializedName->get_initptr() != NULL) { printf ("FIXME: This declaration of a stencil appears to have constrcutor arguments (this not the default constuctor as interprest below). \n"); #if 0 ROSE_ASSERT(false); #endif } foundStencilDeclaration = true; } else { // Verify that this is a Stencil declaration. SgClassType* classType = isSgClassType(initializedName->get_type()); if (classType != NULL) { // Check if this is associated with a template instantiation. SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(classType->get_declaration()); if (templateInstantiationDecl != NULL) { #if 0 printf ("case SgTemplateInstaiationDecl: class name = %s \n",classType->get_name().str()); printf ("case SgTemplateInstaiationDecl: templateInstantiationDecl->get_templateName() = %s \n",templateInstantiationDecl->get_templateName().str()); #endif if (templateInstantiationDecl->get_templateName() == "Stencil") { #if 0 printf ("This is verified to be associated with the Stencil template class \n"); #endif foundStencilDeclaration = true; } } } } if (foundStencilDeclaration == true) { string name = initializedName->get_name(); ROSE_ASSERT(stencilMap.find(name) == stencilMap.end()); // stencilMap[name] = new StencilFSM(); StencilFSM* stencilFSM = new StencilFSM(); ROSE_ASSERT(stencilFSM != NULL); stencilMap[name] = stencilFSM; ROSE_ASSERT(stencilMap.find(name) != stencilMap.end()); #if 0 printf ("Added StencilFSM to stencilMap using name = %s \n",name.c_str()); #endif #if 0 printf ("Trigger an event on the stencilFSM ========================== %p \n",stencilFSM); printf (" --- Use the return_synthesizedAttribute.stencilOffsetFSM = %p \n",return_synthesizedAttribute.stencilOffsetFSM); #endif if (return_synthesizedAttribute.stencilOffsetFSM != NULL) { // Trigger the event to add the stencil offset to the stencil. // Trigger the event on the finite state machine using the elements saved in the synthesized attribute. StencilFSM stencil_rhs (*(return_synthesizedAttribute.stencilOffsetFSM),return_synthesizedAttribute.stencilCoeficientValue); // This reproduces the same semantics in our finite state machine as the Stencil class's operator+() // in the stencil specification. but this permits use to accumulate the state at compile time. stencilFSM->operator+(stencil_rhs); // We have now used these values so avoid letting then be used again. return_synthesizedAttribute.stencilOffsetFSM = NULL; return_synthesizedAttribute.stencilCoeficientValue = 0.0; } #if 0 stencilFSM->display("after FSM stencil default construction plus union event: StencilEvaluationTraversal::evaluateSynthesizedAttribute()"); #endif #if 0 printf ("Exiting as a test! \n"); ROSE_ASSERT(false); #endif } } // Recognize member function calls on "Stencil" objects so that we can trigger events on those associated finite state machines. bool isTemplateClass = true; bool isTemplateFunctionInstantiation = true; SgInitializedName* initializedNameUsedToCallMemberFunction = NULL; SgFunctionCallExp* functionCallExp = detectMemberFunctionOfSpecificClassType(astNode,initializedNameUsedToCallMemberFunction,"Stencil",isTemplateClass,"operator+",isTemplateFunctionInstantiation); if (return_synthesizedAttribute.stencilOffsetFSM != NULL && functionCallExp != NULL) { // This is the DSL specific part of the synthesized attribute evaluation. ROSE_ASSERT(initializedNameUsedToCallMemberFunction != NULL); string name = initializedNameUsedToCallMemberFunction->get_name(); #if 0 printf ("This is verified to be the operator+ member function of the Stencil templated class (so this corresponds to an event in the Stencil finite state machine) \n"); printf (" --- stencil object name = %s \n",name.c_str()); #endif // Lookup the stencil FSM in the map of stencil FSMs using the name as the key. ROSE_ASSERT(stencilMap.find(name) != stencilMap.end()); StencilFSM* stencilFSM = stencilMap[name]; ROSE_ASSERT(stencilFSM != NULL); #if 0 printf ("Trigger an event on the stencilFSM ========================== %p \n",stencilFSM); printf (" --- Use the return_synthesizedAttribute.stencilOffsetFSM = %p \n",return_synthesizedAttribute.stencilOffsetFSM); #endif // Make sure we have the input parameter for the stencil's finite state machine. ROSE_ASSERT(return_synthesizedAttribute.stencilOffsetFSM != NULL); // Trigger the event on the finite state machine using the elements saved in the synthesized attribute. StencilFSM stencil_rhs (*(return_synthesizedAttribute.stencilOffsetFSM),return_synthesizedAttribute.stencilCoeficientValue); // This reproduces the same semantics in our finite state machine as the Stencil class's operator+() // in the stencil specification. but this permits use to accumulate the state at compile time. stencilFSM->operator+(stencil_rhs); // We have now used these values so avoid letting then be used again. return_synthesizedAttribute.stencilOffsetFSM = NULL; return_synthesizedAttribute.stencilCoeficientValue = 0.0; #if 0 stencilFSM->display("after FSM stencil union event: StencilEvaluationTraversal::evaluateSynthesizedAttribute()"); #endif } #if 0 printf ("Leaving StencilEvaluationTraversal::evaluateSynthesizedAttribute(): return_synthesizedAttribute.stencilOffsetFSM = %p \n",return_synthesizedAttribute.stencilOffsetFSM); #endif #if 0 printf ("Leaving StencilEvaluationTraversal::evaluateSynthesizedAttribute(): return_synthesizedAttribute.stencilCoeficientValue = %f \n",return_synthesizedAttribute.stencilCoeficientValue); #endif return return_synthesizedAttribute; }
void FixupSelfReferentialMacrosInAST::visit ( SgNode* node ) { // DQ (3/11/2006): Set NULL pointers where we would like to have none. // printf ("In FixupSelfReferentialMacrosInAST::visit(): node = %s \n",node->class_name().c_str()); ROSE_ASSERT(node != NULL); switch (node->variantT()) { case V_SgInitializedName: { SgInitializedName* initializedName = isSgInitializedName(node); ROSE_ASSERT(initializedName != NULL); SgType* type = initializedName->get_type()->stripType(); SgClassType* classType = isSgClassType(type); if (classType != NULL) { SgClassDeclaration* targetClassDeclaration = isSgClassDeclaration(classType->get_declaration()); SgName className = targetClassDeclaration->get_name(); // printf ("In FixupSelfReferentialMacrosInAST::visit(): Found a class declaration name = %s \n",className.str()); // For sudo_exec_pty.c also look for siginfo if (className == "sigaction" || className == "siginfo") { // printf ("In FixupSelfReferentialMacrosInAST::visit(): Found a sigaction type \n"); // Note we could also check that the declaration came from a known header file. SgStatement* associatedStatement = isSgStatement(initializedName->get_parent()); if (associatedStatement != NULL) { // Add a macro to undefine the "#define sa_handler __sigaction_handler.sa_handler" macro. // printf ("In FixupSelfReferentialMacrosInAST::visit(): Add a macro to undefine the macro #define sa_handler __sigaction_handler.sa_handler \n"); // PreprocessingInfo* macro = new PreprocessingInfo(DirectiveType, const std::string & inputString,const std::string & filenameString, int line_no , int col_no,int nol, RelativePositionType relPos ); PreprocessingInfo::DirectiveType directiveType = PreprocessingInfo::CpreprocessorUndefDeclaration; // We are puting out all macros anytime we see either type. This might be too much... // From the sigaction.h file (included by signal.h): addMacro(associatedStatement,"#undef sa_handler\n",directiveType); addMacro(associatedStatement,"#undef sa_sigaction\n",directiveType); // From the siginfo.h file (included by signal.h): addMacro(associatedStatement,"#undef si_pid\n", directiveType); addMacro(associatedStatement,"#undef si_uid\n", directiveType); addMacro(associatedStatement,"#undef si_timerid\n",directiveType); addMacro(associatedStatement,"#undef si_overrun\n",directiveType); addMacro(associatedStatement,"#undef si_status\n", directiveType); addMacro(associatedStatement,"#undef si_utime\n", directiveType); addMacro(associatedStatement,"#undef si_stime\n", directiveType); addMacro(associatedStatement,"#undef si_value\n", directiveType); addMacro(associatedStatement,"#undef si_int\n", directiveType); addMacro(associatedStatement,"#undef si_ptr\n", directiveType); addMacro(associatedStatement,"#undef si_addr\n", directiveType); addMacro(associatedStatement,"#undef si_band\n", directiveType); addMacro(associatedStatement,"#undef si_fd\n", directiveType); } } } } default: { // printf ("Not handled in FixupSelfReferentialMacrosInAST::visit(%s) \n",node->class_name().c_str()); } } }
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; }
bool ReplacementMapTraversal::verifyODR( SgNode* node, SgNode* duplicateNodeFromOriginalAST ) { bool passesODR = false; // printf ("Verify that node = %p is equivalent to duplicateNodeFromOriginalAST = %p = %s \n",node,duplicateNodeFromOriginalAST,duplicateNodeFromOriginalAST->class_name().c_str()); // Verify that these strings match ROSE_ASSERT (duplicateNodeFromOriginalAST->variantT() == node->variantT()); ROSE_ASSERT (duplicateNodeFromOriginalAST->class_name() == node->class_name()); // ROSE_ASSERT (generateUniqueName(duplicateNodeFromOriginalAST) == generateUniqueName(node)); string nodeString; string duplicateNodeFromOriginalASTstring; #if 0 // DQ (2/3/2007): This is a test to debug the ODR checking. // I think that the unparser has some state specific to the output of access protections. // if the unparsing changes the state then the access permission (public, protected, private) // is output and this cause a falue trigger to the ODR string match. This is a temp fix to // absorbe any change of state, but we need a mechanism to clear the state in the unparser. string absorbeUnparserStateChange_A = node->unparseToString(); string absorbeUnparserStateChange_B = duplicateNodeFromOriginalAST->unparseToString(); #endif #if 0 // DQ (2/3/2007): Make sure that there are close to being related. It appears that if these are if (node->get_parent()->variantT() == duplicateNodeFromOriginalAST->get_parent()->variantT()) { nodeString = node->unparseToString(); duplicateNodeFromOriginalASTstring = duplicateNodeFromOriginalAST->unparseToString(); } #endif bool skip_ODR_test = false; bool nodeIsCompilerGenerated = (node->get_file_info() != NULL) ? node->get_file_info()->isCompilerGenerated() : false; bool duplicateNodeFromOriginalASTIsCompilerGenerated = (duplicateNodeFromOriginalAST->get_file_info() != NULL) ? duplicateNodeFromOriginalAST->get_file_info()->isCompilerGenerated() : false; bool nodeIsFrontendSpecific = (node->get_file_info() != NULL) ? node->get_file_info()->isFrontendSpecific() : false; bool duplicateNodeFromOriginalASTIsFrontendSpecific = (duplicateNodeFromOriginalAST->get_file_info() != NULL) ? duplicateNodeFromOriginalAST->get_file_info()->isFrontendSpecific() : false; // If this is a template declaration for a function then it might have been a part of another template declaration // for the template class and thus might not exist explicitly in the AST (and thus not have enough information from // which to generate a meaningful mangled name). Skip ODR testing of these cases. bool isTemplateMemberFunctionInTemplatedClass = false; SgTemplateDeclaration* templateDeclaration = isSgTemplateDeclaration(node); if (templateDeclaration != NULL) { SgTemplateDeclaration* dup_templateDeclaration = isSgTemplateDeclaration(duplicateNodeFromOriginalAST); ROSE_ASSERT(dup_templateDeclaration != NULL); if ( templateDeclaration->get_string().is_null() && dup_templateDeclaration->get_string().is_null() ) { isTemplateMemberFunctionInTemplatedClass = true; } } if (isTemplateMemberFunctionInTemplatedClass == true) { printf ("ODR not tested isTemplateMemberFunctionInTemplatedClass == true. \n"); skip_ODR_test = true; } if (nodeIsFrontendSpecific == true || duplicateNodeFromOriginalASTIsFrontendSpecific == true || nodeIsCompilerGenerated == true || duplicateNodeFromOriginalASTIsCompilerGenerated == true) { // printf ("ODR not tested for frontend specific compiler generated code. \n"); skip_ODR_test = true; } // DQ (1/20/2007): The unparse will not generate a string if the code is frontend specific or compiler generated (I forget which). // if (nodeIsFrontendSpecific == true || duplicateNodeFromOriginalASTIsFrontendSpecific == true) if (skip_ODR_test == true) { // printf ("ODR not tested for frontend specific compiler generated code. \n"); passesODR = true; } else { SgUnparse_Info info_a; SgUnparse_Info info_b; // DQ (2/6/2007): Force qualified names to be used uniformally (note that info.set_requiresGlobalNameQualification() // causes an error) info.set_requiresGlobalNameQualification(); info_a.set_forceQualifiedNames(); info_b.set_forceQualifiedNames(); nodeString = node->unparseToString(&info_a); // DQ (2/6/2007): The SgUnparse_Info object carries state which controls the use of access qualification and the // first call to unparseToString might have set the access (e.g. to "public") and the second call would drop the // access qualification. We unset the access qualification state in the SgUnparse_Info object so that both will // be unparsed the same (we could have alternatively used two separate SgUnparse_Info objects. // info.set_isUnsetAccess(); duplicateNodeFromOriginalASTstring = duplicateNodeFromOriginalAST->unparseToString(&info_b); passesODR = (nodeString == duplicateNodeFromOriginalASTstring); } // Don't count the cases where the unparse fails to to invalid parent in redundant SgClassDeclaration (fix these later) if (passesODR == false && nodeString.empty() == false && duplicateNodeFromOriginalASTstring.empty() == false) { #if 1 if (SgProject::get_verbose() > 0) printf ("##### In ReplacementMapTraversal::verifyODR() is false: node = %p = %s duplicateNodeFromOriginalAST = %p = %s \n", node,node->class_name().c_str(),duplicateNodeFromOriginalAST,duplicateNodeFromOriginalAST->class_name().c_str()); // printf ("##### passesODR = %s \n",passesODR ? "true" : "false"); // printf ("duplicateNodeFromOriginalASTstring = \n---> %s\n",duplicateNodeFromOriginalASTstring.c_str()); // printf ("nodeString = \n---> %s\n",nodeString.c_str()); if (node->get_file_info() != NULL && duplicateNodeFromOriginalAST->get_file_info() != NULL) { if (SgProject::get_verbose() > 0) { SgNode* parent_node = node->get_parent(); // DQ (9/13/2011): Reported as possible NULL value in static analysis of ROSE code. ROSE_ASSERT(parent_node != NULL); printf ("parent_node = %p = %s = %s \n",parent_node,parent_node->class_name().c_str(),SageInterface::get_name(parent_node).c_str()); SgNode* parent_dup = duplicateNodeFromOriginalAST->get_parent(); // DQ (9/13/2011): Reported as possible NULL value in static analysis of ROSE code. ROSE_ASSERT(parent_dup != NULL); printf ("parent_dup = %p = %s = %s \n",parent_dup,parent_dup->class_name().c_str(),SageInterface::get_name(parent_dup).c_str()); printf ("\nPosition of error: \n"); node->get_file_info()->display("In ReplacementMapTraversal::verifyODR(node) is false: debug"); duplicateNodeFromOriginalAST->get_file_info()->display("In ReplacementMapTraversal::verifyODR(duplicateNodeFromOriginalAST) is false: debug"); printf ("\nPosition of error: \n"); printf ("\nPosition of error (parent IR node): \n"); parent_node->get_file_info()->display("In ReplacementMapTraversal::verifyODR(parent_node) is false: debug"); parent_dup->get_file_info()->display("In ReplacementMapTraversal::verifyODR(parent_dup) is false: debug"); printf ("\nPosition of error (parent IR node): \n"); } } else { SgClassType* classType = isSgClassType(node); SgClassType* duplicateNodeFromOriginalAST_classType = isSgClassType(duplicateNodeFromOriginalAST); if (classType != NULL) { if (SgProject::get_verbose() > 0) { SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration()); ROSE_ASSERT(classDeclaration != NULL); classDeclaration->get_file_info()->display("In ReplacementMapTraversal::verifyODR(node) is false (classType)"); printf ("classDeclaration = %p definingDeclaration = %p nondefiningDeclaration = %p \n", classDeclaration, classDeclaration->get_definingDeclaration(), classDeclaration->get_firstNondefiningDeclaration()); ROSE_ASSERT(duplicateNodeFromOriginalAST_classType != NULL); SgClassDeclaration* duplicateNodeFromOriginalAST_classDeclaration = isSgClassDeclaration(duplicateNodeFromOriginalAST_classType->get_declaration()); ROSE_ASSERT(duplicateNodeFromOriginalAST_classDeclaration != NULL); duplicateNodeFromOriginalAST_classDeclaration->get_file_info()->display("In ReplacementMapTraversal::verifyODR(node) is false (duplicateNodeFromOriginalAST_classType)"); printf ("duplicateNodeFromOriginalAST_classDeclaration = %p definingDeclaration = %p nondefiningDeclaration = %p \n", duplicateNodeFromOriginalAST_classDeclaration, duplicateNodeFromOriginalAST_classDeclaration->get_definingDeclaration(), duplicateNodeFromOriginalAST_classDeclaration->get_firstNondefiningDeclaration()); } } } #endif odrViolations.push_back(pair<SgNode*,SgNode*>(node,duplicateNodeFromOriginalAST)); } #if 0 printf ("duplicateNodeFromOriginalASTstring = %p = %s \n---> %s\n", duplicateNodeFromOriginalAST,duplicateNodeFromOriginalAST->class_name().c_str(),duplicateNodeFromOriginalASTstring.c_str()); printf ("nodeString = %p = %s \n---> %s\n", node,node->class_name().c_str(),nodeString.c_str()); #endif #if 0 SgClassType* original = isSgClassType(duplicateNodeFromOriginalAST); SgClassType* target = isSgClassType(node); if (original != NULL && target != NULL) { printf ("original declaration = %p \n",original->get_declaration()); printf ("target declaration = %p \n",target->get_declaration()); } #endif #if 1 if (passesODR == false) { if (SgProject::get_verbose() > 0) { string node_generatedName = SageInterface::generateUniqueName(node,false); string originalNode_generatedName = SageInterface::generateUniqueName(duplicateNodeFromOriginalAST,false); printf ("ODR Violation Source code: nodeString = \n%s\n \n",nodeString.c_str()); printf ("ODR Violation Source code: duplicateNodeFromOriginalASTstring = \n%s\n \n",duplicateNodeFromOriginalASTstring.c_str()); printf ("nodeString = %s \n",nodeString.c_str()); printf ("node_generatedName = %s \n",node_generatedName.c_str()); printf ("originalNode_generatedName = %s \n",originalNode_generatedName.c_str()); printf ("node = %p = %s = %s \n",node,node->class_name().c_str(),SageInterface::get_name(node).c_str()); printf ("duplicateNodeFromOriginalAST = %p = %s = %s \n",duplicateNodeFromOriginalAST,duplicateNodeFromOriginalAST->class_name().c_str(),SageInterface::get_name(duplicateNodeFromOriginalAST).c_str()); printf ("node (unique string) = %s \n",generateUniqueName(node,true).c_str()); printf ("duplicateNodeFromOriginalAST (unique string) = %s \n",generateUniqueName(duplicateNodeFromOriginalAST,true).c_str()); SgDeclarationStatement* declarationStatement = isSgDeclarationStatement(node); if (declarationStatement != NULL) { printf ("declarationStatement->get_definingDeclaration() = %p \n",declarationStatement->get_definingDeclaration()); printf ("declarationStatement->get_firstNondefiningDeclaration() = %p \n",declarationStatement->get_firstNondefiningDeclaration()); } SgDeclarationStatement* declarationStatement2 = isSgDeclarationStatement(duplicateNodeFromOriginalAST); if (declarationStatement2 != NULL) { printf ("declarationStatement2->get_definingDeclaration() = %p \n",declarationStatement2->get_definingDeclaration()); printf ("declarationStatement2->get_firstNondefiningDeclaration() = %p \n",declarationStatement2->get_firstNondefiningDeclaration()); } printf ("Source code positions of ORD violation: \n"); node->get_file_info()->display("In ReplacementMapTraversal::verifyODR(node) is false: debug"); duplicateNodeFromOriginalAST->get_file_info()->display("In ReplacementMapTraversal::verifyODR(duplicateNodeFromOriginalAST) is false: debug"); } } #endif // ROSE_ASSERT(nodeString == duplicateNodeFromOriginalASTstring); ROSE_ASSERT(passesODR == true); return passesODR; }
bool ArrayAssignmentStatementTransformation::targetForTransformation(SgNode* astNode) { // This is a static function which returns true when the current node // of the AST is a target for transformation. bool returnValue = FALSE; ROSE_ASSERT (astNode != NULL); // This code used to recognize array statements checks to see if the name of the type of the // function contained in the expression statement is "doubleArray". This code will be // dramatically simplified once we can use the higher level grammars to recognise array // statements. At present this code is not a robust test for the use existence of a transformable // array statement it will be robust once we can use the higher level grammars (AST restructuring // tools) generated by ROSETTA. SgExprStatement *expressionStatement = isSgExprStatement(astNode); // In this example we only perform transformations on declaration statements if (expressionStatement != NULL) { SgExpression* expression = expressionStatement->get_expression(); ROSE_ASSERT (expression != NULL); // See if this is an A++ member function call SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(expression); // ROSE_ASSERT (functionCallExp != NULL); if (functionCallExp != NULL) { SgType* type = functionCallExp->get_type(); ROSE_ASSERT (type != NULL); SgClassType* classType = isSgClassType(type); if (classType == NULL) { // Check to see if it a reference to a class type (and get it's base type) SgType* type = functionCallExp->get_type(); ROSE_ASSERT (type != NULL); SgReferenceType* referenceType = isSgReferenceType(type); if (referenceType != NULL) { ROSE_ASSERT (referenceType != NULL); SgType* baseType = referenceType->get_base_type(); ROSE_ASSERT (baseType != NULL); classType = isSgClassType(baseType); ROSE_ASSERT (classType != NULL); } else { return FALSE; } } ROSE_ASSERT (classType != NULL); // It is the get_name which returns the type name (not the qualified name (I forget what it is for) SgName name = classType->get_name(); if (name == "intArray" || name == "floatArray" || name == "doubleArray") { #if DEBUG printf( "ArrayAssignmentStatementTransformation::targetForTransformation Expression Statement %s \n", expressionStatement->unparseToString().c_str()); #endif returnValue = TRUE; } else { printf( "Not a expression statement containing a function call expression of type {double,float,int}Array ... \n"); } } else { // This case could be "A;" in which case there is no transformation printf("Not a expression statement containing a function call expression ... \n"); } } else { // printf ("Not an expression statement (only expression statements qualify!) \n"); } return returnValue; }
void FixupSelfReferentialMacrosInAST::visit ( SgNode* node ) { // DQ (3/11/2006): Set NULL pointers where we would like to have none. // printf ("In FixupSelfReferentialMacrosInAST::visit(): node = %s \n",node->class_name().c_str()); ROSE_ASSERT(node != NULL); switch (node->variantT()) { case V_SgInitializedName: { SgInitializedName* initializedName = isSgInitializedName(node); ROSE_ASSERT(initializedName != NULL); SgType* type = initializedName->get_type()->stripType(); SgClassType* classType = isSgClassType(type); if (classType != NULL) { SgClassDeclaration* targetClassDeclaration = isSgClassDeclaration(classType->get_declaration()); SgName className = targetClassDeclaration->get_name(); // printf ("In FixupSelfReferentialMacrosInAST::visit(): Found a class declaration name = %s \n",className.str()); if (className == "sigaction") { // printf ("In FixupSelfReferentialMacrosInAST::visit(): Found a sigaction type \n"); // Note we could also check that the declaration came from a known header file. SgStatement* associatedStatement = isSgStatement(initializedName->get_parent()); if (associatedStatement != NULL) { // Add a macro to undefine the "#define sa_handler __sigaction_handler.sa_handler" macro. // printf ("In FixupSelfReferentialMacrosInAST::visit(): Add a macro to undefine the macro #define sa_handler __sigaction_handler.sa_handler \n"); // PreprocessingInfo* macro = new PreprocessingInfo(DirectiveType, const std::string & inputString,const std::string & filenameString, int line_no , int col_no,int nol, RelativePositionType relPos ); PreprocessingInfo::DirectiveType directiveType = PreprocessingInfo::CpreprocessorUndefDeclaration; std::string macroString = "#undef sa_handler\n"; std::string filenameString = "macro_call_fixupSelfReferentialMacrosInAST"; int line_no = 1; int col_no = 1; int nol = 1; PreprocessingInfo::RelativePositionType relPos = PreprocessingInfo::before; PreprocessingInfo* macro = new PreprocessingInfo(directiveType,macroString,filenameString,line_no,col_no,nol,relPos); // printf ("Attaching CPP directive %s to IR node %p as attributes. \n",PreprocessingInfo::directiveTypeName(macro->getTypeOfDirective()).c_str(),associatedStatement); associatedStatement->addToAttachedPreprocessingInfo(macro); #if 0 printf ("Exiting as a test! \n"); ROSE_ASSERT(false); #endif } } } } default: { // printf ("Not handled in FixupSelfReferentialMacrosInAST::visit(%s) \n",node->class_name().c_str()); } } }
Detection_InheritedAttribute DetectionTraversal::evaluateInheritedAttribute (SgNode* astNode, Detection_InheritedAttribute inheritedAttribute ) { #if 0 printf ("In DetectionTraversal::evaluateInheritedAttribute(): astNode = %p = %s \n",astNode,astNode->class_name().c_str()); #endif // DQ (2/3/2016): Recognize IR nodes that are representative of target DSL abstractions. bool foundTargetDslAbstraction = DSL_Support::isDslAbstraction(astNode); #if 1 printf ("In DetectionTraversal::evaluateInheritedAttribute(): astNode = %p = %s: foundTargetDslAbstraction = %s \n",astNode,astNode->class_name().c_str(),foundTargetDslAbstraction ? "true" : "false"); #endif #if 0 // OLD CODE (represented by DSL_Support::isDslAbstraction() function). // Detection of stencil declaration and stencil operator. // Where the stencil specification is using std::vectors as parameters to the constructor, we have to first // find the stencil declaration and read the associated SgVarRefExp to get the variable names used. // Then a finite state machine can be constructed for each of the input variables so that we can // interpret the state when the stencil operator is constructed. SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(astNode); if (variableDeclaration != NULL) { // Get the SgInitializedName from the SgVariableDeclaration. SgInitializedName* initializedName = SageInterface::getFirstInitializedName(variableDeclaration); SgType* base_type = initializedName->get_type()->findBaseType(); ROSE_ASSERT(base_type != NULL); // SgClassType* classType = isSgClassType(initializedName->get_type()); SgClassType* classType = isSgClassType(base_type); if (classType != NULL) { #if 1 printf ("In DetectionTraversal::evaluateInheritedAttribute(): case SgClassType: class name = %s \n",classType->get_name().str()); #endif // Check if this is associated with a template instantiation. SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(classType->get_declaration()); if (templateInstantiationDecl != NULL) { #if 1 printf ("case SgTemplateInstaiationDecl: class name = %s \n",classType->get_name().str()); printf ("case SgTemplateInstaiationDecl: templateInstantiationDecl->get_templateName() = %s \n",templateInstantiationDecl->get_templateName().str()); #endif // inheritedAttribute.set_StencilDeclaration(templateInstantiationDecl->get_templateName() == "Stencil"); // inheritedAttribute.set_StencilOperatorDeclaration(templateInstantiationDecl->get_templateName() == "StencilOperator"); if (templateInstantiationDecl->get_templateName() == "Stencil") { // DQ (2/8/2015): Ignore compiler generated IR nodes (from template instantiations, etc.). // Note that simpleCNS.cpp generates one of these from it's use of the tuple template and associated template instantations. // DQ: Test the DSL support. ROSE_ASSERT(isMatchingClassType(classType,"Stencil",true) == true); checkAndResetToMakeConsistantCompilerGenerated(initializedName); if (initializedName->isCompilerGenerated() == false) { // Save the SgInitializedName associated with the stencil. // stencilInitializedNameList.push_back(initializedName); // inheritedAttribute.set_StencilDeclaration(true); // foundStencilVariable = true; #if 1 printf ("Detected Stencil<> typed variable: initializedName = %p name = %s \n",initializedName,initializedName->get_name().str()); // printf (" --- stencilInitializedNameList.size() = %zu \n",stencilInitializedNameList.size()); #endif #if 1 initializedName->get_file_info()->display("In DetectionTraversal::evaluateInheritedAttribute(): initializedName : debug"); #endif #if 0 Stencil_Attribute* dslAttribute = new Stencil_Attribute(); #if 1 printf ("Adding (Stencil) dslAttribute = %p \n",dslAttribute); #endif ROSE_ASSERT(dslAttribute != NULL); // virtual void addNewAttribute (std::string s, AstAttribute *a); initializedName->addNewAttribute(StencilVariable,dslAttribute); #endif } } } SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration()); if (classDeclaration != NULL) { if (classDeclaration->get_name() == "Point") { // Save the SgInitializedName associated with the Point type. #if 0 printf ("Detected Point<> typed variable: initializedName = %p name = %s \n",initializedName,initializedName->get_name().str()); #endif checkAndResetToMakeConsistantCompilerGenerated(initializedName); if (initializedName->isCompilerGenerated() == false) { // pointInitializedNameList.push_back(initializedName); #if 0 Point_Attribute* dslAttribute = new Point_Attribute(); printf ("Adding (Point) dslAttribute = %p \n",dslAttribute); ROSE_ASSERT(dslAttribute != NULL); // virtual void addNewAttribute (std::string s, AstAttribute *a); initializedName->addNewAttribute(PointVariable,dslAttribute); #endif } } } } } #endif #if 1 printf ("Leaving DetectionTraversal::evaluateInheritedAttribute(): astNode = %p = %s \n",astNode,astNode->class_name().c_str()); #endif // Construct the return attribute from the modified input attribute. return Detection_InheritedAttribute(inheritedAttribute); }
int main(int argc, char **argv) { SgProject *project = frontend(argc, argv); // Instantiate a class hierarchy wrapper. ClassHierarchyWrapper classHierarchy( project ); #if 0 std::list<SgNode *> nodes2 = NodeQuery::querySubTree(project, V_SgVariableDefinition); for (std::list<SgNode *>::iterator it = nodes2.begin(); it != nodes2.end(); ++it ) { SgNode *n = *it; ROSE_ASSERT(n != NULL); SgVariableDefinition *varDefn = isSgVariableDefinition(n); ROSE_ASSERT(varDefn != NULL); std::cout << "Var defn: " << varDefn->unparseToCompleteString() << std::endl; } std::list<SgNode *> nodes1 = NodeQuery::querySubTree(project, V_SgVariableDeclaration); for (std::list<SgNode *>::iterator it = nodes1.begin(); it != nodes1.end(); ++it ) { SgNode *n = *it; ROSE_ASSERT(n != NULL); SgVariableDeclaration *varDecl = isSgVariableDeclaration(n); ROSE_ASSERT(varDecl != NULL); SgInitializedNamePtrList &variables = varDecl->get_variables(); SgInitializedNamePtrList::iterator varIter; for (varIter = variables.begin(); varIter != variables.end(); ++varIter) { SgNode *var = *varIter; ROSE_ASSERT(var != NULL); SgInitializedName *initName = isSgInitializedName(var); ROSE_ASSERT(initName != NULL); if ( isSgClassType(initName->get_type()) ) { SgClassType *classType = isSgClassType(initName->get_type()); ROSE_ASSERT(classType != NULL); SgDeclarationStatement *declStmt = classType->get_declaration(); ROSE_ASSERT(declStmt != NULL); SgClassDeclaration *classDeclaration = isSgClassDeclaration(declStmt); ROSE_ASSERT(classDeclaration != NULL); // std::cout << "From var decl got: " << classDeclaration->unparseToCompleteString() << std::endl; SgClassDefinition *classDefinition = classDeclaration->get_definition(); if ( classDefinition != NULL ) { std::cout << "From var decl got: " << classDefinition->unparseToCompleteString() << std::endl; } } } } std::list<SgNode *> nodes = NodeQuery::querySubTree(project, V_SgClassDeclaration); for (std::list<SgNode *>::iterator it = nodes.begin(); it != nodes.end(); ++it ) { SgNode *n = *it; ROSE_ASSERT(n != NULL); SgClassDeclaration *classDeclaration1 = isSgClassDeclaration(n); ROSE_ASSERT(classDeclaration1 != NULL); SgDeclarationStatement *definingDecl = classDeclaration1->get_definingDeclaration(); if ( definingDecl == NULL ) continue; SgClassDeclaration *classDeclaration = isSgClassDeclaration(definingDecl); ROSE_ASSERT(classDeclaration != NULL); SgClassDefinition *classDefinition = classDeclaration->get_definition(); ROSE_ASSERT(classDefinition != NULL); std::cout << "Calling getSubclasses on " << classDefinition->unparseToCompleteString() << std::endl; SgClassDefinitionPtrList subclasses = classHierarchy.getSubclasses(classDefinition); // Iterate over all subclasses. for (SgClassDefinitionPtrList::iterator subclassIt = subclasses.begin(); subclassIt != subclasses.end(); ++subclassIt) { SgClassDefinition *subclass = *subclassIt; ROSE_ASSERT(subclass != NULL); std::cout << "subclass" << std::endl; } } #endif #if 1 #if 0 std::list<SgNode *> nodes = NodeQuery::querySubTree(project, V_SgClassDefinition); for (std::list<SgNode *>::iterator it = nodes.begin(); it != nodes.end(); ++it ) { SgNode *n = *it; ROSE_ASSERT(n != NULL); SgClassDefinition *classDefinition = isSgClassDefinition(n); ROSE_ASSERT(classDefinition != NULL); std::cout << "Calling getSubclasses on " << classDefinition->unparseToCompleteString() << std::endl; SgClassDefinitionPtrList subclasses = classHierarchy.getSubclasses(classDefinition); // Iterate over all subclasses. for (SgClassDefinitionPtrList::iterator subclassIt = subclasses.begin(); subclassIt != subclasses.end(); ++subclassIt) { SgClassDefinition *subclass = *subclassIt; ROSE_ASSERT(subclass != NULL); std::cout << "subclass" << std::endl; } } #else // Collect all function/method invocations. std::list<SgNode *> nodes = NodeQuery::querySubTree(project, V_SgFunctionCallExp); unsigned int numCallSites = 0; unsigned int numMonomorphicCallSites = 0; unsigned int numPossibleResolutions = 0; // Visit each call site. for (std::list<SgNode *>::iterator it = nodes.begin(); it != nodes.end(); ++it ) { SgNode *n = *it; ROSE_ASSERT(n != NULL); SgFunctionCallExp *functionCallExp = isSgFunctionCallExp(n); ROSE_ASSERT(functionCallExp != NULL); // We are only interested in examining method invocations. bool isDotExp = false; bool isLhsRefOrPtr = false; // std::cout << "method?: " << functionCallExp->unparseToCompleteString() << std::endl; if ( !isMethodCall(functionCallExp, isDotExp, isLhsRefOrPtr) ) continue; // std::cout << "method: " << functionCallExp->unparseToCompleteString() << std::endl; numCallSites++; if ( isDotExp && !isLhsRefOrPtr ) { // If this is a dot expression (i.e., a.foo()), we can // statically determine its type-- unless the left-hand // side is a reference type. numMonomorphicCallSites++; numPossibleResolutions++; // std::cout << "dot: " << functionCallExp->unparseToCompleteString() << std::endl; continue; } // std::cout << "methodPtr: " << functionCallExp->unparseToCompleteString() << std::endl; // Retrieve the static function declaration. SgFunctionDeclaration *functionDeclaration = getFunctionDeclaration(functionCallExp); // Ensure it is actually a method declaration. SgMemberFunctionDeclaration *memberFunctionDeclaration = isSgMemberFunctionDeclaration(functionDeclaration); ROSE_ASSERT(memberFunctionDeclaration != NULL); unsigned int numResolutionsForMethod = 0; // Certainly can be resolved to the static method (unless it // is pure virtual). if ( !isPureVirtual(memberFunctionDeclaration) ) { numResolutionsForMethod++; } #if 0 if ( ( isVirtual(functionDeclaration) ) || ( isDeclaredVirtualWithinAncestor(functionDeclaration) ) ) { #else if ( isVirtual(functionDeclaration) ) { #endif // std::cout << "tracking: " << functionDeclaration->unparseToString() << std::endl; SgClassDefinition *classDefinition = isSgClassDefinition(memberFunctionDeclaration->get_scope()); ROSE_ASSERT(classDefinition != NULL); SgClassDefinitionPtrList subclasses = classHierarchy.getSubclasses(classDefinition); // Iterate over all subclasses. for (SgClassDefinitionPtrList::iterator subclassIt = subclasses.begin(); subclassIt != subclasses.end(); ++subclassIt) { SgClassDefinition *subclass = *subclassIt; ROSE_ASSERT(subclass != NULL); // std::cout << "subclass" << std::endl; // Iterate over all of the methods defined in this subclass. SgDeclarationStatementPtrList &decls = subclass->get_members(); for (SgDeclarationStatementPtrList::iterator declIter = decls.begin(); declIter != decls.end(); ++declIter) { SgDeclarationStatement *declStmt = *declIter; ROSE_ASSERT(declStmt != NULL); SgMemberFunctionDeclaration *method = isSgMemberFunctionDeclaration(declStmt); if ( method == NULL ) { continue; } // std::cout << "checking overrides" << std::endl; // Determine whether subclass of the class defining this // method overrides the method. #if 1 if ( matchingFunctions(method, memberFunctionDeclaration) ) { // std::cout << "overries" << std::endl; // Do not consider a pure virtual method to be an // overriding method (since it can not be invoked). if ( !isPureVirtual(method) ) { numResolutionsForMethod++; } } #else if ( methodOverridesVirtualMethod(method, memberFunctionDeclaration) ) { // std::cout << "overries" << std::endl; numResolutionsForMethod++; } #endif } } if ( numResolutionsForMethod <= 1 ) numMonomorphicCallSites++; numPossibleResolutions += numResolutionsForMethod; if ( ( numResolutionsForMethod ) > 1 ) { std::cout << "Method invocation has " << numResolutionsForMethod << " possible resolutions " << std::endl; std::cout << functionCallExp->unparseToCompleteString() << std::endl; } } } #endif #endif return 0; }
SgClassType * SageUtils::buildClassType(SgClassDeclaration * d) { SgClassType * type = new SgClassType(); type->set_declaration(d); return type; }
void FixupSelfReferentialMacrosInAST::visit ( SgNode* node ) { // DQ (3/11/2006): Set NULL pointers where we would like to have none. // printf ("In FixupSelfReferentialMacrosInAST::visit(): node = %s \n",node->class_name().c_str()); ROSE_ASSERT(node != NULL); switch (node->variantT()) { case V_SgInitializedName: { SgInitializedName* initializedName = isSgInitializedName(node); ROSE_ASSERT(initializedName != NULL); SgType* type = initializedName->get_type()->stripType(); SgClassType* classType = isSgClassType(type); if (classType != NULL) { SgClassDeclaration* targetClassDeclaration = isSgClassDeclaration(classType->get_declaration()); SgName className = targetClassDeclaration->get_name(); // printf ("In FixupSelfReferentialMacrosInAST::visit(): Found a class declaration name = %s \n",className.str()); // For sudo_exec_pty.c also look for siginfo if (className == "sigaction" || className == "siginfo") { // printf ("In FixupSelfReferentialMacrosInAST::visit(): Found a sigaction type \n"); // Note we could also check that the declaration came from a known header file. SgStatement* associatedStatement = isSgStatement(initializedName->get_parent()); if (associatedStatement != NULL) { // Add a macro to undefine the "#define sa_handler __sigaction_handler.sa_handler" macro. // printf ("In FixupSelfReferentialMacrosInAST::visit(): Add a macro to undefine the macro #define sa_handler __sigaction_handler.sa_handler \n"); // PreprocessingInfo* macro = new PreprocessingInfo(DirectiveType, const std::string & inputString,const std::string & filenameString, int line_no , int col_no,int nol, RelativePositionType relPos ); PreprocessingInfo::DirectiveType directiveType = PreprocessingInfo::CpreprocessorUndefDeclaration; // We are puting out all macros anytime we see either type. This might be too much... // From the sigaction.h file (included by signal.h): addMacro(associatedStatement,"#undef sa_handler\n",directiveType); addMacro(associatedStatement,"#undef sa_sigaction\n",directiveType); // From the siginfo.h file (included by signal.h): addMacro(associatedStatement,"#undef si_pid\n", directiveType); addMacro(associatedStatement,"#undef si_uid\n", directiveType); addMacro(associatedStatement,"#undef si_timerid\n",directiveType); addMacro(associatedStatement,"#undef si_overrun\n",directiveType); addMacro(associatedStatement,"#undef si_status\n", directiveType); addMacro(associatedStatement,"#undef si_utime\n", directiveType); addMacro(associatedStatement,"#undef si_stime\n", directiveType); addMacro(associatedStatement,"#undef si_value\n", directiveType); addMacro(associatedStatement,"#undef si_int\n", directiveType); addMacro(associatedStatement,"#undef si_ptr\n", directiveType); addMacro(associatedStatement,"#undef si_addr\n", directiveType); addMacro(associatedStatement,"#undef si_band\n", directiveType); addMacro(associatedStatement,"#undef si_fd\n", directiveType); } } } } default: { // printf ("Not handled in FixupSelfReferentialMacrosInAST::visit(%s) \n",node->class_name().c_str()); } } #if 0 // DQ (12/30/2013): Comments and CPP directives have not yet been attached to the AST, so we can't process them here. // SgLocatedNode* locatedNode = isSgLocatedNode(node); // if (locatedNode != NULL) SgStatement* stmt = isSgStatement(node); if (stmt != NULL) { // Find all #define statements and look for self referencing macros int numberOfComments = -1; if (stmt->getAttachedPreprocessingInfo() != NULL) numberOfComments = stmt->getAttachedPreprocessingInfo()->size(); std::string s = std::string(" --- startOfConstruct: file = " ) + stmt->get_startOfConstruct()->get_filenameString() + " raw filename = " + stmt->get_startOfConstruct()->get_raw_filename() + " raw line = " + StringUtility::numberToString(stmt->get_startOfConstruct()->get_raw_line()) + " raw column = " + StringUtility::numberToString(stmt->get_startOfConstruct()->get_raw_col()) + " #comments = " + StringUtility::numberToString(numberOfComments) + " \n "; AttachedPreprocessingInfoType* comments = stmt->getAttachedPreprocessingInfo(); if (comments != NULL) { printf ("Found attached comments (at %p of type: %s): \n",stmt,stmt->class_name().c_str()); AttachedPreprocessingInfoType::iterator i; for (i = comments->begin(); i != comments->end(); i++) { ROSE_ASSERT ( (*i) != NULL ); printf (" Attached Comment (relativePosition=%s): %s\n", ((*i)->getRelativePosition() == PreprocessingInfo::before) ? "before" : "after", (*i)->getString().c_str()); printf ("Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString()); (*i)->get_file_info()->display("comment/directive location"); } } else { printf ("No attached comments (at %p of type: %s): \n",stmt,stmt->class_name().c_str()); } } #endif }
// DQ (8/27/2006): This functionality already exists elsewhere // It is a shame that it is recreated here as well !!! NameQuerySynthesizedAttributeType NameQuery::queryNameTypeName (SgNode * astNode) { ROSE_ASSERT (astNode != NULL); string typeName = ""; Rose_STL_Container< string > returnList; SgType *type = isSgType (astNode); // printf ("In TransformationSupport::getTypeName(): type->sage_class_name() = %s \n",type->sage_class_name()); if (type != NULL) switch (type->variantT ()) { case V_SgTypeComplex: typeName = "complex"; break; case V_SgTypeImaginary: typeName = "imaginary"; break; case V_SgTypeBool: typeName = "bool"; break; case V_SgEnumType: typeName = "enum"; break; case V_SgTypeChar: typeName = "char"; break; case V_SgTypeVoid: typeName = "void"; break; case V_SgTypeInt: typeName = "int"; break; case V_SgTypeDouble: typeName = "double"; break; case V_SgTypeFloat: typeName = "float"; break; case V_SgTypeLong: typeName = "long"; break; case V_SgTypeLongDouble: typeName = "long double"; break; case V_SgTypeEllipse: typeName = "ellipse"; break; case V_SgTypeGlobalVoid: typeName = "void"; break; case V_SgTypeLongLong: typeName = "long long"; break; case V_SgTypeShort: typeName = "short"; break; case V_SgTypeSignedChar: typeName = "signed char"; break; case V_SgTypeSignedInt: typeName = "signed int"; break; case V_SgTypeSignedLong: typeName = "signed long"; break; case V_SgTypeSignedShort: typeName = "signed short"; break; case V_SgTypeString: typeName = "string"; break; case V_SgTypeUnknown: typeName = "unknown"; break; case V_SgTypeUnsignedChar: typeName = "unsigned char"; break; case V_SgTypeUnsignedInt: typeName = "unsigned int"; break; case V_SgTypeUnsignedLong: typeName = "unsigned long"; break; case V_SgTypeUnsignedShort: typeName = "unsigned short"; break; case V_SgTypeUnsignedLongLong: typeName = "unsigned long long"; break; case V_SgReferenceType: { ROSE_ASSERT (isSgReferenceType (type)->get_base_type () != NULL); Rose_STL_Container< string > subTypeNames = queryNameTypeName (isSgReferenceType (type)->get_base_type ()); typedef Rose_STL_Container< string >::iterator typeIterator; //This iterator will only contain one name for (typeIterator i = subTypeNames.begin (); i != subTypeNames.end (); ++i) { string e = *i; typeName = e; break; } break; } case V_SgPointerType: { ROSE_ASSERT (isSgPointerType (type)->get_base_type () != NULL); Rose_STL_Container< string > subTypeNames = queryNameTypeName (isSgPointerType (type)->get_base_type ()); typedef Rose_STL_Container< string >::iterator typeIterator; //This iterator will only contain one name for (typeIterator i = subTypeNames.begin (); i != subTypeNames.end (); ++i) { string e = *i; typeName = e; break; } break; } case V_SgModifierType: { ROSE_ASSERT (isSgModifierType (type)->get_base_type () != NULL); Rose_STL_Container< string > subTypeNames = queryNameTypeName (isSgModifierType (type)->get_base_type ()); typedef Rose_STL_Container< string >::iterator typeIterator; //This iterator will only contain one name for (typeIterator i = subTypeNames.begin (); i != subTypeNames.end (); ++i) { string e = *i; typeName = e; break; } break; } case V_SgNamedType: { SgNamedType *sageNamedType = isSgNamedType (type); ROSE_ASSERT (sageNamedType != NULL); typeName = sageNamedType->get_name ().str (); break; } case V_SgClassType: { SgClassType *sageClassType = isSgClassType (type); ROSE_ASSERT (sageClassType != NULL); typeName = sageClassType->get_name ().str (); break; } case V_SgTypedefType: { SgTypedefType *sageTypedefType = isSgTypedefType (type); ROSE_ASSERT (sageTypedefType != NULL); typeName = sageTypedefType->get_name ().str (); break; } case V_SgPointerMemberType: { SgPointerMemberType *pointerMemberType = isSgPointerMemberType (type); ROSE_ASSERT (pointerMemberType != NULL); SgClassType *classType = isSgClassType(pointerMemberType->get_class_type()->stripTypedefsAndModifiers()); ROSE_ASSERT (classType != NULL); SgClassDeclaration *classDeclaration = isSgClassDeclaration(classType->get_declaration()); ROSE_ASSERT (classDeclaration != NULL); typeName = classDeclaration->get_name ().str (); break; } case V_SgArrayType: { ROSE_ASSERT (isSgArrayType (type)->get_base_type () != NULL); Rose_STL_Container< string > subTypeNames = queryNameTypeName (isSgArrayType (type)->get_base_type ()); typedef Rose_STL_Container< string >::iterator typeIterator; //This iterator will only contain one name for (typeIterator i = subTypeNames.begin (); i != subTypeNames.end (); ++i) { string e = *i; typeName = e; break; } break; } case V_SgFunctionType: { SgFunctionType *functionType = isSgFunctionType (type); ROSE_ASSERT (functionType != NULL); typeName = functionType->get_mangled_type ().str (); break; } case V_SgMemberFunctionType: { SgMemberFunctionType *memberFunctionType = isSgMemberFunctionType (type); ROSE_ASSERT (memberFunctionType != NULL); SgClassType *classType = isSgClassType(memberFunctionType->get_class_type()->stripTypedefsAndModifiers()); ROSE_ASSERT (classType != NULL); SgClassDeclaration *classDeclaration = isSgClassDeclaration(classType->get_declaration()); ROSE_ASSERT (classDeclaration != NULL); typeName = classDeclaration->get_name ().str (); break; } case V_SgTypeWchar: typeName = "wchar"; break; case V_SgTypeDefault: typeName = "default"; break; default: printf ("default reached in switch within TransformationSupport::getTypeName type->sage_class_name() = %s variant = %d \n", type->sage_class_name (), type->variant ()); ROSE_ABORT (); break; } // Fix for purify problem report // typeName = ROSE::stringDuplicate(typeName); if (typeName.size () > 0) returnList.push_back (typeName); //ROSE_ASSERT(typeName.c_str() != NULL); // return typeName; return returnList; //return ROSE::stringDuplicate(typeName.c_str()); }