Sema.cpp revision 86c05f3f28bcf07c97dfb1881686fc43be2f47c2
1//===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements the actions class which performs semantic analysis and 11// builds an AST out of a parse stream. 12// 13//===----------------------------------------------------------------------===// 14 15#include "clang/Sema/SemaInternal.h" 16#include "clang/Sema/DelayedDiagnostic.h" 17#include "TargetAttributesSema.h" 18#include "llvm/ADT/DenseMap.h" 19#include "llvm/ADT/SmallSet.h" 20#include "llvm/ADT/APFloat.h" 21#include "clang/Sema/CXXFieldCollector.h" 22#include "clang/Sema/TemplateDeduction.h" 23#include "clang/Sema/ExternalSemaSource.h" 24#include "clang/Sema/ObjCMethodList.h" 25#include "clang/Sema/PrettyDeclStackTrace.h" 26#include "clang/Sema/Scope.h" 27#include "clang/Sema/ScopeInfo.h" 28#include "clang/Sema/SemaConsumer.h" 29#include "clang/AST/ASTContext.h" 30#include "clang/AST/ASTDiagnostic.h" 31#include "clang/AST/DeclCXX.h" 32#include "clang/AST/DeclObjC.h" 33#include "clang/AST/Expr.h" 34#include "clang/Lex/Preprocessor.h" 35#include "clang/Basic/PartialDiagnostic.h" 36#include "clang/Basic/TargetInfo.h" 37using namespace clang; 38using namespace sema; 39 40FunctionScopeInfo::~FunctionScopeInfo() { } 41 42void FunctionScopeInfo::Clear() { 43 HasBranchProtectedScope = false; 44 HasBranchIntoScope = false; 45 HasIndirectGoto = false; 46 47 LabelMap.clear(); 48 SwitchStack.clear(); 49 Returns.clear(); 50 ErrorTrap.reset(); 51} 52 53BlockScopeInfo::~BlockScopeInfo() { } 54 55void Sema::ActOnTranslationUnitScope(Scope *S) { 56 TUScope = S; 57 PushDeclContext(S, Context.getTranslationUnitDecl()); 58 59 VAListTagName = PP.getIdentifierInfo("__va_list_tag"); 60 61 if (!Context.isInt128Installed() && // May be set by ASTReader. 62 PP.getTargetInfo().getPointerWidth(0) >= 64) { 63 TypeSourceInfo *TInfo; 64 65 // Install [u]int128_t for 64-bit targets. 66 TInfo = Context.getTrivialTypeSourceInfo(Context.Int128Ty); 67 PushOnScopeChains(TypedefDecl::Create(Context, CurContext, 68 SourceLocation(), 69 &Context.Idents.get("__int128_t"), 70 TInfo), TUScope); 71 72 TInfo = Context.getTrivialTypeSourceInfo(Context.UnsignedInt128Ty); 73 PushOnScopeChains(TypedefDecl::Create(Context, CurContext, 74 SourceLocation(), 75 &Context.Idents.get("__uint128_t"), 76 TInfo), TUScope); 77 Context.setInt128Installed(); 78 } 79 80 81 if (!PP.getLangOptions().ObjC1) return; 82 83 // Built-in ObjC types may already be set by ASTReader (hence isNull checks). 84 if (Context.getObjCSelType().isNull()) { 85 // Create the built-in typedef for 'SEL'. 86 QualType SelT = Context.getPointerType(Context.ObjCBuiltinSelTy); 87 TypeSourceInfo *SelInfo = Context.getTrivialTypeSourceInfo(SelT); 88 TypedefDecl *SelTypedef 89 = TypedefDecl::Create(Context, CurContext, SourceLocation(), 90 &Context.Idents.get("SEL"), SelInfo); 91 PushOnScopeChains(SelTypedef, TUScope); 92 Context.setObjCSelType(Context.getTypeDeclType(SelTypedef)); 93 Context.ObjCSelRedefinitionType = Context.getObjCSelType(); 94 } 95 96 // Synthesize "@class Protocol; 97 if (Context.getObjCProtoType().isNull()) { 98 ObjCInterfaceDecl *ProtocolDecl = 99 ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), 100 &Context.Idents.get("Protocol"), 101 SourceLocation(), true); 102 Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); 103 PushOnScopeChains(ProtocolDecl, TUScope, false); 104 } 105 // Create the built-in typedef for 'id'. 106 if (Context.getObjCIdType().isNull()) { 107 QualType T = Context.getObjCObjectType(Context.ObjCBuiltinIdTy, 0, 0); 108 T = Context.getObjCObjectPointerType(T); 109 TypeSourceInfo *IdInfo = Context.getTrivialTypeSourceInfo(T); 110 TypedefDecl *IdTypedef 111 = TypedefDecl::Create(Context, CurContext, SourceLocation(), 112 &Context.Idents.get("id"), IdInfo); 113 PushOnScopeChains(IdTypedef, TUScope); 114 Context.setObjCIdType(Context.getTypeDeclType(IdTypedef)); 115 Context.ObjCIdRedefinitionType = Context.getObjCIdType(); 116 } 117 // Create the built-in typedef for 'Class'. 118 if (Context.getObjCClassType().isNull()) { 119 QualType T = Context.getObjCObjectType(Context.ObjCBuiltinClassTy, 0, 0); 120 T = Context.getObjCObjectPointerType(T); 121 TypeSourceInfo *ClassInfo = Context.getTrivialTypeSourceInfo(T); 122 TypedefDecl *ClassTypedef 123 = TypedefDecl::Create(Context, CurContext, SourceLocation(), 124 &Context.Idents.get("Class"), ClassInfo); 125 PushOnScopeChains(ClassTypedef, TUScope); 126 Context.setObjCClassType(Context.getTypeDeclType(ClassTypedef)); 127 Context.ObjCClassRedefinitionType = Context.getObjCClassType(); 128 } 129} 130 131Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 132 bool CompleteTranslationUnit, 133 CodeCompleteConsumer *CodeCompleter) 134 : TheTargetAttributesSema(0), 135 LangOpts(pp.getLangOptions()), PP(pp), Context(ctxt), Consumer(consumer), 136 Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()), 137 ExternalSource(0), CodeCompleter(CodeCompleter), CurContext(0), 138 PackContext(0), VisContext(0), ParsingDeclDepth(0), 139 IdResolver(pp.getLangOptions()), CXXTypeInfoDecl(0), MSVCGuidDecl(0), 140 GlobalNewDeleteDeclared(false), 141 CompleteTranslationUnit(CompleteTranslationUnit), 142 NumSFINAEErrors(0), SuppressAccessChecking(false), 143 AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false), 144 NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1), 145 CurrentInstantiationScope(0), TyposCorrected(0), 146 AnalysisWarnings(*this) 147{ 148 TUScope = 0; 149 if (getLangOptions().CPlusPlus) 150 FieldCollector.reset(new CXXFieldCollector()); 151 152 // Tell diagnostics how to render things from the AST library. 153 PP.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument, 154 &Context); 155 156 ExprEvalContexts.push_back( 157 ExpressionEvaluationContextRecord(PotentiallyEvaluated, 0)); 158 159 FunctionScopes.push_back(new FunctionScopeInfo(Diags)); 160} 161 162void Sema::Initialize() { 163 // Tell the AST consumer about this Sema object. 164 Consumer.Initialize(Context); 165 166 // FIXME: Isn't this redundant with the initialization above? 167 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) 168 SC->InitializeSema(*this); 169 170 // Tell the external Sema source about this Sema object. 171 if (ExternalSemaSource *ExternalSema 172 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) 173 ExternalSema->InitializeSema(*this); 174} 175 176Sema::~Sema() { 177 if (PackContext) FreePackedContext(); 178 if (VisContext) FreeVisContext(); 179 delete TheTargetAttributesSema; 180 181 // Kill all the active scopes. 182 for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I) 183 delete FunctionScopes[I]; 184 if (FunctionScopes.size() == 1) 185 delete FunctionScopes[0]; 186 187 // Tell the SemaConsumer to forget about us; we're going out of scope. 188 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) 189 SC->ForgetSema(); 190 191 // Detach from the external Sema source. 192 if (ExternalSemaSource *ExternalSema 193 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) 194 ExternalSema->ForgetSema(); 195} 196 197/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. 198/// If there is already an implicit cast, merge into the existing one. 199/// The result is of the given category. 200void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, 201 CastKind Kind, ExprValueKind VK, 202 const CXXCastPath *BasePath) { 203 QualType ExprTy = Context.getCanonicalType(Expr->getType()); 204 QualType TypeTy = Context.getCanonicalType(Ty); 205 206 if (ExprTy == TypeTy) 207 return; 208 209 // If this is a derived-to-base cast to a through a virtual base, we 210 // need a vtable. 211 if (Kind == CK_DerivedToBase && 212 BasePathInvolvesVirtualBase(*BasePath)) { 213 QualType T = Expr->getType(); 214 if (const PointerType *Pointer = T->getAs<PointerType>()) 215 T = Pointer->getPointeeType(); 216 if (const RecordType *RecordTy = T->getAs<RecordType>()) 217 MarkVTableUsed(Expr->getLocStart(), 218 cast<CXXRecordDecl>(RecordTy->getDecl())); 219 } 220 221 if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) { 222 if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { 223 ImpCast->setType(Ty); 224 ImpCast->setValueKind(VK); 225 return; 226 } 227 } 228 229 Expr = ImplicitCastExpr::Create(Context, Ty, Kind, Expr, BasePath, VK); 230} 231 232ExprValueKind Sema::CastCategory(Expr *E) { 233 Expr::Classification Classification = E->Classify(Context); 234 return Classification.isRValue() ? VK_RValue : 235 (Classification.isLValue() ? VK_LValue : VK_XValue); 236} 237 238/// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector. 239static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { 240 if (D->isUsed()) 241 return true; 242 243 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 244 // UnusedFileScopedDecls stores the first declaration. 245 // The declaration may have become definition so check again. 246 const FunctionDecl *DeclToCheck; 247 if (FD->hasBody(DeclToCheck)) 248 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 249 250 // Later redecls may add new information resulting in not having to warn, 251 // so check again. 252 DeclToCheck = FD->getMostRecentDeclaration(); 253 if (DeclToCheck != FD) 254 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 255 } 256 257 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 258 // UnusedFileScopedDecls stores the first declaration. 259 // The declaration may have become definition so check again. 260 const VarDecl *DeclToCheck = VD->getDefinition(); 261 if (DeclToCheck) 262 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 263 264 // Later redecls may add new information resulting in not having to warn, 265 // so check again. 266 DeclToCheck = VD->getMostRecentDeclaration(); 267 if (DeclToCheck != VD) 268 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 269 } 270 271 return false; 272} 273 274/// ActOnEndOfTranslationUnit - This is called at the very end of the 275/// translation unit when EOF is reached and all but the top-level scope is 276/// popped. 277void Sema::ActOnEndOfTranslationUnit() { 278 // At PCH writing, implicit instantiations and VTable handling info are 279 // stored and performed when the PCH is included. 280 if (CompleteTranslationUnit) { 281 // If any dynamic classes have their key function defined within 282 // this translation unit, then those vtables are considered "used" and must 283 // be emitted. 284 for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { 285 assert(!DynamicClasses[I]->isDependentType() && 286 "Should not see dependent types here!"); 287 if (const CXXMethodDecl *KeyFunction 288 = Context.getKeyFunction(DynamicClasses[I])) { 289 const FunctionDecl *Definition = 0; 290 if (KeyFunction->hasBody(Definition)) 291 MarkVTableUsed(Definition->getLocation(), DynamicClasses[I], true); 292 } 293 } 294 295 // If DefinedUsedVTables ends up marking any virtual member functions it 296 // might lead to more pending template instantiations, which we then need 297 // to instantiate. 298 DefineUsedVTables(); 299 300 // C++: Perform implicit template instantiations. 301 // 302 // FIXME: When we perform these implicit instantiations, we do not 303 // carefully keep track of the point of instantiation (C++ [temp.point]). 304 // This means that name lookup that occurs within the template 305 // instantiation will always happen at the end of the translation unit, 306 // so it will find some names that should not be found. Although this is 307 // common behavior for C++ compilers, it is technically wrong. In the 308 // future, we either need to be able to filter the results of name lookup 309 // or we need to perform template instantiations earlier. 310 PerformPendingInstantiations(); 311 } 312 313 // Remove file scoped decls that turned out to be used. 314 UnusedFileScopedDecls.erase(std::remove_if(UnusedFileScopedDecls.begin(), 315 UnusedFileScopedDecls.end(), 316 std::bind1st(std::ptr_fun(ShouldRemoveFromUnused), 317 this)), 318 UnusedFileScopedDecls.end()); 319 320 if (!CompleteTranslationUnit) { 321 TUScope = 0; 322 return; 323 } 324 325 // Check for #pragma weak identifiers that were never declared 326 // FIXME: This will cause diagnostics to be emitted in a non-determinstic 327 // order! Iterating over a densemap like this is bad. 328 for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator 329 I = WeakUndeclaredIdentifiers.begin(), 330 E = WeakUndeclaredIdentifiers.end(); I != E; ++I) { 331 if (I->second.getUsed()) continue; 332 333 Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared) 334 << I->first; 335 } 336 337 // C99 6.9.2p2: 338 // A declaration of an identifier for an object that has file 339 // scope without an initializer, and without a storage-class 340 // specifier or with the storage-class specifier static, 341 // constitutes a tentative definition. If a translation unit 342 // contains one or more tentative definitions for an identifier, 343 // and the translation unit contains no external definition for 344 // that identifier, then the behavior is exactly as if the 345 // translation unit contains a file scope declaration of that 346 // identifier, with the composite type as of the end of the 347 // translation unit, with an initializer equal to 0. 348 llvm::SmallSet<VarDecl *, 32> Seen; 349 for (unsigned i = 0, e = TentativeDefinitions.size(); i != e; ++i) { 350 VarDecl *VD = TentativeDefinitions[i]->getActingDefinition(); 351 352 // If the tentative definition was completed, getActingDefinition() returns 353 // null. If we've already seen this variable before, insert()'s second 354 // return value is false. 355 if (VD == 0 || VD->isInvalidDecl() || !Seen.insert(VD)) 356 continue; 357 358 if (const IncompleteArrayType *ArrayT 359 = Context.getAsIncompleteArrayType(VD->getType())) { 360 if (RequireCompleteType(VD->getLocation(), 361 ArrayT->getElementType(), 362 diag::err_tentative_def_incomplete_type_arr)) { 363 VD->setInvalidDecl(); 364 continue; 365 } 366 367 // Set the length of the array to 1 (C99 6.9.2p5). 368 Diag(VD->getLocation(), diag::warn_tentative_incomplete_array); 369 llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true); 370 QualType T = Context.getConstantArrayType(ArrayT->getElementType(), 371 One, ArrayType::Normal, 0); 372 VD->setType(T); 373 } else if (RequireCompleteType(VD->getLocation(), VD->getType(), 374 diag::err_tentative_def_incomplete_type)) 375 VD->setInvalidDecl(); 376 377 // Notify the consumer that we've completed a tentative definition. 378 if (!VD->isInvalidDecl()) 379 Consumer.CompleteTentativeDefinition(VD); 380 381 } 382 383 // If there were errors, disable 'unused' warnings since they will mostly be 384 // noise. 385 if (!Diags.hasErrorOccurred()) { 386 // Output warning for unused file scoped decls. 387 for (llvm::SmallVectorImpl<const DeclaratorDecl*>::iterator 388 I = UnusedFileScopedDecls.begin(), 389 E = UnusedFileScopedDecls.end(); I != E; ++I) { 390 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) { 391 const FunctionDecl *DiagD; 392 if (!FD->hasBody(DiagD)) 393 DiagD = FD; 394 Diag(DiagD->getLocation(), 395 isa<CXXMethodDecl>(DiagD) ? diag::warn_unused_member_function 396 : diag::warn_unused_function) 397 << DiagD->getDeclName(); 398 } else { 399 const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition(); 400 if (!DiagD) 401 DiagD = cast<VarDecl>(*I); 402 Diag(DiagD->getLocation(), diag::warn_unused_variable) 403 << DiagD->getDeclName(); 404 } 405 } 406 } 407 408 TUScope = 0; 409} 410 411 412//===----------------------------------------------------------------------===// 413// Helper functions. 414//===----------------------------------------------------------------------===// 415 416DeclContext *Sema::getFunctionLevelDeclContext() { 417 DeclContext *DC = CurContext; 418 419 while (isa<BlockDecl>(DC) || isa<EnumDecl>(DC)) 420 DC = DC->getParent(); 421 422 return DC; 423} 424 425/// getCurFunctionDecl - If inside of a function body, this returns a pointer 426/// to the function decl for the function being parsed. If we're currently 427/// in a 'block', this returns the containing context. 428FunctionDecl *Sema::getCurFunctionDecl() { 429 DeclContext *DC = getFunctionLevelDeclContext(); 430 return dyn_cast<FunctionDecl>(DC); 431} 432 433ObjCMethodDecl *Sema::getCurMethodDecl() { 434 DeclContext *DC = getFunctionLevelDeclContext(); 435 return dyn_cast<ObjCMethodDecl>(DC); 436} 437 438NamedDecl *Sema::getCurFunctionOrMethodDecl() { 439 DeclContext *DC = getFunctionLevelDeclContext(); 440 if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC)) 441 return cast<NamedDecl>(DC); 442 return 0; 443} 444 445Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { 446 if (!isActive()) 447 return; 448 449 if (llvm::Optional<TemplateDeductionInfo*> Info = SemaRef.isSFINAEContext()) { 450 switch (DiagnosticIDs::getDiagnosticSFINAEResponse(getDiagID())) { 451 case DiagnosticIDs::SFINAE_Report: 452 // Fall through; we'll report the diagnostic below. 453 break; 454 455 case DiagnosticIDs::SFINAE_AccessControl: 456 // Unless access checking is specifically called out as a SFINAE 457 // error, report this diagnostic. 458 if (!SemaRef.AccessCheckingSFINAE) 459 break; 460 461 case DiagnosticIDs::SFINAE_SubstitutionFailure: 462 // Count this failure so that we know that template argument deduction 463 // has failed. 464 ++SemaRef.NumSFINAEErrors; 465 SemaRef.Diags.setLastDiagnosticIgnored(); 466 SemaRef.Diags.Clear(); 467 Clear(); 468 return; 469 470 case DiagnosticIDs::SFINAE_Suppress: 471 // Make a copy of this suppressed diagnostic and store it with the 472 // template-deduction information; 473 FlushCounts(); 474 DiagnosticInfo DiagInfo(&SemaRef.Diags); 475 476 if (*Info) 477 (*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(), 478 PartialDiagnostic(DiagInfo, 479 SemaRef.Context.getDiagAllocator())); 480 481 // Suppress this diagnostic. 482 SemaRef.Diags.setLastDiagnosticIgnored(); 483 SemaRef.Diags.Clear(); 484 Clear(); 485 return; 486 } 487 } 488 489 // Emit the diagnostic. 490 if (!this->Emit()) 491 return; 492 493 // If this is not a note, and we're in a template instantiation 494 // that is different from the last template instantiation where 495 // we emitted an error, print a template instantiation 496 // backtrace. 497 if (!DiagnosticIDs::isBuiltinNote(DiagID) && 498 !SemaRef.ActiveTemplateInstantiations.empty() && 499 SemaRef.ActiveTemplateInstantiations.back() 500 != SemaRef.LastTemplateInstantiationErrorContext) { 501 SemaRef.PrintInstantiationStack(); 502 SemaRef.LastTemplateInstantiationErrorContext 503 = SemaRef.ActiveTemplateInstantiations.back(); 504 } 505} 506 507Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, unsigned DiagID) { 508 DiagnosticBuilder DB = Diags.Report(Loc, DiagID); 509 return SemaDiagnosticBuilder(DB, *this, DiagID); 510} 511 512Sema::SemaDiagnosticBuilder 513Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) { 514 SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID())); 515 PD.Emit(Builder); 516 517 return Builder; 518} 519 520/// \brief Determines the active Scope associated with the given declaration 521/// context. 522/// 523/// This routine maps a declaration context to the active Scope object that 524/// represents that declaration context in the parser. It is typically used 525/// from "scope-less" code (e.g., template instantiation, lazy creation of 526/// declarations) that injects a name for name-lookup purposes and, therefore, 527/// must update the Scope. 528/// 529/// \returns The scope corresponding to the given declaraion context, or NULL 530/// if no such scope is open. 531Scope *Sema::getScopeForContext(DeclContext *Ctx) { 532 533 if (!Ctx) 534 return 0; 535 536 Ctx = Ctx->getPrimaryContext(); 537 for (Scope *S = getCurScope(); S; S = S->getParent()) { 538 // Ignore scopes that cannot have declarations. This is important for 539 // out-of-line definitions of static class members. 540 if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) 541 if (DeclContext *Entity = static_cast<DeclContext *> (S->getEntity())) 542 if (Ctx == Entity->getPrimaryContext()) 543 return S; 544 } 545 546 return 0; 547} 548 549/// \brief Enter a new function scope 550void Sema::PushFunctionScope() { 551 if (FunctionScopes.size() == 1) { 552 // Use the "top" function scope rather than having to allocate 553 // memory for a new scope. 554 FunctionScopes.back()->Clear(); 555 FunctionScopes.push_back(FunctionScopes.back()); 556 return; 557 } 558 559 FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics())); 560} 561 562void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) { 563 FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics(), 564 BlockScope, Block)); 565} 566 567void Sema::PopFunctionOrBlockScope() { 568 FunctionScopeInfo *Scope = FunctionScopes.pop_back_val(); 569 assert(!FunctionScopes.empty() && "mismatched push/pop!"); 570 if (FunctionScopes.back() != Scope) 571 delete Scope; 572} 573 574/// \brief Determine whether any errors occurred within this function/method/ 575/// block. 576bool Sema::hasAnyErrorsInThisFunction() const { 577 return getCurFunction()->ErrorTrap.hasErrorOccurred(); 578} 579 580BlockScopeInfo *Sema::getCurBlock() { 581 if (FunctionScopes.empty()) 582 return 0; 583 584 return dyn_cast<BlockScopeInfo>(FunctionScopes.back()); 585} 586 587// Pin this vtable to this file. 588ExternalSemaSource::~ExternalSemaSource() {} 589 590std::pair<ObjCMethodList, ObjCMethodList> 591ExternalSemaSource::ReadMethodPool(Selector Sel) { 592 return std::pair<ObjCMethodList, ObjCMethodList>(); 593} 594 595void PrettyDeclStackTraceEntry::print(llvm::raw_ostream &OS) const { 596 SourceLocation Loc = this->Loc; 597 if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation(); 598 if (Loc.isValid()) { 599 Loc.print(OS, S.getSourceManager()); 600 OS << ": "; 601 } 602 OS << Message; 603 604 if (TheDecl && isa<NamedDecl>(TheDecl)) { 605 std::string Name = cast<NamedDecl>(TheDecl)->getNameAsString(); 606 if (!Name.empty()) 607 OS << " '" << Name << '\''; 608 } 609 610 OS << '\n'; 611} 612