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