00001 #ifndef C_DEFINITION_FINDER_H_INCLUDED_
00002 #define C_DEFINITION_FINDER_H_INCLUDED_
00003 
00004 #include "rose.h"
00005 
00006 #include "rose_nodes.h"
00007 
00008 namespace risc {
00009 
00010 namespace tools {
00011 
00016 class CDefinitions {
00017 
00018 public:
00019 
00020   static SgFunctionDeclaration* get_printf()
00021   {
00022     initialize();
00023     return printf_;
00024   }
00025 
00026   static SgFunctionDeclaration* get_fprintf()
00027   {
00028     initialize();
00029     return fprintf_;
00030   }
00031 
00032   static SgFunctionDeclaration* get_main()
00033   {
00034     initialize();
00035     return main_;
00036   }
00037 
00038   static SgTypedefDeclaration* get_file()
00039   {
00040     initialize();
00041     return file_;
00042   }
00043 
00044   static SgTypedefDeclaration* get_std_string()
00045   {
00046     initialize();
00047     return std_string_;
00048   }
00049 
00050 private:
00054   static SgFunctionDeclaration *printf_;
00055   static SgFunctionDeclaration *fprintf_;
00056   static SgFunctionDeclaration *main_;
00057   static SgTypedefDeclaration *std_string_;
00058   static SgTypedefDeclaration *file_;
00059 
00060   static bool is_initialized_;
00061 
00062   static void initialize()
00063   {
00064     if(CDefinitions::is_initialized_ == true) {
00065       return;
00066     }
00067 
00068     
00069     const std::vector<SgNode*> &func_decls = RoseNodes::get_func_decls();
00070     for(std::vector<SgNode*>::const_iterator
00071         iter  = func_decls.begin();
00072         iter != func_decls.end();
00073         iter++) {
00074 
00075       SgFunctionDeclaration *func_decl = isSgFunctionDeclaration(*iter);
00076       std::string qualified_name = func_decl->get_qualified_name();
00077 
00078       if(qualified_name == "::printf") {
00079         printf_ = func_decl;
00080         continue;
00081       }
00082 
00083       if(qualified_name == "::fprintf") {
00084         fprintf_ = func_decl;
00085         continue;
00086       }
00087 
00088       
00089       
00090       
00091       
00092       
00093     }
00094 
00095     
00096     const std::vector<SgNode*> &typedef_decls = RoseNodes::get_typedef_decl();
00097     for(std::vector<SgNode*>::const_iterator
00098         iter  = typedef_decls.begin();
00099         iter != typedef_decls.end();
00100         iter++) {
00101 
00102       SgTypedefDeclaration *typedef_decl = isSgTypedefDeclaration(*iter);
00103       std::string qualified_name = typedef_decl->get_qualified_name();
00104 
00105       if(qualified_name == "::std::string") {
00106         std_string_ = typedef_decl;
00107         continue;
00108       }
00109 
00110       if(qualified_name == "::FILE") {
00111         file_ = typedef_decl;
00112         continue;
00113       }
00114     }
00115 
00116   #if 0
00117     std::cout << "main_ " << main_ << std::endl;
00118     std::cout << "printf_ " << printf_ << std::endl;
00119     std::cout << "fprintf_ " << fprintf_ << std::endl;
00120     std::cout << "file_ " << file_ << std::endl;
00121     std::cout << "std_string_ " << std_string_ << std::endl;
00122   #endif
00123 
00124     CDefinitions::is_initialized_ = true;
00125   }
00126 };
00127 
00128 }; 
00129 
00130 }; 
00131 
00132 #endif 
00133 
00134