]> granicus.if.org Git - clang/commitdiff
When 'bool' is not a built-in type but is defined as a macro, print
authorDouglas Gregor <dgregor@apple.com>
Tue, 27 Sep 2011 22:38:19 +0000 (22:38 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 27 Sep 2011 22:38:19 +0000 (22:38 +0000)
'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

20 files changed:
include/clang/AST/ASTContext.h
include/clang/AST/PrettyPrinter.h
include/clang/AST/Type.h
lib/ARCMigrate/TransUnbridgedCasts.cpp
lib/AST/ASTContext.cpp
lib/AST/ASTDiagnostic.cpp
lib/AST/DeclPrinter.cpp
lib/AST/Type.cpp
lib/AST/TypePrinter.cpp
lib/Frontend/ASTConsumers.cpp
lib/Rewrite/RewriteObjC.cpp
lib/Sema/SemaChecking.cpp
lib/Sema/SemaCodeComplete.cpp
lib/Sema/SemaExceptionSpec.cpp
lib/Sema/SemaOverload.cpp
lib/Sema/SemaTemplate.cpp
lib/Sema/SemaTemplateInstantiate.cpp
test/Index/complete-exprs.m
test/SemaObjC/blocks.m
tools/libclang/CIndex.cpp

index 9d8aa537a33323cf4181b30c624a138b544bcb84..445e96aca8c714e8940a1958a595626cc0cc44b5 100644 (file)
@@ -342,6 +342,8 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> {
   friend class ASTWriter;
   
   const TargetInfo *Target;
+  mutable clang::PrintingPolicy PrintingPolicy;
+  
 public:
   IdentifierTable &Idents;
   SelectorTable &Selectors;
@@ -349,8 +351,9 @@ public:
   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 {
index ae56671d90020a3f77ae17133b32cbe1aa3a3951..6df99659d6d41b4321ceefb5457d3dbdb601579d 100644 (file)
@@ -38,7 +38,8 @@ struct PrintingPolicy {
       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;
@@ -130,6 +131,10 @@ struct PrintingPolicy {
   /// \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
index 90e29ba741e46b6f44837cd87314a95e75f35b97..0b4c8f715d0f27cc7594350011cf9c6f5459cf5d 100644 (file)
@@ -1759,7 +1759,7 @@ public:
   }
 
   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); }
index 047dfb276ad7c22cf6bb6d6322e8be751cb51e6f..69fb2e8949e419376d972009561ea3de15293534 100644 (file)
@@ -182,7 +182,7 @@ private:
       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())) {
@@ -215,7 +215,7 @@ private:
 
     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 "
@@ -230,7 +230,7 @@ private:
       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());
       }
index fa0ebc8a863db8f8e8e51bbffd0a1873ec22ba8f..9a9c95aa2db9a9558909c9c8cdd123d19f72fa6e 100644 (file)
@@ -231,11 +231,11 @@ ASTContext::ASTContext(LangOptions& LOpts, SourceManager &SM,
     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) 
 {
@@ -4385,7 +4385,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
           = TemplateSpecializationType::PrintTemplateArgumentList(
                                             TemplateArgs.data(),
                                             TemplateArgs.size(),
-                                            (*this).PrintingPolicy);
+                                            (*this).getPrintingPolicy());
 
         S += TemplateArgsStr;
       }
@@ -6475,6 +6475,12 @@ MangleContext *ASTContext::createMangleContext() {
 
 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)
