summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/lib/ARCMigrate
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/clang/lib/ARCMigrate')
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/ARCMT.cpp90
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/ARCMTActions.cpp12
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/ObjCMT.cpp105
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/PlistReporter.cpp14
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/TransAPIUses.cpp2
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp2
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/TransUnusedInitDelegate.cpp2
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.cpp8
-rw-r--r--contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.h2
9 files changed, 128 insertions, 109 deletions
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMT.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMT.cpp
index dddc886..e328842 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMT.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMT.cpp
@@ -124,7 +124,7 @@ public:
}
}
- virtual ~CaptureDiagnosticConsumer() {
+ ~CaptureDiagnosticConsumer() override {
assert(!HasBegunSourceFile && "FinishCapture not called!");
}
@@ -166,7 +166,8 @@ static bool HasARCRuntime(CompilerInvocation &origCI) {
}
static CompilerInvocation *
-createInvocationForMigration(CompilerInvocation &origCI) {
+createInvocationForMigration(CompilerInvocation &origCI,
+ const PCHContainerReader &PCHContainerRdr) {
std::unique_ptr<CompilerInvocation> CInvok;
CInvok.reset(new CompilerInvocation(origCI));
PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
@@ -178,9 +179,8 @@ createInvocationForMigration(CompilerInvocation &origCI) {
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
new IgnoringDiagConsumer()));
- std::string OriginalFile =
- ASTReader::getOriginalSourceFile(PPOpts.ImplicitPCHInclude,
- FileMgr, *Diags);
+ std::string OriginalFile = ASTReader::getOriginalSourceFile(
+ PPOpts.ImplicitPCHInclude, FileMgr, PCHContainerRdr, *Diags);
if (!OriginalFile.empty())
PPOpts.Includes.insert(PPOpts.Includes.begin(), OriginalFile);
PPOpts.ImplicitPCHInclude.clear();
@@ -230,11 +230,11 @@ static void emitPremigrationErrors(const CapturedDiagList &arcDiags,
// checkForManualIssues.
//===----------------------------------------------------------------------===//
-bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
- const FrontendInputFile &Input,
- DiagnosticConsumer *DiagClient,
- bool emitPremigrationARCErrors,
- StringRef plistOut) {
+bool arcmt::checkForManualIssues(
+ CompilerInvocation &origCI, const FrontendInputFile &Input,
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ DiagnosticConsumer *DiagClient, bool emitPremigrationARCErrors,
+ StringRef plistOut) {
if (!origCI.getLangOpts()->ObjC1)
return false;
@@ -247,7 +247,8 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
assert(!transforms.empty());
std::unique_ptr<CompilerInvocation> CInvok;
- CInvok.reset(createInvocationForMigration(origCI));
+ CInvok.reset(
+ createInvocationForMigration(origCI, PCHContainerOps->getRawReader()));
CInvok->getFrontendOpts().Inputs.clear();
CInvok->getFrontendOpts().Inputs.push_back(Input);
@@ -263,8 +264,8 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
- std::unique_ptr<ASTUnit> Unit(
- ASTUnit::LoadFromCompilerInvocationAction(CInvok.release(), Diags));
+ std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
+ CInvok.release(), PCHContainerOps, Diags));
if (!Unit) {
errRec.FinishCapture();
return true;
@@ -330,12 +331,11 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
// applyTransformations.
//===----------------------------------------------------------------------===//
-static bool applyTransforms(CompilerInvocation &origCI,
- const FrontendInputFile &Input,
- DiagnosticConsumer *DiagClient,
- StringRef outputDir,
- bool emitPremigrationARCErrors,
- StringRef plistOut) {
+static bool
+applyTransforms(CompilerInvocation &origCI, const FrontendInputFile &Input,
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ DiagnosticConsumer *DiagClient, StringRef outputDir,
+ bool emitPremigrationARCErrors, StringRef plistOut) {
if (!origCI.getLangOpts()->ObjC1)
return false;
@@ -343,15 +343,16 @@ static bool applyTransforms(CompilerInvocation &origCI,
// Make sure checking is successful first.
CompilerInvocation CInvokForCheck(origCI);
- if (arcmt::checkForManualIssues(CInvokForCheck, Input, DiagClient,
- emitPremigrationARCErrors, plistOut))
+ if (arcmt::checkForManualIssues(CInvokForCheck, Input, PCHContainerOps,
+ DiagClient, emitPremigrationARCErrors,
+ plistOut))
return true;
CompilerInvocation CInvok(origCI);
CInvok.getFrontendOpts().Inputs.clear();
CInvok.getFrontendOpts().Inputs.push_back(Input);
-
- MigrationProcess migration(CInvok, DiagClient, outputDir);
+
+ MigrationProcess migration(CInvok, PCHContainerOps, DiagClient, outputDir);
bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
@@ -376,22 +377,22 @@ static bool applyTransforms(CompilerInvocation &origCI,
}
}
-bool arcmt::applyTransformations(CompilerInvocation &origCI,
- const FrontendInputFile &Input,
- DiagnosticConsumer *DiagClient) {
- return applyTransforms(origCI, Input, DiagClient,
+bool arcmt::applyTransformations(
+ CompilerInvocation &origCI, const FrontendInputFile &Input,
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ DiagnosticConsumer *DiagClient) {
+ return applyTransforms(origCI, Input, PCHContainerOps, DiagClient,
StringRef(), false, StringRef());
}
-bool arcmt::migrateWithTemporaryFiles(CompilerInvocation &origCI,
- const FrontendInputFile &Input,
- DiagnosticConsumer *DiagClient,
- StringRef outputDir,
- bool emitPremigrationARCErrors,
- StringRef plistOut) {
+bool arcmt::migrateWithTemporaryFiles(
+ CompilerInvocation &origCI, const FrontendInputFile &Input,
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ DiagnosticConsumer *DiagClient, StringRef outputDir,
+ bool emitPremigrationARCErrors, StringRef plistOut) {
assert(!outputDir.empty() && "Expected output directory path");
- return applyTransforms(origCI, Input, DiagClient,
- outputDir, emitPremigrationARCErrors, plistOut);
+ return applyTransforms(origCI, Input, PCHContainerOps, DiagClient, outputDir,
+ emitPremigrationARCErrors, plistOut);
}
bool arcmt::getFileRemappings(std::vector<std::pair<std::string,std::string> > &
@@ -432,7 +433,7 @@ public:
ARCMTMacroTrackerPPCallbacks(std::vector<SourceLocation> &ARCMTMacroLocs)
: ARCMTMacroLocs(ARCMTMacroLocs) { }
- void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
+ void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
SourceRange Range, const MacroArgs *Args) override {
if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName())
ARCMTMacroLocs.push_back(MacroNameTok.getLocation());
@@ -465,7 +466,7 @@ public:
if (Listener)
Listener->start(ctx);
}
- ~RewritesApplicator() {
+ ~RewritesApplicator() override {
if (Listener)
Listener->finish();
}
@@ -499,10 +500,12 @@ public:
/// \brief Anchor for VTable.
MigrationProcess::RewriteListener::~RewriteListener() { }
-MigrationProcess::MigrationProcess(const CompilerInvocation &CI,
- DiagnosticConsumer *diagClient,
- StringRef outputDir)
- : OrigCI(CI), DiagClient(diagClient), HadARCErrors(false) {
+MigrationProcess::MigrationProcess(
+ const CompilerInvocation &CI,
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ DiagnosticConsumer *diagClient, StringRef outputDir)
+ : OrigCI(CI), PCHContainerOps(PCHContainerOps), DiagClient(diagClient),
+ HadARCErrors(false) {
if (!outputDir.empty()) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
@@ -515,7 +518,8 @@ MigrationProcess::MigrationProcess(const CompilerInvocation &CI,
bool MigrationProcess::applyTransform(TransformFn trans,
RewriteListener *listener) {
std::unique_ptr<CompilerInvocation> CInvok;
- CInvok.reset(createInvocationForMigration(OrigCI));
+ CInvok.reset(
+ createInvocationForMigration(OrigCI, PCHContainerOps->getRawReader()));
CInvok->getDiagnosticOpts().IgnoreWarnings = true;
Remapper.applyMappings(CInvok->getPreprocessorOpts());
@@ -537,7 +541,7 @@ bool MigrationProcess::applyTransform(TransformFn trans,
ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs));
std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
- CInvok.release(), Diags, ASTAction.get()));
+ CInvok.release(), PCHContainerOps, Diags, ASTAction.get()));
if (!Unit) {
errRec.FinishCapture();
return true;
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMTActions.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMTActions.cpp
index 0ed36dd..39a922f 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMTActions.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMTActions.cpp
@@ -16,6 +16,7 @@ using namespace arcmt;
bool CheckAction::BeginInvocation(CompilerInstance &CI) {
if (arcmt::checkForManualIssues(CI.getInvocation(), getCurrentInput(),
+ CI.getPCHContainerOperations(),
CI.getDiagnostics().getClient()))
return false; // errors, stop the action.
@@ -29,6 +30,7 @@ CheckAction::CheckAction(FrontendAction *WrappedAction)
bool ModifyAction::BeginInvocation(CompilerInstance &CI) {
return !arcmt::applyTransformations(CI.getInvocation(), getCurrentInput(),
+ CI.getPCHContainerOperations(),
CI.getDiagnostics().getClient());
}
@@ -36,12 +38,10 @@ ModifyAction::ModifyAction(FrontendAction *WrappedAction)
: WrapperFrontendAction(WrappedAction) {}
bool MigrateAction::BeginInvocation(CompilerInstance &CI) {
- if (arcmt::migrateWithTemporaryFiles(CI.getInvocation(),
- getCurrentInput(),
- CI.getDiagnostics().getClient(),
- MigrateDir,
- EmitPremigrationARCErros,
- PlistOut))
+ if (arcmt::migrateWithTemporaryFiles(
+ CI.getInvocation(), getCurrentInput(), CI.getPCHContainerOperations(),
+ CI.getDiagnostics().getClient(), MigrateDir, EmitPremigrationARCErros,
+ PlistOut))
return false; // errors, stop the action.
// We only want to see diagnostics emitted by migrateWithTemporaryFiles.
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/ObjCMT.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/ObjCMT.cpp
index 52c424c..b61a421 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -48,7 +48,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
};
void migrateDecl(Decl *D);
- void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCContainerDecl *D);
+ void migrateObjCContainerDecl(ASTContext &Ctx, ObjCContainerDecl *D);
void migrateProtocolConformance(ASTContext &Ctx,
const ObjCImplementationDecl *ImpDecl);
void CacheObjCNSIntegerTypedefed(const TypedefDecl *TypedefDcl);
@@ -245,17 +245,16 @@ namespace {
(Msg->getReceiverKind() != ObjCMessageExpr::Instance &&
Msg->getReceiverKind() != ObjCMessageExpr::SuperInstance))
return false;
+ if (const Expr *Receiver = Msg->getInstanceReceiver())
+ if (Receiver->getType()->isObjCBuiltinType())
+ return false;
+
const ObjCMethodDecl *Method = Msg->getMethodDecl();
if (!Method)
return false;
if (!Method->isPropertyAccessor())
return false;
- const ObjCInterfaceDecl *IFace =
- NS.getASTContext().getObjContainingInterface(Method);
- if (!IFace)
- return false;
-
const ObjCPropertyDecl *Prop = Method->findPropertyDecl();
if (!Prop)
return false;
@@ -305,6 +304,10 @@ namespace {
BegLoc = PP.getLocForEndOfToken(BegLoc);
SourceLocation EndLoc = RHS->getLocStart();
EndLoc = EndLoc.getLocWithOffset(-1);
+ const char *colon = PP.getSourceManager().getCharacterData(EndLoc);
+ // Add a space after '=' if there is no space between RHS and '='
+ if (colon && colon[0] == ':')
+ PropertyDotString += " ";
SourceRange Range(BegLoc, EndLoc);
commit.replace(Range, PropertyDotString);
// remove '[' ']'
@@ -352,8 +355,8 @@ public:
bool TraverseObjCMessageExpr(ObjCMessageExpr *E) {
// Do depth first; we want to rewrite the subexpressions first so that if
// we have to move expressions we will move them already rewritten.
- for (Stmt::child_range range = E->children(); range; ++range)
- if (!TraverseStmt(*range))
+ for (Stmt *SubStmt : E->children())
+ if (!TraverseStmt(SubStmt))
return false;
return WalkUpFromObjCMessageExpr(E);
@@ -465,7 +468,7 @@ static void rewriteToObjCProperty(const ObjCMethodDecl *Getter,
ASTContext &Context = NS.getASTContext();
bool LParenAdded = false;
std::string PropertyString = "@property ";
- if (UseNsIosOnlyMacro && Context.Idents.get("NS_NONATOMIC_IOSONLY").hasMacroDefinition()) {
+ if (UseNsIosOnlyMacro && NS.isMacroDefined("NS_NONATOMIC_IOSONLY")) {
PropertyString += "(NS_NONATOMIC_IOSONLY";
LParenAdded = true;
} else if (!Atomic) {
@@ -575,7 +578,7 @@ static bool IsCategoryNameWithDeprecatedSuffix(ObjCContainerDecl *D) {
return false;
}
-void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx,
+void ObjCMigrateASTConsumer::migrateObjCContainerDecl(ASTContext &Ctx,
ObjCContainerDecl *D) {
if (D->isDeprecated() || IsCategoryNameWithDeprecatedSuffix(D))
return;
@@ -616,7 +619,7 @@ ClassImplementsAllMethodsAndProperties(ASTContext &Ctx,
if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
continue;
HasAtleastOneRequiredProperty = true;
- DeclContext::lookup_const_result R = IDecl->lookup(Property->getDeclName());
+ DeclContext::lookup_result R = IDecl->lookup(Property->getDeclName());
if (R.size() == 0) {
// Relax the rule and look into class's implementation for a synthesize
// or dynamic declaration. Class is implementing a property coming from
@@ -647,7 +650,7 @@ ClassImplementsAllMethodsAndProperties(ASTContext &Ctx,
continue;
if (MD->getImplementationControl() == ObjCMethodDecl::Optional)
continue;
- DeclContext::lookup_const_result R = ImpDecl->lookup(MD->getDeclName());
+ DeclContext::lookup_result R = ImpDecl->lookup(MD->getDeclName());
if (R.size() == 0)
return false;
bool match = false;
@@ -768,19 +771,34 @@ static void rewriteToNSMacroDecl(ASTContext &Ctx,
const TypedefDecl *TypedefDcl,
const NSAPI &NS, edit::Commit &commit,
bool IsNSIntegerType) {
- QualType EnumUnderlyingT = EnumDcl->getPromotionType();
- assert(!EnumUnderlyingT.isNull()
+ QualType DesignatedEnumType = EnumDcl->getIntegerType();
+ assert(!DesignatedEnumType.isNull()
&& "rewriteToNSMacroDecl - underlying enum type is null");
PrintingPolicy Policy(Ctx.getPrintingPolicy());
- std::string TypeString = EnumUnderlyingT.getAsString(Policy);
+ std::string TypeString = DesignatedEnumType.getAsString(Policy);
std::string ClassString = IsNSIntegerType ? "NS_ENUM(" : "NS_OPTIONS(";
ClassString += TypeString;
ClassString += ", ";
ClassString += TypedefDcl->getIdentifier()->getName();
ClassString += ')';
- SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart());
+ SourceLocation EndLoc;
+ if (EnumDcl->getIntegerTypeSourceInfo()) {
+ TypeSourceInfo *TSourceInfo = EnumDcl->getIntegerTypeSourceInfo();
+ TypeLoc TLoc = TSourceInfo->getTypeLoc();
+ EndLoc = TLoc.getLocEnd();
+ const char *lbrace = Ctx.getSourceManager().getCharacterData(EndLoc);
+ unsigned count = 0;
+ if (lbrace)
+ while (lbrace[count] != '{')
+ ++count;
+ if (count > 0)
+ EndLoc = EndLoc.getLocWithOffset(count-1);
+ }
+ else
+ EndLoc = EnumDcl->getLocStart();
+ SourceRange R(EnumDcl->getLocStart(), EndLoc);
commit.replace(R, ClassString);
// This is to remove spaces between '}' and typedef name.
SourceLocation StartTypedefLoc = EnumDcl->getLocEnd();
@@ -902,7 +920,7 @@ bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
const EnumDecl *EnumDcl,
const TypedefDecl *TypedefDcl) {
if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() ||
- EnumDcl->isDeprecated() || EnumDcl->getIntegerTypeSourceInfo())
+ EnumDcl->isDeprecated())
return false;
if (!TypedefDcl) {
if (NSIntegerTypedefed) {
@@ -1259,7 +1277,7 @@ void ObjCMigrateASTConsumer::migrateNsReturnsInnerPointer(ASTContext &Ctx,
QualType RT = OM->getReturnType();
if (!TypeIsInnerPointer(RT) ||
- !Ctx.Idents.get("NS_RETURNS_INNER_POINTER").hasMacroDefinition())
+ !NSAPIObj->isMacroDefined("NS_RETURNS_INNER_POINTER"))
return;
edit::Commit commit(*Editor);
@@ -1270,9 +1288,9 @@ void ObjCMigrateASTConsumer::migrateNsReturnsInnerPointer(ASTContext &Ctx,
void ObjCMigrateASTConsumer::migratePropertyNsReturnsInnerPointer(ASTContext &Ctx,
ObjCPropertyDecl *P) {
QualType T = P->getType();
-
+
if (!TypeIsInnerPointer(T) ||
- !Ctx.Idents.get("NS_RETURNS_INNER_POINTER").hasMacroDefinition())
+ !NSAPIObj->isMacroDefined("NS_RETURNS_INNER_POINTER"))
return;
edit::Commit commit(*Editor);
commit.insertBefore(P->getLocEnd(), " NS_RETURNS_INNER_POINTER ");
@@ -1390,7 +1408,7 @@ static bool AuditedType (QualType AT) {
void ObjCMigrateASTConsumer::AnnotateImplicitBridging(ASTContext &Ctx) {
if (CFFunctionIBCandidates.empty())
return;
- if (!Ctx.Idents.get("CF_IMPLICIT_BRIDGING_ENABLED").hasMacroDefinition()) {
+ if (!NSAPIObj->isMacroDefined("CF_IMPLICIT_BRIDGING_ENABLED")) {
CFFunctionIBCandidates.clear();
FileId = FileID();
return;
@@ -1465,16 +1483,14 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
RetEffect Ret = CE.getReturnValue();
const char *AnnotationString = nullptr;
if (Ret.getObjKind() == RetEffect::CF) {
- if (Ret.isOwned() &&
- Ctx.Idents.get("CF_RETURNS_RETAINED").hasMacroDefinition())
+ if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))
AnnotationString = " CF_RETURNS_RETAINED";
else if (Ret.notOwned() &&
- Ctx.Idents.get("CF_RETURNS_NOT_RETAINED").hasMacroDefinition())
+ NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))
AnnotationString = " CF_RETURNS_NOT_RETAINED";
}
else if (Ret.getObjKind() == RetEffect::ObjC) {
- if (Ret.isOwned() &&
- Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition())
+ if (Ret.isOwned() && NSAPIObj->isMacroDefined("NS_RETURNS_RETAINED"))
AnnotationString = " NS_RETURNS_RETAINED";
}
@@ -1491,13 +1507,13 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
const ParmVarDecl *pd = *pi;
ArgEffect AE = AEArgs[i];
if (AE == DecRef && !pd->hasAttr<CFConsumedAttr>() &&
- Ctx.Idents.get("CF_CONSUMED").hasMacroDefinition()) {
+ NSAPIObj->isMacroDefined("CF_CONSUMED")) {
edit::Commit commit(*Editor);
commit.insertBefore(pd->getLocation(), "CF_CONSUMED ");
Editor->commit(commit);
}
else if (AE == DecRefMsg && !pd->hasAttr<NSConsumedAttr>() &&
- Ctx.Idents.get("NS_CONSUMED").hasMacroDefinition()) {
+ NSAPIObj->isMacroDefined("NS_CONSUMED")) {
edit::Commit commit(*Editor);
commit.insertBefore(pd->getLocation(), "NS_CONSUMED ");
Editor->commit(commit);
@@ -1582,11 +1598,10 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
RetEffect Ret = CE.getReturnValue();
const char *AnnotationString = nullptr;
if (Ret.getObjKind() == RetEffect::CF) {
- if (Ret.isOwned() &&
- Ctx.Idents.get("CF_RETURNS_RETAINED").hasMacroDefinition())
+ if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))
AnnotationString = " CF_RETURNS_RETAINED";
else if (Ret.notOwned() &&
- Ctx.Idents.get("CF_RETURNS_NOT_RETAINED").hasMacroDefinition())
+ NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))
AnnotationString = " CF_RETURNS_NOT_RETAINED";
}
else if (Ret.getObjKind() == RetEffect::ObjC) {
@@ -1600,8 +1615,7 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
break;
default:
- if (Ret.isOwned() &&
- Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition())
+ if (Ret.isOwned() && NSAPIObj->isMacroDefined("NS_RETURNS_RETAINED"))
AnnotationString = " NS_RETURNS_RETAINED";
break;
}
@@ -1620,7 +1634,7 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
const ParmVarDecl *pd = *pi;
ArgEffect AE = AEArgs[i];
if (AE == DecRef && !pd->hasAttr<CFConsumedAttr>() &&
- Ctx.Idents.get("CF_CONSUMED").hasMacroDefinition()) {
+ NSAPIObj->isMacroDefined("CF_CONSUMED")) {
edit::Commit commit(*Editor);
commit.insertBefore(pd->getLocation(), "CF_CONSUMED ");
Editor->commit(commit);
@@ -1640,12 +1654,12 @@ void ObjCMigrateASTConsumer::migrateAddMethodAnnotation(
MethodDecl->hasAttr<NSReturnsRetainedAttr>() ||
MethodDecl->hasAttr<NSReturnsNotRetainedAttr>() ||
MethodDecl->hasAttr<NSReturnsAutoreleasedAttr>());
-
- if (CE.getReceiver() == DecRefMsg &&
+
+ if (CE.getReceiver() == DecRefMsg &&
!MethodDecl->hasAttr<NSConsumesSelfAttr>() &&
MethodDecl->getMethodFamily() != OMF_init &&
MethodDecl->getMethodFamily() != OMF_release &&
- Ctx.Idents.get("NS_CONSUMES_SELF").hasMacroDefinition()) {
+ NSAPIObj->isMacroDefined("NS_CONSUMES_SELF")) {
edit::Commit commit(*Editor);
commit.insertBefore(MethodDecl->getLocEnd(), " NS_CONSUMES_SELF");
Editor->commit(commit);
@@ -1711,7 +1725,7 @@ void ObjCMigrateASTConsumer::inferDesignatedInitializers(
const ObjCInterfaceDecl *IFace = ImplD->getClassInterface();
if (!IFace || IFace->hasDesignatedInitializers())
return;
- if (!Ctx.Idents.get("NS_DESIGNATED_INITIALIZER").hasMacroDefinition())
+ if (!NSAPIObj->isMacroDefined("NS_DESIGNATED_INITIALIZER"))
return;
for (const auto *MD : ImplD->instance_methods()) {
@@ -1772,9 +1786,7 @@ public:
: SourceMgr(SM), OS(OS) {
OS << "[\n";
}
- ~JSONEditWriter() {
- OS << "]\n";
- }
+ ~JSONEditWriter() override { OS << "]\n"; }
private:
struct EntryWriter {
@@ -1858,13 +1870,16 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
if (canModify(CDecl))
- migrateObjCInterfaceDecl(Ctx, CDecl);
+ migrateObjCContainerDecl(Ctx, CDecl);
if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) {
if (canModify(CatDecl))
- migrateObjCInterfaceDecl(Ctx, CatDecl);
+ migrateObjCContainerDecl(Ctx, CatDecl);
}
- else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D))
+ else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D)) {
ObjCProtocolDecls.insert(PDecl->getCanonicalDecl());
+ if (canModify(PDecl))
+ migrateObjCContainerDecl(Ctx, PDecl);
+ }
else if (const ObjCImplementationDecl *ImpDecl =
dyn_cast<ObjCImplementationDecl>(*D)) {
if ((ASTMigrateActions & FrontendOptions::ObjCMT_ProtocolConformance) &&
@@ -2268,7 +2283,7 @@ bool arcmt::getFileRemappingsFromFileList(
continue;
}
- remap.push_back(std::make_pair(I->first->getName(), TempFile));
+ remap.emplace_back(I->first->getName(), TempFile);
}
return hasErrorOccurred;
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/PlistReporter.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/PlistReporter.cpp
index 53398b2..9a51690 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/PlistReporter.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/PlistReporter.cpp
@@ -100,16 +100,18 @@ void arcmt::writeARCDiagsToPlist(const std::string &outPath,
// Output the location of the bug.
o << " <key>location</key>\n";
- EmitLocation(o, SM, LangOpts, D.getLocation(), FM, 2);
+ EmitLocation(o, SM, D.getLocation(), FM, 2);
// Output the ranges (if any).
- StoredDiagnostic::range_iterator RI = D.range_begin(), RE = D.range_end();
-
- if (RI != RE) {
+ if (!D.getRanges().empty()) {
o << " <key>ranges</key>\n";
o << " <array>\n";
- for (; RI != RE; ++RI)
- EmitRange(o, SM, LangOpts, *RI, FM, 4);
+ for (auto &R : D.getRanges()) {
+ CharSourceRange ExpansionRange(SM.getExpansionRange(R.getAsRange()),
+ R.isTokenRange());
+ EmitRange(o, SM, Lexer::getAsCharRange(ExpansionRange, SM, LangOpts),
+ FM, 4);
+ }
o << " </array>\n";
}
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/TransAPIUses.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/TransAPIUses.cpp
index 544cb0a..40c8a07 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/TransAPIUses.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/TransAPIUses.cpp
@@ -95,7 +95,7 @@ public:
Pass.TA.clearDiagnostic(diag::err_unavailable,
diag::err_unavailable_message,
E->getSelectorLoc(0));
- Pass.TA.replace(E->getSourceRange(), getNilString(Pass.Ctx));
+ Pass.TA.replace(E->getSourceRange(), getNilString(Pass));
}
return true;
}
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
index bcbc9e9..7db1a1c 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
@@ -145,7 +145,7 @@ public:
// when an exception is thrown.
Pass.TA.replace(RecContainer->getSourceRange(), RecRange);
std::string str = " = ";
- str += getNilString(Pass.Ctx);
+ str += getNilString(Pass);
Pass.TA.insertAfterToken(RecRange.getEnd(), str);
return true;
}
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/TransUnusedInitDelegate.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/TransUnusedInitDelegate.cpp
index 98571c0..70370ec 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/TransUnusedInitDelegate.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/TransUnusedInitDelegate.cpp
@@ -58,7 +58,7 @@ public:
SourceRange ExprRange = ME->getSourceRange();
Pass.TA.insert(ExprRange.getBegin(), "if (!(self = ");
std::string retStr = ")) return ";
- retStr += getNilString(Pass.Ctx);
+ retStr += getNilString(Pass);
Pass.TA.insertAfterToken(ExprRange.getEnd(), retStr);
}
return true;
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.cpp
index 6ff7b6b..56d3af7 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.cpp
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.cpp
@@ -16,6 +16,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "llvm/ADT/DenseSet.h"
@@ -212,11 +213,8 @@ bool trans::isGlobalVar(Expr *E) {
return false;
}
-StringRef trans::getNilString(ASTContext &Ctx) {
- if (Ctx.Idents.get("nil").hasMacroDefinition())
- return "nil";
- else
- return "0";
+StringRef trans::getNilString(MigrationPass &Pass) {
+ return Pass.SemaRef.PP.isMacroDefined("nil") ? "nil" : "0";
}
namespace {
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.h b/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.h
index 12551d2..7e3dd34 100644
--- a/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.h
+++ b/contrib/llvm/tools/clang/lib/ARCMigrate/Transforms.h
@@ -180,7 +180,7 @@ SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx,
bool hasSideEffects(Expr *E, ASTContext &Ctx);
bool isGlobalVar(Expr *E);
/// \brief Returns "nil" or "0" if 'nil' macro is not actually defined.
-StringRef getNilString(ASTContext &Ctx);
+StringRef getNilString(MigrationPass &Pass);
template <typename BODY_TRANS>
class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {
OpenPOWER on IntegriCloud