Changeset 3f7e12cb for src/SymTab/Validate.cc
- Timestamp:
- Nov 8, 2017, 5:43:33 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 954908d
- Parents:
- 78315272 (diff), e35f30a (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
r78315272 r3f7e12cb 56 56 #include "FixFunction.h" // for FixFunction 57 57 #include "Indexer.h" // for Indexer 58 #include "InitTweak/GenInit.h" // for fixReturnStatements 58 59 #include "InitTweak/InitTweak.h" // for isCtorDtorAssign 59 60 #include "Parser/LinkageSpec.h" // for C … … 150 151 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 151 152 struct ForallPointerDecay final { 152 void previsit( ObjectDecl *object ); 153 void previsit( FunctionDecl *func ); 153 void previsit( ObjectDecl * object ); 154 void previsit( FunctionDecl * func ); 155 void previsit( StructDecl * aggrDecl ); 156 void previsit( UnionDecl * aggrDecl ); 154 157 }; 155 158 … … 265 268 HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order 266 269 ReturnTypeFixer::fix( translationUnit ); // must happen before autogen 270 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes because it is an indexer and needs correct types for mangling 267 271 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 268 272 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes 269 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist270 273 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 274 ReturnChecker::checkFunctionReturns( translationUnit ); 275 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen 271 276 Concurrency::applyKeywords( translationUnit ); 277 acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution 272 278 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay 273 279 Concurrency::implementMutexFuncs( translationUnit ); 274 280 Concurrency::implementThreadStarter( translationUnit ); 275 ReturnChecker::checkFunctionReturns( translationUnit );276 281 mutateAll( translationUnit, compoundliteral ); 277 acceptAll( translationUnit, fpd );278 282 ArrayLength::computeLength( translationUnit ); 279 acceptAll( translationUnit, finder ); 283 acceptAll( translationUnit, finder ); // xxx - remove this pass soon 280 284 mutateAll( translationUnit, labelAddrFixer ); 281 285 } … … 368 372 DWTIterator begin( dwts.begin() ), end( dwts.end() ); 369 373 if ( begin == end ) return; 370 FixFunctionfixer;374 PassVisitor<FixFunction> fixer; 371 375 DWTIterator i = begin; 372 376 *i = (*i)->acceptMutator( fixer ); 373 if ( fixer. get_isVoid()) {377 if ( fixer.pass.isVoid ) { 374 378 DWTIterator j = i; 375 379 ++i; … … 382 386 ++i; 383 387 for ( ; i != end; ++i ) { 384 FixFunctionfixer;388 PassVisitor<FixFunction> fixer; 385 389 *i = (*i)->acceptMutator( fixer ); 386 if ( fixer. get_isVoid()) {390 if ( fixer.pass.isVoid ) { 387 391 throw SemanticError( "invalid type void in function type ", func ); 388 392 } // if … … 579 583 580 584 /// Fix up assertions - flattens assertion lists, removing all trait instances 581 void forallFixer( Type * func) {582 for ( TypeDecl * type : f unc->get_forall()) {585 void forallFixer( std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) { 586 for ( TypeDecl * type : forall ) { 583 587 std::list< DeclarationWithType * > asserts; 584 588 asserts.splice( asserts.end(), type->assertions ); … … 596 600 // apply FixFunction to every assertion to check for invalid void type 597 601 for ( DeclarationWithType *& assertion : type->assertions ) { 598 FixFunctionfixer;602 PassVisitor<FixFunction> fixer; 599 603 assertion = assertion->acceptMutator( fixer ); 600 if ( fixer. get_isVoid()) {601 throw SemanticError( "invalid type void in assertion of function ", func);604 if ( fixer.pass.isVoid ) { 605 throw SemanticError( "invalid type void in assertion of function ", node ); 602 606 } // if 603 607 } // for … … 607 611 608 612 void ForallPointerDecay::previsit( ObjectDecl *object ) { 609 forallFixer( object-> get_type());610 if ( PointerType *pointer = dynamic_cast< PointerType * >( object-> get_type()) ) {611 forallFixer( pointer-> get_base());613 forallFixer( object->type->forall, object ); 614 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->type ) ) { 615 forallFixer( pointer->base->forall, object ); 612 616 } // if 613 617 object->fixUniqueId(); … … 615 619 616 620 void ForallPointerDecay::previsit( FunctionDecl *func ) { 617 forallFixer( func-> get_type());621 forallFixer( func->type->forall, func ); 618 622 func->fixUniqueId(); 623 } 624 625 void ForallPointerDecay::previsit( StructDecl * aggrDecl ) { 626 forallFixer( aggrDecl->parameters, aggrDecl ); 627 } 628 629 void ForallPointerDecay::previsit( UnionDecl * aggrDecl ) { 630 forallFixer( aggrDecl->parameters, aggrDecl ); 619 631 } 620 632 … … 656 668 } 657 669 filter( translationUnit, isTypedef, true ); 658 659 670 } 660 671 … … 664 675 TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() ); 665 676 if ( def != typedefNames.end() ) { 666 Type *ret = def->second.first-> get_base()->clone();677 Type *ret = def->second.first->base->clone(); 667 678 ret->get_qualifiers() |= typeInst->get_qualifiers(); 668 679 // place instance parameters on the typedef'd type 669 if ( ! typeInst-> get_parameters().empty() ) {680 if ( ! typeInst->parameters.empty() ) { 670 681 ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret); 671 682 if ( ! rtt ) { 672 throw SemanticError(" cannot apply type parameters to base type of " + typeInst->get_name());683 throw SemanticError("Cannot apply type parameters to base type of " + typeInst->name); 673 684 } 674 685 rtt->get_parameters().clear(); 675 cloneAll( typeInst-> get_parameters(), rtt->get_parameters());676 mutateAll( rtt-> get_parameters(), *visitor ); // recursively fix typedefs on parameters686 cloneAll( typeInst->parameters, rtt->parameters ); 687 mutateAll( rtt->parameters, *visitor ); // recursively fix typedefs on parameters 677 688 } // if 678 689 delete typeInst; … … 680 691 } else { 681 692 TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() ); 682 assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst-> get_name().c_str() );693 assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst->name.c_str() ); 683 694 typeInst->set_baseType( base->second ); 684 695 } // if 685 696 return typeInst; 697 } 698 699 struct VarLenChecker : WithShortCircuiting { 700 void previsit( FunctionType * ) { visit_children = false; } 701 void previsit( ArrayType * at ) { 702 isVarLen |= at->isVarLen; 703 } 704 bool isVarLen = false; 705 }; 706 707 bool isVariableLength( Type * t ) { 708 PassVisitor<VarLenChecker> varLenChecker; 709 maybeAccept( t, varLenChecker ); 710 return varLenChecker.pass.isVarLen; 686 711 } 687 712 … … 694 719 Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base(); 695 720 if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) { 696 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 721 throw SemanticError( "Cannot redefine typedef: " + tyDecl->name ); 722 } 723 // cannot redefine VLA typedefs 724 if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) { 725 throw SemanticError( "Cannot redefine typedef: " + tyDecl->name ); 697 726 } 698 727 } else {
Note:
See TracChangeset
for help on using the changeset viewer.