ROSE  0.9.9.109
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 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 
113  // DQ (12./12/2008): this should be updated to use int instead of strings.
114  // For now I will not touch the Wave specific implementation.
115  // std::map<std::string,ROSEAttributesList*>* currentMapOfAttributes;
116 
118  bool use_Wave;
119 
120  // The mapOfAttributes declaration is specific to wave usage.
122  // std::map<std::string,ROSEAttributesList*>* mapOfAttributes;
123 
126  // int start_index;
127  StartingIndexAttributeMapType startIndexMap;
128 
129  // DQ (12/16/2008): Added support to collect CPP directives and comments from all
130  // include files (except should specified using exclusion lists via the command line).
131  bool processAllIncludeFiles;
132 
133  public:
134  // DQ (9/24/2007): Moved function definition to source file from header file.
135  // AS(011306) Constructor for use of Wave Preprocessor
136  AttachPreprocessingInfoTreeTrav( std::map<std::string,ROSEAttributesList*>* attrMap);
137 
138  public:
139 
140  // Destructor
142 
143  // DQ (9/24/2007): Moved function definition to source file from header file.
144  // Constructor
145  AttachPreprocessingInfoTreeTrav( SgSourceFile* file, bool includeDirectivesAndCommentsFromAllFiles );
146 #if 0
148 #endif
149  void setupPointerToPreviousNode (SgLocatedNode* currentLocNodePtr );
150 
151  void iterateOverListAndInsertPreviouslyUninsertedElementsAppearingBeforeLineNumber
152  ( SgLocatedNode* locatedNode, int lineNumber, PreprocessingInfo::RelativePositionType location,
153  bool reset_start_index, ROSEAttributesList *currentListOfAttributes );
154 
155  // Member function to be executed on each node of the AST
156  // in the course of its traversal
159 
162 
163  // DQ (10/27/2007): Added display function to output information gather durring the collection of
164  // comments and CPP directives across all files.
165  void display(const std::string & label) const;
166 
167  AttributeMapType & get_attributeMapForAllFiles() { return attributeMapForAllFiles; }
168 
169  // Access function for elements in the map of attribute lists.
170  ROSEAttributesList* getListOfAttributes ( int currentFileNameId );
171 
172  void setMapOfAttributes();
173 
174 
175  // output for debugging.
176  // void display_static_data( const std::string & label ) const;
177 
178  // DQ (11/30/2008): Refactored code to isolate this from the inherited attribute evaluation.
179  // static ROSEAttributesList* buildCommentAndCppDirectiveList ( SgFile *currentFilePtr, std::map<std::string,ROSEAttributesList*>* mapOfAttributes, bool use_Wave );
180  ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, std::string currentFilename );
181  };
182 
183 #endif
184 
185 // 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:8322
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.