Only print _Bool as 'bool' when 'bool' is defined as an object-like

macro whose only replacement token is '_Bool'.

llvm-svn: 140656
This commit is contained in:
Douglas Gregor 2011-09-27 23:30:47 +00:00
parent e3e36f80f5
commit 75acd925d0
12 changed files with 98 additions and 65 deletions

View File

@ -342,7 +342,7 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> {
friend class ASTWriter; friend class ASTWriter;
const TargetInfo *Target; const TargetInfo *Target;
mutable clang::PrintingPolicy PrintingPolicy; clang::PrintingPolicy PrintingPolicy;
public: public:
IdentifierTable &Idents; IdentifierTable &Idents;
@ -352,7 +352,11 @@ public:
llvm::OwningPtr<ExternalASTSource> ExternalSource; llvm::OwningPtr<ExternalASTSource> ExternalSource;
ASTMutationListener *Listener; ASTMutationListener *Listener;
clang::PrintingPolicy getPrintingPolicy() const; clang::PrintingPolicy getPrintingPolicy() const { return PrintingPolicy; }
void setPrintingPolicy(clang::PrintingPolicy Policy) {
PrintingPolicy = Policy;
}
SourceManager& getSourceManager() { return SourceMgr; } SourceManager& getSourceManager() { return SourceMgr; }
const SourceManager& getSourceManager() const { return SourceMgr; } const SourceManager& getSourceManager() const { return SourceMgr; }

View File

@ -45,7 +45,7 @@ struct PrintingPolicy {
unsigned Indentation : 8; unsigned Indentation : 8;
/// \brief What language we're printing. /// \brief What language we're printing.
const LangOptions LangOpts; LangOptions LangOpts;
/// \brief Whether we should suppress printing of the actual specifiers for /// \brief Whether we should suppress printing of the actual specifiers for
/// the given type or declaration. /// the given type or declaration.

View File

@ -1098,6 +1098,9 @@ public:
SourceLocation ModulePrivateKeyword SourceLocation ModulePrivateKeyword
= SourceLocation()); = SourceLocation());
/// \brief Retrieve a suitable printing policy.
PrintingPolicy getPrintingPolicy() const;
/// Scope actions. /// Scope actions.
void ActOnPopScope(SourceLocation Loc, Scope *S); void ActOnPopScope(SourceLocation Loc, Scope *S);
void ActOnTranslationUnitScope(Scope *S); void ActOnTranslationUnitScope(Scope *S);

View File

