00001 #ifndef _ATTACH_PREPROCESSING_INFO_TRAVERSAL_H_ 00002 #define _ATTACH_PREPROCESSING_INFO_TRAVERSAL_H_ 00003 00004 // DQ (4/5/2006): Andreas has removed this code! 00005 00006 // void printOutComments ( SgLocatedNode* locatedNode ); 00007 00008 // Need dummy classes and the actual tree traversal class 00009 // DQ: Renamed classes, can't have DI and DS polluting the global name space (potential for strange errors) 00010 // class DI : public SgInheritedAttribute {}; 00011 // class DS : public SgSynthesizedAttribute {}; 00012 00013 // DQ (12/12/2008): This is the type use to hold all the CPP directives 00014 // and comments for each of many files. 00015 typedef std::map<int, ROSEAttributesList*> AttributeMapType; 00016 typedef std::map<int, int> StartingIndexAttributeMapType; 00017 typedef std::map<int, SgLocatedNode*> previousLocatedNodeInFileType; 00018 00019 // DQ (11/29/2008): I don't think these are required to be derived from a special class any more! 00020 // class AttachPreprocessingInfoTreeTraversalInheritedAttrribute : public AstInheritedAttribute {}; 00021 // class AttachPreprocessingInfoTreeTraversalSynthesizedAttribute : public AstSynthesizedAttribute {}; 00022 class AttachPreprocessingInfoTreeTraversalInheritedAttrribute 00023 { 00024 // DQ (11/30/2008): I want to permit different list of directives and comments to be woven into the AST. 00025 // Comments and directives from the original source file need to be inserted into the AST for C/C++/Fortran. 00026 // However, for Fortran we also need to gather and insert the linemarker directives into the AST so that 00027 // we can support an analysis of the AST that will mark where code has been included from for the case of 00028 // Fortran using CPP directives (e.g. #include directives). To support this the mechanism for weaving 00029 // the ROSEAttributesList has be be used twice (just for CPP Fortran code) and we need to use this 00030 // weaving implementat with two different lists of directives. But moving the ROSEAttributesList 00031 // into the inherited attribute we can set it differently for the two times we require it to be done. 00032 00033 public: 00034 // DQ (12/12/2008): Make this a map to handle the attributes from more than one file (even if we 00035 // only handle a single file, this added flexability is easier to support directly than to have 00036 // an outer traversal vll an inner traversal). This more general interface supports the case 00037 // where we save all comments and CPP directives used from include files in addition to the main 00038 // source file. 00039 // ROSEAttributesList* currentListOfAttributes; 00040 // AttributeMapType* attributeMapForAllFiles; 00041 00042 #if 0 00043 // Constructor. 00044 AttachPreprocessingInfoTreeTraversalInheritedAttrribute(ROSEAttributesList* listOfAttributes) 00045 : currentListOfAttributes(listOfAttributes) 00046 { 00047 // Nothing else to do here. 00048 } 00049 #else 00050 // AttachPreprocessingInfoTreeTraversalInheritedAttrribute(AttributeMapType* attributeMap) : attributeMapForAllFiles(attributeMap) 00051 AttachPreprocessingInfoTreeTraversalInheritedAttrribute() 00052 { 00053 // Nothing else to do here. 00054 } 00055 #endif 00056 }; 00057 00058 // This is an empty class, meaning that we could likely just have implemented a TopDownProcessing traversal. 00059 class AttachPreprocessingInfoTreeTraversalSynthesizedAttribute {}; 00060 00061 class AttachPreprocessingInfoTreeTrav 00062 : public SgTopDownBottomUpProcessing<AttachPreprocessingInfoTreeTraversalInheritedAttrribute, 00063 AttachPreprocessingInfoTreeTraversalSynthesizedAttribute> 00064 { 00065 // negara1 (08/12/2011): These lists contain correspondingly pairs of <include_stmt_to_be_inserted, stmt_before_which_should_insert> 00066 // and <include_stmt_to_be_inserted, stmt_after_which_should_insert> 00067 private: 00068 std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertBefore; 00069 std::list<std::pair<SgIncludeDirectiveStatement*, SgStatement*> > statementsToInsertAfter; 00070 00071 protected: // Pi-- private: 00073 // SgLocatedNode *previousLocNodePtr; 00074 00075 // Store the location in the AST of the previous node associated with each file. 00076 previousLocatedNodeInFileType previousLocatedNodeMap; 00077 00078 // DQ (11/30/2008): This is now stored in the inherited attribute (so that it can be set external to the traversal). 00079 // List of all comments and CPP directives 00080 // ROSEAttributesList *currentListOfAttributes; 00081 AttributeMapType attributeMapForAllFiles; 00082 00083 // DQ (12/12/2008): I don't think this is required since it is just the list size! 00084 // size of list? 00085 // int sizeOfCurrentListOfAttributes; 00086 00087 // DQ (12/12/2008): This allows buildCommentAndCppDirectiveList() to get information about what language 00088 // and version of language (fixed or free format for Fortran) as required to gather CPP directives and 00089 // comments (more for comments than for CPP directives). This is required even if processing other files 00090 // (include files). 00092 // int currentFileNameId; 00093 SgSourceFile* sourceFile; 00094 00096 // DQ (12./12/2008): this should be updated to use int instead of strings. 00097 // For now I will not touch the Wave specific implementation. 00098 // std::map<std::string,ROSEAttributesList*>* currentMapOfAttributes; 00099 00101 bool use_Wave; 00102 00103 // The mapOfAttributes declaration is specific to wave usage. 00105 // std::map<std::string,ROSEAttributesList*>* mapOfAttributes; 00106 00109 // int start_index; 00110 StartingIndexAttributeMapType startIndexMap; 00111 00112 // DQ (12/16/2008): Added support to collect CPP directives and comments from all 00113 // include files (except should specified using exclusion lists via the command line). 00114 bool processAllIncludeFiles; 00115 00116 public: 00117 // DQ (9/24/2007): Moved function definition to source file from header file. 00118 // AS(011306) Constructor for use of Wave Preprocessor 00119 AttachPreprocessingInfoTreeTrav( std::map<std::string,ROSEAttributesList*>* attrMap); 00120 00121 public: 00122 00123 // Destructor 00124 ~AttachPreprocessingInfoTreeTrav(); 00125 00126 // DQ (9/24/2007): Moved function definition to source file from header file. 00127 // Constructor 00128 AttachPreprocessingInfoTreeTrav( SgSourceFile* file, bool includeDirectivesAndCommentsFromAllFiles ); 00129 #if 0 00130 AttachPreprocessingInfoTreeTrav(); 00131 #endif 00132 void setupPointerToPreviousNode (SgLocatedNode* currentLocNodePtr ); 00133 00134 void iterateOverListAndInsertPreviouslyUninsertedElementsAppearingBeforeLineNumber 00135 ( SgLocatedNode* locatedNode, int lineNumber, PreprocessingInfo::RelativePositionType location, 00136 bool reset_start_index, ROSEAttributesList *currentListOfAttributes ); 00137 00138 // Member function to be executed on each node of the AST 00139 // in the course of its traversal 00140 AttachPreprocessingInfoTreeTraversalInheritedAttrribute 00141 evaluateInheritedAttribute( SgNode *n, AttachPreprocessingInfoTreeTraversalInheritedAttrribute inh); 00142 00143 AttachPreprocessingInfoTreeTraversalSynthesizedAttribute 00144 evaluateSynthesizedAttribute( SgNode *n, AttachPreprocessingInfoTreeTraversalInheritedAttrribute inh, SubTreeSynthesizedAttributes st); 00145 00146 // DQ (10/27/2007): Added display function to output information gather durring the collection of 00147 // comments and CPP directives across all files. 00148 void display(const std::string & label) const; 00149 00150 AttributeMapType & get_attributeMapForAllFiles() { return attributeMapForAllFiles; } 00151 00152 // Access function for elements in the map of attribute lists. 00153 ROSEAttributesList* getListOfAttributes ( int currentFileNameId ); 00154 00155 void setMapOfAttributes(); 00156 00157 00158 // output for debugging. 00159 // void display_static_data( const std::string & label ) const; 00160 00161 // DQ (11/30/2008): Refactored code to isolate this from the inherited attribute evaluation. 00162 // static ROSEAttributesList* buildCommentAndCppDirectiveList ( SgFile *currentFilePtr, std::map<std::string,ROSEAttributesList*>* mapOfAttributes, bool use_Wave ); 00163 ROSEAttributesList* buildCommentAndCppDirectiveList ( bool use_Wave, std::string currentFilename ); 00164 }; 00165 00166 #endif 00167 00168 // EOF
1.4.7