Sema.cpp revision a5c6c2a84cde5c9b8f8ec0610a9f89ffd54f44ee
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    NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),
144    CurrentInstantiationScope(0), TyposCorrected(0),
145    AnalysisWarnings(*this)
146{
147  TUScope = 0;
148  if (getLangOptions().CPlusPlus)
149    FieldCollector.reset(new CXXFieldCollector());
150
151  // Tell diagnostics how to render things from the AST library.
152  PP.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
153                                       &Context);
154
155  ExprEvalContexts.push_back(
156                  ExpressionEvaluationContextRecord(PotentiallyEvaluated, 0));
157
158  FunctionScopes.push_back(new FunctionScopeInfo(Diags));
159}
160
161void Sema::Initialize() {
162  // Tell the AST consumer about this Sema object.
163  Consumer.Initialize(Context);
164
165  // FIXME: Isn't this redundant with the initialization above?
166  if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
167    SC->InitializeSema(*this);
168
169  // Tell the external Sema source about this Sema object.
170  if (ExternalSemaSource *ExternalSema
171      = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
172    ExternalSema->InitializeSema(*this);
173}
174
175Sema::~Sema() {
176  if (PackContext) FreePackedContext();
177  if (VisContext) FreeVisContext();
178  delete TheTargetAttributesSema;
179
180  // Kill all the active scopes.
181  for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I)
182    delete FunctionScopes[I];
183  if (FunctionScopes.size() == 1)
184    delete FunctionScopes[0];
185
186  // Tell the SemaConsumer to forget about us; we're going out of scope.
187  if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
188    SC->ForgetSema();
189
190  // Detach from the external Sema source.
191  if (ExternalSemaSource *ExternalSema
192        = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
193    ExternalSema->ForgetSema();
194}
195
196/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
197/// If there is already an implicit cast, merge into the existing one.
198/// The result is of the given category.
199void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty,
200                             CastKind Kind, ExprValueKind VK,
201                             const CXXCastPath *BasePath) {
202  QualType ExprTy = Context.getCanonicalType(Expr->getType());
203  QualType TypeTy = Context.getCanonicalType(Ty);
204
205  if (ExprTy == TypeTy)
206    return;
207
208  if (Expr->getType()->isPointerType() && Ty->isPointerType()) {
209    QualType ExprBaseType = cast<PointerType>(ExprTy)->getPointeeType();
210    QualType BaseType = cast<PointerType>(TypeTy)->getPointeeType();
211    if (ExprBaseType.getAddressSpace() != BaseType.getAddressSpace()) {
212      Diag(Expr->getExprLoc(), diag::err_implicit_pointer_address_space_cast)
213        << Expr->getSourceRange();
214    }
215  }
216
217  // If this is a derived-to-base cast to a through a virtual base, we
218  // need a vtable.
219  if (Kind == CK_DerivedToBase &&
220      BasePathInvolvesVirtualBase(*BasePath)) {
221    QualType T = Expr->getType();
222    if (const PointerType *Pointer = T->getAs<PointerType>())
223      T = Pointer->getPointeeType();
224    if (const RecordType *RecordTy = T->getAs<RecordType>())
225      MarkVTableUsed(Expr->getLocStart(),
226                     cast<CXXRecordDecl>(RecordTy->getDecl()));
227  }
228
229  if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) {
230    if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
231      ImpCast->setType(Ty);
232      ImpCast->setValueKind(VK);
233      return;
234    }
235  }
236
237  Expr = ImplicitCastExpr::Create(Context, Ty, Kind, Expr, BasePath, VK);
238}
239
240ExprValueKind Sema::CastCategory(Expr *E) {
241  Expr::Classification Classification = E->Classify(Context);
242  return Classification.isRValue() ? VK_RValue :
243      (Classification.isLValue() ? VK_LValue : VK_XValue);
244}
245
246/// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector.
247static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
248  if (D->isUsed())
249    return true;
250
251  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
252    // UnusedFileScopedDecls stores the first declaration.
253    // The declaration may have become definition so check again.
254    const FunctionDecl *DeclToCheck;
255    if (FD->hasBody(DeclToCheck))
256      return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
257
258    // Later redecls may add new information resulting in not having to warn,
259    // so check again.
260    DeclToCheck = FD->getMostRecentDeclaration();
261    if (DeclToCheck != FD)
262      return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
263  }
264
265  if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
266    // UnusedFileScopedDecls stores the first declaration.
267    // The declaration may have become definition so check again.
268    const VarDecl *DeclToCheck = VD->getDefinition();
269    if (DeclToCheck)
270      return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
271
272    // Later redecls may add new information resulting in not having to warn,
273    // so check again.
274    DeclToCheck = VD->getMostRecentDeclaration();
275    if (DeclToCheck != VD)
276      return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
277  }
278
279  return false;
280}
281
282/// ActOnEndOfTranslationUnit - This is called at the very end of the
283/// translation unit when EOF is reached and all but the top-level scope is
284/// popped.
285void Sema::ActOnEndOfTranslationUnit() {
286  // At PCH writing, implicit instantiations and VTable handling info are
287  // stored and performed when the PCH is included.
288  if (CompleteTranslationUnit) {
289    // If any dynamic classes have their key function defined within
290    // this translation unit, then those vtables are considered "used" and must
291    // be emitted.
292    for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) {
293      assert(!DynamicClasses[I]->isDependentType() &&
294             "Should not see dependent types here!");
295      if (const CXXMethodDecl *KeyFunction
296          = Context.getKeyFunction(DynamicClasses[I])) {
297        const FunctionDecl *Definition = 0;
298        if (KeyFunction->hasBody(Definition))
299          MarkVTableUsed(Definition->getLocation(), DynamicClasses[I], true);
300      }
301    }
302
303    // If DefinedUsedVTables ends up marking any virtual member functions it
304    // might lead to more pending template instantiations, which we then need
305    // to instantiate.
306    DefineUsedVTables();
307
308    // C++: Perform implicit template instantiations.
309    //
310    // FIXME: When we perform these implicit instantiations, we do not
311    // carefully keep track of the point of instantiation (C++ [temp.point]).
312    // This means that name lookup that occurs within the template
313    // instantiation will always happen at the end of the translation unit,
314    // so it will find some names that should not be found. Although this is
315    // common behavior for C++ compilers, it is technically wrong. In the
316    // future, we either need to be able to filter the results of name lookup
317    // or we need to perform template instantiations earlier.
318    PerformPendingInstantiations();
319  }
320
321  // Remove file scoped decls that turned out to be used.
322  UnusedFileScopedDecls.erase(std::remove_if(UnusedFileScopedDecls.begin(),
323                                             UnusedFileScopedDecls.end(),
324                              std::bind1st(std::ptr_fun(ShouldRemoveFromUnused),
325                                           this)),
326                              UnusedFileScopedDecls.end());
327
328  if (!CompleteTranslationUnit) {
329    TUScope = 0;
330    return;
331  }
332
333  // Check for #pragma weak identifiers that were never declared
334  // FIXME: This will cause diagnostics to be emitted in a non-determinstic
335  // order!  Iterating over a densemap like this is bad.
336  for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator
337       I = WeakUndeclaredIdentifiers.begin(),
338       E = WeakUndeclaredIdentifiers.end(); I != E; ++I) {
339    if (I->second.getUsed()) continue;
340
341    Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared)
342      << I->first;
343  }
344
345  // C99 6.9.2p2:
346  //   A declaration of an identifier for an object that has file
347  //   scope without an initializer, and without a storage-class
348  //   specifier or with the storage-class specifier static,
349  //   constitutes a tentative definition. If a translation unit
350  //   contains one or more tentative definitions for an identifier,
351  //   and the translation unit contains no external definition for
352  //   that identifier, then the behavior is exactly as if the
353  //   translation unit contains a file scope declaration of that
354  //   identifier, with the composite type as of the end of the
355  //   translation unit, with an initializer equal to 0.
356  llvm::SmallSet<VarDecl *, 32> Seen;
357  for (unsigned i = 0, e = TentativeDefinitions.size(); i != e; ++i) {
358    VarDecl *VD = TentativeDefinitions[i]->getActingDefinition();
359
360    // If the tentative definition was completed, getActingDefinition() returns
361    // null. If we've already seen this variable before, insert()'s second
362    // return value is false.
363    if (VD == 0 || VD->isInvalidDecl() || !Seen.insert(VD))
364      continue;
365
366    if (const IncompleteArrayType *ArrayT
367        = Context.getAsIncompleteArrayType(VD->getType())) {
368      if (RequireCompleteType(VD->getLocation(),
369                              ArrayT->getElementType(),
370                              diag::err_tentative_def_incomplete_type_arr)) {
371        VD->setInvalidDecl();
372        continue;
373      }
374
375      // Set the length of the array to 1 (C99 6.9.2p5).
376      Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
377      llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true);
378      QualType T = Context.getConstantArrayType(ArrayT->getElementType(),
379                                                One, ArrayType::Normal, 0);
380      VD->setType(T);
381    } else if (RequireCompleteType(VD->getLocation(), VD->getType(),
382                                   diag::err_tentative_def_incomplete_type))
383      VD->setInvalidDecl();
384
385    // Notify the consumer that we've completed a tentative definition.
386    if (!VD->isInvalidDecl())
387      Consumer.CompleteTentativeDefinition(VD);
388
389  }
390
391  // Output warning for unused file scoped decls.
392  for (llvm::SmallVectorImpl<const DeclaratorDecl*>::iterator
393         I = UnusedFileScopedDecls.begin(),
394         E = UnusedFileScopedDecls.end(); I != E; ++I) {
395    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
396      const FunctionDecl *DiagD;
397      if (!FD->hasBody(DiagD))
398        DiagD = FD;
399      Diag(DiagD->getLocation(),
400           isa<CXXMethodDecl>(DiagD) ? diag::warn_unused_member_function
401                                     : diag::warn_unused_function)
402            << DiagD->getDeclName();
403    } else {
404      const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition();
405      if (!DiagD)
406        DiagD = cast<VarDecl>(*I);
407      Diag(DiagD->getLocation(), diag::warn_unused_variable)
408            << DiagD->getDeclName();
409    }
410  }
411
412  TUScope = 0;
413}
414
415
416//===----------------------------------------------------------------------===//
417// Helper functions.
418//===----------------------------------------------------------------------===//
419
420DeclContext *Sema::getFunctionLevelDeclContext() {
421  DeclContext *DC = CurContext;
422
423  while (isa<BlockDecl>(DC) || isa<EnumDecl>(DC))
424    DC = DC->getParent();
425
426  return DC;
427}
428
429/// getCurFunctionDecl - If inside of a function body, this returns a pointer
430/// to the function decl for the function being parsed.  If we're currently
431/// in a 'block', this returns the containing context.
432FunctionDecl *Sema::getCurFunctionDecl() {
433  DeclContext *DC = getFunctionLevelDeclContext();
434  return dyn_cast<FunctionDecl>(DC);
435}
436
437ObjCMethodDecl *Sema::getCurMethodDecl() {
438  DeclContext *DC = getFunctionLevelDeclContext();
439  return dyn_cast<ObjCMethodDecl>(DC);
440}
441
442NamedDecl *Sema::getCurFunctionOrMethodDecl() {
443  DeclContext *DC = getFunctionLevelDeclContext();
444  if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC))
445    return cast<NamedDecl>(DC);
446  return 0;
447}
448
449Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
450  if (!isActive())
451    return;
452
453  if (TemplateDeductionInfo *Info = SemaRef.isSFINAEContext()) {
454    switch (DiagnosticIDs::getDiagnosticSFINAEResponse(getDiagID())) {
455    case DiagnosticIDs::SFINAE_Report:
456      // Fall through; we'll report the diagnostic below.
457      break;
458
459    case DiagnosticIDs::SFINAE_SubstitutionFailure:
460      // Count this failure so that we know that template argument deduction
461      // has failed.
462      ++SemaRef.NumSFINAEErrors;
463      SemaRef.Diags.setLastDiagnosticIgnored();
464      SemaRef.Diags.Clear();
465      Clear();
466      return;
467
468    case DiagnosticIDs::SFINAE_Suppress:
469      // Make a copy of this suppressed diagnostic and store it with the
470      // template-deduction information;
471      FlushCounts();
472      DiagnosticInfo DiagInfo(&SemaRef.Diags);
473
474      Info->addSuppressedDiagnostic(DiagInfo.getLocation(),
475                        PartialDiagnostic(DiagInfo,
476                                          SemaRef.Context.getDiagAllocator()));
477
478      // Suppress this diagnostic.
479      SemaRef.Diags.setLastDiagnosticIgnored();
480      SemaRef.Diags.Clear();
481      Clear();
482      return;
483    }
484  }
485
486  // Emit the diagnostic.
487  if (!this->Emit())
488    return;
489
490  // If this is not a note, and we're in a template instantiation
491  // that is different from the last template instantiation where
492  // we emitted an error, print a template instantiation
493  // backtrace.
494  if (!DiagnosticIDs::isBuiltinNote(DiagID) &&
495      !SemaRef.ActiveTemplateInstantiations.empty() &&
496      SemaRef.ActiveTemplateInstantiations.back()
497        != SemaRef.LastTemplateInstantiationErrorContext) {
498    SemaRef.PrintInstantiationStack();
499    SemaRef.LastTemplateInstantiationErrorContext
500      = SemaRef.ActiveTemplateInstantiations.back();
501  }
502}
503
504Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, unsigned DiagID) {
505  DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
506  return SemaDiagnosticBuilder(DB, *this, DiagID);
507}
508
509Sema::SemaDiagnosticBuilder
510Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) {
511  SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID()));
512  PD.Emit(Builder);
513
514  return Builder;
515}
516
517/// \brief Determines the active Scope associated with the given declaration
518/// context.
519///
520/// This routine maps a declaration context to the active Scope object that
521/// represents that declaration context in the parser. It is typically used
522/// from "scope-less" code (e.g., template instantiation, lazy creation of
523/// declarations) that injects a name for name-lookup purposes and, therefore,
524/// must update the Scope.
525///
526/// \returns The scope corresponding to the given declaraion context, or NULL
527/// if no such scope is open.
528Scope *Sema::getScopeForContext(DeclContext *Ctx) {
529
530  if (!Ctx)
531    return 0;
532
533  Ctx = Ctx->getPrimaryContext();
534  for (Scope *S = getCurScope(); S; S = S->getParent()) {
535    // Ignore scopes that cannot have declarations. This is important for
536    // out-of-line definitions of static class members.
537    if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope))
538      if (DeclContext *Entity = static_cast<DeclContext *> (S->getEntity()))
539        if (Ctx == Entity->getPrimaryContext())
540          return S;
541  }
542
543  return 0;
544}
545
546/// \brief Enter a new function scope
547void Sema::PushFunctionScope() {
548  if (FunctionScopes.size() == 1) {
549    // Use the "top" function scope rather than having to allocate
550    // memory for a new scope.
551    FunctionScopes.back()->Clear();
552    FunctionScopes.push_back(FunctionScopes.back());
553    return;
554  }
555
556  FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics()));
557}
558
559void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) {
560  FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics(),
561                                              BlockScope, Block));
562}
563
564void Sema::PopFunctionOrBlockScope() {
565  FunctionScopeInfo *Scope = FunctionScopes.pop_back_val();
566  assert(!FunctionScopes.empty() && "mismatched push/pop!");
567  if (FunctionScopes.back() != Scope)
568    delete Scope;
569}
570
571/// \brief Determine whether any errors occurred within this function/method/
572/// block.
573bool Sema::hasAnyErrorsInThisFunction() const {
574  return getCurFunction()->ErrorTrap.hasErrorOccurred();
575}
576
577BlockScopeInfo *Sema::getCurBlock() {
578  if (FunctionScopes.empty())
579    return 0;
580
581  return dyn_cast<BlockScopeInfo>(FunctionScopes.back());
582}
583
584// Pin this vtable to this file.
585ExternalSemaSource::~ExternalSemaSource() {}
586
587std::pair<ObjCMethodList, ObjCMethodList>
588ExternalSemaSource::ReadMethodPool(Selector Sel) {
589  return std::pair<ObjCMethodList, ObjCMethodList>();
590}
591
592void PrettyDeclStackTraceEntry::print(llvm::raw_ostream &OS) const {
593  SourceLocation Loc = this->Loc;
594  if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation();
595  if (Loc.isValid()) {
596    Loc.print(OS, S.getSourceManager());
597    OS << ": ";
598  }
599  OS << Message;
600
601  if (TheDecl && isa<NamedDecl>(TheDecl)) {
602    std::string Name = cast<NamedDecl>(TheDecl)->getNameAsString();
603    if (!Name.empty())
604      OS << " '" << Name << '\'';
605  }
606
607  OS << '\n';
608}
609