@ -6475,12 +6475,6 @@ MangleContext *ASTContext::createMangleContext() {
CXXABI::~CXXABI() {} CXXABI::~CXXABI() {}
PrintingPolicy ASTContext::getPrintingPolicy() const {
PrintingPolicy.Bool
= LangOpts.Bool || Idents.get("bool").hasMacroDefinition();
return PrintingPolicy;
}
size_t ASTContext::getSideTableAllocatedMemory() const { size_t ASTContext::getSideTableAllocatedMemory() const {
return ASTRecordLayouts.getMemorySize() return ASTRecordLayouts.getMemorySize()
+ llvm::capacity_in_bytes(ObjCLayouts) + llvm::capacity_in_bytes(ObjCLayouts)

View File

@ -55,6 +55,20 @@ void FunctionScopeInfo::Clear() {
BlockScopeInfo::~BlockScopeInfo() { } BlockScopeInfo::~BlockScopeInfo() { }
PrintingPolicy Sema::getPrintingPolicy() const {
PrintingPolicy Policy = Context.getPrintingPolicy();
Policy.Bool = getLangOptions().Bool;
if (!Policy.Bool) {
if (MacroInfo *BoolMacro = PP.getMacroInfo(&Context.Idents.get("bool"))) {
Policy.Bool = BoolMacro->isObjectLike() &&
BoolMacro->getNumTokens() == 1 &&
BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
}
}
return Policy;
}
void Sema::ActOnTranslationUnitScope(Scope *S) { void Sema::ActOnTranslationUnitScope(Scope *S) {
TUScope = S; TUScope = S;
PushDeclContext(S, Context.getTranslationUnitDecl()); PushDeclContext(S, Context.getTranslationUnitDecl());
@ -678,6 +692,9 @@ Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
} }
} }
// Set up the context's printing policy based on our current state.
SemaRef.Context.setPrintingPolicy(SemaRef.getPrintingPolicy());
// Emit the diagnostic. // Emit the diagnostic.
if (!this->Emit()) if (!this->Emit())
return; return;

View File

@ -2140,7 +2140,7 @@ void Sema::CheckStrlcpycatArguments(const CallExpr *Call,
llvm::SmallString<128> sizeString; llvm::SmallString<128> sizeString;
llvm::raw_svector_ostream OS(sizeString); llvm::raw_svector_ostream OS(sizeString);
OS << "sizeof("; OS << "sizeof(";
DstArg->printPretty(OS, Context, 0, Context.getPrintingPolicy()); DstArg->printPretty(OS, Context, 0, getPrintingPolicy());
OS << ")"; OS << ")";
Diag(OriginalSizeArg->getLocStart(), diag::note_strlcpycat_wrong_size) Diag(OriginalSizeArg->getLocStart(), diag::note_strlcpycat_wrong_size)

View File

@ -1841,8 +1841,8 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC,
} }
/// \brief Retrieve a printing policy suitable for code completion. /// \brief Retrieve a printing policy suitable for code completion.
static PrintingPolicy getCompletionPrintingPolicy(ASTContext &Context) { static PrintingPolicy getCompletionPrintingPolicy(Sema &S) {
PrintingPolicy Policy(Context.getPrintingPolicy()); PrintingPolicy Policy = S.getPrintingPolicy();
Policy.AnonymousTagLocations = false; Policy.AnonymousTagLocations = false;
Policy.SuppressStrongLifetime = true; Policy.SuppressStrongLifetime = true;
return Policy; return Policy;
@ -1855,9 +1855,8 @@ static PrintingPolicy getCompletionPrintingPolicy(ASTContext &Context) {
/// common type names. /// common type names.
static const char *GetCompletionTypeString(QualType T, static const char *GetCompletionTypeString(QualType T,
ASTContext &Context, ASTContext &Context,
const PrintingPolicy &Policy,
CodeCompletionAllocator &Allocator) { CodeCompletionAllocator &Allocator) {
PrintingPolicy Policy = getCompletionPrintingPolicy(Context);
if (!T.getLocalQualifiers()) { if (!T.getLocalQualifiers()) {
// Built-in type names are constant strings. // Built-in type names are constant strings.
if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) if (const BuiltinType *BT = dyn_cast<BuiltinType>(T))
@ -1885,6 +1884,7 @@ static const char *GetCompletionTypeString(QualType T,
/// \brief If the given declaration has an associated type, add it as a result /// \brief If the given declaration has an associated type, add it as a result
/// type chunk. /// type chunk.
static void AddResultTypeChunk(ASTContext &Context, static void AddResultTypeChunk(ASTContext &Context,
const PrintingPolicy &Policy,
NamedDecl *ND, NamedDecl *ND,
CodeCompletionBuilder &Result) { CodeCompletionBuilder &Result) {
if (!ND) if (!ND)
@ -1915,7 +1915,7 @@ static void AddResultTypeChunk(ASTContext &Context,
if (T.isNull() || Context.hasSameType(T, Context.DependentTy)) if (T.isNull() || Context.hasSameType(T, Context.DependentTy))
return; return;
Result.AddResultTypeChunk(GetCompletionTypeString(T, Context, Result.AddResultTypeChunk(GetCompletionTypeString(T, Context, Policy,
Result.getAllocator())); Result.getAllocator()));
} }
@ -1956,9 +1956,9 @@ static std::string formatObjCParamQualifiers(unsigned ObjCQuals) {
} }
static std::string FormatFunctionParameter(ASTContext &Context, static std::string FormatFunctionParameter(ASTContext &Context,
const PrintingPolicy &Policy,
ParmVarDecl *Param, ParmVarDecl *Param,
bool SuppressName = false) { bool SuppressName = false) {
PrintingPolicy Policy = getCompletionPrintingPolicy(Context);
bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->getDeclContext()); bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->getDeclContext());
if (Param->getType()->isDependentType() || if (Param->getType()->isDependentType() ||
!Param->getType()->isBlockPointerType()) { !Param->getType()->isBlockPointerType()) {
@ -2049,7 +2049,7 @@ static std::string FormatFunctionParameter(ASTContext &Context,
for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) { for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) {
if (I) if (I)
Result += ", "; Result += ", ";
Result += FormatFunctionParameter(Context, Block->getArg(I)); Result += FormatFunctionParameter(Context, Policy, Block->getArg(I));
if (I == N - 1 && BlockProto->getTypePtr()->isVariadic()) if (I == N - 1 && BlockProto->getTypePtr()->isVariadic())
Result += ", ..."; Result += ", ...";
@ -2065,6 +2065,7 @@ static std::string FormatFunctionParameter(ASTContext &Context,
/// \brief Add function parameter chunks to the given code completion string. /// \brief Add function parameter chunks to the given code completion string.
static void AddFunctionParameterChunks(ASTContext &Context, static void AddFunctionParameterChunks(ASTContext &Context,
const PrintingPolicy &Policy,
FunctionDecl *Function, FunctionDecl *Function,
CodeCompletionBuilder &Result, CodeCompletionBuilder &Result,
unsigned Start = 0, unsigned Start = 0,
@ -2081,7 +2082,7 @@ static void AddFunctionParameterChunks(ASTContext &Context,
CodeCompletionBuilder Opt(Result.getAllocator()); CodeCompletionBuilder Opt(Result.getAllocator());
if (!FirstParameter) if (!FirstParameter)
Opt.AddChunk(Chunk(CodeCompletionString::CK_Comma)); Opt.AddChunk(Chunk(CodeCompletionString::CK_Comma));
AddFunctionParameterChunks(Context, Function, Opt, P, true); AddFunctionParameterChunks(Context, Policy, Function, Opt, P, true);
Result.AddOptionalChunk(Opt.TakeString()); Result.AddOptionalChunk(Opt.TakeString());
break; break;
} }
@ -2094,7 +2095,8 @@ static void AddFunctionParameterChunks(ASTContext &Context,
InOptional = false; InOptional = false;
// Format the placeholder string. // Format the placeholder string.
std::string PlaceholderStr = FormatFunctionParameter(Context, Param); std::string PlaceholderStr = FormatFunctionParameter(Context, Policy,
Param);
if (Function->isVariadic() && P == N - 1) if (Function->isVariadic() && P == N - 1)
PlaceholderStr += ", ..."; PlaceholderStr += ", ...";
@ -2116,13 +2118,12 @@ static void AddFunctionParameterChunks(ASTContext &Context,
/// \brief Add template parameter chunks to the given code completion string. /// \brief Add template parameter chunks to the given code completion string.
static void AddTemplateParameterChunks(ASTContext &Context, static void AddTemplateParameterChunks(ASTContext &Context,
const PrintingPolicy &Policy,
TemplateDecl *Template, TemplateDecl *Template,
CodeCompletionBuilder &Result, CodeCompletionBuilder &Result,
unsigned MaxParameters = 0, unsigned MaxParameters = 0,
unsigned Start = 0, unsigned Start = 0,
bool InDefaultArg = false) { bool InDefaultArg = false) {
PrintingPolicy Policy = getCompletionPrintingPolicy(Context);
typedef CodeCompletionString::Chunk Chunk; typedef CodeCompletionString::Chunk Chunk;
bool FirstParameter = true; bool FirstParameter = true;
@ -2173,7 +2174,7 @@ static void AddTemplateParameterChunks(ASTContext &Context,
CodeCompletionBuilder Opt(Result.getAllocator()); CodeCompletionBuilder Opt(Result.getAllocator());
if (!FirstParameter) if (!FirstParameter)
Opt.AddChunk(Chunk(CodeCompletionString::CK_Comma)); Opt.AddChunk(Chunk(CodeCompletionString::CK_Comma));
AddTemplateParameterChunks(Context, Template, Opt, MaxParameters, AddTemplateParameterChunks(Context, Policy, Template, Opt, MaxParameters,
P - Params->begin(), true); P - Params->begin(), true);
Result.AddOptionalChunk(Opt.TakeString()); Result.AddOptionalChunk(Opt.TakeString());
break; break;
@ -2198,14 +2199,15 @@ static void
AddQualifierToCompletionString(CodeCompletionBuilder &Result, AddQualifierToCompletionString(CodeCompletionBuilder &Result,
NestedNameSpecifier *Qualifier, NestedNameSpecifier *Qualifier,
bool QualifierIsInformative, bool QualifierIsInformative,
ASTContext &Context) { ASTContext &Context,
const PrintingPolicy &Policy) {
if (!Qualifier) if (!Qualifier)
return; return;
std::string PrintedNNS; std::string PrintedNNS;
{ {
llvm::raw_string_ostream OS(PrintedNNS); llvm::raw_string_ostream OS(PrintedNNS);
Qualifier->print(OS, getCompletionPrintingPolicy(Context)); Qualifier->print(OS, Policy);
} }
if (QualifierIsInformative) if (QualifierIsInformative)
Result.AddInformativeChunk(Result.getAllocator().CopyString(PrintedNNS)); Result.AddInformativeChunk(Result.getAllocator().CopyString(PrintedNNS));
@ -2251,8 +2253,8 @@ AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result,
} }
/// \brief Add the name of the given declaration /// \brief Add the name of the given declaration
static void AddTypedNameChunk(ASTContext &Context, NamedDecl *ND, static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy,
CodeCompletionBuilder &Result) { NamedDecl *ND, CodeCompletionBuilder &Result) {
typedef CodeCompletionString::Chunk Chunk; typedef CodeCompletionString::Chunk Chunk;
DeclarationName Name = ND->getDeclName(); DeclarationName Name = ND->getDeclName();
@ -2317,7 +2319,7 @@ static void AddTypedNameChunk(ASTContext &Context, NamedDecl *ND,
Result.getAllocator().CopyString(Record->getNameAsString())); Result.getAllocator().CopyString(Record->getNameAsString()));
if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) { if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) {
Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle)); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
AddTemplateParameterChunks(Context, Template, Result); AddTemplateParameterChunks(Context, Policy, Template, Result);
Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle)); Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
} }
break; break;
@ -2337,7 +2339,7 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
typedef CodeCompletionString::Chunk Chunk; typedef CodeCompletionString::Chunk Chunk;
CodeCompletionBuilder Result(Allocator, Priority, Availability); CodeCompletionBuilder Result(Allocator, Priority, Availability);
PrintingPolicy Policy = getCompletionPrintingPolicy(S.Context); PrintingPolicy Policy = getCompletionPrintingPolicy(S);
if (Kind == RK_Pattern) { if (Kind == RK_Pattern) {
Pattern->Priority = Priority; Pattern->Priority = Priority;
Pattern->Availability = Availability; Pattern->Availability = Availability;
@ -2415,14 +2417,14 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
return Result.TakeString(); return Result.TakeString();
} }
AddResultTypeChunk(S.Context, ND, Result); AddResultTypeChunk(S.Context, Policy, ND, Result);
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) { if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) {
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
S.Context); S.Context, Policy);
AddTypedNameChunk(S.Context, ND, Result); AddTypedNameChunk(S.Context, Policy, ND, Result);
Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen)); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
AddFunctionParameterChunks(S.Context, Function, Result); AddFunctionParameterChunks(S.Context, Policy, Function, Result);
Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen)); Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
AddFunctionTypeQualsToCompletionString(Result, Function); AddFunctionTypeQualsToCompletionString(Result, Function);
return Result.TakeString(); return Result.TakeString();
@ -2430,9 +2432,9 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) { if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
S.Context); S.Context, Policy);
FunctionDecl *Function = FunTmpl->getTemplatedDecl(); FunctionDecl *Function = FunTmpl->getTemplatedDecl();
AddTypedNameChunk(S.Context, Function, Result); AddTypedNameChunk(S.Context, Policy, Function, Result);
// Figure out which template parameters are deduced (or have default // Figure out which template parameters are deduced (or have default
// arguments). // arguments).
@ -2469,14 +2471,14 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
// function call, so we introduce an explicit template argument list // function call, so we introduce an explicit template argument list
// containing all of the arguments up to the first deducible argument. // containing all of the arguments up to the first deducible argument.
Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle)); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
AddTemplateParameterChunks(S.Context, FunTmpl, Result, AddTemplateParameterChunks(S.Context, Policy, FunTmpl, Result,
LastDeducibleArgument); LastDeducibleArgument);
Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle)); Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
} }
// Add the function parameters // Add the function parameters
Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen)); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
AddFunctionParameterChunks(S.Context, Function, Result); AddFunctionParameterChunks(S.Context, Policy, Function, Result);
Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen)); Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
AddFunctionTypeQualsToCompletionString(Result, Function); AddFunctionTypeQualsToCompletionString(Result, Function);
return Result.TakeString(); return Result.TakeString();
@ -2484,11 +2486,11 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
if (TemplateDecl *Template = dyn_cast<TemplateDecl>(ND)) { if (TemplateDecl *Template = dyn_cast<TemplateDecl>(ND)) {
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
S.Context); S.Context, Policy);
Result.AddTypedTextChunk( Result.AddTypedTextChunk(
Result.getAllocator().CopyString(Template->getNameAsString())); Result.getAllocator().CopyString(Template->getNameAsString()));
Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle)); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
AddTemplateParameterChunks(S.Context, Template, Result); AddTemplateParameterChunks(S.Context, Policy, Template, Result);
Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle)); Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
return Result.TakeString(); return Result.TakeString();
} }
@ -2537,7 +2539,7 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
std::string Arg; std::string Arg;
if ((*P)->getType()->isBlockPointerType() && !DeclaringEntity) if ((*P)->getType()->isBlockPointerType() && !DeclaringEntity)
Arg = FormatFunctionParameter(S.Context, *P, true); Arg = FormatFunctionParameter(S.Context, Policy, *P, true);
else { else {
(*P)->getType().getAsStringInternal(Arg, Policy); (*P)->getType().getAsStringInternal(Arg, Policy);
Arg = "(" + formatObjCParamQualifiers((*P)->getObjCDeclQualifier()) Arg = "(" + formatObjCParamQualifiers((*P)->getObjCDeclQualifier())
@ -2576,7 +2578,7 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
if (Qualifier) if (Qualifier)
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
S.Context); S.Context, Policy);
Result.AddTypedTextChunk( Result.AddTypedTextChunk(
Result.getAllocator().CopyString(ND->getNameAsString())); Result.getAllocator().CopyString(ND->getNameAsString()));
@ -2589,12 +2591,12 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
Sema &S, Sema &S,
CodeCompletionAllocator &Allocator) const { CodeCompletionAllocator &Allocator) const {
typedef CodeCompletionString::Chunk Chunk; typedef CodeCompletionString::Chunk Chunk;
PrintingPolicy Policy = getCompletionPrintingPolicy(S.Context); PrintingPolicy Policy = getCompletionPrintingPolicy(S);
// FIXME: Set priority, availability appropriately. // FIXME: Set priority, availability appropriately.
CodeCompletionBuilder Result(Allocator, 1, CXAvailability_Available); CodeCompletionBuilder Result(Allocator, 1, CXAvailability_Available);
FunctionDecl *FDecl = getFunction(); FunctionDecl *FDecl = getFunction();
AddResultTypeChunk(S.Context, FDecl, Result); AddResultTypeChunk(S.Context, Policy, FDecl, Result);
const FunctionProtoType *Proto const FunctionProtoType *Proto
= dyn_cast<FunctionProtoType>(getFunctionType()); = dyn_cast<FunctionProtoType>(getFunctionType());
if (!FDecl && !Proto) { if (!FDecl && !Proto) {
@ -2602,7 +2604,7 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
// highlighted ellipsis. // highlighted ellipsis.
const FunctionType *FT = getFunctionType(); const FunctionType *FT = getFunctionType();
Result.AddTextChunk(GetCompletionTypeString(FT->getResultType(), Result.AddTextChunk(GetCompletionTypeString(FT->getResultType(),
S.Context, S.Context, Policy,
Result.getAllocator())); Result.getAllocator()));
Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen)); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
Result.AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "...")); Result.AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "..."));
@ -2881,6 +2883,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext,
return; return;
} }
PrintingPolicy Policy = getCompletionPrintingPolicy(S);
for (CXXMethodDecl::method_iterator M = Method->begin_overridden_methods(), for (CXXMethodDecl::method_iterator M = Method->begin_overridden_methods(),
MEnd = Method->end_overridden_methods(); MEnd = Method->end_overridden_methods();
M != MEnd; ++M) { M != MEnd; ++M) {
@ -2897,7 +2900,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext,
if (NNS) { if (NNS) {
std::string Str; std::string Str;
llvm::raw_string_ostream OS(Str); llvm::raw_string_ostream OS(Str);
NNS->print(OS, getCompletionPrintingPolicy(S.Context)); NNS->print(OS, Policy);
Builder.AddTextChunk(Results.getAllocator().CopyString(OS.str())); Builder.AddTextChunk(Results.getAllocator().CopyString(OS.str()));
} }
} else if (!InContext->Equals(Overridden->getDeclContext())) } else if (!InContext->Equals(Overridden->getDeclContext()))
@ -3177,6 +3180,7 @@ static void AddObjCProperties(ObjCContainerDecl *Container,
// Add nullary methods // Add nullary methods
if (AllowNullaryMethods) { if (AllowNullaryMethods) {
ASTContext &Context = Container->getASTContext(); ASTContext &Context = Container->getASTContext();
PrintingPolicy Policy = getCompletionPrintingPolicy(Results.getSema());
for (ObjCContainerDecl::method_iterator M = Container->meth_begin(), for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
MEnd = Container->meth_end(); MEnd = Container->meth_end();
M != MEnd; ++M) { M != MEnd; ++M) {
@ -3184,7 +3188,7 @@ static void AddObjCProperties(ObjCContainerDecl *Container,
if (IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0)) if (IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0))
if (AddedProperties.insert(Name)) { if (AddedProperties.insert(Name)) {
CodeCompletionBuilder Builder(Results.getAllocator()); CodeCompletionBuilder Builder(Results.getAllocator());
AddResultTypeChunk(Context, *M, Builder); AddResultTypeChunk(Context, Policy, *M, Builder);
Builder.AddTypedTextChunk( Builder.AddTypedTextChunk(
Results.getAllocator().CopyString(Name->getName())); Results.getAllocator().CopyString(Name->getName()));
@ -3934,7 +3938,7 @@ void Sema::CodeCompleteOperatorName(Scope *S) {
void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD, void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD,
CXXCtorInitializer** Initializers, CXXCtorInitializer** Initializers,
unsigned NumInitializers) { unsigned NumInitializers) {
PrintingPolicy Policy = getCompletionPrintingPolicy(Context); PrintingPolicy Policy = getCompletionPrintingPolicy(*this);
CXXConstructorDecl *Constructor CXXConstructorDecl *Constructor
= static_cast<CXXConstructorDecl *>(ConstructorD); = static_cast<CXXConstructorDecl *>(ConstructorD);
if (!Constructor) if (!Constructor)
@ -4776,7 +4780,8 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword,
CodeCompletionBuilder Builder(Results.getAllocator()); CodeCompletionBuilder Builder(Results.getAllocator());
// Give this completion a return type. // Give this completion a return type.
AddResultTypeChunk(S.Context, SuperMethod, Builder); AddResultTypeChunk(S.Context, getCompletionPrintingPolicy(S), SuperMethod,
Builder);
// If we need the "super" keyword, add it (plus some spacing). // If we need the "super" keyword, add it (plus some spacing).
if (NeedSuperKeyword) { if (NeedSuperKeyword) {
@ -5650,8 +5655,9 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
CodeCompletionAllocator &Allocator = Results.getAllocator(); CodeCompletionAllocator &Allocator = Results.getAllocator();
CodeCompletionBuilder Builder(Allocator, Priority,CXAvailability_Available); CodeCompletionBuilder Builder(Allocator, Priority,CXAvailability_Available);
PrintingPolicy Policy = getCompletionPrintingPolicy(*this);
Builder.AddResultTypeChunk(GetCompletionTypeString(PropertyType, Context, Builder.AddResultTypeChunk(GetCompletionTypeString(PropertyType, Context,
Allocator)); Policy, Allocator));
Builder.AddTypedTextChunk(Allocator.CopyString(NameWithPrefix)); Builder.AddTypedTextChunk(Allocator.CopyString(NameWithPrefix));
Results.AddResult(Result(Builder.TakeString(), Priority, Results.AddResult(Result(Builder.TakeString(), Priority,
CXCursor_ObjCIvarDecl)); CXCursor_ObjCIvarDecl));
@ -5751,9 +5757,10 @@ static void FindImplementableMethods(ASTContext &Context,
/// completion string. /// completion string.
static void AddObjCPassingTypeChunk(QualType Type, static void AddObjCPassingTypeChunk(QualType Type,
ASTContext &Context, ASTContext &Context,
const PrintingPolicy &Policy,
CodeCompletionBuilder &Builder) { CodeCompletionBuilder &Builder) {
Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Builder.AddTextChunk(GetCompletionTypeString(Type, Context, Builder.AddTextChunk(GetCompletionTypeString(Type, Context, Policy,
Builder.getAllocator())); Builder.getAllocator()));
Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddChunk(CodeCompletionString::CK_RightParen);
} }
@ -5783,6 +5790,7 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property,
if (!PropName || PropName->getLength() == 0) if (!PropName || PropName->getLength() == 0)
return; return;
PrintingPolicy Policy = getCompletionPrintingPolicy(Results.getSema());
// Builder that will create each code completion. // Builder that will create each code completion.
typedef CodeCompletionResult Result; typedef CodeCompletionResult Result;
@ -5826,7 +5834,7 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property,
KnownSelectors.insert(Selectors.getNullarySelector(PropName)) && KnownSelectors.insert(Selectors.getNullarySelector(PropName)) &&
ReturnTypeMatchesProperty && !Property->getGetterMethodDecl()) { ReturnTypeMatchesProperty && !Property->getGetterMethodDecl()) {
if (ReturnType.isNull()) if (ReturnType.isNull())
AddObjCPassingTypeChunk(Property->getType(), Context, Builder); AddObjCPassingTypeChunk(Property->getType(), Context, Policy, Builder);
Builder.AddTypedTextChunk(Key); Builder.AddTypedTextChunk(Key);
Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern,
@ -5872,7 +5880,7 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property,
Builder.AddTypedTextChunk( Builder.AddTypedTextChunk(
Allocator.CopyString(SelectorId->getName())); Allocator.CopyString(SelectorId->getName()));
Builder.AddTypedTextChunk(":"); Builder.AddTypedTextChunk(":");
AddObjCPassingTypeChunk(Property->getType(), Context, Builder); AddObjCPassingTypeChunk(Property->getType(), Context, Policy, Builder);
Builder.AddTextChunk(Key); Builder.AddTextChunk(Key);
Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern,
CXCursor_ObjCInstanceMethodDecl)); CXCursor_ObjCInstanceMethodDecl));
@ -6229,6 +6237,7 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property,
Builder.AddTextChunk(" *"); Builder.AddTextChunk(" *");
} else { } else {
Builder.AddTextChunk(GetCompletionTypeString(ReturnType, Context, Builder.AddTextChunk(GetCompletionTypeString(ReturnType, Context,
Policy,
Builder.getAllocator())); Builder.getAllocator()));
} }
Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddChunk(CodeCompletionString::CK_RightParen);
@ -6442,7 +6451,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
ResultBuilder Results(*this, CodeCompleter->getAllocator(), ResultBuilder Results(*this, CodeCompleter->getAllocator(),
CodeCompletionContext::CCC_Other); CodeCompletionContext::CCC_Other);
Results.EnterNewScope(); Results.EnterNewScope();
PrintingPolicy Policy = getCompletionPrintingPolicy(Context); PrintingPolicy Policy = getCompletionPrintingPolicy(*this);
for (KnownMethodsMap::iterator M = KnownMethods.begin(), for (KnownMethodsMap::iterator M = KnownMethods.begin(),
MEnd = KnownMethods.end(); MEnd = KnownMethods.end();
M != MEnd; ++M) { M != MEnd; ++M) {
@ -6452,7 +6461,8 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
// If the result type was not already provided, add it to the // If the result type was not already provided, add it to the
// pattern as (type). // pattern as (type).
if (ReturnType.isNull()) if (ReturnType.isNull())
AddObjCPassingTypeChunk(Method->getResultType(), Context, Builder); AddObjCPassingTypeChunk(Method->getResultType(), Context, Policy,
Builder);
Selector Sel = Method->getSelector(); Selector Sel = Method->getSelector();
@ -6476,7 +6486,8 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
break; break;
// Add the parameter type. // Add the parameter type.
AddObjCPassingTypeChunk((*P)->getOriginalType(), Context, Builder); AddObjCPassingTypeChunk((*P)->getOriginalType(), Context, Policy,
Builder);
if (IdentifierInfo *Id = (*P)->getIdentifier()) if (IdentifierInfo *Id = (*P)->getIdentifier())
Builder.AddTextChunk(Builder.getAllocator().CopyString( Id->getName())); Builder.AddTextChunk(Builder.getAllocator().CopyString( Id->getName()));

View File

@ -205,7 +205,7 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
else else
OS << ", "; OS << ", ";
OS << E->getAsString(Context.getPrintingPolicy()); OS << E->getAsString(getPrintingPolicy());
} }
OS << ")"; OS << ")";
break; break;
@ -218,7 +218,7 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
case EST_ComputedNoexcept: case EST_ComputedNoexcept:
OS << "noexcept("; OS << "noexcept(";
OldProto->getNoexceptExpr()->printPretty(OS, Context, 0, OldProto->getNoexceptExpr()->printPretty(OS, Context, 0,
Context.getPrintingPolicy()); getPrintingPolicy());
OS << ")"; OS << ")";
break; break;

View File

@ -4049,7 +4049,7 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *From,
QualType ConvTy QualType ConvTy
= Conversion->getConversionType().getNonReferenceType(); = Conversion->getConversionType().getNonReferenceType();
std::string TypeStr; std::string TypeStr;
ConvTy.getAsStringInternal(TypeStr, Context.getPrintingPolicy()); ConvTy.getAsStringInternal(TypeStr, getPrintingPolicy());
Diag(Loc, ExplicitConvDiag) Diag(Loc, ExplicitConvDiag)
<< T << ConvTy << T << ConvTy

View File

@ -6729,7 +6729,7 @@ Sema::getTemplateArgumentBindingsText(const TemplateParameterList *Params,
} }
Out << " = "; Out << " = ";
Args[I].print(Context.getPrintingPolicy(), Out); Args[I].print(getPrintingPolicy(), Out);
} }
Out << ']'; Out << ']';

