All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
c_definitions.h
Go to the documentation of this file.
1 #ifndef C_DEFINITION_FINDER_H_INCLUDED_
2 #define C_DEFINITION_FINDER_H_INCLUDED_
3 
4 #include "rose.h"
5 
6 #include "rose_nodes.h"
7 
8 namespace risc {
9 
10 namespace tools {
11 
16 class CDefinitions {
17 
18 public:
19 
20  static SgFunctionDeclaration* get_printf()
21  {
22  initialize();
23  return printf_;
24  }
25 
26  static SgFunctionDeclaration* get_fprintf()
27  {
28  initialize();
29  return fprintf_;
30  }
31 
32  static SgFunctionDeclaration* get_main()
33  {
34  initialize();
35  return main_;
36  }
37 
38  static SgTypedefDeclaration* get_file()
39  {
40  initialize();
41  return file_;
42  }
43 
44  static SgTypedefDeclaration* get_std_string()
45  {
46  initialize();
47  return std_string_;
48  }
49 
50 private:
54  static SgFunctionDeclaration *printf_;
55  static SgFunctionDeclaration *fprintf_;
56  static SgFunctionDeclaration *main_;
57  static SgTypedefDeclaration *std_string_;
58  static SgTypedefDeclaration *file_;
59 
60  static bool is_initialized_;
61 
62  static void initialize()
63  {
64  if(CDefinitions::is_initialized_ == true) {
65  return;
66  }
67 
68  // Search for function declarations
69  const std::vector<SgNode*> &func_decls = RoseNodes::get_func_decls();
70  for(std::vector<SgNode*>::const_iterator
71  iter = func_decls.begin();
72  iter != func_decls.end();
73  iter++) {
74 
75  SgFunctionDeclaration *func_decl = isSgFunctionDeclaration(*iter);
76  std::string qualified_name = func_decl->get_qualified_name();
77 
78  if(qualified_name == "::printf") {
79  printf_ = func_decl;
80  continue;
81  }
82 
83  if(qualified_name == "::fprintf") {
84  fprintf_ = func_decl;
85  continue;
86  }
87 
88  // The main is hidden in the SystemC library. So, we will not find it.
89  //if(qualified_name == "::main") {
90  // fprintf_ = func_decl;
91  // continue;
92  //}
93  }
94 
95  // search for typedefs
96  const std::vector<SgNode*> &typedef_decls = RoseNodes::get_typedef_decl();
97  for(std::vector<SgNode*>::const_iterator
98  iter = typedef_decls.begin();
99  iter != typedef_decls.end();
100  iter++) {
101 
102  SgTypedefDeclaration *typedef_decl = isSgTypedefDeclaration(*iter);
103  std::string qualified_name = typedef_decl->get_qualified_name();
104 
105  if(qualified_name == "::std::string") {
106  std_string_ = typedef_decl;
107  continue;
108  }
109 
110  if(qualified_name == "::FILE") {
111  file_ = typedef_decl;
112  continue;
113  }
114  }
115 
116  #if 0
117  std::cout << "main_ " << main_ << std::endl;
118  std::cout << "printf_ " << printf_ << std::endl;
119  std::cout << "fprintf_ " << fprintf_ << std::endl;
120  std::cout << "file_ " << file_ << std::endl;
121  std::cout << "std_string_ " << std_string_ << std::endl;
122  #endif
123 
125  }
126 };
127 
128 }; // end of namespace tools
129 
130 }; // end of namespace risc
131 
132 #endif /* C_DEFINITION_FINDER_H_INCLUDED_ */
133 
134 /* ex: set softtabstop=2 tabstop=2 shiftwidth=2 expandtab: */
static SgFunctionDeclaration * printf_
Pointer to the c and c++ declarations in the rose ast tree.
Definition: c_definitions.h:54
static const std::vector< SgNode * > & get_func_decls()
Definition: rose_nodes.h:26
static SgFunctionDeclaration * fprintf_
Definition: c_definitions.h:55
static SgFunctionDeclaration * get_printf()
Definition: c_definitions.h:20
static const std::vector< SgNode * > & get_typedef_decl()
Definition: rose_nodes.h:56
static SgFunctionDeclaration * get_main()
Definition: c_definitions.h:32
static SgTypedefDeclaration * get_std_string()
Definition: c_definitions.h:44
static void initialize()
Definition: c_definitions.h:62
static SgTypedefDeclaration * file_
Definition: c_definitions.h:58
static SgFunctionDeclaration * main_
Definition: c_definitions.h:56
static bool is_initialized_
Definition: c_definitions.h:60
static SgTypedefDeclaration * get_file()
Definition: c_definitions.h:38
static SgFunctionDeclaration * get_fprintf()
Definition: c_definitions.h:26
static SgTypedefDeclaration * std_string_
Definition: c_definitions.h:57
This class stores C and C++ definition pointer This class does not need any initialization.
Definition: c_definitions.h:16