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