View File

@ -484,7 +484,7 @@ void Sema::PrintInstantiationStack() {
= TemplateSpecializationType::PrintTemplateArgumentList( = TemplateSpecializationType::PrintTemplateArgumentList(
Active->TemplateArgs, Active->TemplateArgs,
Active->NumTemplateArgs, Active->NumTemplateArgs,
Context.getPrintingPolicy()); getPrintingPolicy());
Diags.Report(Active->PointOfInstantiation, Diags.Report(Active->PointOfInstantiation,
diag::note_default_arg_instantiation_here) diag::note_default_arg_instantiation_here)
<< (Template->getNameAsString() + TemplateArgsStr) << (Template->getNameAsString() + TemplateArgsStr)
@ -538,7 +538,7 @@ void Sema::PrintInstantiationStack() {
= TemplateSpecializationType::PrintTemplateArgumentList( = TemplateSpecializationType::PrintTemplateArgumentList(
Active->TemplateArgs, Active->TemplateArgs,
Active->NumTemplateArgs, Active->NumTemplateArgs,
Context.getPrintingPolicy()); getPrintingPolicy());
Diags.Report(Active->PointOfInstantiation, Diags.Report(Active->PointOfInstantiation,
diag::note_default_function_arg_instantiation_here) diag::note_default_function_arg_instantiation_here)
<< (FD->getNameAsString() + TemplateArgsStr) << (FD->getNameAsString() + TemplateArgsStr)

View File

@ -23,9 +23,13 @@ void foo4(id (^objectCreationBlock)(int)) {
return bar4(objectCreationBlock); return bar4(objectCreationBlock);
} }
void bar5(id(^)(void)); // expected-note{{passing argument to parameter here}} void bar5(id(^)(void)); // expected-note 3{{passing argument to parameter here}}
void foo5(id (^objectCreationBlock)(bool)) { void foo5(id (^objectCreationBlock)(bool)) {
return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(bool)' to parameter of type 'id (^)(void)'}} bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(bool)' to parameter of type 'id (^)(void)'}}
#undef bool
bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(_Bool)' to parameter of type 'id (^)(void)'}}
#define bool int
bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(_Bool)' to parameter of type 'id (^)(void)'}}
} }
void bar6(id(^)(int)); void bar6(id(^)(int));