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