Changeset 70a06f6 for src/SymTab
- Timestamp:
- Apr 14, 2016, 4:13:10 PM (10 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, with_gc
- Children:
- 356189a
- Parents:
- db4ecc5 (diff), 37f0da8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/SymTab
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/AddVisit.h
rdb4ecc5 r70a06f6 10 10 // Created On : Sun May 17 16:14:32 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : T ue Jul 14 12:26:17 201513 // Update Count : 412 // Last Modified On : Thu Apr 14 15:52:42 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 88 51 template< typename Visitor > … … 99 62 } // while 100 63 } 64 101 65 } // namespace SymTab 102 66 -
src/SymTab/Autogen.cc
rdb4ecc5 r70a06f6 10 10 // Created On : Thu Mar 03 15:45:56 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Apr 04 17:19:28201612 // Last Modified On : Thu Apr 14 16:00:16 2016 13 13 // Update Count : 1 14 14 // … … 41 41 42 42 virtual void visit( CompoundStmt *compoundStmt ); 43 virtual void visit( IfStmt *ifStmt );44 virtual void visit( WhileStmt *whileStmt );45 virtual void visit( ForStmt *forStmt );46 43 virtual void visit( SwitchStmt *switchStmt ); 47 44 virtual void visit( ChooseStmt *chooseStmt ); 48 virtual void visit( CaseStmt *caseStmt ); 49 virtual void visit( CatchStmt *catchStmt ); 45 // virtual void visit( CaseStmt *caseStmt ); 50 46 51 47 AutogenerateRoutines() : functionNesting( 0 ) {} … … 491 487 } 492 488 493 void AutogenerateRoutines::visit( IfStmt *ifStmt ) {494 visitStatement( ifStmt );495 }496 497 void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {498 visitStatement( whileStmt );499 }500 501 void AutogenerateRoutines::visit( ForStmt *forStmt ) {502 visitStatement( forStmt );503 }504 505 489 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 506 490 visitStatement( switchStmt ); … … 511 495 } 512 496 513 void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 514 visitStatement( caseStmt ); 515 } 516 517 void AutogenerateRoutines::visit( CatchStmt *cathStmt ) { 518 visitStatement( cathStmt ); 519 } 520 497 // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 498 // visitStatement( caseStmt ); 499 // } 521 500 } // SymTab -
src/SymTab/Indexer.cc
rdb4ecc5 r70a06f6 344 344 maybeAccept( offsetofExpr->get_type(), *this ); 345 345 maybeAccept( offsetofExpr->get_member(), *this ); 346 } 347 348 void Indexer::visit( OffsetPackExpr *offsetPackExpr ) { 349 acceptAllNewScope( offsetPackExpr->get_results(), *this ); 350 maybeAccept( offsetPackExpr->get_type(), *this ); 346 351 } 347 352 -
src/SymTab/Indexer.h
rdb4ecc5 r70a06f6 59 59 virtual void visit( UntypedOffsetofExpr *offsetofExpr ); 60 60 virtual void visit( OffsetofExpr *offsetofExpr ); 61 virtual void visit( OffsetPackExpr *offsetPackExpr ); 61 62 virtual void visit( AttrExpr *attrExpr ); 62 63 virtual void visit( LogicalExpr *logicalExpr ); -
src/SymTab/Validate.cc
rdb4ecc5 r70a06f6 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Apr 04 17:13:29201612 // Last Modified On : Thu Apr 14 15:37:23 2016 13 13 // Update Count : 297 14 14 // … … 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" … … 71 73 72 74 virtual void visit( CompoundStmt *compoundStmt ); 73 virtual void visit( IfStmt *ifStmt );74 virtual void visit( WhileStmt *whileStmt );75 virtual void visit( ForStmt *forStmt );76 75 virtual void visit( SwitchStmt *switchStmt ); 77 76 virtual void visit( ChooseStmt *chooseStmt ); 78 virtual void visit( CaseStmt *caseStmt ); 79 virtual void visit( CatchStmt *catchStmt ); 77 // virtual void visit( CaseStmt *caseStmt ); 80 78 private: 81 79 HoistStruct(); … … 132 130 /// and return something if the return type is non-void. 133 131 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 134 135 132 private: 136 133 virtual void visit( FunctionDecl * functionDecl ); … … 163 160 AggDecl *handleAggregate( AggDecl * aggDecl ); 164 161 162 template<typename AggDecl> 163 void addImplicitTypedef( AggDecl * aggDecl ); 164 165 165 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; 166 166 TypedefMap typedefNames; … … 175 175 static void verify( std::list< Declaration * > &translationUnit ); 176 176 177 // VerifyCtorDtor() {}178 179 177 virtual void visit( FunctionDecl *funcDecl ); 180 private: 178 }; 179 180 class CompoundLiteral : public GenPoly::DeclMutator { 181 DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass; 182 183 virtual DeclarationWithType * mutate( ObjectDecl *objectDecl ); 184 virtual Expression *mutate( CompoundLiteralExpr *compLitExpr ); 181 185 }; 182 186 … … 185 189 Pass2 pass2( doDebug, 0 ); 186 190 Pass3 pass3( 0 ); 191 CompoundLiteral compoundliteral; 192 187 193 EliminateTypedef::eliminateTypedef( translationUnit ); 188 194 HoistStruct::hoistStruct( translationUnit ); … … 190 196 acceptAll( translationUnit, pass2 ); 191 197 ReturnChecker::checkFunctionReturns( translationUnit ); 198 mutateAll( translationUnit, compoundliteral ); 192 199 autogenerateRoutines( translationUnit ); 193 200 acceptAll( translationUnit, pass3 ); … … 258 265 } 259 266 260 void HoistStruct::visit( IfStmt *ifStmt ) {261 addVisit( ifStmt, *this );262 }263 264 void HoistStruct::visit( WhileStmt *whileStmt ) {265 addVisit( whileStmt, *this );266 }267 268 void HoistStruct::visit( ForStmt *forStmt ) {269 addVisit( forStmt, *this );270 }271 272 267 void HoistStruct::visit( SwitchStmt *switchStmt ) { 273 268 addVisit( switchStmt, *this ); … … 278 273 } 279 274 280 void HoistStruct::visit( CaseStmt *caseStmt ) { 281 addVisit( caseStmt, *this ); 282 } 283 284 void HoistStruct::visit( CatchStmt *cathStmt ) { 285 addVisit( cathStmt, *this ); 286 } 275 // void HoistStruct::visit( CaseStmt *caseStmt ) { 276 // addVisit( caseStmt, *this ); 277 // } 287 278 288 279 void Pass1::visit( EnumDecl *enumDecl ) { … … 620 611 } 621 612 622 // there may be typedefs nested within aggregates 623 // in order for everything to work properly, these 624 // should be removed as well 613 // there may be typedefs nested within aggregates in order for everything to work properly, these should be removed 614 // as well 625 615 template<typename AggDecl> 626 616 AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) { … … 637 627 } 638 628 629 template<typename AggDecl> 630 void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) { 631 if ( typedefNames.count( aggDecl->get_name() ) == 0 ) { 632 Type *type; 633 if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) { 634 type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ); 635 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( aggDecl ) ) { 636 type = new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ); 637 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( aggDecl ) ) { 638 type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ); 639 } // if 640 TypedefDecl * tyDecl = new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type ); 641 typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); 642 } // if 643 } 639 644 Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) { 645 addImplicitTypedef( structDecl ); 640 646 Mutator::mutate( structDecl ); 641 647 return handleAggregate( structDecl ); … … 643 649 644 650 Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) { 651 addImplicitTypedef( unionDecl ); 645 652 Mutator::mutate( unionDecl ); 646 653 return handleAggregate( unionDecl ); … … 648 655 649 656 Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) { 657 addImplicitTypedef( enumDecl ); 650 658 Mutator::mutate( enumDecl ); 651 659 return handleAggregate( enumDecl ); 652 660 } 653 661 654 662 Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) { 655 663 Mutator::mutate( contextDecl ); 656 664 return handleAggregate( contextDecl ); … … 689 697 // added, so not in this pass! 690 698 } 699 700 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) { 701 storageclass = objectDecl->get_storageClass(); 702 DeclarationWithType * temp = Mutator::mutate( objectDecl ); 703 storageclass = DeclarationNode::NoStorageClass; 704 return temp; 705 } 706 707 Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) { 708 // transform [storage_class] ... (struct S){ 3, ... }; 709 // into [storage_class] struct S temp = { 3, ... }; 710 static UniqueName indexName( "_compLit" ); 711 712 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() ); 713 compLitExpr->set_type( 0 ); 714 compLitExpr->set_initializer( 0 ); 715 delete compLitExpr; 716 DeclarationWithType * newtempvar = mutate( tempvar ); 717 addDeclaration( newtempvar ); // add modified temporary to current block 718 return new VariableExpr( newtempvar ); 719 } 691 720 } // namespace SymTab 692 721
Note:
See TracChangeset
for help on using the changeset viewer.