forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataBaseUsage.C
122 lines (101 loc) · 3.97 KB
/
dataBaseUsage.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Example ROSE Translator: used for testing ROSE infrastructure
#include "rose.h"
using namespace std;
using namespace Rose;
// DQ (9/9/2005): Don't include the database by default
// TPS (01Dec2008): Enabled mysql and this fails.
// seems like it is not supposed to be included
#if 0
//#ifdef HAVE_MYSQL
#include "GlobalDatabaseConnectionMYSQL.h"
#endif
int main( int argc, char * argv[] )
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
// TPS (01Dec2008): Enabled mysql and this fails.
// seems like it is not supposed to be included
#if 0
//#ifdef HAVE_MYSQL
// Build the Data base
GlobalDatabaseConnection *gDB;
gDB = new GlobalDatabaseConnection( "functionNameDataBase" );
gDB->initialize();
string command = "";
command = command + "CREATE TABLE Functions ( name TEXT, counter );";
Query *q = gDB->getQuery();
q->set( command );
q->execute();
if ( q->success() != 0 )
cout << "Error creating schema: " << q->error() << "\n";
// Alternative syntax, but does not permit access to error messages and exit codes
// gDB->execute(command.c_str());
#endif
// Build the AST used by ROSE
SgProject* project = frontend(argc,argv);
// Run internal consistency tests on AST
AstTests::runAllTests(project);
// Build a list of functions within the AST
Rose_STL_Container<SgNode*> functionDeclarationList =
NodeQuery::querySubTree (project,V_SgFunctionDeclaration);
int counter = 0;
for (Rose_STL_Container<SgNode*>::iterator i = functionDeclarationList.begin();
i != functionDeclarationList.end(); i++)
{
// Build a pointer to the current type so that we can call
// the get_name() member function.
SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(*i);
ROSE_ASSERT(functionDeclaration != NULL);
SgName func_name = functionDeclaration->get_name();
// Skip builtin functions for shorter output, Liao 4/28/2008
if (func_name.getString().find("__builtin",0)==0)
continue;
// output the function number and the name of the function
printf ("function name #%d is %s at line %d \n",
counter++,func_name.str(),
functionDeclaration->get_file_info()->get_line());
string functionName = functionDeclaration->get_qualified_name().str();
// TPS (01Dec2008): Enabled mysql and this fails.
// seems like it is not supposed to be included
#if 0
//#ifdef HAVE_MYSQL
command = "INSERT INTO Functions values(\"" + functionName + "\"," +
StringUtility::numberToString(counter) + ");";
// Alternative interface
// q->set( command );
// cout << "Executing: " << q->preview() << "\n";
// q->execute();
gDB->execute(command.c_str());
#endif
}
// TPS (01Dec2008): Enabled mysql and this fails.
// seems like it is not supposed to be included
#if 0
//#ifdef HAVE_MYSQL
command = "SELECT * from Functions;";
// Alternative Interface (using query objects)
// q << command;
q->set(command);
cout << "Executing: " << q->preview() << "\n";
// execute and return result (alternative usage: "gDB->select()")
Result *res = q->store();
if ( q->success() != 0 )
cout << "Error reading values: " << q->error() << "\n";
else
{
// Read the table returned from the query
// res->showResult();
for ( Result::iterator i = res->begin(); i != res->end(); i++ )
{
// Alternative syntax is possible: "Row r = *i;"
string functionName = (*i)[0].get_string();
int counter = (*i)[1];
printf ("functionName = %s counter = %d \n",functionName.c_str(),counter);
}
}
gDB->shutdown();
#else
printf ("Program compiled without data base connection support (add using ROSE configure option) \n");
#endif
return 0;
}