3 #ifndef AST_FILE_IO_HEADER
4 #define AST_FILE_IO_HEADER
5 #include "AstSpecificDataManagingClass.h"
14 #define REGISTER_ATTRIBUTE_FOR_FILE_IO(CLASS_TO_BE_REGISTERED ) AST_FILE_IO::registerAttribute<CLASS_TO_BE_REGISTERED> ( ) ;
16 typedef AstSpecificDataManagingClass AstData;
29 void visit (
SgNode* node )
31 ROSE_ASSERT(node != NULL);
44 enum { totalNumberOfIRNodes = 688};
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] ;
51 static SgNode* getPointerFromGlobalIndex (
unsigned long globalIndex );
52 static std::vector<AstData*> vectorOfASTs ;
53 static AstData *actualRebuildAst;
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 ( );
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) ;
95 static void registerAttribute ( );
96 static const std::map <std::string, CONSTRUCTOR>& getRegisteredAttributes ();
102 static void display(
const std::string & label);
106 template <
class TYPE>
108 AST_FILE_IO::registerAttribute ( )
110 std::string
name = TYPE().attribute_class_name();
111 if ( registeredAttributes.find ( name ) == registeredAttributes.end() )
113 registeredAttributes[
name] = (CONSTRUCTOR)(&TYPE::constructor) ;
117 inline const std::map <std::string, AST_FILE_IO::CONSTRUCTOR>&
118 AST_FILE_IO::getRegisteredAttributes ( )
120 return registeredAttributes;
122 #endif //AST_FILE_IO_HEADER