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