ROSE 2.20.0
Loading...
Searching...
No Matches
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 (4/30/2020): We no long need this in the new simplified support for CPP directivces and comments and unparsing of header files.
14// DQ (12/12/2008): This is the type use to hold all the CPP directives 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 to be used twice (just for CPP Fortran code) and we need to use this
30 // weaving implementation with two different lists of directives. By 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 // Pei-Hung (09/17/2020): We need to check if SgInitializedName is part of SgFunctionParameterList and the comment
63 // will not be attached to it.
64 isPartOfFunctionParameterList = false;
65 }
66#endif
67
68 // DQ (8/6/2012): Added copy constructor.
70
71 // PL (10/12/2026): Added operator=
73
74 // DQ (8/6/2012): This is a part of fixing the CPP directives for templates until they are no longer unparsed as strings.
75 bool isPartOfTemplateDeclaration;
76
77 // DQ (7/1/2014): We need to make sure that CPP directives will not be attached to template instantiations that might
78 // not be unparsed (see test2014_68.C).
79 bool isPartOfTemplateInstantiationDeclaration;
80
81 // Pei-Hung (09/17/2020): We need to check if SgInitializedName is part of SgFunctionParameterList and the comment
82 // will not be attached to it.
83 bool isPartOfFunctionParameterList;
84 };
85
86// This is an empty class, meaning that we could likely just have implemented just a TopDownProcessing traversal.
88
90 : public SgTopDownBottomUpProcessing<AttachPreprocessingInfoTreeTraversalInheritedAttrribute,
91 AttachPreprocessingInfoTreeTraversalSynthesizedAttribute>
92 {
93 // negara1 (08/12/2011): These lists contain correspondingly pairs of <include_stmt_to_be_inserted, stmt_before_which_should_insert>
94 // and <include_stmt_to_be_inserted, stmt_after_which_should_insert>
95 private:
96 std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertBefore;
97 std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertAfter;
98
99 protected: // Pi-- private:
101 // SgLocatedNode *previousLocNodePtr;
102
103 // DQ (4/30/2020): We no longer need this in the new simplified support for CPP directivces and comments and unparsing of header files.
104 // Store the location in the AST of the previous node associated with each file.
105 // previousLocatedNodeInFileType previousLocatedNodeMap;
107
108 // DQ (4/30/2020): We no long need this in the new simplified support for CPP directivces and comments and unparsing of header files.
109 // DQ (11/30/2008): This is now stored in the inherited attribute (so that it can be set external to the traversal).
110 // List of all comments and CPP directives
111 // ROSEAttributesList *currentListOfAttributes;
112 // AttributeMapType attributeMapForAllFiles;
113
114 // DQ (4/30/2020): Adding back the original simile level of support for a single ROSEAttributesList data member.
115 ROSEAttributesList *currentListOfAttributes;
116
117 // DQ (12/12/2008): I don't think this is required since it is just the list size!
118 // size of list?
119 // int sizeOfCurrentListOfAttributes;
120
121 // DQ (12/12/2008): This allows buildCommentAndCppDirectiveList() to get information about what language
122 // and version of language (fixed or free format for Fortran) as required to gather CPP directives and
123 // comments (more for comments than for CPP directives). This is required even if processing other files
124 // (include files).
126 // int currentFileNameId;
128
129 // DQ (6/23/2020): We only want to process located nodes that are associated with this file id.
130 int target_source_file_id;
131
132 // DQ (2/28/2019): We need to return the line that is associated with the source file where this can be a node shared between multiple ASTs.
133 int source_file_id;
134
136 // DQ (12./12/2008): this should be updated to use int instead of strings.
137 // For now I will not touch the Wave specific implementation.
138 // std::map<std::string,ROSEAttributesList*>* currentMapOfAttributes;
139
142
143 // The mapOfAttributes declaration is specific to wave usage.
145 // std::map<std::string,ROSEAttributesList*>* mapOfAttributes;
146
147 // DQ (4/30/2020): We no long need this in the new simplified support for CPP directivces and comments and unparsing of header files.
150 // int start_index;
151 // StartingIndexAttributeMapType startIndexMap;
152
153 // DQ (4/30/2020): Adding back the original simile level of support for a single ROSEAttributesList data member.
155
156 // DQ (12/16/2008): Added support to collect CPP directives and comments from all
157 // include files (except should specified using exclusion lists via the command line).
158 bool processAllIncludeFiles;
159
160 public:
161 // DQ (9/24/2007): Moved function definition to source file from header file.
162 // AS(011306) Constructor for use of Wave Preprocessor
163 AttachPreprocessingInfoTreeTrav( std::map<std::string,ROSEAttributesList*>* attrMap);
164
165 public:
166
167 // Destructor
169
170 // DQ (6/2/2020): Change the API for this function.
171 // DQ (9/24/2007): Moved function definition to source file from header file.
172 // Constructor
173 // AttachPreprocessingInfoTreeTrav( SgSourceFile* file, bool includeDirectivesAndCommentsFromAllFiles );
175#if 0
177#endif
178 void setupPointerToPreviousNode (SgLocatedNode* currentLocNodePtr );
179
180 void iterateOverListAndInsertPreviouslyUninsertedElementsAppearingBeforeLineNumber
181 ( SgLocatedNode* locatedNode, int lineNumber, PreprocessingInfo::RelativePositionType location,
182 bool reset_start_index, ROSEAttributesList *currentListOfAttributes );
183
184 // DQ (2/16/2021): This function supports iterateOverListAndInsertPreviouslyUninsertedElementsAppearingBeforeLineNumber().
185 // It separates the case where comments and CPP directives are put in the scope or attached to the bottom of the previous statement.
186 void handleBracedScopes(SgLocatedNode* previousLocatedNode, SgStatement* bracedScope, int lineOfClosingBrace, bool reset_start_index, ROSEAttributesList *currentListOfAttributes);
187
188 // Member function to be executed on each node of the AST
189 // in the course of its traversal
191 evaluateInheritedAttribute( SgNode *n, AttachPreprocessingInfoTreeTraversalInheritedAttrribute inh);
192
195
196 // DQ (10/27/2007): Added display function to output information gather durring the collection of
197 // comments and CPP directives across all files.
198 void display(const std::string & label) const;
199
200 // DQ (4/30/2020): We no long need this in the new simplified support for CPP directivces and comments and unparsing of header files.
201 // AttributeMapType & get_attributeMapForAllFiles() { return attributeMapForAllFiles; }
202
203 // Access function for elements in the map of attribute lists.
204 ROSEAttributesList* getListOfAttributes ( int currentFileNameId );
205
206 void setMapOfAttributes();
207
208 // output for debugging.
209 // void display_static_data( const std::string & label ) const;
210
211 // DQ (1/4/2021): Adding support for comments and CPP directives and tokens to use new_filename.
212 // DQ (7/4/2020): Make this a static function to support Fortran handling.
213 // DQ (11/30/2008): Refactored code to isolate this from the inherited attribute evaluation.
214 // static ROSEAttributesList* buildCommentAndCppDirectiveList ( SgFile *currentFilePtr, std::map<std::string,ROSEAttributesList*>* mapOfAttributes, bool use_Wave );
215 // ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, std::string currentFilename );
216 // static ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, std::string currentFilename );
217 // static ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, SgSourceFile* sourceFile, std::string currentFilename );
218 static ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, SgSourceFile* sourceFile, std::string currentFilename, std::string new_filename );
219 };
220
221#endif
222
223// EOF
SgSourceFile * sourceFile
current source file name id (only handle strings from current file)
SgLocatedNode * previousLocatedNode
accumulator attribute
bool use_Wave
AS(011306) Map of ROSEAttributesLists mapped to filename from Wave.
int start_index
Map of filenames to list of attributes as found by WAVE.
RelativePositionType
MK: Enum type to store if the directive goes before or after the corresponding line of source code.
This class represents the notion of an expression or statement which has a position within the source...
This class represents the base class for all IR nodes within Sage III.
This class represents the notion of a statement.