Changeset 70a06f6 for src/SymTab/Validate.cc
- Timestamp:
- Apr 14, 2016, 4:13:10 PM (8 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.