index 4c115d116ba0461f68efaa8993b049d4b0cc6828..07820dc3cc56930e2bc9c1e5a35c7d129598fa25 100644 (file)
@@ -158,8 +158,8 @@ ConvertTypeToDiagnosticString(ASTContext &Context, QualType Ty,
   // 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) {
@@ -170,10 +170,10 @@ ConvertTypeToDiagnosticString(ASTContext &Context, QualType Ty,
     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
 
@@ -205,7 +205,7 @@ ConvertTypeToDiagnosticString(ASTContext &Context, QualType Ty,
       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;
@@ -270,13 +270,13 @@ void clang::FormatASTNodeDiagnosticArgument(
         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;
     }
@@ -305,7 +305,7 @@ void clang::FormatASTNodeDiagnosticArgument(
           S += "function ";
         
         S += "'";
-        ND->getNameForDiagnostic(S, Context.PrintingPolicy, true);
+        ND->getNameForDiagnostic(S, Context.getPrintingPolicy(), true);
         S += "'";
       }
       NeedQuotes = false;
index 8d8ec2f7d2cb9158b3c8434754d35c1c8974e207..7c61bae9ad1a7abd22af7b1e692b2b41090c0b0b 100644 (file)
@@ -90,7 +90,7 @@ namespace {
 
 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,
@@ -168,7 +168,7 @@ void DeclContext::dumpDeclContext() const {
     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);
 }
 
index ca58ec05ac5bfa1252ef15b8e840a154fb213807..7f28f7c801eef6679f97a68e2298d8e6a6479b75 100644 (file)
@@ -1467,10 +1467,10 @@ const char *Type::getTypeClassName() const {
   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";
index b89d2aa31676380ffcbecd46618c2960b62a835e..855cc02d9e698ce8b6c69956c59930644297137c 100644 (file)
@@ -205,11 +205,11 @@ void TypePrinter::print(const Type *T, Qualifiers Quals, std::string &buffer) {
 
 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;
   }
 }
 
index 70baf7454512f0a4ae823c5072057807db715e41..15ab2f83c241c9c3fbcb4ed8a09c1a0e928259b9 100644 (file)
@@ -39,7 +39,7 @@ namespace {
       : 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);
index 57d1210f31b7e036138633a2154e17553707ec57..dcb3e602c05ff31a4ac2977f69538d02ed563e52 100644 (file)
@@ -854,7 +854,7 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
           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()) {
@@ -1088,11 +1088,11 @@ void RewriteObjC::RewriteTypeIntoString(QualType T, std::string &ResultStr,
       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,
@@ -1150,10 +1150,10 @@ 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.
@@ -1169,9 +1169,9 @@ void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
       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;
     }
   }
@@ -1188,7 +1188,7 @@ void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
       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()) {
@@ -1675,7 +1675,7 @@ Stmt *RewriteObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,
       // 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();
@@ -1691,7 +1691,7 @@ Stmt *RewriteObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,
       // 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 };
@@ -2387,7 +2387,7 @@ void RewriteObjC::RewriteTypeOfDecl(VarDecl *ND) {
   }
   // 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()) {
@@ -2437,7 +2437,7 @@ void RewriteObjC::RewriteFunctionDecl(FunctionDecl *FD) {
 }
 
 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;
@@ -2453,7 +2453,7 @@ void RewriteObjC::RewriteBlockPointerType(std::string& Str, QualType Type) {
 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) {
@@ -2487,7 +2487,7 @@ void RewriteObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {
   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 +=  "(";
@@ -4235,7 +4235,7 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
   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();
@@ -4259,9 +4259,9 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
       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()) {
@@ -4310,7 +4310,7 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
       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";
     }
@@ -4408,8 +4408,8 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag,
         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";
@@ -5222,7 +5222,7 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
 
   QualType T = Ty;
   (void)convertBlockPointerToFunctionPointer(T);
-  T.getAsStringInternal(Name, Context->PrintingPolicy);
+  T.getAsStringInternal(Name, Context->getPrintingPolicy());
     
   ByrefType += " " + Name + ";\n";
   ByrefType += "};\n";
index 8339bddf8736d8c19481548746122f57b379c558..ae6f1d9809266e97be1f423e9775e6dc38915c5f 100644 (file)
@@ -2140,7 +2140,7 @@ void Sema::CheckStrlcpycatArguments(const CallExpr *Call,
   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)
index 283f4fb731da1c5c46f73d217bfe85bb0f94a6f7..307472504401e8bd8a1c22b5f37f8a9c4aad024f 100644 (file)
@@ -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) {
index aba7b34977347cb94013aa832248c6b74cf2227d..95fdd031fab4c9cc170af16eda02e0b6e1f784ed 100644 (file)
@@ -205,7 +205,7 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
         else
           OS << ", ";
         
-        OS << E->getAsString(Context.PrintingPolicy);
+        OS << E->getAsString(Context.getPrintingPolicy());
       }
       OS << ")";
       break;
@@ -218,7 +218,7 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
     case EST_ComputedNoexcept:
       OS << "noexcept(";
       OldProto->getNoexceptExpr()->printPretty(OS, Context, 0,
-                                               Context.PrintingPolicy);
+                                               Context.getPrintingPolicy());
       OS << ")";
       break;
 
index 185e339db3827e8334395293338cb4344ca72b4b..ada98de4ceee94b8bf17d56a819ed77921a89e5e 100644 (file)
@@ -4049,7 +4049,7 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *From,
       QualType ConvTy
         = Conversion->getConversionType().getNonReferenceType();
       std::string TypeStr;
-      ConvTy.getAsStringInternal(TypeStr, Context.PrintingPolicy);
+      ConvTy.getAsStringInternal(TypeStr, Context.getPrintingPolicy());
 
       Diag(Loc, ExplicitConvDiag)
         << T << ConvTy
index d283b6d2344f0da323ddcd0a4fc1c756f4fbd8a1..0f2f6329aabf244aaa02bb88f4f977454e60ed0d 100644 (file)
@@ -6729,7 +6729,7 @@ Sema::getTemplateArgumentBindingsText(const TemplateParameterList *Params,
     }
 
     Out << " = ";
-    Args[I].print(Context.PrintingPolicy, Out);
+    Args[I].print(Context.getPrintingPolicy(), Out);
   }
 
   Out << ']';
