ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
attachPreprocessingInfoTraversal.h
Go to the documentation of this file.
1 #ifndef _ATTACH_PREPROCESSING_INFO_TRAVERSAL_H_
2 #define _ATTACH_PREPROCESSING_INFO_TRAVERSAL_H_
3 
4 // DQ (4/5/2006): Andreas has removed this code!
5 
6 // void printOutComments ( SgLocatedNode* locatedNode );
7 
8 // Need dummy classes and the actual tree traversal class
9 // DQ: Renamed classes, can't have DI and DS polluting the global name space (potential for strange errors)
10 // class DI : public SgInheritedAttribute {};
11 // class DS : public SgSynthesizedAttribute {};
12 
13 // DQ (12/12/2008): This is the type use to hold all the CPP directives
14 // and comments for each of many files.
15 typedef std::map<int, ROSEAttributesList*> AttributeMapType;
16 typedef std::map<int, int> StartingIndexAttributeMapType;
17 typedef std::map<int, SgLocatedNode*> previousLocatedNodeInFileType;
18 
19 // DQ (11/29/2008): I don't think these are required to be derived from a special class any more!
20 // class AttachPreprocessingInfoTreeTraversalInheritedAttrribute : public AstInheritedAttribute {};
21 // class AttachPreprocessingInfoTreeTraversalSynthesizedAttribute : public AstSynthesizedAttribute {};
23  {
24  // DQ (11/30/2008): I want to permit different list of directives and comments to be woven into the AST.
25  // Comments and directives from the original source file need to be inserted into the AST for C/C++/Fortran.
26  // However, for Fortran we also need to gather and insert the linemarker directives into the AST so that
27  // we can support an analysis of the AST that will mark where code has been included from for the case of
28  // Fortran using CPP directives (e.g. #include directives). To support this the mechanism for weaving
29  // the ROSEAttributesList has be be used twice (just for CPP Fortran code) and we need to use this
30  // weaving implementat with two different lists of directives. But moving the ROSEAttributesList
31  // into the inherited attribute we can set it differently for the two times we require it to be done.
32 
33  public:
34  // DQ (12/12/2008): Make this a map to handle the attributes from more than one file (even if we
35  // only handle a single file, this added flexability is easier to support directly than to have
36  // an outer traversal vll an inner traversal). This more general interface supports the case
37  // where we save all comments and CPP directives used from include files in addition to the main
38  // source file.
39  // ROSEAttributesList* currentListOfAttributes;
40  // AttributeMapType* attributeMapForAllFiles;
41 
42 #if 0
43  // Constructor.
45  : currentListOfAttributes(listOfAttributes)
46  {
47  // Nothing else to do here.
48  }
49 #else
50  // AttachPreprocessingInfoTreeTraversalInheritedAttrribute(AttributeMapType* attributeMap) : attributeMapForAllFiles(attributeMap)
52  {
53  // Nothing else to do here.
54 
55  // DQ (8/6/2012): This is a part of fixing the CPP directives for templates until they are no longer unparsed as strings.
57  }
58 #endif
59 
60  // DQ (8/6/2012): Added copy constructor.
62 
63  // DQ (8/6/2012): This is a part of fixing the CPP directives for templates until they are no longer unparsed as strings.
65  };
66 
67 // This is an empty class, meaning that we could likely just have implemented a TopDownProcessing traversal.
69 
71  : public SgTopDownBottomUpProcessing<AttachPreprocessingInfoTreeTraversalInheritedAttrribute,
72  AttachPreprocessingInfoTreeTraversalSynthesizedAttribute>
73  {
74  // negara1 (08/12/2011): These lists contain correspondingly pairs of <include_stmt_to_be_inserted, stmt_before_which_should_insert>
75  // and <include_stmt_to_be_inserted, stmt_after_which_should_insert>
76  private:
77  std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertBefore;
78  std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertAfter;
79 
80  protected: // Pi-- private:
82  // SgLocatedNode *previousLocNodePtr;
83 
84  // Store the location in the AST of the previous node associated with each file.
86 
87  // DQ (11/30/2008): This is now stored in the inherited attribute (so that it can be set external to the traversal).
88  // List of all comments and CPP directives
89  // ROSEAttributesList *currentListOfAttributes;
91 
92  // DQ (12/12/2008): I don't think this is required since it is just the list size!
93  // size of list?
94  // int sizeOfCurrentListOfAttributes;
95 
96  // DQ (12/12/2008): This allows buildCommentAndCppDirectiveList() to get information about what language
97  // and version of language (fixed or free format for Fortran) as required to gather CPP directives and
98  // comments (more for comments than for CPP directives). This is required even if processing other files
99  // (include files).
101  // int currentFileNameId;
103 
105  // DQ (12./12/2008): this should be updated to use int instead of strings.
106  // For now I will not touch the Wave specific implementation.
107  // std::map<std::string,ROSEAttributesList*>* currentMapOfAttributes;
108 
110  bool use_Wave;
111 
112  // The mapOfAttributes declaration is specific to wave usage.
114  // std::map<std::string,ROSEAttributesList*>* mapOfAttributes;
115 
118  // int start_index;
120 
121  // DQ (12/16/2008): Added support to collect CPP directives and comments from all
122  // include files (except should specified using exclusion lists via the command line).
124 
125  public:
126  // DQ (9/24/2007): Moved function definition to source file from header file.
127  // AS(011306) Constructor for use of Wave Preprocessor
128  AttachPreprocessingInfoTreeTrav( std::map<std::string,ROSEAttributesList*>* attrMap);
129 
130  public:
131 
132  // Destructor
134 
135  // DQ (9/24/2007): Moved function definition to source file from header file.
136  // Constructor
137  AttachPreprocessingInfoTreeTrav( SgSourceFile* file, bool includeDirectivesAndCommentsFromAllFiles );
138 #if 0
140 #endif
141  void setupPointerToPreviousNode (SgLocatedNode* currentLocNodePtr );
142 
144  ( SgLocatedNode* locatedNode, int lineNumber, PreprocessingInfo::RelativePositionType location,
145  bool reset_start_index, ROSEAttributesList *currentListOfAttributes );
146 
147  // Member function to be executed on each node of the AST
148  // in the course of its traversal
151 
154 
155  // DQ (10/27/2007): Added display function to output information gather durring the collection of
156  // comments and CPP directives across all files.
157  void display(const std::string & label) const;
158 
160 
161  // Access function for elements in the map of attribute lists.
162  ROSEAttributesList* getListOfAttributes ( int currentFileNameId );
163 
164  void setMapOfAttributes();
165 
166 
167  // output for debugging.
168  // void display_static_data( const std::string & label ) const;
169 
170  // DQ (11/30/2008): Refactored code to isolate this from the inherited attribute evaluation.
171  // static ROSEAttributesList* buildCommentAndCppDirectiveList ( SgFile *currentFilePtr, std::map<std::string,ROSEAttributesList*>* mapOfAttributes, bool use_Wave );
172  ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, std::string currentFilename );
173  };
174 
175 #endif
176 
177 // EOF