From de557f84dd46edf201b4bcbaf1dc988521304762 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 9 Oct 2013 17:37:28 +0000 Subject: [PATCH] ObjectiveC migrator. Introduce a new print policy for suppression of strong lifetime qualifiers when inferring property. // rdar://15082812 llvm-svn: 192305 --- clang/include/clang/AST/PrettyPrinter.h | 8 ++++++-- clang/lib/ARCMigrate/ObjCMT.cpp | 1 + clang/lib/AST/TypePrinter.cpp | 3 ++- clang/test/ARCMT/objcmt-property.m.result | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index adfd1ac..7642699 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -39,8 +39,8 @@ struct PrintingPolicy { SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false), SuppressUnwrittenScope(false), SuppressInitializers(false), ConstantArraySizeAsWritten(false), AnonymousTagLocations(true), - SuppressStrongLifetime(false), Bool(LO.Bool), - TerseOutput(false), PolishForDeclaration(false), + SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false), + Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false), MSWChar(LO.MicrosoftExt && !LO.WChar) { } /// \brief What language we're printing. @@ -132,6 +132,10 @@ struct PrintingPolicy { /// ARC. unsigned SuppressStrongLifetime : 1; + /// \brief When true, suppress printing of lifetime qualifier in + /// ARC. + unsigned SuppressLifetimeQualifiers : 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; diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 8d5395a..f1ab4fc 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -324,6 +324,7 @@ static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter, PropertyString += " "; PrintingPolicy SubPolicy(Context.getPrintingPolicy()); SubPolicy.SuppressStrongLifetime = true; + SubPolicy.SuppressLifetimeQualifiers = true; std::string TypeString = RT.getAsString(SubPolicy); if (LengthOfPrefix > 0) { // property name must strip off "is" and lower case the first character diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index ec7559c..571e3db 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -36,7 +36,8 @@ namespace { public: explicit IncludeStrongLifetimeRAII(PrintingPolicy &Policy) : Policy(Policy), Old(Policy.SuppressStrongLifetime) { - Policy.SuppressStrongLifetime = false; + if (!Policy.SuppressLifetimeQualifiers) + Policy.SuppressStrongLifetime = false; } ~IncludeStrongLifetimeRAII() { diff --git a/clang/test/ARCMT/objcmt-property.m.result b/clang/test/ARCMT/objcmt-property.m.result index 29559bf..bd9b38b 100644 --- a/clang/test/ARCMT/objcmt-property.m.result +++ b/clang/test/ARCMT/objcmt-property.m.result @@ -223,7 +223,7 @@ DEPRECATED @property (nonatomic, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *); @property (nonatomic, copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *); -@property (nonatomic, readonly) id (*expressionFuncptr)(__strong id, NSArray *__strong, NSMutableDictionary *__strong); -@property (nonatomic) id (*MyFuncptr)(__strong id, NSArray *__strong, NSMutableDictionary *__strong); +@property (nonatomic, readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *); +@property (nonatomic) id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *); @end -- 2.7.4