index 38cd349601b7662f81119f677ece535194a55111..a3b826d1ddd5f2d34d767f8dd5dc53c8fdae0286 100644 (file)
@@ -484,7 +484,7 @@ void Sema::PrintInstantiationStack() {
         = TemplateSpecializationType::PrintTemplateArgumentList(
                                                          Active->TemplateArgs,
                                                       Active->NumTemplateArgs,
-                                                      Context.PrintingPolicy);
+                                                      Context.getPrintingPolicy());
       Diags.Report(Active->PointOfInstantiation,
                    diag::note_default_arg_instantiation_here)
         << (Template->getNameAsString() + TemplateArgsStr)
@@ -538,7 +538,7 @@ void Sema::PrintInstantiationStack() {
         = TemplateSpecializationType::PrintTemplateArgumentList(
                                                          Active->TemplateArgs,
                                                       Active->NumTemplateArgs,
-                                                      Context.PrintingPolicy);
+                                                      Context.getPrintingPolicy());
       Diags.Report(Active->PointOfInstantiation,
                    diag::note_default_function_arg_instantiation_here)
         << (FD->getNameAsString() + TemplateArgsStr)
index dfa114dcc095a72a50434017b0e3149f2f5979fd..08ec019003f3bee1ca270e6584ad3d9a9c7dbc47 100644 (file)
@@ -10,7 +10,7 @@ typedef signed char BOOL;
 __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
@@ -29,6 +29,6 @@ __strong id global;
 // 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)
index 15aa5811cc53518a0be4dc98c042c5b0acaf94f4..187f7d8274d1862f01987e054a15d1c87ae005f4 100644 (file)
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
+
+#define bool _Bool
 @protocol NSObject;
 
 void bar(id(^)(void));
@@ -22,8 +24,8 @@ void foo4(id (^objectCreationBlock)(int)) {
 }
 
 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));
index f71f1530558e7c60f6949a9f35c29ac54ae3191c..73718174177647cc14e09c030de565f3357dc11f 100644 (file)
@@ -3199,7 +3199,7 @@ CXString clang_getCursorDisplayName(CXCursor C) {
   if (!D)
     return createCXString("");
 
-  PrintingPolicy &Policy = getCursorContext(C).PrintingPolicy;
+  PrintingPolicy Policy = getCursorContext(C).getPrintingPolicy();
   if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
     D = FunTmpl->getTemplatedDecl();