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