ROSE  0.9.10.220
attachPreprocessingInfoTraversal.h
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.
56  isPartOfTemplateDeclaration = false;
57 
58  // DQ (7/1/2014): We need to make sure that CPP directives will not be attached to template instantiations that might
59  // not be unparsed (see test2014_68.C).
60  isPartOfTemplateInstantiationDeclaration = false;
61  }
62 #endif
63 
64  // DQ (8/6/2012): Added copy constructor.
66 
67  // DQ (8/6/2012): This is a part of fixing the CPP directives for templates until they are no longer unparsed as strings.
68  bool isPartOfTemplateDeclaration;
69 
70  // DQ (7/1/2014): We need to make sure that CPP directives will not be attached to template instantiations that might
71  // not be unparsed (see test2014_68.C).
72  bool isPartOfTemplateInstantiationDeclaration;
73  };
74 
75 // This is an empty class, meaning that we could likely just have implemented just a TopDownProcessing traversal.
77 
79  : public SgTopDownBottomUpProcessing<AttachPreprocessingInfoTreeTraversalInheritedAttrribute,
80  AttachPreprocessingInfoTreeTraversalSynthesizedAttribute>
81  {
82  // negara1 (08/12/2011): These lists contain correspondingly pairs of <include_stmt_to_be_inserted, stmt_before_which_should_insert>
83  // and <include_stmt_to_be_inserted, stmt_after_which_should_insert>
84  private:
85  std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertBefore;
86  std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertAfter;
87 
88  protected: // Pi-- private:
90  // SgLocatedNode *previousLocNodePtr;
91 
92  // Store the location in the AST of the previous node associated with each file.
93  previousLocatedNodeInFileType previousLocatedNodeMap;
94 
95  // DQ (11/30/2008): This is now stored in the inherited attribute (so that it can be set external to the traversal).
96  // List of all comments and CPP directives
97  // ROSEAttributesList *currentListOfAttributes;
98  AttributeMapType attributeMapForAllFiles;
99 
100  // DQ (12/12/2008): I don't think this is required since it is just the list size!
101  // size of list?
102  // int sizeOfCurrentListOfAttributes;
103 
104  // DQ (12/12/2008): This allows buildCommentAndCppDirectiveList() to get information about what language
105  // and version of language (fixed or free format for Fortran) as required to gather CPP directives and
106  // comments (more for comments than for CPP directives). This is required even if processing other files
107  // (include files).
109  // int currentFileNameId;
111 
112  // DQ (2/28/2019): We need to return the line that is associated with the source file where this can be a ode shared between multiple ASTs.
113  int source_file_id;
114 
116  // DQ (12./12/2008): this should be updated to use int instead of strings.
117  // For now I will not touch the Wave specific implementation.
118  // std::map<std::string,ROSEAttributesList*>* currentMapOfAttributes;
119 
121  bool use_Wave;
122 
123  // The mapOfAttributes declaration is specific to wave usage.
125  // std::map<std::string,ROSEAttributesList*>* mapOfAttributes;
126 
129  // int start_index;
130  StartingIndexAttributeMapType startIndexMap;
131 
132  // DQ (12/16/2008): Added support to collect CPP directives and comments from all
133  // include files (except should specified using exclusion lists via the command line).
134  bool processAllIncludeFiles;
135 
136  public:
137  // DQ (9/24/2007): Moved function definition to source file from header file.
138  // AS(011306) Constructor for use of Wave Preprocessor
139  AttachPreprocessingInfoTreeTrav( std::map<std::string,ROSEAttributesList*>* attrMap);
140 
141  public:
142 
143  // Destructor
145 
146  // DQ (9/24/2007): Moved function definition to source file from header file.
147  // Constructor
148  AttachPreprocessingInfoTreeTrav( SgSourceFile* file, bool includeDirectivesAndCommentsFromAllFiles );
149 #if 0
151 #endif
152  void setupPointerToPreviousNode (SgLocatedNode* currentLocNodePtr );
153 
154  void iterateOverListAndInsertPreviouslyUninsertedElementsAppearingBeforeLineNumber
155  ( SgLocatedNode* locatedNode, int lineNumber, PreprocessingInfo::RelativePositionType location,
156  bool reset_start_index, ROSEAttributesList *currentListOfAttributes );
157 
158  // Member function to be executed on each node of the AST
159  // in the course of its traversal
162 
165 
166  // DQ (10/27/2007): Added display function to output information gather durring the collection of
167  // comments and CPP directives across all files.
168  void display(const std::string & label) const;
169 
170  AttributeMapType & get_attributeMapForAllFiles() { return attributeMapForAllFiles; }
171 
172  // Access function for elements in the map of attribute lists.
173  ROSEAttributesList* getListOfAttributes ( int currentFileNameId );
174 
175  void setMapOfAttributes();
176 
177 
178  // output for debugging.
179  // void display_static_data( const std::string & label ) const;
180 
181  // DQ (11/30/2008): Refactored code to isolate this from the inherited attribute evaluation.
182  // static ROSEAttributesList* buildCommentAndCppDirectiveList ( SgFile *currentFilePtr, std::map<std::string,ROSEAttributesList*>* mapOfAttributes, bool use_Wave );
183  ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, std::string currentFilename );
184  };
185 
186 #endif
187 
188 // EOF
previousLocatedNodeInFileType previousLocatedNodeMap
accumulator attribute
bool use_Wave
AS(011306) Map of ROSEAttributesLists mapped to filename from Wave.
AttachPreprocessingInfoTreeTraversalSynthesizedAttribute evaluateSynthesizedAttribute(SgNode *n, AttachPreprocessingInfoTreeTraversalInheritedAttrribute inh, SubTreeSynthesizedAttributes st)
pure virtual function which must be implemented to compute the synthesized attribute at a node...
RelativePositionType
MK: Enum type to store if the directive goes before or after the corresponding line of source code...
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8908
SgSourceFile * sourceFile
current source file name id (only handle strings from current file)
This class represents the notion of an expression or statement which has a position within the source...
AttachPreprocessingInfoTreeTraversalInheritedAttrribute evaluateInheritedAttribute(SgNode *n, AttachPreprocessingInfoTreeTraversalInheritedAttrribute inh)
pure virtual function which must be implemented to compute the inherited attribute at a node ...
StartingIndexAttributeMapType startIndexMap
Map of filenames to list of attributes as found by WAVE.