Changeset 06edda0 for src/SymTab/Validate.cc
- Timestamp:
- Jun 21, 2017, 1:40:54 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:
- e9a3b20b
- Parents:
- af5c204a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
raf5c204a r06edda0 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; … … 246 245 247 246 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 248 EnumAndPointerDecayPassepc;247 PassVisitor<EnumAndPointerDecay> epc; 249 248 LinkReferenceToTypes lrt( doDebug, 0 ); 250 Pass3 pass3( 0 );249 ForallPointerDecay fpd( 0 ); 251 250 CompoundLiteral compoundliteral; 252 251 PassVisitor<ValidateGenericParameters> genericParams; … … 260 259 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 261 260 Concurrency::applyKeywords( translationUnit ); 262 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 263 262 Concurrency::implementMutexFuncs( translationUnit ); 264 263 Concurrency::implementThreadStarter( translationUnit ); 265 264 ReturnChecker::checkFunctionReturns( translationUnit ); 266 265 compoundliteral.mutateDeclarationList( translationUnit ); 267 acceptAll( translationUnit, pass3);266 acceptAll( translationUnit, fpd ); 268 267 ArrayLength::computeLength( translationUnit ); 269 268 } 270 269 271 270 void validateType( Type *type, const Indexer *indexer ) { 272 EnumAndPointerDecayPassepc;271 PassVisitor<EnumAndPointerDecay> epc; 273 272 LinkReferenceToTypes lrt( false, indexer ); 274 Pass3 pass3( indexer );273 ForallPointerDecay fpd( indexer ); 275 274 type->accept( epc ); 276 275 type->accept( lrt ); 277 type->accept( pass3);276 type->accept( fpd ); 278 277 } 279 278 … … 354 353 } 355 354 356 void EnumAndPointerDecay Pass::visit( EnumDecl *enumDecl ) {355 void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) { 357 356 // Set the type of each member of the enumeration to be EnumConstant 358 357 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { … … 361 360 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) ); 362 361 } // for 363 Parent::visit( enumDecl );364 362 } 365 363 … … 368 366 void fixFunctionList( DWTList & dwts, FunctionType * func ) { 369 367 // the only case in which "void" is valid is where it is the only one in the list; then it should be removed 370 // entirely other fix ups are handled by the FixFunction class368 // entirely. other fix ups are handled by the FixFunction class 371 369 typedef typename DWTList::iterator DWTIterator; 372 370 DWTIterator begin( dwts.begin() ), end( dwts.end() ); … … 387 385 for ( ; i != end; ++i ) { 388 386 FixFunction fixer; 389 *i = (*i 387 *i = (*i)->acceptMutator( fixer ); 390 388 if ( fixer.get_isVoid() ) { 391 389 throw SemanticError( "invalid type void in function type ", func ); … … 396 394 } 397 395 398 void EnumAndPointerDecay Pass::visit( FunctionType *func ) {396 void EnumAndPointerDecay::previsit( FunctionType *func ) { 399 397 // Fix up parameters and return types 400 398 fixFunctionList( func->get_parameters(), func ); 401 399 fixFunctionList( func->get_returnVals(), func ); 402 Visitor::visit( func );403 400 } 404 401 … … 547 544 } 548 545 549 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) {546 ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) : Indexer( false ) { 550 547 if ( other_indexer ) { 551 548 indexer = other_indexer; … … 585 582 } 586 583 587 void Pass3::visit( ObjectDecl *object ) {584 void ForallPointerDecay::visit( ObjectDecl *object ) { 588 585 forallFixer( object->get_type() ); 589 586 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 594 591 } 595 592 596 void Pass3::visit( FunctionDecl *func ) {593 void ForallPointerDecay::visit( FunctionDecl *func ) { 597 594 forallFixer( func->get_type() ); 598 595 Parent::visit( func );
Note: See TracChangeset
for help on using the changeset viewer.