Changes in src/SymTab/Validate.cc [98538288:4615ac8]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r98538288 r4615ac8 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Dec 13 23:43:34201913 // Update Count : 36 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 7 6:42:00 2019 13 // Update Count : 360 14 14 // 15 15 … … 69 69 #include "InitTweak/GenInit.h" // for fixReturnStatements 70 70 #include "InitTweak/InitTweak.h" // for isCtorDtorAssign 71 #include "Parser/LinkageSpec.h" // for C 71 72 #include "ResolvExpr/typeops.h" // for typesCompatible 72 73 #include "ResolvExpr/Resolver.h" // for findSingleExpression 73 74 #include "ResolvExpr/ResolveTypeof.h" // for resolveTypeof 74 75 #include "SymTab/Autogen.h" // for SizeType 75 #include "SynTree/LinkageSpec.h" // for C76 76 #include "SynTree/Attribute.h" // for noAttributes, Attribute 77 77 #include "SynTree/Constant.h" // for Constant … … 81 81 #include "SynTree/Label.h" // for operator==, Label 82 82 #include "SynTree/Mutator.h" // for Mutator 83 #include "SynTree/TopLvalue.h" // for assertTopLvalue, clearInnerLvalue 83 84 #include "SynTree/Type.h" // for Type, TypeInstType, EnumInstType 84 85 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution … … 308 309 PassVisitor<FixQualifiedTypes> fixQual; 309 310 311 assertTopLvalue( translationUnit ); 310 312 { 311 313 Stats::Heap::newPass("validate-A"); 312 314 Stats::Time::BlockGuard guard("validate-A"); 313 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors314 315 acceptAll( translationUnit, hoistDecls ); 315 316 ReplaceTypedef::replaceTypedef( translationUnit ); … … 317 318 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling 318 319 } 320 assertTopLvalue( translationUnit ); 319 321 { 320 322 Stats::Heap::newPass("validate-B"); 321 323 Stats::Time::BlockGuard guard("validate-B"); 324 assertTopLvalue( translationUnit ); 322 325 Stats::Time::TimeBlock("Link Reference To Types", [&]() { 323 326 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 324 327 }); 328 clearInnerLvalue( translationUnit ); 329 assertTopLvalue( translationUnit ); 325 330 Stats::Time::TimeBlock("Fix Qualified Types", [&]() { 326 331 mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed 327 332 }); 333 assertTopLvalue( translationUnit ); 328 334 Stats::Time::TimeBlock("Hoist Structs", [&]() { 329 335 HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order 330 336 }); 337 assertTopLvalue( translationUnit ); 331 338 Stats::Time::TimeBlock("Eliminate Typedefs", [&]() { 332 339 EliminateTypedef::eliminateTypedef( translationUnit ); // 333 340 }); 334 341 } 342 assertTopLvalue( translationUnit ); 335 343 { 336 344 Stats::Heap::newPass("validate-C"); 337 345 Stats::Time::BlockGuard guard("validate-C"); 338 346 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes_old 347 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 339 348 ReturnChecker::checkFunctionReturns( translationUnit ); 340 349 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen 341 350 } 351 assertTopLvalue( translationUnit ); 342 352 { 343 353 Stats::Heap::newPass("validate-D"); 344 354 Stats::Time::BlockGuard guard("validate-D"); 355 assertTopLvalue( translationUnit ); 345 356 Stats::Time::TimeBlock("Apply Concurrent Keywords", [&]() { 346 357 Concurrency::applyKeywords( translationUnit ); 347 358 }); 359 clearInnerLvalue( translationUnit ); 360 assertTopLvalue( translationUnit ); 348 361 Stats::Time::TimeBlock("Forall Pointer Decay", [&]() { 349 362 acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution 350 363 }); 364 assertTopLvalue( translationUnit ); 351 365 Stats::Time::TimeBlock("Hoist Control Declarations", [&]() { 352 366 ControlStruct::hoistControlDecls( translationUnit ); // hoist initialization out of for statements; must happen before autogenerateRoutines 353 367 }); 368 assertTopLvalue( translationUnit ); 354 369 Stats::Time::TimeBlock("Generate Autogen routines", [&]() { 355 370 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay_old 356 371 }); 357 } 372 clearInnerLvalue( translationUnit ); 373 } 374 assertTopLvalue( translationUnit ); 358 375 { 359 376 Stats::Heap::newPass("validate-E"); 360 377 Stats::Time::BlockGuard guard("validate-E"); 378 assertTopLvalue( translationUnit ); 361 379 Stats::Time::TimeBlock("Implement Mutex Func", [&]() { 362 380 Concurrency::implementMutexFuncs( translationUnit ); 363 381 }); 382 clearInnerLvalue( translationUnit ); 383 assertTopLvalue( translationUnit ); 364 384 Stats::Time::TimeBlock("Implement Thread Start", [&]() { 365 385 Concurrency::implementThreadStarter( translationUnit ); 366 386 }); 387 assertTopLvalue( translationUnit ); 367 388 Stats::Time::TimeBlock("Compound Literal", [&]() { 368 389 mutateAll( translationUnit, compoundliteral ); 369 390 }); 391 assertTopLvalue( translationUnit ); 370 392 Stats::Time::TimeBlock("Resolve With Expressions", [&]() { 371 393 ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables 372 394 }); 373 } 395 clearInnerLvalue( translationUnit ); 396 } 397 assertTopLvalue( translationUnit ); 374 398 { 375 399 Stats::Heap::newPass("validate-F"); 376 400 Stats::Time::BlockGuard guard("validate-F"); 377 Stats::Time::TimeCall("Fix Object Type", 378 FixObjectType::fix, translationUnit); 379 Stats::Time::TimeCall("Array Length", 380 ArrayLength::computeLength, translationUnit); 381 Stats::Time::TimeCall("Find Special Declarations", 382 Validate::findSpecialDecls, translationUnit); 383 Stats::Time::TimeCall("Fix Label Address", 384 mutateAll<LabelAddressFixer>, translationUnit, labelAddrFixer); 385 Stats::Time::TimeCall("Handle Attributes", 386 Validate::handleAttributes, translationUnit); 387 } 401 assertTopLvalue( translationUnit ); 402 Stats::Time::TimeBlock("Fix Object Type", [&]() { 403 FixObjectType::fix( translationUnit ); 404 }); 405 assertTopLvalue( translationUnit ); 406 Stats::Time::TimeBlock("Array Length", [&]() { 407 ArrayLength::computeLength( translationUnit ); 408 }); 409 clearInnerLvalue( translationUnit ); 410 assertTopLvalue( translationUnit ); 411 Stats::Time::TimeBlock("Find Special Declarations", [&]() { 412 Validate::findSpecialDecls( translationUnit ); 413 }); 414 assertTopLvalue( translationUnit ); 415 Stats::Time::TimeBlock("Fix Label Address", [&]() { 416 mutateAll( translationUnit, labelAddrFixer ); 417 }); 418 assertTopLvalue( translationUnit ); 419 Stats::Time::TimeBlock("Handle Attributes", [&]() { 420 Validate::handleAttributes( translationUnit ); 421 }); 422 } 423 assertTopLvalue( translationUnit ); 388 424 } 389 425 … … 1044 1080 Type * designatorType = tyDecl->base->stripDeclarator(); 1045 1081 if ( StructInstType * aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) { 1046 declsToAddBefore.push_back( new StructDecl( aggDecl->name, AggregateDecl::Struct, noAttributes, tyDecl->linkage ) );1082 declsToAddBefore.push_back( new StructDecl( aggDecl->name, DeclarationNode::Struct, noAttributes, tyDecl->linkage ) ); 1047 1083 } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) { 1048 1084 declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) ); … … 1182 1218 if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc. 1183 1219 if ( params.size() == 0 ) { 1184 SemanticError( funcDecl ->location, "Constructors, destructors, and assignment functions require at least one parameter." );1220 SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " ); 1185 1221 } 1186 1222 ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() ); 1187 1223 if ( ! refType ) { 1188 SemanticError( funcDecl ->location, "First parameter of a constructor, destructor, or assignment function must be a reference." );1224 SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " ); 1189 1225 } 1190 1226 if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) { 1191 if(!returnVals.front()->get_type()->isVoid()) { 1192 SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." ); 1193 } 1227 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " ); 1194 1228 } 1195 1229 } … … 1300 1334 void FixObjectType::previsit( ObjectDecl * objDecl ) { 1301 1335 Type * new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer ); 1336 new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type 1302 1337 objDecl->set_type( new_type ); 1303 1338 } … … 1305 1340 void FixObjectType::previsit( FunctionDecl * funcDecl ) { 1306 1341 Type * new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer ); 1342 new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type 1307 1343 funcDecl->set_type( new_type ); 1308 1344 } … … 1311 1347 if ( typeDecl->get_base() ) { 1312 1348 Type * new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer ); 1349 new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type 1313 1350 typeDecl->set_base( new_type ); 1314 1351 } // if
Note:
See TracChangeset
for help on using the changeset viewer.