forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectComments.C
63 lines (52 loc) · 2.2 KB
/
collectComments.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Example ROSE Translator: used within ROSE/tutorial
#include "rose.h"
using namespace std;
// Class declaration
class visitorTraversal : public AstSimpleProcessing
{
public:
virtual void visit(SgNode* n);
};
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());
}
}
}
int main( int argc, char * argv[] )
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
// Build the AST used by ROSE
SgProject* project = frontend(argc,argv);
// Build the traversal object
visitorTraversal exampleTraversal;
// Call the traversal starting at the project node of the AST
// Traverse all header files and source file (the -rose:collectAllCommentsAndDirectives
// commandline option controls if comments and CPP directives are separately extracted
// from header files).
// exampleTraversal.traverse(project,preorder);
exampleTraversal.traverseInputFiles(project,preorder);
return 0;
}