forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addComments.C
57 lines (43 loc) · 1.77 KB
/
addComments.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
// Example ROSE Translator: used within ROSE/tutorial
#include "rose.h"
using namespace std;
class visitorTraversal : public AstSimpleProcessing
{
public:
virtual void visit(SgNode* n);
};
void visitorTraversal::visit(SgNode* n)
{
SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(n);
if (functionDeclaration != NULL)
{
string comment = string("Auto-comment function name: ") +
functionDeclaration->get_name().str() +
" is now a commented function";
// Note that this function will add the "//" or "/* */" comment syntax as required for C or C++, or Fortran.
SageInterface::attachComment(functionDeclaration,comment);
}
SgValueExp* valueExp = isSgValueExp(n);
if (valueExp != NULL)
{
// Check if there is an expression tree from the original unfolded expression.
// This is a trivial example ouf the output of an analysis result.
string comment = string("Auto-comment value: ") +
((valueExp->get_originalExpressionTree() != NULL) ?
" this IS a constant folded value" : " this is NOT a constant folded value");
SageInterface::attachComment(valueExp,comment);
}
}
// Typical main function for ROSE translator
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
exampleTraversal.traverseInputFiles(project,preorder);
return backend(project);
}