ROSE  0.9.9.139
AST_FILE_IO.h
1 /* #line 1 "/export/tmp.rose-mgr/applications/jenkins/data/1.0.0/jobs/release-ROSE-docs/workspace/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...
25  {
26  public:
27  // int counter;
28 
29  void visit ( SgNode* node )
30  {
31  ROSE_ASSERT(node != NULL);
32  // printf ("MemoryCheckingTraversalForAstFileIO::visit: node = %s \n",node->class_name().c_str());
33  ROSE_ASSERT(node->get_freepointer() == AST_FileIO::IS_VALID_POINTER());
35  }
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 = 840};
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 deleteStaticData( );
76  static void deleteStoredAsts( );
77  static void setStaticDataOfAst(AstData* astInPool);
78  static int getNumberOfAsts ();
79  static void addNewAst (AstData* newAst);
80  static void extendMemoryPoolsForRebuildingAST ( );
81  static void writeASTToStream ( std::ostream& out );
82  static void writeASTToFile ( std::string fileName );
83  static std::string writeASTToString ();
84  static SgProject* readASTFromStream ( std::istream& in );
85  static SgProject* readASTFromFile (std::string fileName );
86  static SgProject* readASTFromString ( const std::string& s );
87  static void printFileMaps () ;
88  static void printListOfPoolSizes () ;
89  static void printListOfPoolSizesOfAst (int index) ;
90  static AstData* getAst (int index) ;
91  static AstData* getAstWithRoot (SgProject* root) ;
92 
93  template <class TYPE>
94  static void registerAttribute ( );
95  static const std::map <std::string, CONSTRUCTOR>& getRegisteredAttributes ();
96 
97  // DQ (2/27/2010): Reset the AST File I/O data structures to permit writing a file after the reading and merging of files.
98  static void reset();
99 
100  // DQ (2/27/2010): Show what the values are for debugging (e.g. write after read).
101  static void display(const std::string & label);
102  };
103 
104 
105 template <class TYPE>
106 inline void
107  AST_FILE_IO::registerAttribute ( )
108  {
109  std::string name = TYPE().attribute_class_name();
110  if ( registeredAttributes.find ( name ) == registeredAttributes.end() )
111  {
112  registeredAttributes[name] = (CONSTRUCTOR)(&TYPE::constructor) ;
113  }
114  }
115 
116 inline const std::map <std::string, AST_FILE_IO::CONSTRUCTOR>&
117  AST_FILE_IO::getRegisteredAttributes ( )
118  {
119  return registeredAttributes;
120  }
121 #endif //AST_FILE_IO_HEADER
122 
123 
virtual void checkDataMemberPointersIfInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
Class holding static data and functions supporting File I/O.
Definition: AST_FILE_IO.h:18
SgNode * IS_VALID_POINTER()
This function returns a static pointer used with SgNode::p_freepointer.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
This class represents a source project, with a list of SgFile objects and global information about th...