Line data Source code
1 : /* #line 1 "/home/yyan7/compiler/rexompiler/src/ROSETTA/Grammar/grammarAST_FileIoHeader.code" */ 2 : 3 : #ifndef AST_FILE_IO_HEADER 4 : #define AST_FILE_IO_HEADER 5 : #include "AstSpecificDataManagingClass.h" 6 : #include <ostream> 7 : #include <string> 8 : /* JH (11/23/2005) : This class provides all memory management ans methods to handle the 9 : file storage of ASTs. For more inforamtion about the methods have a look at : 10 : src/ROSETTA/Grammar/grammarAST_FileIoHeader.code 11 : */ 12 : 13 : 14 : #define REGISTER_ATTRIBUTE_FOR_FILE_IO(CLASS_TO_BE_REGISTERED ) AST_FILE_IO::registerAttribute<CLASS_TO_BE_REGISTERED> ( ) ; 15 : 16 : typedef AstSpecificDataManagingClass AstData; 17 : 18 : class ROSE_DLL_API AST_FILE_IO 19 : { 20 : public: 21 : 22 : #if 1 23 : // This class is used only for debugging... 24 : class MemoryCheckingTraversalForAstFileIO : public ROSE_VisitTraversal 25 : { 26 : public: 27 : // int counter; 28 : 29 0 : void visit ( SgNode* node ) 30 : { 31 0 : ROSE_ASSERT(node != NULL); 32 : // printf ("MemoryCheckingTraversalForAstFileIO::visit: node = %s \n",node->class_name().c_str()); 33 0 : ROSE_ASSERT(node->get_freepointer() == AST_FileIO::IS_VALID_POINTER()); 34 0 : node->checkDataMemberPointersIfInMemoryPool(); 35 0 : } 36 : }; 37 : #endif 38 : 39 : typedef AstAttribute* (AstAttribute::*CONSTRUCTOR)( void ); 40 : /* We are using the V_Sg... enumeration. Additionally, we introduce totalNumberOfIRNodes the number 41 : of non terminals and terminals . 42 : */ 43 : private: 44 : enum { totalNumberOfIRNodes = 690}; 45 : static unsigned long binarySearch( unsigned long globalIndex, int start = 0 , int end = totalNumberOfIRNodes ); 46 : static unsigned long linearSearch( unsigned long globalIndex ) ; 47 : static std :: map < std::string, CONSTRUCTOR > registeredAttributes; 48 : static bool freepointersOfCurrentAstAreSetToGlobalIndices; 49 : static unsigned long listOfMemoryPoolSizes [ totalNumberOfIRNodes + 1] ; 50 : // searches pointerContainingGlobalIndex in regions of listOfAccumulatedPoolSizes, in order to compute the global index 51 : static SgNode* getPointerFromGlobalIndex ( unsigned long globalIndex ); 52 : static std::vector<AstData*> vectorOfASTs ; 53 : static AstData *actualRebuildAst; 54 : 55 : public: 56 : // sets up the lost of pool sizes that contain valid entries 57 : static void startUp ( SgProject* root ); 58 : 59 : // sets up the lost of pool sizes that contain valid entries 60 : static unsigned long getSizeOfMemoryPool ( const int position ); 61 : static unsigned long getSizeOfMemoryPoolUpToAst ( AstData* astInPool, const int position ); 62 : static unsigned long getAccumulatedPoolSizeOfNewAst( const int position); 63 : static unsigned long getAccumulatedPoolSizeOfAst( AstData* astInPool, const int position); 64 : static unsigned long getPoolSizeOfNewAst( const int sgVariant); 65 : static unsigned long getTotalNumberOfNodesOfAstInMemoryPool ( ); 66 : static unsigned long getTotalNumberOfNodesOfNewAst (); 67 : static bool areFreepointersContainingGlobalIndices ( ); 68 : 69 : // some methods not used so far ... or not more used 70 : static unsigned long getGlobalIndexFromSgClassPointer ( SgNode* pointer ) ; 71 : static SgNode* getSgClassPointerFromGlobalIndex ( unsigned long globalIndex) ; 72 : static void compressAstInMemoryPool() ; 73 : static void resetValidAstAfterWriting(); 74 : static void clearAllMemoryPools ( ); 75 : static void deleteMemoryPools ( ); 76 : static void deleteStaticData( ); 77 : static void deleteStoredAsts( ); 78 : static void setStaticDataOfAst(AstData* astInPool); 79 : static int getNumberOfAsts (); 80 : static void addNewAst (AstData* newAst); 81 : static void extendMemoryPoolsForRebuildingAST ( ); 82 : static void writeASTToStream ( std::ostream& out ); 83 : static void writeASTToFile ( std::string fileName ); 84 : static std::string writeASTToString (); 85 : static SgProject* readASTFromStream ( std::istream& in ); 86 : static SgProject* readASTFromFile (std::string fileName ); 87 : static SgProject* readASTFromString ( const std::string& s ); 88 : static void printFileMaps () ; 89 : static void printListOfPoolSizes () ; 90 : static void printListOfPoolSizesOfAst (int index) ; 91 : static AstData* getAst (int index) ; 92 : static AstData* getAstWithRoot (SgProject* root) ; 93 : 94 : template <class TYPE> 95 : static void registerAttribute ( ); 96 : static const std::map <std::string, CONSTRUCTOR>& getRegisteredAttributes (); 97 : 98 : // DQ (2/27/2010): Reset the AST File I/O data structures to permit writing a file after the reading and merging of files. 99 : static void reset(); 100 : 101 : // DQ (2/27/2010): Show what the values are for debugging (e.g. write after read). 102 : static void display(const std::string & label); 103 : }; 104 : 105 : 106 : template <class TYPE> 107 : inline void 108 7 : AST_FILE_IO::registerAttribute ( ) 109 : { 110 7 : std::string name = TYPE().attribute_class_name(); 111 7 : if ( registeredAttributes.find ( name ) == registeredAttributes.end() ) 112 : { 113 5 : registeredAttributes[name] = (CONSTRUCTOR)(&TYPE::constructor) ; 114 : } 115 7 : } 116 : 117 : inline const std::map <std::string, AST_FILE_IO::CONSTRUCTOR>& 118 0 : AST_FILE_IO::getRegisteredAttributes ( ) 119 : { 120 0 : return registeredAttributes; 121 : } 122 : #endif //AST_FILE_IO_HEADER 123 : 124 :