diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-09-27 22:38:19 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-09-27 22:38:19 +0000 |
commit | 30c42404202d2e2512e51efc6066bd614cfdb5a4 (patch) | |
tree | 5ac5699fb4d6d06231673b2e9a4887e4870684fb /lib/Sema/SemaCodeComplete.cpp | |
parent | 3240fe3b715327c8fda6f5a3bc8a092b1fce82a7 (diff) |
When 'bool' is not a built-in type but is defined as a macro, print
'bool' rather than '_Bool' within types, to make things a bit more
readable. Fixes <rdar://problem/10063263>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140650 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 283f4fb731..3074725044 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -1840,6 +1840,14 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Results.AddResult(Result("operator")); } +/// \brief Retrieve a printing policy suitable for code completion. +static PrintingPolicy getCompletionPrintingPolicy(ASTContext &Context) { + PrintingPolicy Policy(Context.getPrintingPolicy()); + Policy.AnonymousTagLocations = false; + Policy.SuppressStrongLifetime = true; + return Policy; +} + /// \brief Retrieve the string representation of the given type as a string /// that has the appropriate lifetime for code completion. /// @@ -1848,14 +1856,12 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, static const char *GetCompletionTypeString(QualType T, ASTContext &Context, CodeCompletionAllocator &Allocator) { - PrintingPolicy Policy(Context.PrintingPolicy); - Policy.AnonymousTagLocations = false; - Policy.SuppressStrongLifetime = true; + PrintingPolicy Policy = getCompletionPrintingPolicy(Context); if (!T.getLocalQualifiers()) { // Built-in type names are constant strings. if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) - return BT->getName(Context.getLangOptions()); + return BT->getName(Policy); // Anonymous tag types are constant strings. if (const TagType *TagT = dyn_cast<TagType>(T)) @@ -1952,10 +1958,7 @@ static std::string formatObjCParamQualifiers(unsigned ObjCQuals) { static std::string FormatFunctionParameter(ASTContext &Context, ParmVarDecl *Param, bool SuppressName = false) { - PrintingPolicy Policy(Context.PrintingPolicy); - Policy.AnonymousTagLocations = false; - Policy.SuppressStrongLifetime = true; - + PrintingPolicy Policy = getCompletionPrintingPolicy(Context); bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->getDeclContext()); if (Param->getType()->isDependentType() || !Param->getType()->isBlockPointerType()) { @@ -2118,8 +2121,7 @@ static void AddTemplateParameterChunks(ASTContext &Context, unsigned MaxParameters = 0, unsigned Start = 0, bool InDefaultArg = false) { - PrintingPolicy Policy(Context.PrintingPolicy); - Policy.AnonymousTagLocations = false; + PrintingPolicy Policy = getCompletionPrintingPolicy(Context); typedef CodeCompletionString::Chunk Chunk; bool FirstParameter = true; @@ -2203,7 +2205,7 @@ AddQualifierToCompletionString(CodeCompletionBuilder &Result, std::string PrintedNNS; { llvm::raw_string_ostream OS(PrintedNNS); - Qualifier->print(OS, Context.PrintingPolicy); + Qualifier->print(OS, getCompletionPrintingPolicy(Context)); } if (QualifierIsInformative) Result.AddInformativeChunk(Result.getAllocator().CopyString(PrintedNNS)); @@ -2335,10 +2337,7 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, typedef CodeCompletionString::Chunk Chunk; CodeCompletionBuilder Result(Allocator, Priority, Availability); - PrintingPolicy Policy(S.Context.PrintingPolicy); - Policy.AnonymousTagLocations = false; - Policy.SuppressStrongLifetime = true; - + PrintingPolicy Policy = getCompletionPrintingPolicy(S.Context); if (Kind == RK_Pattern) { Pattern->Priority = Priority; Pattern->Availability = Availability; @@ -2590,9 +2589,7 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( Sema &S, CodeCompletionAllocator &Allocator) const { typedef CodeCompletionString::Chunk Chunk; - PrintingPolicy Policy(S.Context.PrintingPolicy); - Policy.AnonymousTagLocations = false; - Policy.SuppressStrongLifetime = true; + PrintingPolicy Policy = getCompletionPrintingPolicy(S.Context); // FIXME: Set priority, availability appropriately. CodeCompletionBuilder Result(Allocator, 1, CXAvailability_Available); @@ -2900,7 +2897,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, if (NNS) { std::string Str; llvm::raw_string_ostream OS(Str); - NNS->print(OS, S.Context.PrintingPolicy); + NNS->print(OS, getCompletionPrintingPolicy(S.Context)); Builder.AddTextChunk(Results.getAllocator().CopyString(OS.str())); } } else if (!InContext->Equals(Overridden->getDeclContext())) @@ -3937,10 +3934,7 @@ void Sema::CodeCompleteOperatorName(Scope *S) { void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD, CXXCtorInitializer** Initializers, unsigned NumInitializers) { - PrintingPolicy Policy(Context.PrintingPolicy); - Policy.AnonymousTagLocations = false; - Policy.SuppressStrongLifetime = true; - + PrintingPolicy Policy = getCompletionPrintingPolicy(Context); CXXConstructorDecl *Constructor = static_cast<CXXConstructorDecl *>(ConstructorD); if (!Constructor) @@ -6448,9 +6442,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompletionContext::CCC_Other); Results.EnterNewScope(); - PrintingPolicy Policy(Context.PrintingPolicy); - Policy.AnonymousTagLocations = false; - Policy.SuppressStrongLifetime = true; + PrintingPolicy Policy = getCompletionPrintingPolicy(Context); for (KnownMethodsMap::iterator M = KnownMethods.begin(), MEnd = KnownMethods.end(); M != MEnd; ++M) { |