diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/ARCMigrate')
8 files changed, 76 insertions, 61 deletions
diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMT.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/ARCMT.cpp index dddc886..f266eaf 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!"); } @@ -432,7 +432,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 +465,7 @@ public: if (Listener) Listener->start(ctx); } - ~RewritesApplicator() { + ~RewritesApplicator() override { if (Listener) Listener->finish(); } diff --git a/contrib/llvm/tools/clang/lib/ARCMigrate/ObjCMT.cpp b/contrib/llvm/tools/clang/lib/ARCMigrate/ObjCMT.cpp index 52c424c..8c2e0f4 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 '[' ']' @@ -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> > { |