00001 /* #line 1 "/export/tmp.hudson-rose/hudson/workspace/a90-ROSE-daily-release/label/amd64-linux/src/ROSETTA/Grammar/grammarAST_FileIoHeader.code" */ 00002 00003 #ifndef AST_FILE_IO_HEADER 00004 #define AST_FILE_IO_HEADER 00005 #include "AstSpecificDataManagingClass.h" 00006 #include <ostream> 00007 #include <string> 00008 /* JH (11/23/2005) : This class provides all memory management ans methods to handle the 00009 file storage of ASTs. For more inforamtion about the methods have a look at : 00010 src/ROSETTA/Grammar/grammarAST_FileIoHeader.code 00011 */ 00012 00013 00014 #define REGISTER_ATTRIBUTE_FOR_FILE_IO(CLASS_TO_BE_REGISTERED ) AST_FILE_IO::registerAttribute<CLASS_TO_BE_REGISTERED> ( ) ; 00015 00016 typedef AstSpecificDataManagingClass AstData; 00017 00018 class AST_FILE_IO 00019 { 00020 public: 00021 00022 #if 1 00023 // This class is used only for debugging... 00024 class MemoryCheckingTraversalForAstFileIO : public ROSE_VisitTraversal 00025 { 00026 public: 00027 // int counter; 00028 00029 void visit ( SgNode* node ) 00030 { 00031 ROSE_ASSERT(node != NULL); 00032 // printf ("MemoryCheckingTraversalForAstFileIO::visit: node = %s \n",node->class_name().c_str()); 00033 ROSE_ASSERT(node->get_freepointer() == AST_FileIO::IS_VALID_POINTER()); 00034 node->checkDataMemberPointersIfInMemoryPool(); 00035 } 00036 }; 00037 #endif 00038 00039 typedef AstAttribute* (AstAttribute::*CONSTRUCTOR)( void ); 00040 /* We are using the V_Sg... enumeration. Additionally, we introduce totalNumberOfIRNodes the number 00041 of non terminals and terminals . 00042 */ 00043 private: 00044 enum { totalNumberOfIRNodes = 712}; 00045 static unsigned long binarySearch( unsigned long globalIndex, int start = 0 , int end = totalNumberOfIRNodes ); 00046 static unsigned long linearSearch( unsigned long globalIndex ) ; 00047 static std :: map < std::string, CONSTRUCTOR > registeredAttributes; 00048 static bool freepointersOfCurrentAstAreSetToGlobalIndices; 00049 static unsigned long listOfMemoryPoolSizes [ totalNumberOfIRNodes + 1] ; 00050 // searches pointerContainingGlobalIndex in regions of listOfAccumulatedPoolSizes, in order to compute the global index 00051 static SgNode* getPointerFromGlobalIndex ( unsigned long globalIndex ); 00052 static std::vector<AstData*> vectorOfASTs ; 00053 static AstData *actualRebuildAst; 00054 00055 public: 00056 // sets up the lost of pool sizes that contain valid entries 00057 static void startUp ( SgProject* root ); 00058 00059 // sets up the lost of pool sizes that contain valid entries 00060 static unsigned long getSizeOfMemoryPool ( const int position ); 00061 static unsigned long getSizeOfMemoryPoolUpToAst ( AstData* astInPool, const int position ); 00062 static unsigned long getAccumulatedPoolSizeOfNewAst( const int position); 00063 static unsigned long getAccumulatedPoolSizeOfAst( AstData* astInPool, const int position); 00064 static unsigned long getPoolSizeOfNewAst( const int sgVariant); 00065 static unsigned long getTotalNumberOfNodesOfAstInMemoryPool ( ); 00066 static unsigned long getTotalNumberOfNodesOfNewAst (); 00067 static bool areFreepointersContainingGlobalIndices ( ); 00068 00069 // some methods not used so far ... or not more used 00070 static unsigned long getGlobalIndexFromSgClassPointer ( SgNode* pointer ) ; 00071 static SgNode* getSgClassPointerFromGlobalIndex ( unsigned long globalIndex) ; 00072 static void compressAstInMemoryPool() ; 00073 static void resetValidAstAfterWriting(); 00074 static void clearAllMemoryPools ( ); 00075 static void deleteStaticData( ); 00076 static void deleteStoredAsts( ); 00077 static void setStaticDataOfAst(AstData* astInPool); 00078 static int getNumberOfAsts (); 00079 static void addNewAst (AstData* newAst); 00080 static void extendMemoryPoolsForRebuildingAST ( ); 00081 static void writeASTToStream ( std::ostream& out ); 00082 static void writeASTToFile ( std::string fileName ); 00083 static std::string writeASTToString (); 00084 static SgProject* readASTFromStream ( std::istream& in ); 00085 static SgProject* readASTFromFile (std::string fileName ); 00086 static SgProject* readASTFromString ( const std::string& s ); 00087 static void printFileMaps () ; 00088 static void printListOfPoolSizes () ; 00089 static void printListOfPoolSizesOfAst (int index) ; 00090 static AstData* getAst (int index) ; 00091 static AstData* getAstWithRoot (SgProject* root) ; 00092 00093 template <class TYPE> 00094 static void registerAttribute ( ); 00095 static const std::map <std::string, CONSTRUCTOR>& getRegisteredAttributes (); 00096 00097 // DQ (2/27/2010): Reset the AST File I/O data structures to permit writing a file after the reading and merging of files. 00098 static void reset(); 00099 00100 // DQ (2/27/2010): Show what the values are for debugging (e.g. write after read). 00101 static void display(const std::string & label); 00102 }; 00103 00104 00105 template <class TYPE> 00106 inline void 00107 AST_FILE_IO::registerAttribute ( ) 00108 { 00109 std::string name = TYPE().attribute_class_name(); 00110 if ( registeredAttributes.find ( name ) == registeredAttributes.end() ) 00111 { 00112 registeredAttributes[name] = (CONSTRUCTOR)(&TYPE::constructor) ; 00113 } 00114 } 00115 00116 inline const std::map <std::string, AST_FILE_IO::CONSTRUCTOR>& 00117 AST_FILE_IO::getRegisteredAttributes ( ) 00118 { 00119 return registeredAttributes; 00120 } 00121 #endif //AST_FILE_IO_HEADER 00122 00123
1.4.7