DoxygenGroup * DoxygenFile::findGroup(DoxygenComment *comm) { AttachedPreprocessingInfoType *info = commentParent->getAttachedPreprocessingInfo(); AttachedPreprocessingInfoType::iterator groupStart; bool groupStartValid = false; for (AttachedPreprocessingInfoType::iterator i = info->begin(); i != info->end(); ++i) { if (Doxygen::isGroupStart(*i)) { groupStart = i; groupStartValid = true; } else if (Doxygen::isGroupEnd(*i)) { groupStartValid = false; } else if (*i == comm->originalComment) { if (groupStartValid) { for (map<string, DoxygenGroup *>::iterator j = groups.begin(); j != groups.end(); ++j) { if (j->second->groupStart == *groupStart) { return j->second; } } } return 0; } } puts("findGroup called on the wrong file!"); return 0; }
void visitorTraversal::visit(SgNode* n) { // On each node look for any comments of CPP directives SgLocatedNode* locatedNode = isSgLocatedNode(n); if (locatedNode != NULL) { AttachedPreprocessingInfoType* comments = locatedNode->getAttachedPreprocessingInfo(); if (comments != NULL) { printf ("Found attached comments (to IR node at %p of type: %s): \n",locatedNode,locatedNode->class_name().c_str()); int counter = 0; AttachedPreprocessingInfoType::iterator i; for (i = comments->begin(); i != comments->end(); i++) { printf (" Attached Comment #%d in file %s (relativePosition=%s): classification %s :\n%s\n", counter++,(*i)->get_file_info()->get_filenameString().c_str(), ((*i)->getRelativePosition() == PreprocessingInfo::before) ? "before" : "after", PreprocessingInfo::directiveTypeName((*i)->getTypeOfDirective()).c_str(), (*i)->getString().c_str()); } } else { printf ("No attached comments (at %p of type: %s): \n",locatedNode,locatedNode->sage_class_name()); } } }
bool isDocumented(SgFunctionDeclaration* funcDecl) { bool isComment = false; if(funcDecl == NULL ) return isComment; AttachedPreprocessingInfoType* comments = funcDecl->getAttachedPreprocessingInfo(); if (comments!=NULL) { AttachedPreprocessingInfoType::iterator i; for (i=comments->begin(); i!= comments->end(); i++) { PreprocessingInfo::DirectiveType dirType = (*i)->getTypeOfDirective(); if( dirType == PreprocessingInfo::C_StyleComment || dirType == PreprocessingInfo::CplusplusStyleComment ) { isComment =true; break; } } } return isComment; };
void visit ( SgNode* n ) { SgLocatedNode* locatedNode = isSgLocatedNode(n); if (locatedNode != NULL) { AttachedPreprocessingInfoType* comments = locatedNode->getAttachedPreprocessingInfo(); if (comments != NULL) { printf ("Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->sage_class_name()); 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()); #if 1 // This does not appear to be a valid object when read in from an AST file. printf ("Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString()); #endif #if 1 // This does not appear to be a valid object when read in from an AST file. (*i)->get_file_info()->display("comment/directive location"); #endif } } } }
void DoxygenComment::attach(DoxygenFile *newParent, DoxygenGroup *newGroup) { AttachedPreprocessingInfoType* attachedComments = newGroup->comment->originalNode->getAttachedPreprocessingInfo(); AttachedPreprocessingInfoType::iterator groupEnd = std::find( attachedComments->begin(), attachedComments->end(), newGroup->groupEnd ); ROSE_ASSERT( groupEnd != attachedComments->end() ); attach(newParent->commentParent, groupEnd ); originalFile = newParent; }
virtual void visit(SgNode *n) { SgDeclarationStatement *st = isSgDeclarationStatement(n); if (!st) { return; } if (!isRecognizedDeclaration(st)) { return; } string proto = getProtoName(st); SgDeclarationStatement *dxSt = getDoxygenAttachedDeclaration(st); if ((*symTab)[proto].count(dxSt) == 0) { DoxygenCommentListAttribute *attr = new DoxygenCommentListAttribute(); // King84 (2010.08.03) : This seems to be called with the same node multiple times. // From what I can tell, this is because a single function has been documented multiple times. // At the moment this function is AssemblerX86::AssemblerX86() from src/frontend/Disassemblers/AssemblerX86.h // For now, we will print out a warning and use the new documentation (instead of addNewAttribute we use setAttribute). if (dxSt->attributeExists("DoxygenCommentList")) { std::cerr << "Warning: Multiple Doxygen comments found for function " << dxSt->get_mangled_name().getString() << " at file " << dxSt->get_file_info()->get_filenameString() << ":" << dxSt->get_file_info()->get_line() << "," << dxSt->get_file_info()->get_col() << ". Picking the last." << std::endl; } dxSt->setAttribute("DoxygenCommentList", attr); // dxSt->addNewAttribute("DoxygenCommentList", attr); (*symTab)[proto][dxSt] = &(attr->commentList); } list<DoxygenComment *> *commentList = (*symTab)[proto][dxSt]; AttachedPreprocessingInfoType *info = st->getAttachedPreprocessingInfo(); if (info) { for (AttachedPreprocessingInfoType::iterator i = info->begin(); i != info->end(); ++i) { PreprocessingInfo *pi = *i; if (pi->getRelativePosition() == PreprocessingInfo::before && DoxygenComment::isDoxygenComment(pi)) { commentList->push_back(new DoxygenComment(st, pi)); } } } }
void DoxygenFile::sortComments( bool (*pred)(DoxygenComment*,DoxygenComment*) ) { ROSE_ASSERT(isSgDeclarationStatement(commentParent) != NULL ); //Create map between PreprocessingInfo objects and DoxygenComments // AttachedPreprocessingInfoType* comments = commentParent->getAttachedPreprocessingInfo(); PreprocessingInfoToDoxygenComment convert(&commentMap, pred ); IsDoxygenCommentNotGroup isDox(&commentMap) ; for( std::map<std::string, DoxygenGroup *>::iterator gItr = groups.begin(); gItr != groups.end(); ++ gItr ) { DoxygenGroup* doxGroup = gItr->second; //Find the iterator to the beginning and end of this group in AttachedPreprocessingInfoType //of the original AST node. AttachedPreprocessingInfoType* currentComments = doxGroup->comment->originalNode->getAttachedPreprocessingInfo(); AttachedPreprocessingInfoType::iterator beg_group = std::find(currentComments->begin(), currentComments->end(), doxGroup->groupStart); ROSE_ASSERT( beg_group != currentComments->end() ); AttachedPreprocessingInfoType::iterator end_group = std::find(beg_group, currentComments->end(), doxGroup->groupEnd); ROSE_ASSERT( end_group != currentComments->end() ); //Find the beginning and end of the DoxygenComments that is not the comment for the group start '//@{' //or group end '//@}' std::vector<PreprocessingInfo*>::iterator itBeg = find_if( beg_group, end_group,isDox ); ROSE_ASSERT( itBeg != end_group ); std::vector<PreprocessingInfo*>::iterator itEnd = ( --find_if( itBeg, end_group,not1<IsDoxygenCommentNotGroup>(isDox) )); ROSE_ASSERT( itEnd != end_group ); sort(itBeg,itEnd,convert); } }
void visitorTraversal::visit (SgNode * n) { // On each node look for any comments of CPP directives SgLocatedNode *locatedNode = isSgLocatedNode (n); if (locatedNode != NULL) { AttachedPreprocessingInfoType *comments = locatedNode->getAttachedPreprocessingInfo (); if (comments != NULL) { printf ("-----------------------------------------------\n"); printf ("Found an IR node with preprocessing Info attached:\n"); printf ("(memory address: %p Sage type: %s) in file \n%s (line %d column %d) \n", locatedNode, locatedNode->class_name ().c_str (), (locatedNode->get_file_info ()->get_filenameString ()).c_str (), locatedNode->get_file_info ()->get_line(), locatedNode->get_file_info ()->get_col() ); int counter = 0; AttachedPreprocessingInfoType::iterator i; for (i = comments->begin (); i != comments->end (); i++) { printf("-------------PreprocessingInfo #%d ----------- : \n",counter++); printf("classification = %s:\n String format = %s\n", PreprocessingInfo::directiveTypeName((*i)->getTypeOfDirective ()). c_str (), (*i)->getString ().c_str ()); printf ("relative position is = "); if ((*i)->getRelativePosition () == PreprocessingInfo::inside) printf ("inside\n"); else printf ("%s\n", \ ((*i)->getRelativePosition () == PreprocessingInfo::before) ? "before" : "after"); } } } }
virtual void visit(SgNode *n) { SgVariableDeclaration *vd = isSgVariableDeclaration(n); if (!vd) { return; } if (isRecognizedDeclaration(vd)) { return; } AttachedPreprocessingInfoType *info = vd->getAttachedPreprocessingInfo(); if (info) { DoxygenFile *f = new DoxygenFile(vd); DoxygenGroup *currentGroup = 0; DoxygenComment *groupComment = 0; (*docsList)[vd->get_file_info()->get_filenameString()] = f; for (AttachedPreprocessingInfoType::iterator i = info->begin(); i != info->end(); ++i) { PreprocessingInfo *pi = *i; //printf("pass %d: processing comment %s\n", inexact ? 3 : 2, pi->getString().c_str()); //printf("processing comment %s\n", pi->getString().c_str()); if (DoxygenComment::isDoxygenComment(pi)) { DoxygenComment *comm = new DoxygenComment(vd, pi); comm->originalFile = f; if (comm->entry.type() == DoxygenEntry::None) { if (comm->entry.hasName()) { // this is a group //printf("name = '%s'\n", comm->entry.name().c_str()); if (currentGroup) { currentGroup->comment = comm; } else { groupComment = comm; } } else { delete comm; continue; } } commentList->push_back(comm); #if 0 pair<SymTab::iterator, SymTab::iterator> bounds = symTab->equal_range(DoxygenClass::getProtoName(comm->entry.prototype)); for (SymTab::iterator i = bounds.first; i != bounds.second; ) { if (inexact || comm->entry.prototype == getQualifiedPrototype((*i).second)) { DoxygenCommentListAttribute *attr = dynamic_cast<DoxygenCommentListAttribute *>((*i).second->attribute()["DoxygenCommentList"]); ROSE_ASSERT(attr); printf("attaching to node %s\n", (*i).second->unparseToString().c_str()); attr->commentList.push_back(comm); SymTab::iterator ii = i; ++i; symTab->erase(ii); } else { ++i; } } #endif } else if (isGroupStart(pi)) { if (currentGroup) { puts("Group already open!"); } //puts("opening group"); currentGroup = new DoxygenGroup(); currentGroup->groupStart = *i; currentGroup->comment = groupComment; groupComment = 0; } else if (isGroupEnd(pi)) { //puts("closing group"); if (!currentGroup) { puts("Group-end encountered without group begin!"); } else { currentGroup->groupEnd = *i; if (currentGroup->comment) { f->groups[currentGroup->comment->entry.name()] = currentGroup; } else { puts("Group wasn't given a name!"); } currentGroup = 0; } } } } }
Rose_STL_Container< ControlStructureContainer * >queryFindCommentsInScope (const string stringPrefixToMatch, const string stringToMatch, SgScopeStatement * sageScopeStatement) { ROSE_ASSERT (stringPrefixToMatch.length () > 0); ROSE_ASSERT (stringToMatch.length () > 0); ROSE_ASSERT (sageScopeStatement != NULL); Rose_STL_Container< ControlStructureContainer * >returnList; //find all pragmas who match the stringToMatch //cout << "Before pragma search" << endl; /*list < SgNode * >pragmaStatements = NodeQuery::querySubTree (sageScopeStatement, new SgName (stringToMatch.c_str ()), NodeQuery::PragmaDeclarationFromName); */ //list<SGNode*> pragmaStatements ; //cout << "After pragma search" << endl; /* cout << "BEFORE LIST" << endl; list < SgNode * >pragmaStatements = queryNodePragmaStatementFromName2(sageScopeStatement, new SgName(stringToMatch.c_str())); cout << "AFTER LIST" << endl;*/ //return the pragmas in containers /* for (list < SgNode * >::iterator i = pragmaStatements.begin (); i != pragmaStatements.end (); ++i) { SgPragmaDeclaration *sagePragma = isSgPragmaDeclaration (*i); ROSE_ASSERT (sagePragma); ROSE_ASSERT (sagePragma->get_pragma () != NULL); ROSE_ASSERT (sagePragma->get_pragma ()->get_pragma ()); ControlStructureContainer *container = new ControlStructureContainer (); container->setPragmaString (sagePragma->get_pragma ()->get_pragma ()); container->setAssociatedStatement (sagePragma); returnList.push_back (container); } */ //find all statements in the current scope if (sageScopeStatement->variantT () == V_SgClassDefinition) { SgDeclarationStatementPtrList statementsInScope = sageScopeStatement->getDeclarationList (); SgDeclarationStatementPtrList::iterator i; for (i = statementsInScope.begin (); i != statementsInScope.end (); i++) { SgLocatedNode *locatedNode = isSgLocatedNode (*i); ROSE_ASSERT (locatedNode != NULL); //find all comments attached to current node. AttachedPreprocessingInfoType *comments = locatedNode->getAttachedPreprocessingInfo (); if(locatedNode->variantT() == V_SgPragmaDeclaration){ SgPragmaDeclaration* sagePragmaDeclaration = isSgPragmaDeclaration(locatedNode); ROSE_ASSERT( sagePragmaDeclaration ); ROSE_ASSERT( sagePragmaDeclaration->get_pragma() != NULL ); string pragmaDeclarationString = sagePragmaDeclaration->get_pragma()->get_pragma(); //extract the part before the leftmost = is pragmaDeclarationString pragmaDeclarationString = pragmaDeclarationString.substr(0,pragmaDeclarationString.find("=")); //if the name-criteria is met accept node if(pragmaDeclarationString.find( stringToMatch ) != string::npos ){ cout << pragmaDeclarationString << endl; ControlStructureContainer *container = new ControlStructureContainer (); container->setPragmaString (sagePragmaDeclaration->get_pragma ()->get_pragma ()); container->setAssociatedStatement (sagePragmaDeclaration); returnList.push_back (container); } } if (comments != NULL) { //We need to find comments which fits the criteria printf ("Found attached comments (at %p of type: %s): \n", locatedNode, locatedNode->sage_class_name ()); AttachedPreprocessingInfoType::iterator j; for (j = comments->begin (); j != comments->end (); j++) { ROSE_ASSERT ((*j) != NULL); string comment = (*j)->getString (); //see if comment begins with stringPrefixToMatch string tempString = comment.substr (0, comment.find (' ')); if (tempString == stringPrefixToMatch) { //+stringPrefixToMatch ){ //cout << "Found string" << endl; comment = StringUtility::copyEdit (comment, stringPrefixToMatch, ""); //see if the comment has an element which matches the stringToMatch if (comment.find (stringToMatch) != string::npos) { //puit the matching comment into a container ControlStructureContainer *container = new ControlStructureContainer (); container->setPragmaString (comment); container->setAssociatedStatement (locatedNode); returnList.push_back (container); } } // printf (" Attached Comment (relativePosition=%s):\n %s\n Next comment: \n", // ((*j)->relativePosition == PreprocessingInfo::before) ? "before" : "after",(*j)->getString()); } } } } else { // AS 12/18/03 PS!! The same as the above, but a different iterator. Will replace this when a // different solution has arisen. PS!! SgStatementPtrList statementsInScope = sageScopeStatement->getStatementList (); SgStatementPtrList::iterator i; for (i = statementsInScope.begin (); i != statementsInScope.end (); i++) { SgLocatedNode *locatedNode = isSgLocatedNode (*i); ROSE_ASSERT (locatedNode != NULL); if(locatedNode->variantT() == V_SgPragmaDeclaration){ SgPragmaDeclaration* sagePragmaDeclaration = isSgPragmaDeclaration(locatedNode); ROSE_ASSERT( sagePragmaDeclaration ); ROSE_ASSERT( sagePragmaDeclaration->get_pragma() != NULL ); string pragmaDeclarationString = sagePragmaDeclaration->get_pragma()->get_pragma(); //extract the part before the leftmost = is pragmaDeclarationString pragmaDeclarationString = pragmaDeclarationString.substr(0,pragmaDeclarationString.find("=")); //if the name-criteria is met accept node if(pragmaDeclarationString.find( stringToMatch ) != string::npos ){ cout << pragmaDeclarationString << endl; ControlStructureContainer *container = new ControlStructureContainer (); container->setPragmaString (sagePragmaDeclaration->get_pragma ()->get_pragma ()); container->setAssociatedStatement (sagePragmaDeclaration); returnList.push_back (container); } } //find all comments attached to current node. AttachedPreprocessingInfoType *comments = locatedNode->getAttachedPreprocessingInfo (); if (comments != NULL) { //We need to find comments which fits the criteria //printf ("Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->sage_class_name()); AttachedPreprocessingInfoType::iterator j; for (j = comments->begin (); j != comments->end (); j++) { ROSE_ASSERT ((*j) != NULL); string comment = (*j)->getString (); //see if comment begins with stringPrefixToMatch string tempString = comment.substr (0, comment.find (' ')); if (tempString == stringPrefixToMatch) { //+stringPrefixToMatch ){ comment = StringUtility::copyEdit (comment, stringPrefixToMatch, ""); cout << "And the string is: " << comment << endl; if (comment.find (stringToMatch) != string::npos) { cout << "And even the string is matched." << endl; //ROSE_ASSERT(comment.find('=') != comment.length()); //string variableName = comment.substr(comment.find(stringToMatch), comment.find('=')); cout << "And the string is a match" << endl; //puit the matching comment into a container ControlStructureContainer *container = new ControlStructureContainer (); container->setPragmaString (comment); container->setAssociatedStatement (locatedNode); returnList.push_back (container); } } /* printf (" Attached Comment (relativePosition=%s):\n %s\n Next comment: \n", ((*j)->relativePosition == PreprocessingInfo::before) ? "before" : "after", (*j)->getString ());*/ } } } } return returnList; } /* End function: queryFindCommentsInScope() */
void visitorTraversal::visit(SgNode* n) { SgFile* file = isSgFile(n); if (file != NULL) { filename = file->get_sourceFileNameWithPath(); } // On each statement node and output it's position. SgStatement* statement = isSgStatement(n); bool outputStatement = (statement != NULL) ? true : false; // Check for the statement to exist in the input source file outputStatement = outputStatement && (statement->get_file_info()->get_filenameString() == filename); // Skip SgGlobal IR nodes outputStatement = outputStatement && (isSgGlobal(statement) == NULL); if (outputStatement == true) { AttachedPreprocessingInfoType* comments = statement->getAttachedPreprocessingInfo(); if (comments != NULL) { // printf ("Found attached comments (to IR node at %p of type: %s): \n",statement,statement->class_name().c_str()); // int counter = 0; AttachedPreprocessingInfoType::iterator i; for (i = comments->begin(); i != comments->end(); i++) { #if 0 printf (" Attached Comment #%d in file %s (relativePosition=%s): classification %s :\n%s\n", counter++,(*i)->get_file_info()->get_filenameString().c_str(), ((*i)->getRelativePosition() == PreprocessingInfo::before) ? "before" : "after", PreprocessingInfo::directiveTypeName((*i)->getTypeOfDirective()).c_str(), (*i)->getString().c_str()); #endif // Mark comments and CPP directives a few different colors. int startingLineNumber = (*i)->get_file_info()->get_line(); int startingColumnNumber = (*i)->get_file_info()->get_col(); // Subtract 1 from number of lines to avoid over counting the current line. int endingLineNumber = startingLineNumber + ((*i)->getNumberOfLines() - 1); int endingColumnNumber = (*i)->getColumnNumberOfEndOfString(); string color = directiveTypeColor((*i)->getTypeOfDirective()); #if 0 printf ("%d,%d,%s,%d,%d\n",startingLineNumber,startingColumnNumber,color.c_str(),endingLineNumber,endingColumnNumber); #endif dataFile << startingLineNumber << "," << startingColumnNumber << "," << color << "," << endingLineNumber << "," << endingColumnNumber << endl; } } else { // printf ("No attached comments (at %p of type: %s): \n",statement,statement->sage_class_name()); } ROSE_ASSERT(statement->get_startOfConstruct() != NULL); int startingLineNumber = statement->get_startOfConstruct()->get_line(); int startingColumnNumber = statement->get_startOfConstruct()->get_col(); if (statement->get_endOfConstruct() == NULL) { printf ("Error: statement->get_endOfConstruct() == NULL (statement = %p = %s) \n",statement,statement->class_name().c_str()); } ROSE_ASSERT(statement->get_endOfConstruct() != NULL); int endingLineNumber = statement->get_endOfConstruct()->get_line(); int endingColumnNumber = statement->get_endOfConstruct()->get_col(); // Catch errors (likely compiler generate IR node or NULL file) if (endingLineNumber == 0) { endingLineNumber = startingLineNumber; endingColumnNumber = startingColumnNumber; } #if 0 // Mark all statements blue string color = "blue"; if (isSgScopeStatement(statement) != NULL) color = "red"; #else string color = nodeColor(statement); #endif #if 0 printf ("%d,%d,%s,%d,%d %s = %p \n",startingLineNumber,startingColumnNumber,color.c_str(),endingLineNumber,endingColumnNumber,statement->class_name().c_str(),statement); #endif dataFile << startingLineNumber << "," << startingColumnNumber << "," << color << "," << endingLineNumber << "," << endingColumnNumber << endl; } // On each statement node and output it's position. SgExpression* expression = isSgExpression(n); bool outputExpression = (expression != NULL) ? true : false; // Check for the statement to exist in the input source file outputExpression = outputExpression && (expression->get_file_info()->get_filenameString() == filename); if (outputExpression == true) { // Currently we don't attach comments to expressions (as I recall). AttachedPreprocessingInfoType* comments = expression->getAttachedPreprocessingInfo(); ROSE_ASSERT(comments == NULL); ROSE_ASSERT(expression->get_startOfConstruct() != NULL); int startingLineNumber = expression->get_startOfConstruct()->get_line(); int startingColumnNumber = expression->get_startOfConstruct()->get_col(); // For expressions I would like to be a bit more tollerant of a few mistakes. if (expression->get_endOfConstruct() == NULL) { printf ("Error: expression->get_endOfConstruct() == NULL (expression = %p = %s) \n",expression,expression->class_name().c_str()); } // ROSE_ASSERT(expression->get_endOfConstruct() != NULL); int endingLineNumber = startingLineNumber; int endingColumnNumber = startingColumnNumber; if (expression->get_endOfConstruct() != NULL) { endingLineNumber = expression->get_endOfConstruct()->get_line(); endingColumnNumber = expression->get_endOfConstruct()->get_col(); } // Catch errors (likely compiler generate IR node or NULL file) if (endingLineNumber == 0) { endingLineNumber = startingLineNumber; endingColumnNumber = startingColumnNumber; } string color = nodeColor(expression); #if 0 printf ("%d,%d,%s,%d,%d %s = %p \n",startingLineNumber,startingColumnNumber,color.c_str(),endingLineNumber,endingColumnNumber,expression->class_name().c_str(),expression); #endif dataFile << startingLineNumber << "," << startingColumnNumber << "," << color << "," << endingLineNumber << "," << endingColumnNumber << endl; } // On each statement node and output it's position. SgInitializedName* initializedName = isSgInitializedName(n); bool outputInitializedName = (initializedName != NULL) ? true : false; // Check for the statement to exist in the input source file outputInitializedName = outputInitializedName && (initializedName->get_file_info()->get_filenameString() == filename); if (outputInitializedName == true) { // Currently we don't attach comments to SgInitializedName IR nodes (as I recall). // AttachedPreprocessingInfoType* comments = initializedName->getAttachedPreprocessingInfo(); // ROSE_ASSERT(comments == NULL); ROSE_ASSERT(initializedName->get_startOfConstruct() != NULL); int startingLineNumber = initializedName->get_startOfConstruct()->get_line(); int startingColumnNumber = initializedName->get_startOfConstruct()->get_col(); #if 0 // For SgInitializedName I would like to be a bit more tollerant of a few mistakes. if (initializedName->get_endOfConstruct() == NULL) { printf ("Note: initializedName->get_endOfConstruct() == NULL is OK (initializedName = %p = %s) \n",initializedName,initializedName->class_name().c_str()); } // ROSE_ASSERT(initializedName->get_endOfConstruct() != NULL); #endif int endingLineNumber = startingLineNumber; int endingColumnNumber = startingColumnNumber; if (initializedName->get_endOfConstruct() != NULL) { endingLineNumber = initializedName->get_endOfConstruct()->get_line(); endingColumnNumber = initializedName->get_endOfConstruct()->get_col(); } // Catch errors (likely compiler generate IR node or NULL file) if (endingLineNumber == 0) { endingLineNumber = startingLineNumber; endingColumnNumber = startingColumnNumber; } string color = nodeColor(initializedName); #if 0 // This is redundant I/O for debugging. printf ("%d,%d,%s,%d,%d %s = %p \n",startingLineNumber,startingColumnNumber,color.c_str(),endingLineNumber,endingColumnNumber,initializedName->class_name().c_str(),initializedName); #endif dataFile << startingLineNumber << "," << startingColumnNumber << "," << color << "," << endingLineNumber << "," << endingColumnNumber << endl; } }
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 }