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