[cfe-commits] r140650 - in /cfe/trunk: include/clang/AST/ lib/ARCMigrate/ lib/AST/ lib/Frontend/ lib/Rewrite/ lib/Sema/ test/Index/ test/SemaObjC/ tools/libclang/

Eli Friedman eli.friedman at gmail.com
Tue Sep 27 15:48:23 PDT 2011


On Tue, Sep 27, 2011 at 3:38 PM, Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Tue Sep 27 17:38:19 2011
> New Revision: 140650
>
> URL: http://llvm.org/viewvc/llvm-project?rev=140650&view=rev
> Log:
> 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>.

Is it actually safe to assume that bool is defined to _Bool?  It's
probably not hard to find code that has constructs like "#define bool
int"...

-Eli

> Modified:
>    cfe/trunk/include/clang/AST/ASTContext.h
>    cfe/trunk/include/clang/AST/PrettyPrinter.h
>    cfe/trunk/include/clang/AST/Type.h
>    cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp
>    cfe/trunk/lib/AST/ASTContext.cpp
>    cfe/trunk/lib/AST/ASTDiagnostic.cpp
>    cfe/trunk/lib/AST/DeclPrinter.cpp
>    cfe/trunk/lib/AST/Type.cpp
>    cfe/trunk/lib/AST/TypePrinter.cpp
>    cfe/trunk/lib/Frontend/ASTConsumers.cpp
>    cfe/trunk/lib/Rewrite/RewriteObjC.cpp
>    cfe/trunk/lib/Sema/SemaChecking.cpp
>    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
>    cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
>    cfe/trunk/lib/Sema/SemaOverload.cpp
>    cfe/trunk/lib/Sema/SemaTemplate.cpp
>    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
>    cfe/trunk/test/Index/complete-exprs.m
>    cfe/trunk/test/SemaObjC/blocks.m
>    cfe/trunk/tools/libclang/CIndex.cpp
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Tue Sep 27 17:38:19 2011
> @@ -342,6 +342,8 @@
>   friend class ASTWriter;
>
>   const TargetInfo *Target;
> +  mutable clang::PrintingPolicy PrintingPolicy;
> +
>  public:
>   IdentifierTable &Idents;
>   SelectorTable &Selectors;
> @@ -349,8 +351,9 @@
>   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 {
>
> Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
> +++ cfe/trunk/include/clang/AST/PrettyPrinter.h Tue Sep 27 17:38:19 2011
> @@ -38,7 +38,8 @@
>       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 @@
>   /// \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
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Tue Sep 27 17:38:19 2011
> @@ -1759,7 +1759,7 @@
>   }
>
>   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); }
>
> Modified: cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp (original)
> +++ cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp Tue Sep 27 17:38:19 2011
> @@ -182,7 +182,7 @@
>       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 @@
>
>     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 @@
>       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());
>       }
>
> Modified: cfe/trunk/lib/AST/ASTContext.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
> +++ cfe/trunk/lib/AST/ASTContext.cpp Tue Sep 27 17:38:19 2011
> @@ -231,11 +231,11 @@
>     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 @@
>           = TemplateSpecializationType::PrintTemplateArgumentList(
>                                             TemplateArgs.data(),
>                                             TemplateArgs.size(),
> -                                            (*this).PrintingPolicy);
> +                                            (*this).getPrintingPolicy());
>
>         S += TemplateArgsStr;
>       }
> @@ -6475,6 +6475,12 @@
>
>  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)
>
> Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Tue Sep 27 17:38:19 2011
> @@ -158,8 +158,8 @@
>   // 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 @@
>     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 @@
>       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 @@
>         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 @@
>           S += "function ";
>
>         S += "'";
> -        ND->getNameForDiagnostic(S, Context.PrintingPolicy, true);
> +        ND->getNameForDiagnostic(S, Context.getPrintingPolicy(), true);
>         S += "'";
>       }
>       NeedQuotes = false;
>
> Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
> +++ cfe/trunk/lib/AST/DeclPrinter.cpp Tue Sep 27 17:38:19 2011
> @@ -90,7 +90,7 @@
>
>  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 @@
>     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);
>  }
>
>
> Modified: cfe/trunk/lib/AST/Type.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/Type.cpp (original)
> +++ cfe/trunk/lib/AST/Type.cpp Tue Sep 27 17:38:19 2011
> @@ -1467,10 +1467,10 @@
>   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";
>
> Modified: cfe/trunk/lib/AST/TypePrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/TypePrinter.cpp (original)
> +++ cfe/trunk/lib/AST/TypePrinter.cpp Tue Sep 27 17:38:19 2011
> @@ -205,11 +205,11 @@
>
>  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;
>   }
>  }
>
>
> Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
> +++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Sep 27 17:38:19 2011
> @@ -39,7 +39,7 @@
>       : 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);
>
> Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
> +++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Tue Sep 27 17:38:19 2011
> @@ -854,7 +854,7 @@
>           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 @@
>       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 @@
>   }
>   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 @@
>       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 @@
>       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 @@
>       // 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 @@
>       // 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 @@
>   }
>   // 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::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::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 @@
>   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 @@
>   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 @@
>       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 @@
>       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 @@
>         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 @@
>
>   QualType T = Ty;
>   (void)convertBlockPointerToFunctionPointer(T);
> -  T.getAsStringInternal(Name, Context->PrintingPolicy);
> +  T.getAsStringInternal(Name, Context->getPrintingPolicy());
>
>   ByrefType += " " + Name + ";\n";
>   ByrefType += "};\n";
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 27 17:38:19 2011
> @@ -2140,7 +2140,7 @@
>   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)
>
> Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Sep 27 17:38:19 2011
> @@ -1840,6 +1840,14 @@
>     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 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 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 @@
>                                        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 @@
>   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 @@
>   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 @@
>                                                                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 @@
>       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::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 @@
>   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) {
>
> Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Tue Sep 27 17:38:19 2011
> @@ -205,7 +205,7 @@
>         else
>           OS << ", ";
>
> -        OS << E->getAsString(Context.PrintingPolicy);
> +        OS << E->getAsString(Context.getPrintingPolicy());
>       }
>       OS << ")";
>       break;
> @@ -218,7 +218,7 @@
>     case EST_ComputedNoexcept:
>       OS << "noexcept(";
>       OldProto->getNoexceptExpr()->printPretty(OS, Context, 0,
> -                                               Context.PrintingPolicy);
> +                                               Context.getPrintingPolicy());
>       OS << ")";
>       break;
>
>
> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Sep 27 17:38:19 2011
> @@ -4049,7 +4049,7 @@
>       QualType ConvTy
>         = Conversion->getConversionType().getNonReferenceType();
>       std::string TypeStr;
> -      ConvTy.getAsStringInternal(TypeStr, Context.PrintingPolicy);
> +      ConvTy.getAsStringInternal(TypeStr, Context.getPrintingPolicy());
>
>       Diag(Loc, ExplicitConvDiag)
>         << T << ConvTy
>
> Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Sep 27 17:38:19 2011
> @@ -6729,7 +6729,7 @@
>     }
>
>     Out << " = ";
> -    Args[I].print(Context.PrintingPolicy, Out);
> +    Args[I].print(Context.getPrintingPolicy(), Out);
>   }
>
>   Out << ']';
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Sep 27 17:38:19 2011
> @@ -484,7 +484,7 @@
>         = 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 @@
>         = TemplateSpecializationType::PrintTemplateArgumentList(
>                                                          Active->TemplateArgs,
>                                                       Active->NumTemplateArgs,
> -                                                      Context.PrintingPolicy);
> +                                                      Context.getPrintingPolicy());
>       Diags.Report(Active->PointOfInstantiation,
>                    diag::note_default_function_arg_instantiation_here)
>         << (FD->getNameAsString() + TemplateArgsStr)
>
> Modified: cfe/trunk/test/Index/complete-exprs.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-exprs.m?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/complete-exprs.m (original)
> +++ cfe/trunk/test/Index/complete-exprs.m Tue Sep 27 17:38:19 2011
> @@ -10,7 +10,7 @@
>  __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 @@
>  // 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)
>
> Modified: cfe/trunk/test/SemaObjC/blocks.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/blocks.m?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/blocks.m (original)
> +++ cfe/trunk/test/SemaObjC/blocks.m Tue Sep 27 17:38:19 2011
> @@ -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 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));
>
> Modified: cfe/trunk/tools/libclang/CIndex.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=140650&r1=140649&r2=140650&view=diff
> ==============================================================================
> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
> +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Sep 27 17:38:19 2011
> @@ -3199,7 +3199,7 @@
>   if (!D)
>     return createCXString("");
>
> -  PrintingPolicy &Policy = getCursorContext(C).PrintingPolicy;
> +  PrintingPolicy Policy = getCursorContext(C).getPrintingPolicy();
>   if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
>     D = FunTmpl->getTemplatedDecl();
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list