Changes in src/SymTab/Validate.cc [d24d4e1:c6d2e93]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rd24d4e1 rc6d2e93 106 106 107 107 /// Fix return types so that every function returns exactly one value 108 struct ReturnTypeFixer { 108 class ReturnTypeFixer { 109 public: 109 110 static void fix( std::list< Declaration * > &translationUnit ); 110 111 … … 114 115 115 116 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 116 struct EnumAndPointerDecay { 117 void previsit( EnumDecl *aggregateDecl ); 118 void 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 ); 119 121 }; 120 122 … … 124 126 public: 125 127 LinkReferenceToTypes( bool doDebug, const Indexer *indexer ); 128 private: 126 129 using Parent::visit; 127 130 void visit( EnumInstType *enumInst ) final; … … 133 136 void visit( UnionDecl *unionDecl ) final; 134 137 void visit( TypeInstType *typeInst ) final; 135 private: 138 136 139 const Indexer *indexer; 137 140 … … 144 147 }; 145 148 146 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.147 class ForallPointerDecayfinal : public Indexer {149 /// Replaces array and function types in forall lists by appropriate pointer type 150 class Pass3 final : public Indexer { 148 151 typedef Indexer Parent; 149 152 public: 150 153 using Parent::visit; 151 ForallPointerDecay( const Indexer *indexer );152 154 Pass3( const Indexer *indexer ); 155 private: 153 156 virtual void visit( ObjectDecl *object ) override; 154 157 virtual void visit( FunctionDecl *func ) override; … … 157 160 }; 158 161 159 struct ReturnChecker : public WithGuards { 162 class ReturnChecker { 163 public: 160 164 /// Checks that return statements return nothing if their return type is void 161 165 /// and return something if the return type is non-void. 162 166 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 163 167 private: 164 168 void previsit( FunctionDecl * functionDecl ); 169 void postvisit( FunctionDecl * functionDecl ); 165 170 void previsit( ReturnStmt * returnStmt ); 166 171 167 172 typedef std::list< DeclarationWithType * > ReturnVals; 168 173 ReturnVals returnVals; 174 std::stack< ReturnVals > returnValsStack; 169 175 }; 170 176 … … 202 208 }; 203 209 204 struct VerifyCtorDtorAssign { 210 class VerifyCtorDtorAssign { 211 public: 205 212 /// ensure that constructors, destructors, and assignment have at least one 206 213 /// parameter, the first of which must be a pointer, and that ctor/dtors have no … … 212 219 213 220 /// ensure that generic types have the correct number of type arguments 214 struct ValidateGenericParameters { 221 class ValidateGenericParameters { 222 public: 215 223 void previsit( StructInstType * inst ); 216 224 void previsit( UnionInstType * inst ); 217 225 }; 218 226 219 struct ArrayLength { 227 class ArrayLength { 228 public: 220 229 /// for array types without an explicit length, compute the length and store it so that it 221 230 /// is known to the rest of the phases. For example, … … 230 239 }; 231 240 232 struct CompoundLiteral final : public WithDeclsToAdd, public WithVisitorRef<CompoundLiteral>{241 class CompoundLiteral final : public GenPoly::DeclMutator { 233 242 Type::StorageClasses storageClasses; 234 243 235 void premutate( ObjectDecl *objectDecl ); 236 Expression * postmutate( CompoundLiteralExpr *compLitExpr ); 244 using GenPoly::DeclMutator::mutate; 245 DeclarationWithType * mutate( ObjectDecl *objectDecl ) final; 246 Expression *mutate( CompoundLiteralExpr *compLitExpr ) final; 237 247 }; 238 248 239 249 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 240 PassVisitor<EnumAndPointerDecay>epc;250 EnumAndPointerDecayPass epc; 241 251 LinkReferenceToTypes lrt( doDebug, 0 ); 242 ForallPointerDecay fpd( 0 );243 PassVisitor<CompoundLiteral>compoundliteral;252 Pass3 pass3( 0 ); 253 CompoundLiteral compoundliteral; 244 254 PassVisitor<ValidateGenericParameters> genericParams; 245 255 … … 252 262 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 253 263 Concurrency::applyKeywords( translationUnit ); 254 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 255 265 Concurrency::implementMutexFuncs( translationUnit ); 256 266 Concurrency::implementThreadStarter( translationUnit ); 257 267 ReturnChecker::checkFunctionReturns( translationUnit ); 258 mutateAll( translationUnit, compoundliteral);259 acceptAll( translationUnit, fpd);268 compoundliteral.mutateDeclarationList( translationUnit ); 269 acceptAll( translationUnit, pass3 ); 260 270 ArrayLength::computeLength( translationUnit ); 261 271 } 262 272 263 273 void validateType( Type *type, const Indexer *indexer ) { 264 PassVisitor<EnumAndPointerDecay>epc;274 EnumAndPointerDecayPass epc; 265 275 LinkReferenceToTypes lrt( false, indexer ); 266 ForallPointerDecay fpd( indexer );276 Pass3 pass3( indexer ); 267 277 type->accept( epc ); 268 278 type->accept( lrt ); 269 type->accept( fpd);279 type->accept( pass3 ); 270 280 } 271 281 … … 346 356 } 347 357 348 void EnumAndPointerDecay ::previsit( EnumDecl *enumDecl ) {358 void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) { 349 359 // Set the type of each member of the enumeration to be EnumConstant 350 360 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { … … 353 363 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) ); 354 364 } // for 365 Parent::visit( enumDecl ); 355 366 } 356 367 … … 359 370 void fixFunctionList( DWTList & dwts, FunctionType * func ) { 360 371 // the only case in which "void" is valid is where it is the only one in the list; then it should be removed 361 // entirely .other fix ups are handled by the FixFunction class372 // entirely other fix ups are handled by the FixFunction class 362 373 typedef typename DWTList::iterator DWTIterator; 363 374 DWTIterator begin( dwts.begin() ), end( dwts.end() ); … … 378 389 for ( ; i != end; ++i ) { 379 390 FixFunction fixer; 380 *i = (*i )->acceptMutator( fixer );391 *i = (*i )->acceptMutator( fixer ); 381 392 if ( fixer.get_isVoid() ) { 382 393 throw SemanticError( "invalid type void in function type ", func ); … … 387 398 } 388 399 389 void EnumAndPointerDecay ::previsit( FunctionType *func ) {400 void EnumAndPointerDecayPass::visit( FunctionType *func ) { 390 401 // Fix up parameters and return types 391 402 fixFunctionList( func->get_parameters(), func ); 392 403 fixFunctionList( func->get_returnVals(), func ); 404 Visitor::visit( func ); 393 405 } 394 406 … … 537 549 } 538 550 539 ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) : Indexer( false ) {551 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) { 540 552 if ( other_indexer ) { 541 553 indexer = other_indexer; … … 575 587 } 576 588 577 void ForallPointerDecay::visit( ObjectDecl *object ) {589 void Pass3::visit( ObjectDecl *object ) { 578 590 forallFixer( object->get_type() ); 579 591 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 584 596 } 585 597 586 void ForallPointerDecay::visit( FunctionDecl *func ) {598 void Pass3::visit( FunctionDecl *func ) { 587 599 forallFixer( func->get_type() ); 588 600 Parent::visit( func ); … … 596 608 597 609 void ReturnChecker::previsit( FunctionDecl * functionDecl ) { 598 GuardValue( returnVals );610 returnValsStack.push( returnVals ); 599 611 returnVals = functionDecl->get_functionType()->get_returnVals(); 612 } 613 void ReturnChecker::postvisit( FunctionDecl * functionDecl ) { 614 returnVals = returnValsStack.top(); 615 returnValsStack.pop(); 600 616 } 601 617 … … 876 892 } 877 893 878 void CompoundLiteral::premutate( ObjectDecl *objectDecl ) {894 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) { 879 895 storageClasses = objectDecl->get_storageClasses(); 880 } 881 882 Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) { 896 DeclarationWithType * temp = Mutator::mutate( objectDecl ); 897 return temp; 898 } 899 900 Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) { 883 901 // transform [storage_class] ... (struct S){ 3, ... }; 884 902 // into [storage_class] struct S temp = { 3, ... }; 885 903 static UniqueName indexName( "_compLit" ); 886 904 887 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );888 compLitExpr->set_result( nullptr);889 compLitExpr->set_initializer( nullptr);905 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, 0, compLitExpr->get_result(), compLitExpr->get_initializer() ); 906 compLitExpr->set_result( 0 ); 907 compLitExpr->set_initializer( 0 ); 890 908 delete compLitExpr; 891 declsToAddBefore.push_back( tempvar ); // add modified temporary to current block 892 return new VariableExpr( tempvar ); 909 DeclarationWithType * newtempvar = mutate( tempvar ); 910 addDeclaration( newtempvar ); // add modified temporary to current block 911 return new VariableExpr( newtempvar ); 893 912 } 894 913
Note:
See TracChangeset
for help on using the changeset viewer.