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