friend class ASTWriter;
const TargetInfo *Target;
+ mutable clang::PrintingPolicy PrintingPolicy;
+
public:
IdentifierTable &Idents;
SelectorTable &Selectors;
mutable DeclarationNameTable DeclarationNames;
llvm::OwningPtr<ExternalASTSource> ExternalSource;
ASTMutationListener *Listener;
- clang::PrintingPolicy PrintingPolicy;
+ clang::PrintingPolicy getPrintingPolicy() const;
+
SourceManager& getSourceManager() { return SourceMgr; }
const SourceManager& getSourceManager() const { return SourceMgr; }
void *Allocate(unsigned Size, unsigned Align = 8) const {
SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false),
SuppressInitializers(false),
Dump(false), ConstantArraySizeAsWritten(false),
- AnonymousTagLocations(true), SuppressStrongLifetime(false) { }
+ AnonymousTagLocations(true), SuppressStrongLifetime(false),
+ Bool(LO.Bool) { }
/// \brief The number of spaces to use to indent each line.
unsigned Indentation : 8;
/// \brief When true, suppress printing of the __strong lifetime qualifier in
/// ARC.
unsigned SuppressStrongLifetime : 1;
+
+ /// \brief Whether we can use 'bool' rather than '_Bool', even if the language
+ /// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
+ unsigned Bool : 1;
};
} // end namespace clang
}
Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
- const char *getName(const LangOptions &LO) const;
+ const char *getName(const PrintingPolicy &Policy) const;
bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }
llvm::SmallString<128> newCast;
newCast += '(';
newCast += bridge;
- newCast += E->getType().getAsString(Pass.Ctx.PrintingPolicy);
+ newCast += E->getType().getAsString(Pass.Ctx.getPrintingPolicy());
newCast += ')';
if (isa<ParenExpr>(E->getSubExpr())) {
if (family == OMF_autorelease || family == OMF_release) {
std::string err = "it is not safe to cast to '";
- err += E->getType().getAsString(Pass.Ctx.PrintingPolicy);
+ err += E->getType().getAsString(Pass.Ctx.getPrintingPolicy());
err += "' the result of '";
err += family == OMF_autorelease ? "autorelease" : "release";
err += "' message; a __bridge cast may result in a pointer to a "
if (ReturnStmt *retS = dyn_cast_or_null<ReturnStmt>(parent)) {
std::string note = "remove the cast and change return type of function "
"to '";
- note += E->getSubExpr()->getType().getAsString(Pass.Ctx.PrintingPolicy);
+ note += E->getSubExpr()->getType().getAsString(Pass.Ctx.getPrintingPolicy());
note += "' to have the object automatically autoreleased";
Pass.TA.reportNote(note, retS->getLocStart());
}
BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0),
NullTypeSourceInfo(QualType()),
SourceMgr(SM), LangOpts(LOpts),
- AddrSpaceMap(0), Target(t),
+ AddrSpaceMap(0), Target(t), PrintingPolicy(LOpts),
Idents(idents), Selectors(sels),
BuiltinInfo(builtins),
DeclarationNames(*this),
- ExternalSource(0), Listener(0), PrintingPolicy(LOpts),
+ ExternalSource(0), Listener(0),
LastSDM(0, 0),
UniqueBlockByRefTypeID(0)
{
= TemplateSpecializationType::PrintTemplateArgumentList(
TemplateArgs.data(),
TemplateArgs.size(),
- (*this).PrintingPolicy);
+ (*this).getPrintingPolicy());
S += TemplateArgsStr;
}
CXXABI::~CXXABI() {}
+PrintingPolicy ASTContext::getPrintingPolicy() const {
+ PrintingPolicy.Bool
+ = LangOpts.Bool || Idents.get("bool").hasMacroDefinition();
+ return PrintingPolicy;
+}
+
size_t ASTContext::getSideTableAllocatedMemory() const {
return ASTRecordLayouts.getMemorySize()
+ llvm::capacity_in_bytes(ObjCLayouts)
// FIXME: Playing with std::string is really slow.
bool ForceAKA = false;
QualType CanTy = Ty.getCanonicalType();
- std::string S = Ty.getAsString(Context.PrintingPolicy);
- std::string CanS = CanTy.getAsString(Context.PrintingPolicy);
+ std::string S = Ty.getAsString(Context.getPrintingPolicy());
+ std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
for (SmallVectorImpl<intptr_t>::iterator I = QualTypeVals.begin(),
E = QualTypeVals.end(); I != E; ++I) {
QualType CompareCanTy = CompareTy.getCanonicalType();
if (CompareCanTy == CanTy)
continue; // Same canonical types
- std::string CompareS = CompareTy.getAsString(Context.PrintingPolicy);
+ std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
if (CompareS != S)
continue; // Original strings are different
- std::string CompareCanS = CompareCanTy.getAsString(Context.PrintingPolicy);
+ std::string CompareCanS = CompareCanTy.getAsString(Context.getPrintingPolicy());
if (CompareCanS == CanS)
continue; // No new info from canonical type
if (DesugaredTy == Ty) {
DesugaredTy = Ty.getCanonicalType();
}
- std::string akaStr = DesugaredTy.getAsString(Context.PrintingPolicy);
+ std::string akaStr = DesugaredTy.getAsString(Context.getPrintingPolicy());
if (akaStr != S) {
S = "'" + S + "' (aka '" + akaStr + "')";
return S;
Qualified = false;
}
const NamedDecl *ND = reinterpret_cast<const NamedDecl*>(Val);
- ND->getNameForDiagnostic(S, Context.PrintingPolicy, Qualified);
+ ND->getNameForDiagnostic(S, Context.getPrintingPolicy(), Qualified);
break;
}
case DiagnosticsEngine::ak_nestednamespec: {
llvm::raw_string_ostream OS(S);
reinterpret_cast<NestedNameSpecifier*>(Val)->print(OS,
- Context.PrintingPolicy);
+ Context.getPrintingPolicy());
NeedQuotes = false;
break;
}
S += "function ";
S += "'";
- ND->getNameForDiagnostic(S, Context.PrintingPolicy, true);
+ ND->getNameForDiagnostic(S, Context.getPrintingPolicy(), true);
S += "'";
}
NeedQuotes = false;
void Decl::print(raw_ostream &Out, unsigned Indentation,
bool PrintInstantiation) const {
- print(Out, getASTContext().PrintingPolicy, Indentation, PrintInstantiation);
+ print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
}
void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
DC = DC->getParent();
ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
- DeclPrinter Printer(llvm::errs(), Ctx, Ctx.PrintingPolicy, 0);
+ DeclPrinter Printer(llvm::errs(), Ctx, Ctx.getPrintingPolicy(), 0);
Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
}
return 0;
}
-const char *BuiltinType::getName(const LangOptions &LO) const {
+const char *BuiltinType::getName(const PrintingPolicy &Policy) const {
switch (getKind()) {
case Void: return "void";
- case Bool: return LO.Bool ? "bool" : "_Bool";
+ case Bool: return Policy.Bool ? "bool" : "_Bool";
case Char_S: return "char";
case Char_U: return "char";
case SChar: return "signed char";
void TypePrinter::printBuiltin(const BuiltinType *T, std::string &S) {
if (S.empty()) {
- S = T->getName(Policy.LangOpts);
+ S = T->getName(Policy);
} else {
// Prefix the basic type, e.g. 'int X'.
S = ' ' + S;
- S = T->getName(Policy.LangOpts) + S;
+ S = T->getName(Policy) + S;
}
}
: Out(o? *o : llvm::outs()), Dump(Dump) { }
virtual void HandleTranslationUnit(ASTContext &Context) {
- PrintingPolicy Policy = Context.PrintingPolicy;
+ PrintingPolicy Policy = Context.getPrintingPolicy();
Policy.Dump = Dump;
Context.getTranslationUnitDecl()->print(Out, Policy, /*Indentation=*/0,
/*PrintInstantiation=*/true);
for (unsigned i = 0, e = FT->getNumArgs(); i != e; ++i) {
if (i) Getr += ", ";
std::string ParamStr = FT->getArgType(i).getAsString(
- Context->PrintingPolicy);
+ Context->getPrintingPolicy());
Getr += ParamStr;
}
if (FT->isVariadic()) {
PointeeTy = BPT->getPointeeType();
if ((FPRetType = PointeeTy->getAs<FunctionType>())) {
ResultStr += FPRetType->getResultType().getAsString(
- Context->PrintingPolicy);
+ Context->getPrintingPolicy());
ResultStr += "(*";
}
} else
- ResultStr += T.getAsString(Context->PrintingPolicy);
+ ResultStr += T.getAsString(Context->getPrintingPolicy());
}
void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
}
else
ResultStr += Context->getObjCClassType().getAsString(
- Context->PrintingPolicy);
+ Context->getPrintingPolicy());
ResultStr += " self, ";
- ResultStr += Context->getObjCSelType().getAsString(Context->PrintingPolicy);
+ ResultStr += Context->getObjCSelType().getAsString(Context->getPrintingPolicy());
ResultStr += " _cmd";
// Method arguments.
QualType QT = PDecl->getType();
// Make sure we convert "t (^)(...)" to "t (*)(...)".
if (convertBlockPointerToFunctionPointer(QT))
- QT.getAsStringInternal(Name, Context->PrintingPolicy);
+ QT.getAsStringInternal(Name, Context->getPrintingPolicy());
else
- PDecl->getType().getAsStringInternal(Name, Context->PrintingPolicy);
+ PDecl->getType().getAsStringInternal(Name, Context->getPrintingPolicy());
ResultStr += Name;
}
}
for (unsigned i = 0, e = FT->getNumArgs(); i != e; ++i) {
if (i) ResultStr += ", ";
std::string ParamStr = FT->getArgType(i).getAsString(
- Context->PrintingPolicy);
+ Context->getPrintingPolicy());
ResultStr += ParamStr;
}
if (FT->isVariadic()) {
// Simply use 'id' for all qualified types.
elementTypeAsString = "id";
else
- elementTypeAsString = ElementType.getAsString(Context->PrintingPolicy);
+ elementTypeAsString = ElementType.getAsString(Context->getPrintingPolicy());
buf += elementTypeAsString;
buf += " ";
elementName = D->getName();
// Simply use 'id' for all qualified types.
elementTypeAsString = "id";
else
- elementTypeAsString = VD->getType().getAsString(Context->PrintingPolicy);
+ elementTypeAsString = VD->getType().getAsString(Context->getPrintingPolicy());
}
// struct __objcFastEnumerationState enumState = { 0 };
}
// FIXME. This will not work for multiple declarators; as in:
// __typeof__(a) b,c,d;
- std::string TypeAsString(QT.getAsString(Context->PrintingPolicy));
+ std::string TypeAsString(QT.getAsString(Context->getPrintingPolicy()));
SourceLocation DeclLoc = ND->getTypeSpecStartLoc();
const char *startBuf = SM->getCharacterData(DeclLoc);
if (ND->getInit()) {
}
void RewriteObjC::RewriteBlockPointerType(std::string& Str, QualType Type) {
- std::string TypeString(Type.getAsString(Context->PrintingPolicy));
+ std::string TypeString(Type.getAsString(Context->getPrintingPolicy()));
const char *argPtr = TypeString.c_str();
if (!strchr(argPtr, '^')) {
Str += TypeString;
void RewriteObjC::RewriteBlockPointerTypeVariable(std::string& Str,
ValueDecl *VD) {
QualType Type = VD->getType();
- std::string TypeString(Type.getAsString(Context->PrintingPolicy));
+ std::string TypeString(Type.getAsString(Context->getPrintingPolicy()));
const char *argPtr = TypeString.c_str();
int paren = 0;
while (*argPtr) {
if (!proto)
return;
QualType Type = proto->getResultType();
- std::string FdStr = Type.getAsString(Context->PrintingPolicy);
+ std::string FdStr = Type.getAsString(Context->getPrintingPolicy());
FdStr += " ";
FdStr += FD->getName();
FdStr += "(";
const FunctionType *AFT = CE->getFunctionType();
QualType RT = AFT->getResultType();
std::string StructRef = "struct " + Tag;
- std::string S = "static " + RT.getAsString(Context->PrintingPolicy) + " __" +
+ std::string S = "static " + RT.getAsString(Context->getPrintingPolicy()) + " __" +
funcName.str() + "_" + "block_func_" + utostr(i);
BlockDecl *BD = CE->getBlockDecl();
ParamStr = (*AI)->getNameAsString();
QualType QT = (*AI)->getType();
if (convertBlockPointerToFunctionPointer(QT))
- QT.getAsStringInternal(ParamStr, Context->PrintingPolicy);
+ QT.getAsStringInternal(ParamStr, Context->getPrintingPolicy());
else
- QT.getAsStringInternal(ParamStr, Context->PrintingPolicy);
+ QT.getAsStringInternal(ParamStr, Context->getPrintingPolicy());
S += ParamStr;
}
if (FT->isVariadic()) {
QualType QT = (*I)->getType();
if (HasLocalVariableExternalStorage(*I))
QT = Context->getPointerType(QT);
- QT.getAsStringInternal(Name, Context->PrintingPolicy);
+ QT.getAsStringInternal(Name, Context->getPrintingPolicy());
S += Name + " = __cself->" +
(*I)->getNameAsString() + "; // bound by copy\n";
}
QualType QT = (*I)->getType();
if (HasLocalVariableExternalStorage(*I))
QT = Context->getPointerType(QT);
- QT.getAsStringInternal(FieldName, Context->PrintingPolicy);
- QT.getAsStringInternal(ArgName, Context->PrintingPolicy);
+ QT.getAsStringInternal(FieldName, Context->getPrintingPolicy());
+ QT.getAsStringInternal(ArgName, Context->getPrintingPolicy());
Constructor += ", " + ArgName;
}
S += FieldName + ";\n";
QualType T = Ty;
(void)convertBlockPointerToFunctionPointer(T);
- T.getAsStringInternal(Name, Context->PrintingPolicy);
+ T.getAsStringInternal(Name, Context->getPrintingPolicy());
ByrefType += " " + Name + ";\n";
ByrefType += "};\n";
llvm::SmallString<128> sizeString;
llvm::raw_svector_ostream OS(sizeString);
OS << "sizeof(";
- DstArg->printPretty(OS, Context, 0, Context.PrintingPolicy);
+ DstArg->printPretty(OS, Context, 0, Context.getPrintingPolicy());
OS << ")";
Diag(OriginalSizeArg->getLocStart(), diag::note_strlcpycat_wrong_size)
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.
///
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))
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()) {
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;
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));
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;
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);
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()))
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)
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) {
else
OS << ", ";
- OS << E->getAsString(Context.PrintingPolicy);
+ OS << E->getAsString(Context.getPrintingPolicy());
}
OS << ")";
break;
case EST_ComputedNoexcept:
OS << "noexcept(";
OldProto->getNoexceptExpr()->printPretty(OS, Context, 0,
- Context.PrintingPolicy);
+ Context.getPrintingPolicy());
OS << ")";
break;
QualType ConvTy
= Conversion->getConversionType().getNonReferenceType();
std::string TypeStr;
- ConvTy.getAsStringInternal(TypeStr, Context.PrintingPolicy);
+ ConvTy.getAsStringInternal(TypeStr, Context.getPrintingPolicy());
Diag(Loc, ExplicitConvDiag)
<< T << ConvTy
}
Out << " = ";
- Args[I].print(Context.PrintingPolicy, Out);
+ Args[I].print(Context.getPrintingPolicy(), Out);
}
Out << ']';
= TemplateSpecializationType::PrintTemplateArgumentList(
Active->TemplateArgs,
Active->NumTemplateArgs,
- Context.PrintingPolicy);
+ Context.getPrintingPolicy());
Diags.Report(Active->PointOfInstantiation,
diag::note_default_arg_instantiation_here)
<< (Template->getNameAsString() + TemplateArgsStr)
= TemplateSpecializationType::PrintTemplateArgumentList(
Active->TemplateArgs,
Active->NumTemplateArgs,
- Context.PrintingPolicy);
+ Context.getPrintingPolicy());
Diags.Report(Active->PointOfInstantiation,
diag::note_default_function_arg_instantiation_here)
<< (FD->getNameAsString() + TemplateArgsStr)
__strong id global;
@implementation A
- (int)method:(id)param1 {
- void foo(id (^block)(id x, A* y));
+ void foo(bool (^block)(id x, A* y));
for(BOOL B = YES; ; ) { }
}
@end
// CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (40)
// RUN: c-index-test -code-completion-at=%s:15:1 -fobjc-arc -fobjc-nonfragile-abi %s | FileCheck -check-prefix=CHECK-CC3 %s
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:15:1 -fobjc-arc -fobjc-nonfragile-abi %s | FileCheck -check-prefix=CHECK-CC3 %s
-// CHECK-CC3: FunctionDecl:{ResultType void}{TypedText foo}{LeftParen (}{Placeholder ^id(id x, A *y)block}{RightParen )} (34)
+// CHECK-CC3: FunctionDecl:{ResultType void}{TypedText foo}{LeftParen (}{Placeholder ^bool(id x, A *y)block}{RightParen )} (34)
// CHECK-CC3: VarDecl:{ResultType id}{TypedText global} (50)
// CHECK-CC3: ParmDecl:{ResultType id}{TypedText param1} (34)
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
+
+#define bool _Bool
@protocol NSObject;
void bar(id(^)(void));
}
void bar5(id(^)(void)); // expected-note{{passing argument to parameter here}}
-void foo5(id (^objectCreationBlock)(int)) {
- return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(int)' to parameter of type 'id (^)(void)'}}
+void foo5(id (^objectCreationBlock)(bool)) {
+ return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(bool)' to parameter of type 'id (^)(void)'}}
}
void bar6(id(^)(int));
if (!D)
return createCXString("");
- PrintingPolicy &Policy = getCursorContext(C).PrintingPolicy;
+ PrintingPolicy Policy = getCursorContext(C).getPrintingPolicy();
if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
D = FunTmpl->getTemplatedDecl();