Changeset 925b7f4 for src/SymTab/Validate.cc
- Timestamp:
- Jun 22, 2017, 9:49:39 AM (7 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:
- 65dc863
- Parents:
- 35df560 (diff), e9a3b20b (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
r35df560 r925b7f4 115 115 116 116 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 117 class EnumAndPointerDecay Pass final : public Visitor{118 typedef Visitor Parent;119 v irtual voidvisit( EnumDecl *aggregateDecl );120 v irtual voidvisit( FunctionType *func );117 class EnumAndPointerDecay { 118 public: 119 void previsit( EnumDecl *aggregateDecl ); 120 void previsit( FunctionType *func ); 121 121 }; 122 122 … … 126 126 public: 127 127 LinkReferenceToTypes( bool doDebug, const Indexer *indexer ); 128 private:129 128 using Parent::visit; 130 129 void visit( EnumInstType *enumInst ) final; … … 136 135 void visit( UnionDecl *unionDecl ) final; 137 136 void visit( TypeInstType *typeInst ) final; 138 137 private: 139 138 const Indexer *indexer; 140 139 … … 147 146 }; 148 147 149 /// Replaces array and function types in forall lists by appropriate pointer type 150 class Pass3final : public Indexer {148 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 149 class ForallPointerDecay final : public Indexer { 151 150 typedef Indexer Parent; 152 151 public: 153 152 using Parent::visit; 154 Pass3( const Indexer *indexer );155 private: 153 ForallPointerDecay( const Indexer *indexer ); 154 156 155 virtual void visit( ObjectDecl *object ) override; 157 156 virtual void visit( FunctionDecl *func ) override; … … 160 159 }; 161 160 162 class ReturnChecker {161 class ReturnChecker : public WithScopes { 163 162 public: 164 163 /// Checks that return statements return nothing if their return type is void … … 167 166 private: 168 167 void previsit( FunctionDecl * functionDecl ); 169 void postvisit( FunctionDecl * functionDecl );170 168 void previsit( ReturnStmt * returnStmt ); 171 169 172 170 typedef std::list< DeclarationWithType * > ReturnVals; 173 171 ReturnVals returnVals; 174 std::stack< ReturnVals > returnValsStack;175 172 }; 176 173 … … 248 245 249 246 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 250 EnumAndPointerDecayPassepc;247 PassVisitor<EnumAndPointerDecay> epc; 251 248 LinkReferenceToTypes lrt( doDebug, 0 ); 252 Pass3 pass3( 0 );249 ForallPointerDecay fpd( 0 ); 253 250 CompoundLiteral compoundliteral; 254 251 PassVisitor<ValidateGenericParameters> genericParams; … … 262 259 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 263 260 Concurrency::applyKeywords( translationUnit ); 264 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay Pass261 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay 265 262 Concurrency::implementMutexFuncs( translationUnit ); 266 263 Concurrency::implementThreadStarter( translationUnit ); 267 264 ReturnChecker::checkFunctionReturns( translationUnit ); 268 265 compoundliteral.mutateDeclarationList( translationUnit ); 269 acceptAll( translationUnit, pass3);266 acceptAll( translationUnit, fpd ); 270 267 ArrayLength::computeLength( translationUnit ); 271 268 } 272 269 273 270 void validateType( Type *type, const Indexer *indexer ) { 274 EnumAndPointerDecayPassepc;271 PassVisitor<EnumAndPointerDecay> epc; 275 272 LinkReferenceToTypes lrt( false, indexer ); 276 Pass3 pass3( indexer );273 ForallPointerDecay fpd( indexer ); 277 274 type->accept( epc ); 278 275 type->accept( lrt ); 279 type->accept( pass3);276 type->accept( fpd ); 280 277 } 281 278 … … 356 353 } 357 354 358 void EnumAndPointerDecay Pass::visit( EnumDecl *enumDecl ) {355 void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) { 359 356 // Set the type of each member of the enumeration to be EnumConstant 360 357 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { … … 363 360 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) ); 364 361 } // for 365 Parent::visit( enumDecl );366 362 } 367 363 … … 370 366 void fixFunctionList( DWTList & dwts, FunctionType * func ) { 371 367 // the only case in which "void" is valid is where it is the only one in the list; then it should be removed 372 // entirely other fix ups are handled by the FixFunction class368 // entirely. other fix ups are handled by the FixFunction class 373 369 typedef typename DWTList::iterator DWTIterator; 374 370 DWTIterator begin( dwts.begin() ), end( dwts.end() ); … … 389 385 for ( ; i != end; ++i ) { 390 386 FixFunction fixer; 391 *i = (*i 387 *i = (*i)->acceptMutator( fixer ); 392 388 if ( fixer.get_isVoid() ) { 393 389 throw SemanticError( "invalid type void in function type ", func ); … … 398 394 } 399 395 400 void EnumAndPointerDecay Pass::visit( FunctionType *func ) {396 void EnumAndPointerDecay::previsit( FunctionType *func ) { 401 397 // Fix up parameters and return types 402 398 fixFunctionList( func->get_parameters(), func ); 403 399 fixFunctionList( func->get_returnVals(), func ); 404 Visitor::visit( func );405 400 } 406 401 … … 549 544 } 550 545 551 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) {546 ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) : Indexer( false ) { 552 547 if ( other_indexer ) { 553 548 indexer = other_indexer; … … 587 582 } 588 583 589 void Pass3::visit( ObjectDecl *object ) {584 void ForallPointerDecay::visit( ObjectDecl *object ) { 590 585 forallFixer( object->get_type() ); 591 586 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 596 591 } 597 592 598 void Pass3::visit( FunctionDecl *func ) {593 void ForallPointerDecay::visit( FunctionDecl *func ) { 599 594 forallFixer( func->get_type() ); 600 595 Parent::visit( func ); … … 608 603 609 604 void ReturnChecker::previsit( FunctionDecl * functionDecl ) { 610 returnValsStack.push( returnVals );605 GuardValue( returnVals ); 611 606 returnVals = functionDecl->get_functionType()->get_returnVals(); 612 }613 void ReturnChecker::postvisit( __attribute__((unused)) FunctionDecl * functionDecl ) {614 returnVals = returnValsStack.top();615 returnValsStack.pop();616 607 } 617 608
Note: See TracChangeset
for help on using the changeset viewer.