SgType* findBaseType(SgType* sageType){ ROSE_ASSERT( sageType != NULL); SgType* baseType = sageType; switch(sageType->variantT()) { case V_SgReferenceType: { baseType = isSgReferenceType(sageType)->get_base_type(); break; } case V_SgPointerType: { baseType = isSgPointerType(sageType)->get_base_type(); break; } case V_SgTypedefType: { while(isSgTypedefType(baseType) != NULL) baseType = isSgTypedefType(baseType)->get_base_type(); break; } default: break; }; ROSE_ASSERT ( baseType != NULL ); return baseType; };
void StaticConstructorTraversal::visit(SgNode *n) { // Get declared variables SgInitializedName *vName = isSgInitializedName(n); if (vName && !isAcreIgnore(vName->get_declaration())) { Sg_File_Info *fInfo = vName->get_file_info(); SgScopeStatement *scope = vName->get_scope(); // Find global variables (variables in namespaces count, e.g. std) if (!fInfo->isCompilerGenerated() && (isSgGlobal(scope) || isSgNamespaceDefinitionStatement(scope))) { // Walk typedefs until reach pointer to base type SgTypedefType *tdType = isSgTypedefType(vName->get_type()); while (tdType && isSgTypedefType(tdType->get_base_type())) tdType = isSgTypedefType(tdType->get_base_type()); // Determine if type is a class (i.e. type with a constructor) SgClassType *cType = isSgClassType(vName->get_type()); if (tdType) cType = isSgClassType(tdType->get_base_type()); // Output location of globals with a static constructor if (cType) { *out << "Static Constructor Violation: " << fInfo->get_filename() << " @ " << fInfo->get_line() << "\n"; } } } }
/* * The function: * buildTypedefTranslationTable() * takes as a parameter a SgProject*. It will return a map<SgTypedefDeclaration*, SgType*> * where the idea is that all SgTypedefDeclaration* are unique, and therefore it is * possible to create a map with it's corresponding type for easy access. */ map< SgTypedefDeclaration*, SgType*> typeInterpreter::buildTypedefTranslationTable(SgProject* project){ ROSE_ASSERT (project != NULL); const SgFilePtrList sageFilePtrList = project->get_fileList (); //Iterate over all global scopes in the all the files the project spans. for (unsigned int i = 0; i < sageFilePtrList.size (); i += 1) { const SgFile *sageFile = isSgFile (sageFilePtrList[i]); ROSE_ASSERT (sageFile != NULL); if(isSgSourceFile(sageFile) == NULL ) continue; SgGlobal *sageGlobal = isSgSourceFile(sageFile)->get_globalScope (); ROSE_ASSERT (sageGlobal != NULL); SgTypedefDeclaration* typedefDeclaration; //Find all TypedefdefDeclarations in current global scope. vector < SgNode * > typedefDeclarationList = NodeQuery::querySubTree (sageGlobal, NodeQuery::TypedefDeclarations); unique(typedefDeclarationList.begin(),typedefDeclarationList.end()); //Iterate over all SgTypedefDeclarations in current global scope, //and find corresponding SgType*. for (vector < SgNode * >::iterator typedefDeclarationElm = typedefDeclarationList.begin (); typedefDeclarationElm != typedefDeclarationList.end (); ++typedefDeclarationElm) { typedefDeclaration = isSgTypedefDeclaration (*typedefDeclarationElm); ROSE_ASSERT (typedefDeclaration != NULL); //We only register a typedef once ROSE_ASSERT (typedefTranslationTable.find (typedefDeclaration) == typedefTranslationTable.end ()); SgType* typedefBaseType = typedefDeclaration->get_base_type(); ROSE_ASSERT(typedefBaseType != NULL ); SgType* baseType = typedefBaseType->findBaseType(); //If the SgTypedefDeclarations has a base type which is of SgTypedefType, find a //SgType* which is not of type SgTypedefType. That is the corresponging SgType*. while(isSgTypedefType(baseType) != NULL) baseType = isSgTypedefType(baseType)->get_base_type(); /* cout << "The name of the typedef is:" << typedefDeclaration->get_name().str() ; string baseName = TransformationSupport::getTypeName(baseType); cout << " The correpsonding basetype is:" << baseName << endl; if(isSgClassType(baseType) == NULL) cout << "It is NOT a CLASS TYPE." << endl; */ ROSE_ASSERT( baseType != NULL ); typedefTranslationTable[typedefDeclaration] = baseType; } } return typedefTranslationTable; } /* End method: buildTypedefTranslationTable */
SgNode * findClassDeclarationFromType (SgNodePtrVector nodeVector, SgType * sageType) { string sageName = TransformationSupport::getTypeName (sageType); ROSE_ASSERT (sageName.length () > 0); typedef SgNodePtrVector::iterator nodeIterator; SgNode *returnNode = NULL; vector < SgNode * >tempNodeList; /* The traversal flag is set so that the class declaration pointer in * the typedef is not traversed. Therefore I have to look for this * pointer myself. */ if (isSgTypedefType (sageType) != NULL) { for (nodeIterator i = nodeVector.begin (); i != nodeVector.end (); ++i) { ROSE_ASSERT (isSgScopeStatement (*i) != NULL); tempNodeList = NodeQuery::querySubTree (*i, new SgName (sageName.c_str ()), queryNodeClassDeclarationFromTypedefName, NodeQuery::ChildrenOnly); if (tempNodeList.empty () != true) { ROSE_ASSERT (tempNodeList.size () < 2); returnNode = isSgNode (*tempNodeList.begin ()); ROSE_ASSERT (returnNode != NULL); } } if (tempNodeList.empty () == true) cerr << "the tempNodeList is empty.\n"; else cerr << "the tempNodeList is not empty.\n"; } else { /* If the class declaraiton was not hidden in a typedef look for it * elsewhere. * */ if (tempNodeList.empty () == true) for (nodeIterator i = nodeVector.begin (); i != nodeVector.end (); ++i) { ROSE_ASSERT (isSgScopeStatement (*i) != NULL); tempNodeList = NodeQuery::querySubTree (*i, new SgName (sageName.c_str ()), NodeQuery::ClassDeclarationFromName, NodeQuery::ChildrenOnly); if (tempNodeList.empty () != true) { ROSE_ASSERT (tempNodeList.size () < 2); returnNode = isSgNode (*tempNodeList.begin ()); ROSE_ASSERT (returnNode != NULL); } } } return returnNode; }
void ModelBuilder::add(Model::model_t & model, SgType * sg_type) { SgModifierType * modifier_type = isSgModifierType(sg_type); if (modifier_type != NULL) { add(model, modifier_type->get_base_type()); return; } Model::type_t element = Model::build<Model::e_model_type>(); element->node->type = sg_type; SgNamedType * named_type = isSgNamedType(sg_type); SgArrayType * array_type = isSgArrayType(sg_type); SgPointerType * pointer_type = isSgPointerType(sg_type); SgReferenceType * reference_type = isSgReferenceType(sg_type); if (named_type != NULL) { SgClassType * class_type = isSgClassType(named_type); SgEnumType * enum_type = isSgEnumType(named_type); SgTypedefType * typedef_type = isSgTypedefType(named_type); SgDeclarationStatement * decl_stmt = named_type->get_declaration()->get_firstNondefiningDeclaration(); assert(decl_stmt != NULL); SgSymbol * decl_sym = decl_stmt->get_symbol_from_symbol_table(); assert(decl_sym != NULL); if (class_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_class_type; SgClassSymbol * class_sym = isSgClassSymbol(decl_sym); assert(class_sym != NULL); element->node->base_class = model.lookup_class(class_sym); if (element->node->base_class == NULL) { add(model, class_sym); element->node->base_class = model.lookup_class(class_sym); } assert(element->node->base_class != NULL); } else if (enum_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_enum_type; SgEnumSymbol * enum_sym = isSgEnumSymbol(decl_sym); assert(enum_sym != NULL); element->node->enum_symbol = enum_sym; } else if (typedef_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_typedef_type; SgTypedefSymbol * typedef_sym = isSgTypedefSymbol(decl_sym); assert(typedef_sym != NULL); element->node->typedef_symbol = typedef_sym; element->node->base_type = model.lookup_type(typedef_type->get_base_type()); if (element->node->base_type == NULL) { add(model, typedef_type->get_base_type()); element->node->base_type = model.lookup_type(typedef_type->get_base_type()); } assert(element->node->base_type != NULL); } else assert(false); } else if (array_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_array_type; element->node->base_type = model.lookup_type(array_type->get_base_type()); if (element->node->base_type == NULL) { add(model, array_type->get_base_type()); element->node->base_type = model.lookup_type(array_type->get_base_type()); } assert(element->node->base_type != NULL); } else if (pointer_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_pointer_type; element->node->base_type = model.lookup_type(pointer_type->get_base_type()); if (element->node->base_type == NULL) { add(model, pointer_type->get_base_type()); element->node->base_type = model.lookup_type(pointer_type->get_base_type()); } assert(element->node->base_type != NULL); } else if (reference_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_reference_type; element->node->base_type = model.lookup_type(reference_type->get_base_type()); if (element->node->base_type == NULL) { add(model, reference_type->get_base_type()); element->node->base_type = model.lookup_type(reference_type->get_base_type()); } assert(element->node->base_type != NULL); } else { element->node->kind = Model::node_t<Model::e_model_type>::e_native_type; } element->scope->parent.a_namespace = NULL; /// \todo model.types.push_back(element); }
bool Type::isTypedef() const { return isSgTypedefType(orig_) != 0; }