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