Changeset 630a82a for src/SymTab
- Timestamp:
- Apr 8, 2016, 5:22:29 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 3da470c
- Parents:
- 3d9b5da
- Location:
- src/SymTab
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/AddVisit.h
r3d9b5da r630a82a 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 16:14:32 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T ue Jul 14 12:26:17 201513 // Update Count : 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 7 14:42:21 2016 13 // Update Count : 5 14 14 // 15 15 … … 27 27 28 28 template< typename Visitor > 29 inline void addVisitStatement( Statement *stmt, Visitor &visitor ) {30 maybeAccept( stmt, visitor );31 /// if ( ! declsToAdd.empty() ) {32 /// CompoundStmt *compound = new CompoundStmt( noLabels );33 /// compound->get_kids().push_back( stmt );34 /// addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() );35 /// }36 }37 38 template< typename Visitor >39 29 inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) { 40 30 addVisitStatementList( compoundStmt->get_kids(), visitor ); 41 }42 43 template< typename Visitor >44 inline void addVisit(IfStmt *ifStmt, Visitor &visitor) {45 addVisitStatement( ifStmt->get_thenPart(), visitor );46 addVisitStatement( ifStmt->get_elsePart(), visitor );47 maybeAccept( ifStmt->get_condition(), visitor );48 }49 50 template< typename Visitor >51 inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) {52 addVisitStatement( whileStmt->get_body(), visitor );53 maybeAccept( whileStmt->get_condition(), visitor );54 }55 56 template< typename Visitor >57 inline void addVisit(ForStmt *forStmt, Visitor &visitor) {58 addVisitStatement( forStmt->get_body(), visitor );59 acceptAll( forStmt->get_initialization(), visitor );60 maybeAccept( forStmt->get_condition(), visitor );61 maybeAccept( forStmt->get_increment(), visitor );62 31 } 63 32 … … 74 43 } 75 44 76 template< typename Visitor > 77 inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) { 78 addVisitStatementList( caseStmt->get_statements(), visitor ); 79 maybeAccept( caseStmt->get_condition(), visitor ); 80 } 81 82 template< typename Visitor > 83 inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) { 84 addVisitStatement( cathStmt->get_body(), visitor ); 85 maybeAccept( cathStmt->get_decl(), visitor ); 86 } 45 // template< typename Visitor > 46 // inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) { 47 // addVisitStatementList( caseStmt->get_statements(), visitor ); 48 // maybeAccept( caseStmt->get_condition(), visitor ); 49 // } 87 50 } // namespace SymTab 88 51 -
src/SymTab/Validate.cc
r3d9b5da r630a82a 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:31:39201613 // Update Count : 2 2612 // Last Modified On : Thu Apr 7 16:45:30 2016 13 // Update Count : 243 14 14 // 15 15 … … 40 40 #include <list> 41 41 #include <iterator> 42 #include "Common/utility.h" 43 #include "Common/UniqueName.h" 42 44 #include "Validate.h" 43 45 #include "SynTree/Visitor.h" 44 46 #include "SynTree/Mutator.h" 45 47 #include "SynTree/Type.h" 48 #include "SynTree/Expression.h" 46 49 #include "SynTree/Statement.h" 47 50 #include "SynTree/TypeSubstitution.h" … … 49 52 #include "FixFunction.h" 50 53 // #include "ImplementationType.h" 51 #include "Common/utility.h" 52 #include "Common/UniqueName.h" 54 #include "GenPoly/DeclMutator.h" 53 55 #include "AddVisit.h" 54 56 #include "MakeLibCfa.h" … … 70 72 71 73 virtual void visit( CompoundStmt *compoundStmt ); 72 virtual void visit( IfStmt *ifStmt );73 virtual void visit( WhileStmt *whileStmt );74 virtual void visit( ForStmt *forStmt );75 74 virtual void visit( SwitchStmt *switchStmt ); 76 75 virtual void visit( ChooseStmt *chooseStmt ); 77 virtual void visit( CaseStmt *caseStmt ); 78 virtual void visit( CatchStmt *catchStmt ); 76 // virtual void visit( CaseStmt *caseStmt ); 79 77 private: 80 78 HoistStruct(); … … 144 142 145 143 virtual void visit( CompoundStmt *compoundStmt ); 146 virtual void visit( IfStmt *ifStmt );147 virtual void visit( WhileStmt *whileStmt );148 virtual void visit( ForStmt *forStmt );149 144 virtual void visit( SwitchStmt *switchStmt ); 150 145 virtual void visit( ChooseStmt *chooseStmt ); 151 virtual void visit( CaseStmt *caseStmt ); 152 virtual void visit( CatchStmt *catchStmt ); 146 // virtual void visit( CaseStmt *caseStmt ); 153 147 154 148 AutogenerateRoutines() : functionNesting( 0 ) {} … … 166 160 /// and return something if the return type is non-void. 167 161 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 168 169 162 private: 170 163 virtual void visit( FunctionDecl * functionDecl ); … … 202 195 }; 203 196 197 class CompoundLiteral : public GenPoly::DeclMutator { 198 DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass; 199 200 virtual DeclarationWithType * mutate( ObjectDecl *objectDecl ); 201 virtual Expression *mutate( CompoundLiteralExpr *compLitExpr ); 202 }; 203 204 204 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 205 205 Pass1 pass1; 206 206 Pass2 pass2( doDebug, 0 ); 207 207 Pass3 pass3( 0 ); 208 CompoundLiteral compoundliteral; 209 208 210 EliminateTypedef::eliminateTypedef( translationUnit ); 209 211 HoistStruct::hoistStruct( translationUnit ); … … 211 213 acceptAll( translationUnit, pass2 ); 212 214 ReturnChecker::checkFunctionReturns( translationUnit ); 215 mutateAll( translationUnit, compoundliteral ); 213 216 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 214 217 acceptAll( translationUnit, pass3 ); … … 292 295 } 293 296 294 void HoistStruct::visit( IfStmt *ifStmt ) {295 addVisit( ifStmt, *this );296 }297 298 void HoistStruct::visit( WhileStmt *whileStmt ) {299 addVisit( whileStmt, *this );300 }301 302 void HoistStruct::visit( ForStmt *forStmt ) {303 addVisit( forStmt, *this );304 }305 306 297 void HoistStruct::visit( SwitchStmt *switchStmt ) { 307 298 addVisit( switchStmt, *this ); … … 312 303 } 313 304 314 void HoistStruct::visit( CaseStmt *caseStmt ) { 315 addVisit( caseStmt, *this ); 316 } 317 318 void HoistStruct::visit( CatchStmt *cathStmt ) { 319 addVisit( cathStmt, *this ); 320 } 305 // void HoistStruct::visit( CaseStmt *caseStmt ) { 306 // addVisit( caseStmt, *this ); 307 // } 321 308 322 309 void Pass1::visit( EnumDecl *enumDecl ) { … … 874 861 } 875 862 876 void AutogenerateRoutines::visit( IfStmt *ifStmt ) {877 visitStatement( ifStmt );878 }879 880 void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {881 visitStatement( whileStmt );882 }883 884 void AutogenerateRoutines::visit( ForStmt *forStmt ) {885 visitStatement( forStmt );886 }887 888 863 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 889 864 visitStatement( switchStmt ); … … 894 869 } 895 870 896 void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 897 visitStatement( caseStmt ); 898 } 899 900 void AutogenerateRoutines::visit( CatchStmt *cathStmt ) { 901 visitStatement( cathStmt ); 902 } 871 // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 872 // visitStatement( caseStmt ); 873 // } 903 874 904 875 void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) { … … 1080 1051 } 1081 1052 1053 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) { 1054 storageclass = objectDecl->get_storageClass(); 1055 DeclarationWithType * temp = Mutator::mutate( objectDecl ); 1056 storageclass = DeclarationNode::NoStorageClass; 1057 return temp; 1058 } 1059 1060 Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) { 1061 // transform [storage_class] ... (struct S){ 3, ... }; 1062 // into [storage_class] struct S temp = { 3, ... }; 1063 static UniqueName indexName( "_compLit" ); 1064 1065 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() ); 1066 compLitExpr->set_type( 0 ); 1067 compLitExpr->set_initializer( 0 ); 1068 delete compLitExpr; 1069 DeclarationWithType * newtempvar = mutate( tempvar ); 1070 addDeclaration( newtempvar ); // add modified temporary to current block 1071 return new VariableExpr( newtempvar ); 1072 } 1082 1073 } // namespace SymTab 1083 1074
Note: See TracChangeset
for help on using the changeset viewer.