clang  15.0.0git
ObjCMT.cpp
Go to the documentation of this file.
1 //===--- ObjCMT.cpp - ObjC Migrate Tool -----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Transforms.h"
11 #include "clang/ARCMigrate/ARCMT.h"
13 #include "clang/AST/ASTConsumer.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/NSAPI.h"
17 #include "clang/AST/ParentMap.h"
21 #include "clang/Edit/Commit.h"
24 #include "clang/Edit/Rewriters.h"
28 #include "clang/Lex/Preprocessor.h"
30 #include "llvm/ADT/SmallString.h"
31 #include "llvm/ADT/StringSet.h"
32 #include "llvm/Support/Path.h"
33 #include "llvm/Support/SourceMgr.h"
34 #include "llvm/Support/YAMLParser.h"
35 
36 using namespace clang;
37 using namespace arcmt;
38 using namespace ento;
39 
40 namespace {
41 
42 class ObjCMigrateASTConsumer : public ASTConsumer {
43  enum CF_BRIDGING_KIND {
44  CF_BRIDGING_NONE,
45  CF_BRIDGING_ENABLE,
46  CF_BRIDGING_MAY_INCLUDE
47  };
48 
49  void migrateDecl(Decl *D);
50  void migrateObjCContainerDecl(ASTContext &Ctx, ObjCContainerDecl *D);
51  void migrateProtocolConformance(ASTContext &Ctx,
52  const ObjCImplementationDecl *ImpDecl);
53  void CacheObjCNSIntegerTypedefed(const TypedefDecl *TypedefDcl);
54  bool migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl,
55  const TypedefDecl *TypedefDcl);
56  void migrateAllMethodInstaceType(ASTContext &Ctx, ObjCContainerDecl *CDecl);
57  void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl,
58  ObjCMethodDecl *OM);
59  bool migrateProperty(ASTContext &Ctx, ObjCContainerDecl *D, ObjCMethodDecl *OM);
60  void migrateNsReturnsInnerPointer(ASTContext &Ctx, ObjCMethodDecl *OM);
61  void migratePropertyNsReturnsInnerPointer(ASTContext &Ctx, ObjCPropertyDecl *P);
62  void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl,
63  ObjCMethodDecl *OM,
64  ObjCInstanceTypeFamily OIT_Family = OIT_None);
65 
66  void migrateCFAnnotation(ASTContext &Ctx, const Decl *Decl);
67  void AddCFAnnotations(ASTContext &Ctx,
68  const RetainSummary *RS,
69  const FunctionDecl *FuncDecl, bool ResultAnnotated);
70  void AddCFAnnotations(ASTContext &Ctx,
71  const RetainSummary *RS,
72  const ObjCMethodDecl *MethodDecl, bool ResultAnnotated);
73 
74  void AnnotateImplicitBridging(ASTContext &Ctx);
75 
76  CF_BRIDGING_KIND migrateAddFunctionAnnotation(ASTContext &Ctx,
77  const FunctionDecl *FuncDecl);
78 
79  void migrateARCSafeAnnotation(ASTContext &Ctx, ObjCContainerDecl *CDecl);
80 
81  void migrateAddMethodAnnotation(ASTContext &Ctx,
82  const ObjCMethodDecl *MethodDecl);
83 
84  void inferDesignatedInitializers(ASTContext &Ctx,
85  const ObjCImplementationDecl *ImplD);
86 
87  bool InsertFoundation(ASTContext &Ctx, SourceLocation Loc);
88 
89  std::unique_ptr<RetainSummaryManager> Summaries;
90 
91 public:
92  std::string MigrateDir;
93  unsigned ASTMigrateActions;
94  FileID FileId;
95  const TypedefDecl *NSIntegerTypedefed;
96  const TypedefDecl *NSUIntegerTypedefed;
97  std::unique_ptr<NSAPI> NSAPIObj;
98  std::unique_ptr<edit::EditedSource> Editor;
99  FileRemapper &Remapper;
100  FileManager &FileMgr;
101  const PPConditionalDirectiveRecord *PPRec;
102  Preprocessor &PP;
103  bool IsOutputFile;
104  bool FoundationIncluded;
106  llvm::SmallVector<const Decl *, 8> CFFunctionIBCandidates;
107  llvm::StringSet<> AllowListFilenames;
108 
109  RetainSummaryManager &getSummaryManager(ASTContext &Ctx) {
110  if (!Summaries)
111  Summaries.reset(new RetainSummaryManager(Ctx,
112  /*TrackNSCFObjects=*/true,
113  /*trackOSObjects=*/false));
114  return *Summaries;
115  }
116 
117  ObjCMigrateASTConsumer(StringRef migrateDir, unsigned astMigrateActions,
118  FileRemapper &remapper, FileManager &fileMgr,
119  const PPConditionalDirectiveRecord *PPRec,
120  Preprocessor &PP, bool isOutputFile,
121  ArrayRef<std::string> AllowList)
122  : MigrateDir(migrateDir), ASTMigrateActions(astMigrateActions),
123  NSIntegerTypedefed(nullptr), NSUIntegerTypedefed(nullptr),
124  Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
125  IsOutputFile(isOutputFile), FoundationIncluded(false) {
126  // FIXME: StringSet should have insert(iter, iter) to use here.
127  for (const std::string &Val : AllowList)
128  AllowListFilenames.insert(Val);
129  }
130 
131 protected:
132  void Initialize(ASTContext &Context) override {
133  NSAPIObj.reset(new NSAPI(Context));
134  Editor.reset(new edit::EditedSource(Context.getSourceManager(),
135  Context.getLangOpts(),
136  PPRec));
137  }
138 
139  bool HandleTopLevelDecl(DeclGroupRef DG) override {
140  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
141  migrateDecl(*I);
142  return true;
143  }
144  void HandleInterestingDecl(DeclGroupRef DG) override {
145  // Ignore decls from the PCH.
146  }
147  void HandleTopLevelDeclInObjCContainer(DeclGroupRef DG) override {
148  ObjCMigrateASTConsumer::HandleTopLevelDecl(DG);
149  }
150 
151  void HandleTranslationUnit(ASTContext &Ctx) override;
152 
153  bool canModifyFile(StringRef Path) {
154  if (AllowListFilenames.empty())
155  return true;
156  return AllowListFilenames.find(llvm::sys::path::filename(Path)) !=
157  AllowListFilenames.end();
158  }
159  bool canModifyFile(Optional<FileEntryRef> FE) {
160  if (!FE)
161  return false;
162  return canModifyFile(FE->getName());
163  }
164  bool canModifyFile(FileID FID) {
165  if (FID.isInvalid())
166  return false;
167  return canModifyFile(PP.getSourceManager().getFileEntryRefForID(FID));
168  }
169 
170  bool canModify(const Decl *D) {
171  if (!D)
172  return false;
173  if (const ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(D))
174  return canModify(CatImpl->getCategoryDecl());
175  if (const ObjCImplementationDecl *Impl = dyn_cast<ObjCImplementationDecl>(D))
176  return canModify(Impl->getClassInterface());
177  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
178  return canModify(cast<Decl>(MD->getDeclContext()));
179 
180  FileID FID = PP.getSourceManager().getFileID(D->getLocation());
181  return canModifyFile(FID);
182  }
183 };
184 
185 } // end anonymous namespace
186 
188  std::unique_ptr<FrontendAction> WrappedAction, StringRef migrateDir,
189  unsigned migrateAction)
190  : WrapperFrontendAction(std::move(WrappedAction)), MigrateDir(migrateDir),
191  ObjCMigAction(migrateAction), CompInst(nullptr) {
192  if (MigrateDir.empty())
193  MigrateDir = "."; // user current directory if none is given.
194 }
195 
196 std::unique_ptr<ASTConsumer>
199  PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager());
200  CI.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(PPRec));
201  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
202  Consumers.push_back(WrapperFrontendAction::CreateASTConsumer(CI, InFile));
203  Consumers.push_back(std::make_unique<ObjCMigrateASTConsumer>(
204  MigrateDir, ObjCMigAction, Remapper, CompInst->getFileManager(), PPRec,
205  CompInst->getPreprocessor(), false, None));
206  return std::make_unique<MultiplexConsumer>(std::move(Consumers));
207 }
208 
210  Remapper.initFromDisk(MigrateDir, CI.getDiagnostics(),
211  /*ignoreIfFilesChanged=*/true);
212  CompInst = &CI;
214  return true;
215 }
216 
217 namespace {
218  // FIXME. This duplicates one in RewriteObjCFoundationAPI.cpp
220  const Expr* Expr = FullExpr->IgnoreImpCasts();
221  return !(isa<ArraySubscriptExpr>(Expr) || isa<CallExpr>(Expr) ||
222  isa<DeclRefExpr>(Expr) || isa<CXXNamedCastExpr>(Expr) ||
223  isa<CXXConstructExpr>(Expr) || isa<CXXThisExpr>(Expr) ||
224  isa<CXXTypeidExpr>(Expr) ||
225  isa<CXXUnresolvedConstructExpr>(Expr) ||
226  isa<ObjCMessageExpr>(Expr) || isa<ObjCPropertyRefExpr>(Expr) ||
227  isa<ObjCProtocolExpr>(Expr) || isa<MemberExpr>(Expr) ||
228  isa<ObjCIvarRefExpr>(Expr) || isa<ParenExpr>(FullExpr) ||
229  isa<ParenListExpr>(Expr) || isa<SizeOfPackExpr>(Expr));
230  }
231 
232  /// - Rewrite message expression for Objective-C setter and getters into
233  /// property-dot syntax.
234  bool rewriteToPropertyDotSyntax(const ObjCMessageExpr *Msg,
235  Preprocessor &PP,
236  const NSAPI &NS, edit::Commit &commit,
237  const ParentMap *PMap) {
238  if (!Msg || Msg->isImplicit() ||
241  return false;
242  if (const Expr *Receiver = Msg->getInstanceReceiver())
243  if (Receiver->getType()->isObjCBuiltinType())
244  return false;
245 
246  const ObjCMethodDecl *Method = Msg->getMethodDecl();
247  if (!Method)
248  return false;
249  if (!Method->isPropertyAccessor())
250  return false;
251 
252  const ObjCPropertyDecl *Prop = Method->findPropertyDecl();
253  if (!Prop)
254  return false;
255 
256  SourceRange MsgRange = Msg->getSourceRange();
257  bool ReceiverIsSuper =
259  // for 'super' receiver is nullptr.
260  const Expr *receiver = Msg->getInstanceReceiver();
261  bool NeedsParen =
262  ReceiverIsSuper ? false : subscriptOperatorNeedsParens(receiver);
263  bool IsGetter = (Msg->getNumArgs() == 0);
264  if (IsGetter) {
265  // Find space location range between receiver expression and getter method.
266  SourceLocation BegLoc =
267  ReceiverIsSuper ? Msg->getSuperLoc() : receiver->getEndLoc();
268  BegLoc = PP.getLocForEndOfToken(BegLoc);
269  SourceLocation EndLoc = Msg->getSelectorLoc(0);
270  SourceRange SpaceRange(BegLoc, EndLoc);
271  std::string PropertyDotString;
272  // rewrite getter method expression into: receiver.property or
273  // (receiver).property
274  if (NeedsParen) {
275  commit.insertBefore(receiver->getBeginLoc(), "(");
276  PropertyDotString = ").";
277  }
278  else
279  PropertyDotString = ".";
280  PropertyDotString += Prop->getName();
281  commit.replace(SpaceRange, PropertyDotString);
282 
283  // remove '[' ']'
284  commit.replace(SourceRange(MsgRange.getBegin(), MsgRange.getBegin()), "");
285  commit.replace(SourceRange(MsgRange.getEnd(), MsgRange.getEnd()), "");
286  } else {
287  if (NeedsParen)
288  commit.insertWrap("(", receiver->getSourceRange(), ")");
289  std::string PropertyDotString = ".";
290  PropertyDotString += Prop->getName();
291  PropertyDotString += " =";
292  const Expr*const* Args = Msg->getArgs();
293  const Expr *RHS = Args[0];
294  if (!RHS)
295  return false;
296  SourceLocation BegLoc =
297  ReceiverIsSuper ? Msg->getSuperLoc() : receiver->getEndLoc();
298  BegLoc = PP.getLocForEndOfToken(BegLoc);
299  SourceLocation EndLoc = RHS->getBeginLoc();
300  EndLoc = EndLoc.getLocWithOffset(-1);
301  const char *colon = PP.getSourceManager().getCharacterData(EndLoc);
302  // Add a space after '=' if there is no space between RHS and '='
303  if (colon && colon[0] == ':')
304  PropertyDotString += " ";
305  SourceRange Range(BegLoc, EndLoc);
306  commit.replace(Range, PropertyDotString);
307  // remove '[' ']'
308  commit.replace(SourceRange(MsgRange.getBegin(), MsgRange.getBegin()), "");
309  commit.replace(SourceRange(MsgRange.getEnd(), MsgRange.getEnd()), "");
310  }
311  return true;
312  }
313 
314 class ObjCMigrator : public RecursiveASTVisitor<ObjCMigrator> {
315  ObjCMigrateASTConsumer &Consumer;
316  ParentMap &PMap;
317 
318 public:
319  ObjCMigrator(ObjCMigrateASTConsumer &consumer, ParentMap &PMap)
320  : Consumer(consumer), PMap(PMap) { }
321 
322  bool shouldVisitTemplateInstantiations() const { return false; }
323  bool shouldWalkTypesOfTypeLocs() const { return false; }
324 
325  bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
326  if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Literals) {
327  edit::Commit commit(*Consumer.Editor);
328  edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap);
329  Consumer.Editor->commit(commit);
330  }
331 
332  if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Subscripting) {
333  edit::Commit commit(*Consumer.Editor);
334  edit::rewriteToObjCSubscriptSyntax(E, *Consumer.NSAPIObj, commit);
335  Consumer.Editor->commit(commit);
336  }
337 
338  if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_PropertyDotSyntax) {
339  edit::Commit commit(*Consumer.Editor);
340  rewriteToPropertyDotSyntax(E, Consumer.PP, *Consumer.NSAPIObj,
341  commit, &PMap);
342  Consumer.Editor->commit(commit);
343  }
344 
345  return true;
346  }
347 
348  bool TraverseObjCMessageExpr(ObjCMessageExpr *E) {
349  // Do depth first; we want to rewrite the subexpressions first so that if
350  // we have to move expressions we will move them already rewritten.
351  for (Stmt *SubStmt : E->children())
352  if (!TraverseStmt(SubStmt))
353  return false;
354 
355  return WalkUpFromObjCMessageExpr(E);
356  }
357 };
358 
359 class BodyMigrator : public RecursiveASTVisitor<BodyMigrator> {
360  ObjCMigrateASTConsumer &Consumer;
361  std::unique_ptr<ParentMap> PMap;
362 
363 public:
364  BodyMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) { }
365 
366  bool shouldVisitTemplateInstantiations() const { return false; }
367  bool shouldWalkTypesOfTypeLocs() const { return false; }
368 
369  bool TraverseStmt(Stmt *S) {
370  PMap.reset(new ParentMap(S));
371  ObjCMigrator(Consumer, *PMap).TraverseStmt(S);
372  return true;
373  }
374 };
375 } // end anonymous namespace
376 
377 void ObjCMigrateASTConsumer::migrateDecl(Decl *D) {
378  if (!D)
379  return;
380  if (isa<ObjCMethodDecl>(D))
381  return; // Wait for the ObjC container declaration.
382 
383  BodyMigrator(*this).TraverseDecl(D);
384 }
385 
386 static void append_attr(std::string &PropertyString, const char *attr,
387  bool &LParenAdded) {
388  if (!LParenAdded) {
389  PropertyString += "(";
390  LParenAdded = true;
391  }
392  else
393  PropertyString += ", ";
394  PropertyString += attr;
395 }
396 
397 static
399  const std::string& TypeString,
400  const char *name) {
401  const char *argPtr = TypeString.c_str();
402  int paren = 0;
403  while (*argPtr) {
404  switch (*argPtr) {
405  case '(':
406  PropertyString += *argPtr;
407  paren++;
408  break;
409  case ')':
410  PropertyString += *argPtr;
411  paren--;
412  break;
413  case '^':
414  case '*':
415  PropertyString += (*argPtr);
416  if (paren == 1) {
417  PropertyString += name;
418  name = "";
419  }
420  break;
421  default:
422  PropertyString += *argPtr;
423  break;
424  }
425  argPtr++;
426  }
427 }
428 
429 static const char *PropertyMemoryAttribute(ASTContext &Context, QualType ArgType) {
430  Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
431  bool RetainableObject = ArgType->isObjCRetainableType();
432  if (RetainableObject &&
433  (propertyLifetime == Qualifiers::OCL_Strong
434  || propertyLifetime == Qualifiers::OCL_None)) {
435  if (const ObjCObjectPointerType *ObjPtrTy =
436  ArgType->getAs<ObjCObjectPointerType>()) {
437  ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
438  if (IDecl &&
439  IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
440  return "copy";
441  else
442  return "strong";
443  }
444  else if (ArgType->isBlockPointerType())
445  return "copy";
446  } else if (propertyLifetime == Qualifiers::OCL_Weak)
447  // TODO. More precise determination of 'weak' attribute requires
448  // looking into setter's implementation for backing weak ivar.
449  return "weak";
450  else if (RetainableObject)
451  return ArgType->isBlockPointerType() ? "copy" : "strong";
452  return nullptr;
453 }
454 
455 static void rewriteToObjCProperty(const ObjCMethodDecl *Getter,
456  const ObjCMethodDecl *Setter,
457  const NSAPI &NS, edit::Commit &commit,
458  unsigned LengthOfPrefix,
459  bool Atomic, bool UseNsIosOnlyMacro,
460  bool AvailabilityArgsMatch) {
461  ASTContext &Context = NS.getASTContext();
462  bool LParenAdded = false;
463  std::string PropertyString = "@property ";
464  if (UseNsIosOnlyMacro && NS.isMacroDefined("NS_NONATOMIC_IOSONLY")) {
465  PropertyString += "(NS_NONATOMIC_IOSONLY";
466  LParenAdded = true;
467  } else if (!Atomic) {
468  PropertyString += "(nonatomic";
469  LParenAdded = true;
470  }
471 
472  std::string PropertyNameString = Getter->getNameAsString();
473  StringRef PropertyName(PropertyNameString);
474  if (LengthOfPrefix > 0) {
475  if (!LParenAdded) {
476  PropertyString += "(getter=";
477  LParenAdded = true;
478  }
479  else
480  PropertyString += ", getter=";
481  PropertyString += PropertyNameString;
482  }
483  // Property with no setter may be suggested as a 'readonly' property.
484  if (!Setter)
485  append_attr(PropertyString, "readonly", LParenAdded);
486 
487 
488  // Short circuit 'delegate' properties that contain the name "delegate" or
489  // "dataSource", or have exact name "target" to have 'assign' attribute.
490  if (PropertyName.equals("target") || PropertyName.contains("delegate") ||
491  PropertyName.contains("dataSource")) {
492  QualType QT = Getter->getReturnType();
493  if (!QT->isRealType())
494  append_attr(PropertyString, "assign", LParenAdded);
495  } else if (!Setter) {
496  QualType ResType = Context.getCanonicalType(Getter->getReturnType());
497  if (const char *MemoryManagementAttr = PropertyMemoryAttribute(Context, ResType))
498  append_attr(PropertyString, MemoryManagementAttr, LParenAdded);
499  } else {
500  const ParmVarDecl *argDecl = *Setter->param_begin();
501  QualType ArgType = Context.getCanonicalType(argDecl->getType());
502  if (const char *MemoryManagementAttr = PropertyMemoryAttribute(Context, ArgType))
503  append_attr(PropertyString, MemoryManagementAttr, LParenAdded);
504  }
505  if (LParenAdded)
506  PropertyString += ')';
507  QualType RT = Getter->getReturnType();
508  if (!isa<TypedefType>(RT)) {
509  // strip off any ARC lifetime qualifier.
510  QualType CanResultTy = Context.getCanonicalType(RT);
511  if (CanResultTy.getQualifiers().hasObjCLifetime()) {
512  Qualifiers Qs = CanResultTy.getQualifiers();
513  Qs.removeObjCLifetime();
514  RT = Context.getQualifiedType(CanResultTy.getUnqualifiedType(), Qs);
515  }
516  }
517  PropertyString += " ";
518  PrintingPolicy SubPolicy(Context.getPrintingPolicy());
519  SubPolicy.SuppressStrongLifetime = true;
520  SubPolicy.SuppressLifetimeQualifiers = true;
521  std::string TypeString = RT.getAsString(SubPolicy);
522  if (LengthOfPrefix > 0) {
523  // property name must strip off "is" and lower case the first character
524  // after that; e.g. isContinuous will become continuous.
525  StringRef PropertyNameStringRef(PropertyNameString);
526  PropertyNameStringRef = PropertyNameStringRef.drop_front(LengthOfPrefix);
527  PropertyNameString = std::string(PropertyNameStringRef);
528  bool NoLowering = (isUppercase(PropertyNameString[0]) &&
529  PropertyNameString.size() > 1 &&
530  isUppercase(PropertyNameString[1]));
531  if (!NoLowering)
532  PropertyNameString[0] = toLowercase(PropertyNameString[0]);
533  }
534  if (RT->isBlockPointerType() || RT->isFunctionPointerType())
536  TypeString,
537  PropertyNameString.c_str());
538  else {
539  char LastChar = TypeString[TypeString.size()-1];
540  PropertyString += TypeString;
541  if (LastChar != '*')
542  PropertyString += ' ';
543  PropertyString += PropertyNameString;
544  }
545  SourceLocation StartGetterSelectorLoc = Getter->getSelectorStartLoc();
546  Selector GetterSelector = Getter->getSelector();
547 
548  SourceLocation EndGetterSelectorLoc =
549  StartGetterSelectorLoc.getLocWithOffset(GetterSelector.getNameForSlot(0).size());
551  EndGetterSelectorLoc),
552  PropertyString);
553  if (Setter && AvailabilityArgsMatch) {
554  SourceLocation EndLoc = Setter->getDeclaratorEndLoc();
555  // Get location past ';'
556  EndLoc = EndLoc.getLocWithOffset(1);
557  SourceLocation BeginOfSetterDclLoc = Setter->getBeginLoc();
558  // FIXME. This assumes that setter decl; is immediately preceded by eoln.
559  // It is trying to remove the setter method decl. line entirely.
560  BeginOfSetterDclLoc = BeginOfSetterDclLoc.getLocWithOffset(-1);
561  commit.remove(SourceRange(BeginOfSetterDclLoc, EndLoc));
562  }
563 }
564 
566  if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(D)) {
567  StringRef Name = CatDecl->getName();
568  return Name.endswith("Deprecated");
569  }
570  return false;
571 }
572 
573 void ObjCMigrateASTConsumer::migrateObjCContainerDecl(ASTContext &Ctx,
574  ObjCContainerDecl *D) {
576  return;
577 
578  for (auto *Method : D->methods()) {
579  if (Method->isDeprecated())
580  continue;
581  bool PropertyInferred = migrateProperty(Ctx, D, Method);
582  // If a property is inferred, do not attempt to attach NS_RETURNS_INNER_POINTER to
583  // the getter method as it ends up on the property itself which we don't want
584  // to do unless -objcmt-returns-innerpointer-property option is on.
585  if (!PropertyInferred ||
587  if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)
588  migrateNsReturnsInnerPointer(Ctx, Method);
589  }
590  if (!(ASTMigrateActions & FrontendOptions::ObjCMT_ReturnsInnerPointerProperty))
591  return;
592 
593  for (auto *Prop : D->instance_properties()) {
594  if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) &&
595  !Prop->isDeprecated())
596  migratePropertyNsReturnsInnerPointer(Ctx, Prop);
597  }
598 }
599 
600 static bool
602  const ObjCImplementationDecl *ImpDecl,
603  const ObjCInterfaceDecl *IDecl,
604  ObjCProtocolDecl *Protocol) {
605  // In auto-synthesis, protocol properties are not synthesized. So,
606  // a conforming protocol must have its required properties declared
607  // in class interface.
608  bool HasAtleastOneRequiredProperty = false;
609  if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition())
610  for (const auto *Property : PDecl->instance_properties()) {
611  if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
612  continue;
613  HasAtleastOneRequiredProperty = true;
614  DeclContext::lookup_result R = IDecl->lookup(Property->getDeclName());
615  if (R.empty()) {
616  // Relax the rule and look into class's implementation for a synthesize
617  // or dynamic declaration. Class is implementing a property coming from
618  // another protocol. This still makes the target protocol as conforming.
619  if (!ImpDecl->FindPropertyImplDecl(
620  Property->getDeclName().getAsIdentifierInfo(),
621  Property->getQueryKind()))
622  return false;
623  } else if (auto *ClassProperty = R.find_first<ObjCPropertyDecl>()) {
624  if ((ClassProperty->getPropertyAttributes() !=
625  Property->getPropertyAttributes()) ||
626  !Ctx.hasSameType(ClassProperty->getType(), Property->getType()))
627  return false;
628  } else
629  return false;
630  }
631 
632  // At this point, all required properties in this protocol conform to those
633  // declared in the class.
634  // Check that class implements the required methods of the protocol too.
635  bool HasAtleastOneRequiredMethod = false;
636  if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) {
637  if (PDecl->meth_begin() == PDecl->meth_end())
638  return HasAtleastOneRequiredProperty;
639  for (const auto *MD : PDecl->methods()) {
640  if (MD->isImplicit())
641  continue;
642  if (MD->getImplementationControl() == ObjCMethodDecl::Optional)
643  continue;
644  DeclContext::lookup_result R = ImpDecl->lookup(MD->getDeclName());
645  if (R.empty())
646  return false;
647  bool match = false;
648  HasAtleastOneRequiredMethod = true;
649  for (NamedDecl *ND : R)
650  if (ObjCMethodDecl *ImpMD = dyn_cast<ObjCMethodDecl>(ND))
651  if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) {
652  match = true;
653  break;
654  }
655  if (!match)
656  return false;
657  }
658  }
659  return HasAtleastOneRequiredProperty || HasAtleastOneRequiredMethod;
660 }
661 
663  llvm::SmallVectorImpl<ObjCProtocolDecl*> &ConformingProtocols,
664  const NSAPI &NS, edit::Commit &commit) {
665  const ObjCList<ObjCProtocolDecl> &Protocols = IDecl->getReferencedProtocols();
666  std::string ClassString;
667  SourceLocation EndLoc =
668  IDecl->getSuperClass() ? IDecl->getSuperClassLoc() : IDecl->getLocation();
669 
670  if (Protocols.empty()) {
671  ClassString = '<';
672  for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
673  ClassString += ConformingProtocols[i]->getNameAsString();
674  if (i != (e-1))
675  ClassString += ", ";
676  }
677  ClassString += "> ";
678  }
679  else {
680  ClassString = ", ";
681  for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
682  ClassString += ConformingProtocols[i]->getNameAsString();
683  if (i != (e-1))
684  ClassString += ", ";
685  }
687  EndLoc = *PL;
688  }
689 
690  commit.insertAfterToken(EndLoc, ClassString);
691  return true;
692 }
693 
694 static StringRef GetUnsignedName(StringRef NSIntegerName) {
695  StringRef UnsignedName = llvm::StringSwitch<StringRef>(NSIntegerName)
696  .Case("int8_t", "uint8_t")
697  .Case("int16_t", "uint16_t")
698  .Case("int32_t", "uint32_t")
699  .Case("NSInteger", "NSUInteger")
700  .Case("int64_t", "uint64_t")
701  .Default(NSIntegerName);
702  return UnsignedName;
703 }
704 
705 static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
706  const TypedefDecl *TypedefDcl,
707  const NSAPI &NS, edit::Commit &commit,
708  StringRef NSIntegerName,
709  bool NSOptions) {
710  std::string ClassString;
711  if (NSOptions) {
712  ClassString = "typedef NS_OPTIONS(";
713  ClassString += GetUnsignedName(NSIntegerName);
714  }
715  else {
716  ClassString = "typedef NS_ENUM(";
717  ClassString += NSIntegerName;
718  }
719  ClassString += ", ";
720 
721  ClassString += TypedefDcl->getIdentifier()->getName();
722  ClassString += ')';
723  SourceRange R(EnumDcl->getBeginLoc(), EnumDcl->getBeginLoc());
724  commit.replace(R, ClassString);
725  SourceLocation EndOfEnumDclLoc = EnumDcl->getEndLoc();
726  EndOfEnumDclLoc = trans::findSemiAfterLocation(EndOfEnumDclLoc,
727  NS.getASTContext(), /*IsDecl*/true);
728  if (EndOfEnumDclLoc.isValid()) {
729  SourceRange EnumDclRange(EnumDcl->getBeginLoc(), EndOfEnumDclLoc);
730  commit.insertFromRange(TypedefDcl->getBeginLoc(), EnumDclRange);
731  }
732  else
733  return false;
734 
735  SourceLocation EndTypedefDclLoc = TypedefDcl->getEndLoc();
736  EndTypedefDclLoc = trans::findSemiAfterLocation(EndTypedefDclLoc,
737  NS.getASTContext(), /*IsDecl*/true);
738  if (EndTypedefDclLoc.isValid()) {
739  SourceRange TDRange(TypedefDcl->getBeginLoc(), EndTypedefDclLoc);
740  commit.remove(TDRange);
741  }
742  else
743  return false;
744 
745  EndOfEnumDclLoc =
747  /*IsDecl*/ true);
748  if (EndOfEnumDclLoc.isValid()) {
749  SourceLocation BeginOfEnumDclLoc = EnumDcl->getBeginLoc();
750  // FIXME. This assumes that enum decl; is immediately preceded by eoln.
751  // It is trying to remove the enum decl. lines entirely.
752  BeginOfEnumDclLoc = BeginOfEnumDclLoc.getLocWithOffset(-1);
753  commit.remove(SourceRange(BeginOfEnumDclLoc, EndOfEnumDclLoc));
754  return true;
755  }
756  return false;
757 }
758 
760  const EnumDecl *EnumDcl,
761  const TypedefDecl *TypedefDcl,
762  const NSAPI &NS, edit::Commit &commit,
763  bool IsNSIntegerType) {
764  QualType DesignatedEnumType = EnumDcl->getIntegerType();
765  assert(!DesignatedEnumType.isNull()
766  && "rewriteToNSMacroDecl - underlying enum type is null");
767 
768  PrintingPolicy Policy(Ctx.getPrintingPolicy());
769  std::string TypeString = DesignatedEnumType.getAsString(Policy);
770  std::string ClassString = IsNSIntegerType ? "NS_ENUM(" : "NS_OPTIONS(";
771  ClassString += TypeString;
772  ClassString += ", ";
773 
774  ClassString += TypedefDcl->getIdentifier()->getName();
775  ClassString += ") ";
776  SourceLocation EndLoc = EnumDcl->getBraceRange().getBegin();
777  if (EndLoc.isInvalid())
778  return;
779  CharSourceRange R =
780  CharSourceRange::getCharRange(EnumDcl->getBeginLoc(), EndLoc);
781  commit.replace(R, ClassString);
782  // This is to remove spaces between '}' and typedef name.
783  SourceLocation StartTypedefLoc = EnumDcl->getEndLoc();
784  StartTypedefLoc = StartTypedefLoc.getLocWithOffset(+1);
785  SourceLocation EndTypedefLoc = TypedefDcl->getEndLoc();
786 
787  commit.remove(SourceRange(StartTypedefLoc, EndTypedefLoc));
788 }
789 
791  const EnumDecl *EnumDcl) {
792  bool PowerOfTwo = true;
793  bool AllHexdecimalEnumerator = true;
794  uint64_t MaxPowerOfTwoVal = 0;
795  for (auto Enumerator : EnumDcl->enumerators()) {
796  const Expr *InitExpr = Enumerator->getInitExpr();
797  if (!InitExpr) {
798  PowerOfTwo = false;
799  AllHexdecimalEnumerator = false;
800  continue;
801  }
802  InitExpr = InitExpr->IgnoreParenCasts();
803  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(InitExpr))
804  if (BO->isShiftOp() || BO->isBitwiseOp())
805  return true;
806 
807  uint64_t EnumVal = Enumerator->getInitVal().getZExtValue();
808  if (PowerOfTwo && EnumVal) {
809  if (!llvm::isPowerOf2_64(EnumVal))
810  PowerOfTwo = false;
811  else if (EnumVal > MaxPowerOfTwoVal)
812  MaxPowerOfTwoVal = EnumVal;
813  }
814  if (AllHexdecimalEnumerator && EnumVal) {
815  bool FoundHexdecimalEnumerator = false;
816  SourceLocation EndLoc = Enumerator->getEndLoc();
817  Token Tok;
818  if (!PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true))
819  if (Tok.isLiteral() && Tok.getLength() > 2) {
820  if (const char *StringLit = Tok.getLiteralData())
821  FoundHexdecimalEnumerator =
822  (StringLit[0] == '0' && (toLowercase(StringLit[1]) == 'x'));
823  }
824  if (!FoundHexdecimalEnumerator)
825  AllHexdecimalEnumerator = false;
826  }
827  }
828  return AllHexdecimalEnumerator || (PowerOfTwo && (MaxPowerOfTwoVal > 2));
829 }
830 
831 void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
832  const ObjCImplementationDecl *ImpDecl) {
833  const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface();
834  if (!IDecl || ObjCProtocolDecls.empty() || IDecl->isDeprecated())
835  return;
836  // Find all implicit conforming protocols for this class
837  // and make them explicit.
839  Ctx.CollectInheritedProtocols(IDecl, ExplicitProtocols);
840  llvm::SmallVector<ObjCProtocolDecl *, 8> PotentialImplicitProtocols;
841 
842  for (ObjCProtocolDecl *ProtDecl : ObjCProtocolDecls)
843  if (!ExplicitProtocols.count(ProtDecl))
844  PotentialImplicitProtocols.push_back(ProtDecl);
845 
846  if (PotentialImplicitProtocols.empty())
847  return;
848 
849  // go through list of non-optional methods and properties in each protocol
850  // in the PotentialImplicitProtocols list. If class implements every one of the
851  // methods and properties, then this class conforms to this protocol.
852  llvm::SmallVector<ObjCProtocolDecl*, 8> ConformingProtocols;
853  for (unsigned i = 0, e = PotentialImplicitProtocols.size(); i != e; i++)
854  if (ClassImplementsAllMethodsAndProperties(Ctx, ImpDecl, IDecl,
855  PotentialImplicitProtocols[i]))
856  ConformingProtocols.push_back(PotentialImplicitProtocols[i]);
857 
858  if (ConformingProtocols.empty())
859  return;
860 
861  // Further reduce number of conforming protocols. If protocol P1 is in the list
862  // protocol P2 (P2<P1>), No need to include P1.
863  llvm::SmallVector<ObjCProtocolDecl*, 8> MinimalConformingProtocols;
864  for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
865  bool DropIt = false;
866  ObjCProtocolDecl *TargetPDecl = ConformingProtocols[i];
867  for (unsigned i1 = 0, e1 = ConformingProtocols.size(); i1 != e1; i1++) {
868  ObjCProtocolDecl *PDecl = ConformingProtocols[i1];
869  if (PDecl == TargetPDecl)
870  continue;
871  if (PDecl->lookupProtocolNamed(
872  TargetPDecl->getDeclName().getAsIdentifierInfo())) {
873  DropIt = true;
874  break;
875  }
876  }
877  if (!DropIt)
878  MinimalConformingProtocols.push_back(TargetPDecl);
879  }
880  if (MinimalConformingProtocols.empty())
881  return;
882  edit::Commit commit(*Editor);
883  rewriteToObjCInterfaceDecl(IDecl, MinimalConformingProtocols,
884  *NSAPIObj, commit);
885  Editor->commit(commit);
886 }
887 
888 void ObjCMigrateASTConsumer::CacheObjCNSIntegerTypedefed(
889  const TypedefDecl *TypedefDcl) {
890 
891  QualType qt = TypedefDcl->getTypeSourceInfo()->getType();
892  if (NSAPIObj->isObjCNSIntegerType(qt))
893  NSIntegerTypedefed = TypedefDcl;
894  else if (NSAPIObj->isObjCNSUIntegerType(qt))
895  NSUIntegerTypedefed = TypedefDcl;
896 }
897 
898 bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
899  const EnumDecl *EnumDcl,
900  const TypedefDecl *TypedefDcl) {
901  if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() ||
902  EnumDcl->isDeprecated())
903  return false;
904  if (!TypedefDcl) {
905  if (NSIntegerTypedefed) {
906  TypedefDcl = NSIntegerTypedefed;
907  NSIntegerTypedefed = nullptr;
908  }
909  else if (NSUIntegerTypedefed) {
910  TypedefDcl = NSUIntegerTypedefed;
911  NSUIntegerTypedefed = nullptr;
912  }
913  else
914  return false;
915  FileID FileIdOfTypedefDcl =
916  PP.getSourceManager().getFileID(TypedefDcl->getLocation());
917  FileID FileIdOfEnumDcl =
918  PP.getSourceManager().getFileID(EnumDcl->getLocation());
919  if (FileIdOfTypedefDcl != FileIdOfEnumDcl)
920  return false;
921  }
922  if (TypedefDcl->isDeprecated())
923  return false;
924 
925  QualType qt = TypedefDcl->getTypeSourceInfo()->getType();
926  StringRef NSIntegerName = NSAPIObj->GetNSIntegralKind(qt);
927 
928  if (NSIntegerName.empty()) {
929  // Also check for typedef enum {...} TD;
930  if (const EnumType *EnumTy = qt->getAs<EnumType>()) {
931  if (EnumTy->getDecl() == EnumDcl) {
932  bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl);
933  if (!InsertFoundation(Ctx, TypedefDcl->getBeginLoc()))
934  return false;
935  edit::Commit commit(*Editor);
936  rewriteToNSMacroDecl(Ctx, EnumDcl, TypedefDcl, *NSAPIObj, commit, !NSOptions);
937  Editor->commit(commit);
938  return true;
939  }
940  }
941  return false;
942  }
943 
944  // We may still use NS_OPTIONS based on what we find in the enumertor list.
945  bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl);
946  if (!InsertFoundation(Ctx, TypedefDcl->getBeginLoc()))
947  return false;
948  edit::Commit commit(*Editor);
949  bool Res = rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj,
950  commit, NSIntegerName, NSOptions);
951  Editor->commit(commit);
952  return Res;
953 }
954 
956  const ObjCMigrateASTConsumer &ASTC,
957  ObjCMethodDecl *OM) {
958  if (OM->getReturnType() == Ctx.getObjCInstanceType())
959  return; // already has instancetype.
960 
961  SourceRange R;
962  std::string ClassString;
963  if (TypeSourceInfo *TSInfo = OM->getReturnTypeSourceInfo()) {
964  TypeLoc TL = TSInfo->getTypeLoc();
965  R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
966  ClassString = "instancetype";
967  }
968  else {
969  R = SourceRange(OM->getBeginLoc(), OM->getBeginLoc());
970  ClassString = OM->isInstanceMethod() ? '-' : '+';
971  ClassString += " (instancetype)";
972  }
973  edit::Commit commit(*ASTC.Editor);
974  commit.replace(R, ClassString);
975  ASTC.Editor->commit(commit);
976 }
977 
978 static void ReplaceWithClasstype(const ObjCMigrateASTConsumer &ASTC,
979  ObjCMethodDecl *OM) {
980  ObjCInterfaceDecl *IDecl = OM->getClassInterface();
981  SourceRange R;
982  std::string ClassString;
983  if (TypeSourceInfo *TSInfo = OM->getReturnTypeSourceInfo()) {
984  TypeLoc TL = TSInfo->getTypeLoc();
985  R = SourceRange(TL.getBeginLoc(), TL.getEndLoc()); {
986  ClassString = std::string(IDecl->getName());
987  ClassString += "*";
988  }
989  }
990  else {
991  R = SourceRange(OM->getBeginLoc(), OM->getBeginLoc());
992  ClassString = "+ (";
993  ClassString += IDecl->getName(); ClassString += "*)";
994  }
995  edit::Commit commit(*ASTC.Editor);
996  commit.replace(R, ClassString);
997  ASTC.Editor->commit(commit);
998 }
999 
1000 void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
1001  ObjCContainerDecl *CDecl,
1002  ObjCMethodDecl *OM) {
1003  ObjCInstanceTypeFamily OIT_Family =
1005 
1006  std::string ClassName;
1007  switch (OIT_Family) {
1008  case OIT_None:
1009  migrateFactoryMethod(Ctx, CDecl, OM);
1010  return;
1011  case OIT_Array:
1012  ClassName = "NSArray";
1013  break;
1014  case OIT_Dictionary:
1015  ClassName = "NSDictionary";
1016  break;
1017  case OIT_Singleton:
1018  migrateFactoryMethod(Ctx, CDecl, OM, OIT_Singleton);
1019  return;
1020  case OIT_Init:
1021  if (OM->getReturnType()->isObjCIdType())
1022  ReplaceWithInstancetype(Ctx, *this, OM);
1023  return;
1024  case OIT_ReturnsSelf:
1025  migrateFactoryMethod(Ctx, CDecl, OM, OIT_ReturnsSelf);
1026  return;
1027  }
1028  if (!OM->getReturnType()->isObjCIdType())
1029  return;
1030 
1031  ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
1032  if (!IDecl) {
1033  if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
1034  IDecl = CatDecl->getClassInterface();
1035  else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
1036  IDecl = ImpDecl->getClassInterface();
1037  }
1038  if (!IDecl ||
1039  !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName))) {
1040  migrateFactoryMethod(Ctx, CDecl, OM);
1041  return;
1042  }
1043  ReplaceWithInstancetype(Ctx, *this, OM);
1044 }
1045 
1047  if (!T->isAnyPointerType())
1048  return false;
1049  if (T->isObjCObjectPointerType() || T->isObjCBuiltinType() ||
1052  return false;
1053  // Also, typedef-of-pointer-to-incomplete-struct is something that we assume
1054  // is not an innter pointer type.
1055  QualType OrigT = T;
1056  while (const TypedefType *TD = dyn_cast<TypedefType>(T.getTypePtr()))
1057  T = TD->getDecl()->getUnderlyingType();
1058  if (OrigT == T || !T->isPointerType())
1059  return true;
1060  const PointerType* PT = T->getAs<PointerType>();
1061  QualType UPointeeT = PT->getPointeeType().getUnqualifiedType();
1062  if (UPointeeT->isRecordType()) {
1063  const RecordType *RecordTy = UPointeeT->getAs<RecordType>();
1064  if (!RecordTy->getDecl()->isCompleteDefinition())
1065  return false;
1066  }
1067  return true;
1068 }
1069 
1070 /// Check whether the two versions match.
1071 static bool versionsMatch(const VersionTuple &X, const VersionTuple &Y) {
1072  return (X == Y);
1073 }
1074 
1075 /// AvailabilityAttrsMatch - This routine checks that if comparing two
1076 /// availability attributes, all their components match. It returns
1077 /// true, if not dealing with availability or when all components of
1078 /// availability attributes match. This routine is only called when
1079 /// the attributes are of the same kind.
1080 static bool AvailabilityAttrsMatch(Attr *At1, Attr *At2) {
1081  const AvailabilityAttr *AA1 = dyn_cast<AvailabilityAttr>(At1);
1082  if (!AA1)
1083  return true;
1084  const AvailabilityAttr *AA2 = cast<AvailabilityAttr>(At2);
1085 
1086  VersionTuple Introduced1 = AA1->getIntroduced();
1087  VersionTuple Deprecated1 = AA1->getDeprecated();
1088  VersionTuple Obsoleted1 = AA1->getObsoleted();
1089  bool IsUnavailable1 = AA1->getUnavailable();
1090  VersionTuple Introduced2 = AA2->getIntroduced();
1091  VersionTuple Deprecated2 = AA2->getDeprecated();
1092  VersionTuple Obsoleted2 = AA2->getObsoleted();
1093  bool IsUnavailable2 = AA2->getUnavailable();
1094  return (versionsMatch(Introduced1, Introduced2) &&
1095  versionsMatch(Deprecated1, Deprecated2) &&
1096  versionsMatch(Obsoleted1, Obsoleted2) &&
1097  IsUnavailable1 == IsUnavailable2);
1098 }
1099 
1100 static bool MatchTwoAttributeLists(const AttrVec &Attrs1, const AttrVec &Attrs2,
1101  bool &AvailabilityArgsMatch) {
1102  // This list is very small, so this need not be optimized.
1103  for (unsigned i = 0, e = Attrs1.size(); i != e; i++) {
1104  bool match = false;
1105  for (unsigned j = 0, f = Attrs2.size(); j != f; j++) {
1106  // Matching attribute kind only. Except for Availability attributes,
1107  // we are not getting into details of the attributes. For all practical purposes
1108  // this is sufficient.
1109  if (Attrs1[i]->getKind() == Attrs2[j]->getKind()) {
1110  if (AvailabilityArgsMatch)
1111  AvailabilityArgsMatch = AvailabilityAttrsMatch(Attrs1[i], Attrs2[j]);
1112  match = true;
1113  break;
1114  }
1115  }
1116  if (!match)
1117  return false;
1118  }
1119  return true;
1120 }
1121 
1122 /// AttributesMatch - This routine checks list of attributes for two
1123 /// decls. It returns false, if there is a mismatch in kind of
1124 /// attributes seen in the decls. It returns true if the two decls
1125 /// have list of same kind of attributes. Furthermore, when there
1126 /// are availability attributes in the two decls, it sets the
1127 /// AvailabilityArgsMatch to false if availability attributes have
1128 /// different versions, etc.
1129 static bool AttributesMatch(const Decl *Decl1, const Decl *Decl2,
1130  bool &AvailabilityArgsMatch) {
1131  if (!Decl1->hasAttrs() || !Decl2->hasAttrs()) {
1132  AvailabilityArgsMatch = (Decl1->hasAttrs() == Decl2->hasAttrs());
1133  return true;
1134  }
1135  AvailabilityArgsMatch = true;
1136  const AttrVec &Attrs1 = Decl1->getAttrs();
1137  const AttrVec &Attrs2 = Decl2->getAttrs();
1138  bool match = MatchTwoAttributeLists(Attrs1, Attrs2, AvailabilityArgsMatch);
1139  if (match && (Attrs2.size() > Attrs1.size()))
1140  return MatchTwoAttributeLists(Attrs2, Attrs1, AvailabilityArgsMatch);
1141  return match;
1142 }
1143 
1145  const char *Name) {
1146  if (!isAsciiIdentifierStart(Name[0]))
1147  return false;
1148  std::string NameString = Name;
1149  NameString[0] = toLowercase(NameString[0]);
1150  IdentifierInfo *II = &Ctx.Idents.get(NameString);
1151  return II->getTokenID() == tok::identifier;
1152 }
1153 
1154 bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
1155  ObjCContainerDecl *D,
1156  ObjCMethodDecl *Method) {
1157  if (Method->isPropertyAccessor() || !Method->isInstanceMethod() ||
1158  Method->param_size() != 0)
1159  return false;
1160  // Is this method candidate to be a getter?
1161  QualType GRT = Method->getReturnType();
1162  if (GRT->isVoidType())
1163  return false;
1164 
1165  Selector GetterSelector = Method->getSelector();
1166  ObjCInstanceTypeFamily OIT_Family =
1167  Selector::getInstTypeMethodFamily(GetterSelector);
1168 
1169  if (OIT_Family != OIT_None)
1170  return false;
1171 
1172  IdentifierInfo *getterName = GetterSelector.getIdentifierInfoForSlot(0);
1173  Selector SetterSelector =
1175  PP.getSelectorTable(),
1176  getterName);
1177  ObjCMethodDecl *SetterMethod = D->getInstanceMethod(SetterSelector);
1178  unsigned LengthOfPrefix = 0;
1179  if (!SetterMethod) {
1180  // try a different naming convention for getter: isXxxxx
1181  StringRef getterNameString = getterName->getName();
1182  bool IsPrefix = getterNameString.startswith("is");
1183  // Note that we don't want to change an isXXX method of retainable object
1184  // type to property (readonly or otherwise).
1185  if (IsPrefix && GRT->isObjCRetainableType())
1186  return false;
1187  if (IsPrefix || getterNameString.startswith("get")) {
1188  LengthOfPrefix = (IsPrefix ? 2 : 3);
1189  const char *CGetterName = getterNameString.data() + LengthOfPrefix;
1190  // Make sure that first character after "is" or "get" prefix can
1191  // start an identifier.
1192  if (!IsValidIdentifier(Ctx, CGetterName))
1193  return false;
1194  if (CGetterName[0] && isUppercase(CGetterName[0])) {
1195  getterName = &Ctx.Idents.get(CGetterName);
1196  SetterSelector =
1198  PP.getSelectorTable(),
1199  getterName);
1200  SetterMethod = D->getInstanceMethod(SetterSelector);
1201  }
1202  }
1203  }
1204 
1205  if (SetterMethod) {
1206  if ((ASTMigrateActions & FrontendOptions::ObjCMT_ReadwriteProperty) == 0)
1207  return false;
1208  bool AvailabilityArgsMatch;
1209  if (SetterMethod->isDeprecated() ||
1210  !AttributesMatch(Method, SetterMethod, AvailabilityArgsMatch))
1211  return false;
1212 
1213  // Is this a valid setter, matching the target getter?
1214  QualType SRT = SetterMethod->getReturnType();
1215  if (!SRT->isVoidType())
1216  return false;
1217  const ParmVarDecl *argDecl = *SetterMethod->param_begin();
1218  QualType ArgType = argDecl->getType();
1219  if (!Ctx.hasSameUnqualifiedType(ArgType, GRT))
1220  return false;
1221  edit::Commit commit(*Editor);
1222  rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit,
1223  LengthOfPrefix,
1224  (ASTMigrateActions &
1226  (ASTMigrateActions &
1228  AvailabilityArgsMatch);
1229  Editor->commit(commit);
1230  return true;
1231  }
1232  else if (ASTMigrateActions & FrontendOptions::ObjCMT_ReadonlyProperty) {
1233  // Try a non-void method with no argument (and no setter or property of same name
1234  // as a 'readonly' property.
1235  edit::Commit commit(*Editor);
1236  rewriteToObjCProperty(Method, nullptr /*SetterMethod*/, *NSAPIObj, commit,
1237  LengthOfPrefix,
1238  (ASTMigrateActions &
1240  (ASTMigrateActions &
1242  /*AvailabilityArgsMatch*/false);
1243  Editor->commit(commit);
1244  return true;
1245  }
1246  return false;
1247 }
1248 
1249 void ObjCMigrateASTConsumer::migrateNsReturnsInnerPointer(ASTContext &Ctx,
1250  ObjCMethodDecl *OM) {
1251  if (OM->isImplicit() ||
1252  !OM->isInstanceMethod() ||
1253  OM->hasAttr<ObjCReturnsInnerPointerAttr>())
1254  return;
1255 
1256  QualType RT = OM->getReturnType();
1257  if (!TypeIsInnerPointer(RT) ||
1258  !NSAPIObj->isMacroDefined("NS_RETURNS_INNER_POINTER"))
1259  return;
1260 
1261  edit::Commit commit(*Editor);
1262  commit.insertBefore(OM->getEndLoc(), " NS_RETURNS_INNER_POINTER");
1263  Editor->commit(commit);
1264 }
1265 
1266 void ObjCMigrateASTConsumer::migratePropertyNsReturnsInnerPointer(ASTContext &Ctx,
1267  ObjCPropertyDecl *P) {
1268  QualType T = P->getType();
1269 
1270  if (!TypeIsInnerPointer(T) ||
1271  !NSAPIObj->isMacroDefined("NS_RETURNS_INNER_POINTER"))
1272  return;
1273  edit::Commit commit(*Editor);
1274  commit.insertBefore(P->getEndLoc(), " NS_RETURNS_INNER_POINTER ");
1275  Editor->commit(commit);
1276 }
1277 
1278 void ObjCMigrateASTConsumer::migrateAllMethodInstaceType(ASTContext &Ctx,
1279  ObjCContainerDecl *CDecl) {
1280  if (CDecl->isDeprecated() || IsCategoryNameWithDeprecatedSuffix(CDecl))
1281  return;
1282 
1283  // migrate methods which can have instancetype as their result type.
1284  for (auto *Method : CDecl->methods()) {
1285  if (Method->isDeprecated())
1286  continue;
1287  migrateMethodInstanceType(Ctx, CDecl, Method);
1288  }
1289 }
1290 
1291 void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
1292  ObjCContainerDecl *CDecl,
1293  ObjCMethodDecl *OM,
1294  ObjCInstanceTypeFamily OIT_Family) {
1295  if (OM->isInstanceMethod() ||
1296  OM->getReturnType() == Ctx.getObjCInstanceType() ||
1297  !OM->getReturnType()->isObjCIdType())
1298  return;
1299 
1300  // Candidate factory methods are + (id) NaMeXXX : ... which belong to a class
1301  // NSYYYNamE with matching names be at least 3 characters long.
1302  ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
1303  if (!IDecl) {
1304  if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
1305  IDecl = CatDecl->getClassInterface();
1306  else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
1307  IDecl = ImpDecl->getClassInterface();
1308  }
1309  if (!IDecl)
1310  return;
1311 
1312  std::string StringClassName = std::string(IDecl->getName());
1313  StringRef LoweredClassName(StringClassName);
1314  std::string StringLoweredClassName = LoweredClassName.lower();
1315  LoweredClassName = StringLoweredClassName;
1316 
1317  IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0);
1318  // Handle method with no name at its first selector slot; e.g. + (id):(int)x.
1319  if (!MethodIdName)
1320  return;
1321 
1322  std::string MethodName = std::string(MethodIdName->getName());
1323  if (OIT_Family == OIT_Singleton || OIT_Family == OIT_ReturnsSelf) {
1324  StringRef STRefMethodName(MethodName);
1325  size_t len = 0;
1326  if (STRefMethodName.startswith("standard"))
1327  len = strlen("standard");
1328  else if (STRefMethodName.startswith("shared"))
1329  len = strlen("shared");
1330  else if (STRefMethodName.startswith("default"))
1331  len = strlen("default");
1332  else
1333  return;
1334  MethodName = std::string(STRefMethodName.substr(len));
1335  }
1336  std::string MethodNameSubStr = MethodName.substr(0, 3);
1337  StringRef MethodNamePrefix(MethodNameSubStr);
1338  std::string StringLoweredMethodNamePrefix = MethodNamePrefix.lower();
1339  MethodNamePrefix = StringLoweredMethodNamePrefix;
1340  size_t Ix = LoweredClassName.rfind(MethodNamePrefix);
1341  if (Ix == StringRef::npos)
1342  return;
1343  std::string ClassNamePostfix = std::string(LoweredClassName.substr(Ix));
1344  StringRef LoweredMethodName(MethodName);
1345  std::string StringLoweredMethodName = LoweredMethodName.lower();
1346  LoweredMethodName = StringLoweredMethodName;
1347  if (!LoweredMethodName.startswith(ClassNamePostfix))
1348  return;
1349  if (OIT_Family == OIT_ReturnsSelf)
1350  ReplaceWithClasstype(*this, OM);
1351  else
1352  ReplaceWithInstancetype(Ctx, *this, OM);
1353 }
1354 
1355 static bool IsVoidStarType(QualType Ty) {
1356  if (!Ty->isPointerType())
1357  return false;
1358 
1359  while (const TypedefType *TD = dyn_cast<TypedefType>(Ty.getTypePtr()))
1360  Ty = TD->getDecl()->getUnderlyingType();
1361 
1362  // Is the type void*?
1363  const PointerType* PT = Ty->castAs<PointerType>();
1365  return true;
1366  return IsVoidStarType(PT->getPointeeType());
1367 }
1368 
1369 /// AuditedType - This routine audits the type AT and returns false if it is one of known
1370 /// CF object types or of the "void *" variety. It returns true if we don't care about the type
1371 /// such as a non-pointer or pointers which have no ownership issues (such as "int *").
1372 static bool AuditedType (QualType AT) {
1373  if (!AT->isAnyPointerType() && !AT->isBlockPointerType())
1374  return true;
1375  // FIXME. There isn't much we can say about CF pointer type; or is there?
1377  IsVoidStarType(AT) ||
1378  // If an ObjC object is type, assuming that it is not a CF function and
1379  // that it is an un-audited function.
1381  return false;
1382  // All other pointers are assumed audited as harmless.
1383  return true;
1384 }
1385 
1386 void ObjCMigrateASTConsumer::AnnotateImplicitBridging(ASTContext &Ctx) {
1387  if (CFFunctionIBCandidates.empty())
1388  return;
1389  if (!NSAPIObj->isMacroDefined("CF_IMPLICIT_BRIDGING_ENABLED")) {
1390  CFFunctionIBCandidates.clear();
1391  FileId = FileID();
1392  return;
1393  }
1394  // Insert CF_IMPLICIT_BRIDGING_ENABLE/CF_IMPLICIT_BRIDGING_DISABLED
1395  const Decl *FirstFD = CFFunctionIBCandidates[0];
1396  const Decl *LastFD =
1397  CFFunctionIBCandidates[CFFunctionIBCandidates.size()-1];
1398  const char *PragmaString = "\nCF_IMPLICIT_BRIDGING_ENABLED\n\n";
1399  edit::Commit commit(*Editor);
1400  commit.insertBefore(FirstFD->getBeginLoc(), PragmaString);
1401  PragmaString = "\n\nCF_IMPLICIT_BRIDGING_DISABLED\n";
1402  SourceLocation EndLoc = LastFD->getEndLoc();
1403  // get location just past end of function location.
1404  EndLoc = PP.getLocForEndOfToken(EndLoc);
1405  if (isa<FunctionDecl>(LastFD)) {
1406  // For Methods, EndLoc points to the ending semcolon. So,
1407  // not of these extra work is needed.
1408  Token Tok;
1409  // get locaiton of token that comes after end of function.
1410  bool Failed = PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true);
1411  if (!Failed)
1412  EndLoc = Tok.getLocation();
1413  }
1414  commit.insertAfterToken(EndLoc, PragmaString);
1415  Editor->commit(commit);
1416  FileId = FileID();
1417  CFFunctionIBCandidates.clear();
1418 }
1419 
1420 void ObjCMigrateASTConsumer::migrateCFAnnotation(ASTContext &Ctx, const Decl *Decl) {
1421  if (Decl->isDeprecated())
1422  return;
1423 
1424  if (Decl->hasAttr<CFAuditedTransferAttr>()) {
1425  assert(CFFunctionIBCandidates.empty() &&
1426  "Cannot have audited functions/methods inside user "
1427  "provided CF_IMPLICIT_BRIDGING_ENABLE");
1428  return;
1429  }
1430 
1431  // Finction must be annotated first.
1432  if (const FunctionDecl *FuncDecl = dyn_cast<FunctionDecl>(Decl)) {
1433  CF_BRIDGING_KIND AuditKind = migrateAddFunctionAnnotation(Ctx, FuncDecl);
1434  if (AuditKind == CF_BRIDGING_ENABLE) {
1435  CFFunctionIBCandidates.push_back(Decl);
1436  if (FileId.isInvalid())
1437  FileId = PP.getSourceManager().getFileID(Decl->getLocation());
1438  }
1439  else if (AuditKind == CF_BRIDGING_MAY_INCLUDE) {
1440  if (!CFFunctionIBCandidates.empty()) {
1441  CFFunctionIBCandidates.push_back(Decl);
1442  if (FileId.isInvalid())
1443  FileId = PP.getSourceManager().getFileID(Decl->getLocation());
1444  }
1445  }
1446  else
1447  AnnotateImplicitBridging(Ctx);
1448  }
1449  else {
1450  migrateAddMethodAnnotation(Ctx, cast<ObjCMethodDecl>(Decl));
1451  AnnotateImplicitBridging(Ctx);
1452  }
1453 }
1454 
1455 void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
1456  const RetainSummary *RS,
1457  const FunctionDecl *FuncDecl,
1458  bool ResultAnnotated) {
1459  // Annotate function.
1460  if (!ResultAnnotated) {
1461  RetEffect Ret = RS->getRetEffect();
1462  const char *AnnotationString = nullptr;
1463  if (Ret.getObjKind() == ObjKind::CF) {
1464  if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))
1465  AnnotationString = " CF_RETURNS_RETAINED";
1466  else if (Ret.notOwned() &&
1467  NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))
1468  AnnotationString = " CF_RETURNS_NOT_RETAINED";
1469  }
1470  else if (Ret.getObjKind() == ObjKind::ObjC) {
1471  if (Ret.isOwned() && NSAPIObj->isMacroDefined("NS_RETURNS_RETAINED"))
1472  AnnotationString = " NS_RETURNS_RETAINED";
1473  }
1474 
1475  if (AnnotationString) {
1476  edit::Commit commit(*Editor);
1477  commit.insertAfterToken(FuncDecl->getEndLoc(), AnnotationString);
1478  Editor->commit(commit);
1479  }
1480  }
1481  unsigned i = 0;
1482  for (FunctionDecl::param_const_iterator pi = FuncDecl->param_begin(),
1483  pe = FuncDecl->param_end(); pi != pe; ++pi, ++i) {
1484  const ParmVarDecl *pd = *pi;
1485  ArgEffect AE = RS->getArg(i);
1486  if (AE.getKind() == DecRef && AE.getObjKind() == ObjKind::CF &&
1487  !pd->hasAttr<CFConsumedAttr>() &&
1488  NSAPIObj->isMacroDefined("CF_CONSUMED")) {
1489  edit::Commit commit(*Editor);
1490  commit.insertBefore(pd->getLocation(), "CF_CONSUMED ");
1491  Editor->commit(commit);
1492  } else if (AE.getKind() == DecRef && AE.getObjKind() == ObjKind::ObjC &&
1493  !pd->hasAttr<NSConsumedAttr>() &&
1494  NSAPIObj->isMacroDefined("NS_CONSUMED")) {
1495  edit::Commit commit(*Editor);
1496  commit.insertBefore(pd->getLocation(), "NS_CONSUMED ");
1497  Editor->commit(commit);
1498  }
1499  }
1500 }
1501 
1502 ObjCMigrateASTConsumer::CF_BRIDGING_KIND
1503  ObjCMigrateASTConsumer::migrateAddFunctionAnnotation(
1504  ASTContext &Ctx,
1505  const FunctionDecl *FuncDecl) {
1506  if (FuncDecl->hasBody())
1507  return CF_BRIDGING_NONE;
1508 
1509  const RetainSummary *RS =
1510  getSummaryManager(Ctx).getSummary(AnyCall(FuncDecl));
1511  bool FuncIsReturnAnnotated = (FuncDecl->hasAttr<CFReturnsRetainedAttr>() ||
1512  FuncDecl->hasAttr<CFReturnsNotRetainedAttr>() ||
1513  FuncDecl->hasAttr<NSReturnsRetainedAttr>() ||
1514  FuncDecl->hasAttr<NSReturnsNotRetainedAttr>() ||
1515  FuncDecl->hasAttr<NSReturnsAutoreleasedAttr>());
1516 
1517  // Trivial case of when function is annotated and has no argument.
1518  if (FuncIsReturnAnnotated && FuncDecl->getNumParams() == 0)
1519  return CF_BRIDGING_NONE;
1520 
1521  bool ReturnCFAudited = false;
1522  if (!FuncIsReturnAnnotated) {
1523  RetEffect Ret = RS->getRetEffect();
1524  if (Ret.getObjKind() == ObjKind::CF &&
1525  (Ret.isOwned() || Ret.notOwned()))
1526  ReturnCFAudited = true;
1527  else if (!AuditedType(FuncDecl->getReturnType()))
1528  return CF_BRIDGING_NONE;
1529  }
1530 
1531  // At this point result type is audited for potential inclusion.
1532  unsigned i = 0;
1533  bool ArgCFAudited = false;
1534  for (FunctionDecl::param_const_iterator pi = FuncDecl->param_begin(),
1535  pe = FuncDecl->param_end(); pi != pe; ++pi, ++i) {
1536  const ParmVarDecl *pd = *pi;
1537  ArgEffect AE = RS->getArg(i);
1538  if ((AE.getKind() == DecRef /*CFConsumed annotated*/ ||
1539  AE.getKind() == IncRef) && AE.getObjKind() == ObjKind::CF) {
1540  if (AE.getKind() == DecRef && !pd->hasAttr<CFConsumedAttr>())
1541  ArgCFAudited = true;
1542  else if (AE.getKind() == IncRef)
1543  ArgCFAudited = true;
1544  } else {
1545  QualType AT = pd->getType();
1546  if (!AuditedType(AT)) {
1547  AddCFAnnotations(Ctx, RS, FuncDecl, FuncIsReturnAnnotated);
1548  return CF_BRIDGING_NONE;
1549  }
1550  }
1551  }
1552  if (ReturnCFAudited || ArgCFAudited)
1553  return CF_BRIDGING_ENABLE;
1554 
1555  return CF_BRIDGING_MAY_INCLUDE;
1556 }
1557 
1558 void ObjCMigrateASTConsumer::migrateARCSafeAnnotation(ASTContext &Ctx,
1559  ObjCContainerDecl *CDecl) {
1560  if (!isa<ObjCInterfaceDecl>(CDecl) || CDecl->isDeprecated())
1561  return;
1562 
1563  // migrate methods which can have instancetype as their result type.
1564  for (const auto *Method : CDecl->methods())
1565  migrateCFAnnotation(Ctx, Method);
1566 }
1567 
1568 void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
1569  const RetainSummary *RS,
1570  const ObjCMethodDecl *MethodDecl,
1571  bool ResultAnnotated) {
1572  // Annotate function.
1573  if (!ResultAnnotated) {
1574  RetEffect Ret = RS->getRetEffect();
1575  const char *AnnotationString = nullptr;
1576  if (Ret.getObjKind() == ObjKind::CF) {
1577  if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))
1578  AnnotationString = " CF_RETURNS_RETAINED";
1579  else if (Ret.notOwned() &&
1580  NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))
1581  AnnotationString = " CF_RETURNS_NOT_RETAINED";
1582  }
1583  else if (Ret.getObjKind() == ObjKind::ObjC) {
1584  ObjCMethodFamily OMF = MethodDecl->getMethodFamily();
1585  switch (OMF) {
1586  case clang::OMF_alloc:
1587  case clang::OMF_new:
1588  case clang::OMF_copy:
1589  case clang::OMF_init:
1591  break;
1592 
1593  default:
1594  if (Ret.isOwned() && NSAPIObj->isMacroDefined("NS_RETURNS_RETAINED"))
1595  AnnotationString = " NS_RETURNS_RETAINED";
1596  break;
1597  }
1598  }
1599 
1600  if (AnnotationString) {
1601  edit::Commit commit(*Editor);
1602  commit.insertBefore(MethodDecl->getEndLoc(), AnnotationString);
1603  Editor->commit(commit);
1604  }
1605  }
1606  unsigned i = 0;
1607  for (ObjCMethodDecl::param_const_iterator pi = MethodDecl->param_begin(),
1608  pe = MethodDecl->param_end(); pi != pe; ++pi, ++i) {
1609  const ParmVarDecl *pd = *pi;
1610  ArgEffect AE = RS->getArg(i);
1611  if (AE.getKind() == DecRef
1612  && AE.getObjKind() == ObjKind::CF
1613  && !pd->hasAttr<CFConsumedAttr>() &&
1614  NSAPIObj->isMacroDefined("CF_CONSUMED")) {
1615  edit::Commit commit(*Editor);
1616  commit.insertBefore(pd->getLocation(), "CF_CONSUMED ");
1617  Editor->commit(commit);
1618  }
1619  }
1620 }
1621 
1622 void ObjCMigrateASTConsumer::migrateAddMethodAnnotation(
1623  ASTContext &Ctx,
1624  const ObjCMethodDecl *MethodDecl) {
1625  if (MethodDecl->hasBody() || MethodDecl->isImplicit())
1626  return;
1627 
1628  const RetainSummary *RS =
1629  getSummaryManager(Ctx).getSummary(AnyCall(MethodDecl));
1630 
1631  bool MethodIsReturnAnnotated =
1632  (MethodDecl->hasAttr<CFReturnsRetainedAttr>() ||
1633  MethodDecl->hasAttr<CFReturnsNotRetainedAttr>() ||
1634  MethodDecl->hasAttr<NSReturnsRetainedAttr>() ||
1635  MethodDecl->hasAttr<NSReturnsNotRetainedAttr>() ||
1636  MethodDecl->hasAttr<NSReturnsAutoreleasedAttr>());
1637 
1638  if (RS->getReceiverEffect().getKind() == DecRef &&
1639  !MethodDecl->hasAttr<NSConsumesSelfAttr>() &&
1640  MethodDecl->getMethodFamily() != OMF_init &&
1641  MethodDecl->getMethodFamily() != OMF_release &&
1642  NSAPIObj->isMacroDefined("NS_CONSUMES_SELF")) {
1643  edit::Commit commit(*Editor);
1644  commit.insertBefore(MethodDecl->getEndLoc(), " NS_CONSUMES_SELF");
1645  Editor->commit(commit);
1646  }
1647 
1648  // Trivial case of when function is annotated and has no argument.
1649  if (MethodIsReturnAnnotated &&
1650  (MethodDecl->param_begin() == MethodDecl->param_end()))
1651  return;
1652 
1653  if (!MethodIsReturnAnnotated) {
1654  RetEffect Ret = RS->getRetEffect();
1655  if ((Ret.getObjKind() == ObjKind::CF ||
1656  Ret.getObjKind() == ObjKind::ObjC) &&
1657  (Ret.isOwned() || Ret.notOwned())) {
1658  AddCFAnnotations(Ctx, RS, MethodDecl, false);
1659  return;
1660  } else if (!AuditedType(MethodDecl->getReturnType()))
1661  return;
1662  }
1663 
1664  // At this point result type is either annotated or audited.
1665  unsigned i = 0;
1666  for (ObjCMethodDecl::param_const_iterator pi = MethodDecl->param_begin(),
1667  pe = MethodDecl->param_end(); pi != pe; ++pi, ++i) {
1668  const ParmVarDecl *pd = *pi;
1669  ArgEffect AE = RS->getArg(i);
1670  if ((AE.getKind() == DecRef && !pd->hasAttr<CFConsumedAttr>()) ||
1671  AE.getKind() == IncRef || !AuditedType(pd->getType())) {
1672  AddCFAnnotations(Ctx, RS, MethodDecl, MethodIsReturnAnnotated);
1673  return;
1674  }
1675  }
1676 }
1677 
1678 namespace {
1679 class SuperInitChecker : public RecursiveASTVisitor<SuperInitChecker> {
1680 public:
1681  bool shouldVisitTemplateInstantiations() const { return false; }
1682  bool shouldWalkTypesOfTypeLocs() const { return false; }
1683 
1684  bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
1686  if (E->getMethodFamily() == OMF_init)
1687  return false;
1688  }
1689  return true;
1690  }
1691 };
1692 } // end anonymous namespace
1693 
1694 static bool hasSuperInitCall(const ObjCMethodDecl *MD) {
1695  return !SuperInitChecker().TraverseStmt(MD->getBody());
1696 }
1697 
1698 void ObjCMigrateASTConsumer::inferDesignatedInitializers(
1699  ASTContext &Ctx,
1700  const ObjCImplementationDecl *ImplD) {
1701 
1702  const ObjCInterfaceDecl *IFace = ImplD->getClassInterface();
1703  if (!IFace || IFace->hasDesignatedInitializers())
1704  return;
1705  if (!NSAPIObj->isMacroDefined("NS_DESIGNATED_INITIALIZER"))
1706  return;
1707 
1708  for (const auto *MD : ImplD->instance_methods()) {
1709  if (MD->isDeprecated() ||
1710  MD->getMethodFamily() != OMF_init ||
1711  MD->isDesignatedInitializerForTheInterface())
1712  continue;
1713  const ObjCMethodDecl *IFaceM = IFace->getMethod(MD->getSelector(),
1714  /*isInstance=*/true);
1715  if (!IFaceM)
1716  continue;
1717  if (hasSuperInitCall(MD)) {
1718  edit::Commit commit(*Editor);
1719  commit.insert(IFaceM->getEndLoc(), " NS_DESIGNATED_INITIALIZER");
1720  Editor->commit(commit);
1721  }
1722  }
1723 }
1724 
1725 bool ObjCMigrateASTConsumer::InsertFoundation(ASTContext &Ctx,
1726  SourceLocation Loc) {
1727  if (FoundationIncluded)
1728  return true;
1729  if (Loc.isInvalid())
1730  return false;
1731  auto *nsEnumId = &Ctx.Idents.get("NS_ENUM");
1732  if (PP.getMacroDefinitionAtLoc(nsEnumId, Loc)) {
1733  FoundationIncluded = true;
1734  return true;
1735  }
1736  edit::Commit commit(*Editor);
1737  if (Ctx.getLangOpts().Modules)
1738  commit.insert(Loc, "#ifndef NS_ENUM\n@import Foundation;\n#endif\n");
1739  else
1740  commit.insert(Loc, "#ifndef NS_ENUM\n#import <Foundation/Foundation.h>\n#endif\n");
1741  Editor->commit(commit);
1742  FoundationIncluded = true;
1743  return true;
1744 }
1745 
1746 namespace {
1747 
1748 class RewritesReceiver : public edit::EditsReceiver {
1749  Rewriter &Rewrite;
1750 
1751 public:
1752  RewritesReceiver(Rewriter &Rewrite) : Rewrite(Rewrite) { }
1753 
1754  void insert(SourceLocation loc, StringRef text) override {
1755  Rewrite.InsertText(loc, text);
1756  }
1757  void replace(CharSourceRange range, StringRef text) override {
1758  Rewrite.ReplaceText(range.getBegin(), Rewrite.getRangeSize(range), text);
1759  }
1760 };
1761 
1762 class JSONEditWriter : public edit::EditsReceiver {
1763  SourceManager &SourceMgr;
1764  llvm::raw_ostream &OS;
1765 
1766 public:
1767  JSONEditWriter(SourceManager &SM, llvm::raw_ostream &OS)
1768  : SourceMgr(SM), OS(OS) {
1769  OS << "[\n";
1770  }
1771  ~JSONEditWriter() override { OS << "]\n"; }
1772 
1773 private:
1774  struct EntryWriter {
1775  SourceManager &SourceMgr;
1776  llvm::raw_ostream &OS;
1777 
1778  EntryWriter(SourceManager &SM, llvm::raw_ostream &OS)
1779  : SourceMgr(SM), OS(OS) {
1780  OS << " {\n";
1781  }
1782  ~EntryWriter() {
1783  OS << " },\n";
1784  }
1785 
1786  void writeLoc(SourceLocation Loc) {
1787  FileID FID;
1788  unsigned Offset;
1789  std::tie(FID, Offset) = SourceMgr.getDecomposedLoc(Loc);
1790  assert(FID.isValid());
1791  SmallString<200> Path =
1792  StringRef(SourceMgr.getFileEntryForID(FID)->getName());
1793  llvm::sys::fs::make_absolute(Path);
1794  OS << " \"file\": \"";
1795  OS.write_escaped(Path.str()) << "\",\n";
1796  OS << " \"offset\": " << Offset << ",\n";
1797  }
1798 
1799  void writeRemove(CharSourceRange Range) {
1800  assert(Range.isCharRange());
1801  std::pair<FileID, unsigned> Begin =
1802  SourceMgr.getDecomposedLoc(Range.getBegin());
1803  std::pair<FileID, unsigned> End =
1804  SourceMgr.getDecomposedLoc(Range.getEnd());
1805  assert(Begin.first == End.first);
1806  assert(Begin.second <= End.second);
1807  unsigned Length = End.second - Begin.second;
1808 
1809  OS << " \"remove\": " << Length << ",\n";
1810  }
1811 
1812  void writeText(StringRef Text) {
1813  OS << " \"text\": \"";
1814  OS.write_escaped(Text) << "\",\n";
1815  }
1816  };
1817 
1818  void insert(SourceLocation Loc, StringRef Text) override {
1819  EntryWriter Writer(SourceMgr, OS);
1820  Writer.writeLoc(Loc);
1821  Writer.writeText(Text);
1822  }
1823 
1824  void replace(CharSourceRange Range, StringRef Text) override {
1825  EntryWriter Writer(SourceMgr, OS);
1826  Writer.writeLoc(Range.getBegin());
1827  Writer.writeRemove(Range);
1828  Writer.writeText(Text);
1829  }
1830 
1831  void remove(CharSourceRange Range) override {
1832  EntryWriter Writer(SourceMgr, OS);
1833  Writer.writeLoc(Range.getBegin());
1834  Writer.writeRemove(Range);
1835  }
1836 };
1837 
1838 } // end anonymous namespace
1839 
1840 void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
1841 
1843  if (ASTMigrateActions & FrontendOptions::ObjCMT_MigrateDecls) {
1844  for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end();
1845  D != DEnd; ++D) {
1846  FileID FID = PP.getSourceManager().getFileID((*D)->getLocation());
1847  if (FID.isValid())
1848  if (FileId.isValid() && FileId != FID) {
1849  if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)
1850  AnnotateImplicitBridging(Ctx);
1851  }
1852 
1853  if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
1854  if (canModify(CDecl))
1855  migrateObjCContainerDecl(Ctx, CDecl);
1856  if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) {
1857  if (canModify(CatDecl))
1858  migrateObjCContainerDecl(Ctx, CatDecl);
1859  }
1860  else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D)) {
1861  ObjCProtocolDecls.insert(PDecl->getCanonicalDecl());
1862  if (canModify(PDecl))
1863  migrateObjCContainerDecl(Ctx, PDecl);
1864  }
1865  else if (const ObjCImplementationDecl *ImpDecl =
1866  dyn_cast<ObjCImplementationDecl>(*D)) {
1867  if ((ASTMigrateActions & FrontendOptions::ObjCMT_ProtocolConformance) &&
1868  canModify(ImpDecl))
1869  migrateProtocolConformance(Ctx, ImpDecl);
1870  }
1871  else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*D)) {
1872  if (!(ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros))
1873  continue;
1874  if (!canModify(ED))
1875  continue;
1877  if (++N != DEnd) {
1878  const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N);
1879  if (migrateNSEnumDecl(Ctx, ED, TD) && TD)
1880  D++;
1881  }
1882  else
1883  migrateNSEnumDecl(Ctx, ED, /*TypedefDecl */nullptr);
1884  }
1885  else if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*D)) {
1886  if (!(ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros))
1887  continue;
1888  if (!canModify(TD))
1889  continue;
1891  if (++N == DEnd)
1892  continue;
1893  if (const EnumDecl *ED = dyn_cast<EnumDecl>(*N)) {
1894  if (canModify(ED)) {
1895  if (++N != DEnd)
1896  if (const TypedefDecl *TDF = dyn_cast<TypedefDecl>(*N)) {
1897  // prefer typedef-follows-enum to enum-follows-typedef pattern.
1898  if (migrateNSEnumDecl(Ctx, ED, TDF)) {
1899  ++D; ++D;
1900  CacheObjCNSIntegerTypedefed(TD);
1901  continue;
1902  }
1903  }
1904  if (migrateNSEnumDecl(Ctx, ED, TD)) {
1905  ++D;
1906  continue;
1907  }
1908  }
1909  }
1910  CacheObjCNSIntegerTypedefed(TD);
1911  }
1912  else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D)) {
1913  if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) &&
1914  canModify(FD))
1915  migrateCFAnnotation(Ctx, FD);
1916  }
1917 
1918  if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D)) {
1919  bool CanModify = canModify(CDecl);
1920  // migrate methods which can have instancetype as their result type.
1921  if ((ASTMigrateActions & FrontendOptions::ObjCMT_Instancetype) &&
1922  CanModify)
1923  migrateAllMethodInstaceType(Ctx, CDecl);
1924  // annotate methods with CF annotations.
1925  if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) &&
1926  CanModify)
1927  migrateARCSafeAnnotation(Ctx, CDecl);
1928  }
1929 
1930  if (const ObjCImplementationDecl *
1931  ImplD = dyn_cast<ObjCImplementationDecl>(*D)) {
1932  if ((ASTMigrateActions & FrontendOptions::ObjCMT_DesignatedInitializer) &&
1933  canModify(ImplD))
1934  inferDesignatedInitializers(Ctx, ImplD);
1935  }
1936  }
1937  if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)
1938  AnnotateImplicitBridging(Ctx);
1939  }
1940 
1941  if (IsOutputFile) {
1942  std::error_code EC;
1943  llvm::raw_fd_ostream OS(MigrateDir, EC, llvm::sys::fs::OF_None);
1944  if (EC) {
1945  DiagnosticsEngine &Diags = Ctx.getDiagnostics();
1946  Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
1947  << EC.message();
1948  return;
1949  }
1950 
1951  JSONEditWriter Writer(Ctx.getSourceManager(), OS);
1952  Editor->applyRewrites(Writer);
1953  return;
1954  }
1955 
1956  Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
1957  RewritesReceiver Rec(rewriter);
1958  Editor->applyRewrites(Rec);
1959 
1961  I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
1962  FileID FID = I->first;
1963  RewriteBuffer &buf = I->second;
1965  assert(file);
1966  SmallString<512> newText;
1967  llvm::raw_svector_ostream vecOS(newText);
1968  buf.write(vecOS);
1969  std::unique_ptr<llvm::MemoryBuffer> memBuf(
1970  llvm::MemoryBuffer::getMemBufferCopy(
1971  StringRef(newText.data(), newText.size()), file->getName()));
1972  SmallString<64> filePath(file->getName());
1973  FileMgr.FixupRelativePath(filePath);
1974  Remapper.remap(filePath.str(), std::move(memBuf));
1975  }
1976 
1977  if (IsOutputFile) {
1978  Remapper.flushToFile(MigrateDir, Ctx.getDiagnostics());
1979  } else {
1980  Remapper.flushToDisk(MigrateDir, Ctx.getDiagnostics());
1981  }
1982 }
1983 
1986  return true;
1987 }
1988 
1989 static std::vector<std::string> getAllowListFilenames(StringRef DirPath) {
1990  using namespace llvm::sys::fs;
1991  using namespace llvm::sys::path;
1992 
1993  std::vector<std::string> Filenames;
1994  if (DirPath.empty() || !is_directory(DirPath))
1995  return Filenames;
1996 
1997  std::error_code EC;
1998  directory_iterator DI = directory_iterator(DirPath, EC);
1999  directory_iterator DE;
2000  for (; !EC && DI != DE; DI = DI.increment(EC)) {
2001  if (is_regular_file(DI->path()))
2002  Filenames.push_back(std::string(filename(DI->path())));
2003  }
2004 
2005  return Filenames;
2006 }
2007 
2008 std::unique_ptr<ASTConsumer>
2012  unsigned ObjCMTAction = CI.getFrontendOpts().ObjCMTAction;
2013  unsigned ObjCMTOpts = ObjCMTAction;
2014  // These are companion flags, they do not enable transformations.
2015  ObjCMTOpts &= ~(FrontendOptions::ObjCMT_AtomicProperty |
2017  if (ObjCMTOpts == FrontendOptions::ObjCMT_None) {
2018  // If no specific option was given, enable literals+subscripting transforms
2019  // by default.
2020  ObjCMTAction |=
2022  }
2023  CI.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(PPRec));
2024  std::vector<std::string> AllowList =
2026  return std::make_unique<ObjCMigrateASTConsumer>(
2027  CI.getFrontendOpts().OutputFile, ObjCMTAction, Remapper,
2028  CI.getFileManager(), PPRec, CI.getPreprocessor(),
2029  /*isOutputFile=*/true, AllowList);
2030 }
2031 
2032 namespace {
2033 struct EditEntry {
2035  unsigned Offset = 0;
2036  unsigned RemoveLen = 0;
2037  std::string Text;
2038 };
2039 } // end anonymous namespace
2040 
2041 namespace llvm {
2042 template<> struct DenseMapInfo<EditEntry> {
2043  static inline EditEntry getEmptyKey() {
2044  EditEntry Entry;
2045  Entry.Offset = unsigned(-1);
2046  return Entry;
2047  }
2048  static inline EditEntry getTombstoneKey() {
2049  EditEntry Entry;
2050  Entry.Offset = unsigned(-2);
2051  return Entry;
2052  }
2053  static unsigned getHashValue(const EditEntry& Val) {
2054  return (unsigned)llvm::hash_combine(Val.File, Val.Offset, Val.RemoveLen,
2055  Val.Text);
2056  }
2057  static bool isEqual(const EditEntry &LHS, const EditEntry &RHS) {
2058  return LHS.File == RHS.File &&
2059  LHS.Offset == RHS.Offset &&
2060  LHS.RemoveLen == RHS.RemoveLen &&
2061  LHS.Text == RHS.Text;
2062  }
2063 };
2064 } // end namespace llvm
2065 
2066 namespace {
2067 class RemapFileParser {
2068  FileManager &FileMgr;
2069 
2070 public:
2071  RemapFileParser(FileManager &FileMgr) : FileMgr(FileMgr) { }
2072 
2073  bool parse(StringRef File, SmallVectorImpl<EditEntry> &Entries) {
2074  using namespace llvm::yaml;
2075 
2076  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
2077  llvm::MemoryBuffer::getFile(File);
2078  if (!FileBufOrErr)
2079  return true;
2080 
2081  llvm::SourceMgr SM;
2082  Stream YAMLStream(FileBufOrErr.get()->getMemBufferRef(), SM);
2083  document_iterator I = YAMLStream.begin();
2084  if (I == YAMLStream.end())
2085  return true;
2086  Node *Root = I->getRoot();
2087  if (!Root)
2088  return true;
2089 
2090  SequenceNode *SeqNode = dyn_cast<SequenceNode>(Root);
2091  if (!SeqNode)
2092  return true;
2093 
2094  for (SequenceNode::iterator
2095  AI = SeqNode->begin(), AE = SeqNode->end(); AI != AE; ++AI) {
2096  MappingNode *MapNode = dyn_cast<MappingNode>(&*AI);
2097  if (!MapNode)
2098  continue;
2099  parseEdit(MapNode, Entries);
2100  }
2101 
2102  return false;
2103  }
2104 
2105 private:
2106  void parseEdit(llvm::yaml::MappingNode *Node,
2107  SmallVectorImpl<EditEntry> &Entries) {
2108  using namespace llvm::yaml;
2109  EditEntry Entry;
2110  bool Ignore = false;
2111 
2112  for (MappingNode::iterator
2113  KVI = Node->begin(), KVE = Node->end(); KVI != KVE; ++KVI) {
2114  ScalarNode *KeyString = dyn_cast<ScalarNode>((*KVI).getKey());
2115  if (!KeyString)
2116  continue;
2117  SmallString<10> KeyStorage;
2118  StringRef Key = KeyString->getValue(KeyStorage);
2119 
2120  ScalarNode *ValueString = dyn_cast<ScalarNode>((*KVI).getValue());
2121  if (!ValueString)
2122  continue;
2123  SmallString<64> ValueStorage;
2124  StringRef Val = ValueString->getValue(ValueStorage);
2125 
2126  if (Key == "file") {
2127  if (auto File = FileMgr.getOptionalFileRef(Val))
2128  Entry.File = File;
2129  else
2130  Ignore = true;
2131  } else if (Key == "offset") {
2132  if (Val.getAsInteger(10, Entry.Offset))
2133  Ignore = true;
2134  } else if (Key == "remove") {
2135  if (Val.getAsInteger(10, Entry.RemoveLen))
2136  Ignore = true;
2137  } else if (Key == "text") {
2138  Entry.Text = std::string(Val);
2139  }
2140  }
2141 
2142  if (!Ignore)
2143  Entries.push_back(Entry);
2144  }
2145 };
2146 } // end anonymous namespace
2147 
2148 static bool reportDiag(const Twine &Err, DiagnosticsEngine &Diag) {
2149  Diag.Report(Diag.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
2150  << Err.str();
2151  return true;
2152 }
2153 
2155  ArrayRef<EditEntry> Edits,
2156  FileManager &FileMgr,
2158  using namespace llvm::sys;
2159 
2160  SourceManager SM(Diag, FileMgr);
2161  FileID FID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User);
2162  LangOptions LangOpts;
2163  edit::EditedSource Editor(SM, LangOpts);
2165  I = Edits.begin(), E = Edits.end(); I != E; ++I) {
2166  const EditEntry &Entry = *I;
2167  assert(Entry.File == FE);
2169  SM.getLocForStartOfFile(FID).getLocWithOffset(Entry.Offset);
2171  if (Entry.RemoveLen != 0) {
2173  Loc.getLocWithOffset(Entry.RemoveLen));
2174  }
2175 
2176  edit::Commit commit(Editor);
2177  if (Range.isInvalid()) {
2178  commit.insert(Loc, Entry.Text);
2179  } else if (Entry.Text.empty()) {
2180  commit.remove(Range);
2181  } else {
2182  commit.replace(Range, Entry.Text);
2183  }
2184  Editor.commit(commit);
2185  }
2186 
2187  Rewriter rewriter(SM, LangOpts);
2188  RewritesReceiver Rec(rewriter);
2189  Editor.applyRewrites(Rec, /*adjustRemovals=*/false);
2190 
2191  const RewriteBuffer *Buf = rewriter.getRewriteBufferFor(FID);
2192  SmallString<512> NewText;
2193  llvm::raw_svector_ostream OS(NewText);
2194  Buf->write(OS);
2195 
2196  SmallString<64> TempPath;
2197  int FD;
2198  if (fs::createTemporaryFile(path::filename(FE.getName()),
2199  path::extension(FE.getName()).drop_front(), FD,
2200  TempPath)) {
2201  reportDiag("Could not create file: " + TempPath.str(), Diag);
2202  return std::string();
2203  }
2204 
2205  llvm::raw_fd_ostream TmpOut(FD, /*shouldClose=*/true);
2206  TmpOut.write(NewText.data(), NewText.size());
2207  TmpOut.close();
2208 
2209  return std::string(TempPath.str());
2210 }
2211 
2213  std::vector<std::pair<std::string,std::string> > &remap,
2214  ArrayRef<StringRef> remapFiles,
2215  DiagnosticConsumer *DiagClient) {
2216  bool hasErrorOccurred = false;
2217 
2218  FileSystemOptions FSOpts;
2219  FileManager FileMgr(FSOpts);
2220  RemapFileParser Parser(FileMgr);
2221 
2224  new DiagnosticsEngine(DiagID, new DiagnosticOptions,
2225  DiagClient, /*ShouldOwnClient=*/false));
2226 
2227  typedef llvm::DenseMap<FileEntryRef, std::vector<EditEntry> >
2228  FileEditEntriesTy;
2229  FileEditEntriesTy FileEditEntries;
2230 
2231  llvm::DenseSet<EditEntry> EntriesSet;
2232 
2234  I = remapFiles.begin(), E = remapFiles.end(); I != E; ++I) {
2236  if (Parser.parse(*I, Entries))
2237  continue;
2238 
2240  EI = Entries.begin(), EE = Entries.end(); EI != EE; ++EI) {
2241  EditEntry &Entry = *EI;
2242  if (!Entry.File)
2243  continue;
2244  std::pair<llvm::DenseSet<EditEntry>::iterator, bool>
2245  Insert = EntriesSet.insert(Entry);
2246  if (!Insert.second)
2247  continue;
2248 
2249  FileEditEntries[*Entry.File].push_back(Entry);
2250  }
2251  }
2252 
2253  for (FileEditEntriesTy::iterator
2254  I = FileEditEntries.begin(), E = FileEditEntries.end(); I != E; ++I) {
2255  std::string TempFile = applyEditsToTemp(I->first, I->second,
2256  FileMgr, *Diags);
2257  if (TempFile.empty()) {
2258  hasErrorOccurred = true;
2259  continue;
2260  }
2261 
2262  remap.emplace_back(std::string(I->first.getName()), TempFile);
2263  }
2264 
2265  return hasErrorOccurred;
2266 }
clang::ObjCMessageExpr::SuperInstance
@ SuperInstance
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1097
clang::FileManager::getOptionalFileRef
llvm::Optional< FileEntryRef > getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:234
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
NSAPI.h
clang::comments::tok::text
@ text
Definition: CommentLexer.h:35
clang::ASTContext::getQualifiedType
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2126
clang::QualType::getObjCLifetime
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1128
clang::Type::isRealType
bool isRealType() const
Definition: Type.cpp:2143
clang::DeclContext::decls_end
decl_iterator decls_end() const
Definition: DeclBase.h:2133
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::Decl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:417
clang::FrontendOptions::ObjCMT_ReadonlyProperty
@ ObjCMT_ReadonlyProperty
Enable migration to modern ObjC readonly property.
Definition: FrontendOptions.h:372
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3442
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6756
clang::FileEntryRef
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition: FileEntry.h:60
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6482
clang::ASTContext::getObjCInstanceType
QualType getObjCInstanceType()
Retrieve the Objective-C "instancetype" type, if already known; otherwise, returns a NULL type;.
Definition: ASTContext.h:1914
clang::FrontendOptions::ObjCMT_None
@ ObjCMT_None
Definition: FrontendOptions.h:363
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2557
clang::Decl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:421
clang::DeclaratorContext::File
@ File
clang::Type::isObjCRetainableType
bool isObjCRetainableType() const
Definition: Type.cpp:4335
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::ObjCMethodFamily
ObjCMethodFamily
A family of Objective-C methods.
Definition: IdentifierTable.h:690
Ret
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:542
clang::edit::Commit::insertWrap
bool insertWrap(StringRef before, CharSourceRange range, StringRef after)
Definition: Commit.cpp:103
clang::edit::Commit::insertFromRange
bool insertFromRange(SourceLocation loc, CharSourceRange range, bool afterToken=false, bool beforePreviousInsertions=false)
Definition: Commit.cpp:64
reportDiag
static bool reportDiag(const Twine &Err, DiagnosticsEngine &Diag)
Definition: ObjCMT.cpp:2148
clang::ObjCMethodDecl::getDeclaratorEndLoc
SourceLocation getDeclaratorEndLoc() const
Returns the location where the declarator ends.
Definition: DeclObjC.h:282
clang::ObjCImplementationDecl
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2548
llvm::DenseMapInfo< EditEntry >::isEqual
static bool isEqual(const EditEntry &LHS, const EditEntry &RHS)
Definition: ObjCMT.cpp:2057
clang::EnumDecl::enumerators
enumerator_range enumerators() const
Definition: Decl.h:3761
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:78
Transforms.h
clang::Qualifiers::OCL_Weak
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:178
clang::Token::getLiteralData
const char * getLiteralData() const
getLiteralData - For a literal token (numeric constant, string, etc), this returns a pointer to the s...
Definition: Token.h:216
getAllowListFilenames
static std::vector< std::string > getAllowListFilenames(StringRef DirPath)
Definition: ObjCMT.cpp:1989
llvm::SmallVector
Definition: LLVM.h:38
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:596
clang::DiagnosticsEngine::setIgnoreAllWarnings
void setIgnoreAllWarnings(bool Val)
When set to true, any unmapped warnings are ignored.
Definition: Diagnostic.h:644
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::QualType::getQualifiers
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6527
clang::ObjCMessageExpr::getSelectorLoc
SourceLocation getSelectorLoc(unsigned Index) const
Definition: ExprObjC.h:1415
clang::ObjCInterfaceDecl::hasDesignatedInitializers
bool hasDesignatedInitializers() const
Returns true if this interface decl contains at least one initializer marked with the 'objc_designate...
Definition: DeclObjC.cpp:1573
clang::OMF_release
@ OMF_release
Definition: IdentifierTable.h:709
llvm::DenseMapInfo< EditEntry >::getEmptyKey
static EditEntry getEmptyKey()
Definition: ObjCMT.cpp:2043
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:219
ARCMT.h
clang::edit::Commit::insert
bool insert(SourceLocation loc, StringRef text, bool afterToken=false, bool beforePreviousInsertions=false)
Definition: Commit.cpp:48
clang::Stmt::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
clang::ento::ArgEffect::getKind
ArgEffectKind getKind() const
Definition: RetainSummaryManager.h:125
clang::ObjCInstanceTypeFamily
ObjCInstanceTypeFamily
A family of Objective-C methods.
Definition: IdentifierTable.h:730
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:675
Attr.h
clang::DiagnosticConsumer
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1738
clang::TypedefNameDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3250
clang::RewriteBuffer::write
raw_ostream & write(raw_ostream &Stream) const
Write to Stream the result of applying all changes to the original buffer.
Definition: Rewriter.cpp:37
clang::OMF_init
@ OMF_init
Definition: IdentifierTable.h:700
clang::edit::Commit::replace
bool replace(CharSourceRange range, StringRef text)
Definition: Commit.cpp:116
clang::TemplateSubstitutionKind::Rewrite
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1680
clang::ObjCContainerDecl::instance_methods
instmeth_range instance_methods() const
Definition: DeclObjC.h:1029
clang::ObjCProtocolDecl::getCanonicalDecl
ObjCProtocolDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C protocol.
Definition: DeclObjC.h:2246
clang::ObjCMethodDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1176
clang::Parser
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:60
clang::ObjCMessageExpr::getInstanceReceiver
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Definition: ExprObjC.h:1250
clang::DeclGroupRef::begin
iterator begin()
Definition: DeclGroup.h:99
clang::arcmt::FileRemapper::flushToDisk
bool flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag)
Definition: FileRemapper.cpp:109
llvm::Optional< FileEntryRef >
clang::TypeLoc::getEndLoc
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:228
clang::ObjCMethodDecl::param_end
param_const_iterator param_end() const
Definition: DeclObjC.h:361
llvm::SmallPtrSet
Definition: ASTContext.h:82
clang::QualType::getAsString
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1023
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:7037
IsVoidStarType
static bool IsVoidStarType(QualType Ty)
Definition: ObjCMT.cpp:1355
clang::FrontendOptions::ObjCMT_ProtocolConformance
@ ObjCMT_ProtocolConformance
Enable migration to add conforming protocols.
Definition: FrontendOptions.h:390
clang::tooling::X
static ToolExecutorPluginRegistry::Add< AllTUsToolExecutorPlugin > X("all-TUs", "Runs FrontendActions on all TUs in the compilation database. " "Tool results are stored in memory.")
clang::toLowercase
LLVM_READONLY char toLowercase(char c)
Converts the given ASCII character to its lowercase equivalent.
Definition: CharInfo.h:208
subscriptOperatorNeedsParens
static bool subscriptOperatorNeedsParens(const Expr *FullExpr)
Definition: RewriteObjCFoundationAPI.cpp:891
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
clang::DeclGroupRef::end
iterator end()
Definition: DeclGroup.h:105
clang::DeclarationName::getAsIdentifierInfo
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
Definition: DeclarationName.h:419
clang::edit::Commit::insertAfterToken
bool insertAfterToken(SourceLocation loc, StringRef text, bool beforePreviousInsertions=false)
Definition: Commit.h:73
clang::IdentifierInfo::getTokenID
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
Definition: IdentifierTable.h:261
clang::Decl::isDeprecated
bool isDeprecated(std::string *Message=nullptr) const
Determine whether this declaration is marked 'deprecated'.
Definition: DeclBase.h:694
clang::ObjCPropertyDecl::Optional
@ Optional
Definition: DeclObjC.h:737
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
EditsReceiver.h
clang::Expr::IgnoreImpCasts
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:2927
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition: ASTContext.h:716
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1078
clang::arcmt::trans::findLocationAfterSemi
SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
'Loc' is the end of a statement range.
Definition: Transforms.cpp:116
clang::edit::EditedSource::applyRewrites
void applyRewrites(EditsReceiver &receiver, bool adjustRemovals=true)
Definition: EditedSource.cpp:409
clang::edit::EditsReceiver
Definition: EditsReceiver.h:19
clang::NSAPI::getASTContext
ASTContext & getASTContext() const
Definition: NSAPI.h:27
clang::Preprocessor::getIdentifierTable
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:1001
rewriteToNSEnumDecl
static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl, const NSAPI &NS, edit::Commit &commit, StringRef NSIntegerName, bool NSOptions)
Definition: ObjCMT.cpp:705
clang::ObjCImplDecl::getClassInterface
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2436
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:627
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3628
Preprocessor.h
clang::edit::EditedSource
Definition: EditedSource.h:35
clang::TypedefType
Definition: Type.h:4405
clang::FullExpr
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:1004
Offset
unsigned Offset
Definition: Format.cpp:2553
clang::FileSystemOptions
Keeps track of options that affect how file operations are performed.
Definition: FileSystemOptions.h:22
clang::TypeLoc::getBeginLoc
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:191
clang::Type::isObjCBuiltinType
bool isObjCBuiltinType() const
Definition: Type.h:6927
clang::arcmt::FileRemapper::initFromDisk
bool initFromDisk(StringRef outputDir, DiagnosticsEngine &Diag, bool ignoreIfFilesChanged)
Definition: FileRemapper.cpp:49
TypeIsInnerPointer
static bool TypeIsInnerPointer(QualType T)
Definition: ObjCMT.cpp:1046
clang::OIT_ReturnsSelf
@ OIT_ReturnsSelf
Definition: IdentifierTable.h:736
clang::ObjCMethodDecl::param_const_iterator
const ParmVarDecl *const * param_const_iterator
Definition: DeclObjC.h:352
clang::OMF_copy
@ OMF_copy
Definition: IdentifierTable.h:699
clang::Preprocessor::getMacroDefinitionAtLoc
MacroDefinition getMacroDefinitionAtLoc(const IdentifierInfo *II, SourceLocation Loc)
Definition: Preprocessor.h:1159
clang::CharSourceRange::getCharRange
static CharSourceRange getCharRange(SourceRange R)
Definition: SourceLocation.h:265
clang::ObjCInterfaceDecl::lookupNestedProtocol
ObjCProtocolDecl * lookupNestedProtocol(IdentifierInfo *Name)
Definition: DeclObjC.cpp:680
clang::CompilerInstance::getFileManager
FileManager & getFileManager() const
Return the current file manager to the caller.
Definition: CompilerInstance.h:402
clang::OIT_Dictionary
@ OIT_Dictionary
Definition: IdentifierTable.h:733
clang::ASTContext::CollectInheritedProtocols
void CollectInheritedProtocols(const Decl *CDecl, llvm::SmallPtrSet< ObjCProtocolDecl *, 8 > &Protocols)
CollectInheritedProtocols - Collect all protocols in current class and those inherited by it.
Definition: ASTContext.cpp:2616
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:80
clang::OIT_Array
@ OIT_Array
Definition: IdentifierTable.h:732
clang::ast_matchers::attr
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
Definition: ASTMatchersInternal.cpp:1030
clang::ObjCMessageExpr::children
child_range children()
Definition: ExprObjC.cpp:326
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4647
clang::Selector::getInstTypeMethodFamily
static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel)
Definition: IdentifierTable.cpp:617
clang::AnyCall
An instance of this class corresponds to a call.
Definition: AnyCall.h:25
IsValidIdentifier
static bool IsValidIdentifier(ASTContext &Ctx, const char *Name)
Definition: ObjCMT.cpp:1144
clang::arcmt::trans::findSemiAfterLocation
SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
'Loc' is the end of a statement range.
Definition: Transforms.cpp:128
clang::ento::Range
A Range represents the closed range [from, to].
Definition: RangedConstraintManager.h:29
clang::Selector::getNameForSlot
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
Definition: IdentifierTable.cpp:514
llvm::DenseMapInfo< EditEntry >::getHashValue
static unsigned getHashValue(const EditEntry &Val)
Definition: ObjCMT.cpp:2053
Node
DynTypedNode Node
Definition: ASTMatchFinder.cpp:68
clang::FunctionDecl::param_end
param_iterator param_end()
Definition: Decl.h:2516
clang::FrontendOptions::OutputFile
std::string OutputFile
The output file, if any.
Definition: FrontendOptions.h:433
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3807
clang::Qualifiers::OCL_Strong
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:175
MatchTwoAttributeLists
static bool MatchTwoAttributeLists(const AttrVec &Attrs1, const AttrVec &Attrs2, bool &AvailabilityArgsMatch)
Definition: ObjCMT.cpp:1100
clang::Type::isObjCIdType
bool isObjCIdType() const
Definition: Type.h:6909
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:220
clang::Type::isFunctionPointerType
bool isFunctionPointerType() const
Definition: Type.h:6782
clang::OIT_Init
@ OIT_Init
Definition: IdentifierTable.h:735
clang::ObjCMethodDecl::getMethodFamily
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Definition: DeclObjC.cpp:1018
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:208
applyEditsToTemp
static std::string applyEditsToTemp(FileEntryRef FE, ArrayRef< EditEntry > Edits, FileManager &FileMgr, DiagnosticsEngine &Diag)
Definition: ObjCMT.cpp:2154
AvailabilityAttrsMatch
static bool AvailabilityAttrsMatch(Attr *At1, Attr *At2)
AvailabilityAttrsMatch - This routine checks that if comparing two availability attributes,...
Definition: ObjCMT.cpp:1080
rewriteToNSMacroDecl
static void rewriteToNSMacroDecl(ASTContext &Ctx, const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl, const NSAPI &NS, edit::Commit &commit, bool IsNSIntegerType)
Definition: ObjCMT.cpp:759
clang::FrontendOptions::ObjCMT_Instancetype
@ ObjCMT_Instancetype
Enable migration of ObjC methods to 'instancetype'.
Definition: FrontendOptions.h:384
clang::FileID::isValid
bool isValid() const
Definition: SourceLocation.h:44
clang::arcmt::FileRemapper
Definition: FileRemapper.h:32
clang::RecursiveASTVisitor
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Definition: RecursiveASTVisitor.h:165
clang::Preprocessor::getSelectorTable
SelectorTable & getSelectorTable()
Definition: Preprocessor.h:1003
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7243
clang::DiagnosticsEngine::Error
@ Error
Definition: Diagnostic.h:200
clang::ObjCContainerDecl::methods
method_range methods() const
Definition: DeclObjC.h:1012
clang::ASTConsumer
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:33
clang::ento::RetainSummary::getRetEffect
RetEffect getRetEffect() const
getRetEffect - Returns the effect on the return value of the call.
Definition: RetainSummaryManager.h:331
clang::ObjCInterfaceDecl::getReferencedProtocols
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1319
clang::ObjCMethodDecl::getSelector
Selector getSelector() const
Definition: DeclObjC.h:330
clang::ObjCMethodDecl::getSelectorStartLoc
SourceLocation getSelectorStartLoc() const
Definition: DeclObjC.h:291
clang::ObjCMessageExpr::getReceiverKind
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition: ExprObjC.h:1224
clang::DeclContext::decl_iterator
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:2088
clang::ento::RetainSummary::getReceiverEffect
ArgEffect getReceiverEffect() const
getReceiverEffect - Returns the effect on the receiver of the call.
Definition: RetainSummaryManager.h:342
clang::NSAPI
Definition: NSAPI.h:23
clang::Stmt::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
GetUnsignedName
static StringRef GetUnsignedName(StringRef NSIntegerName)
Definition: ObjCMT.cpp:694
clang::SourceManager::getFileID
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
Definition: SourceManager.h:1108
Rewriters.h
clang::FileManager::FixupRelativePath
bool FixupRelativePath(SmallVectorImpl< char > &path) const
If path is not absolute and FileSystemOptions set the working directory, the path is modified to be r...
Definition: FileManager.cpp:528
clang::Qualifiers::hasObjCLifetime
bool hasObjCLifetime() const
Definition: Type.h:336
llvm::SmallString
Definition: LLVM.h:37
clang::FrontendOptions::ObjCMTAction
unsigned ObjCMTAction
Definition: FrontendOptions.h:415
ASTContext.h
clang::TypeDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3185
clang::ObjCMethodDecl::getReturnType
QualType getReturnType() const
Definition: DeclObjC.h:332
clang::ObjCProtocolDecl::lookupProtocolNamed
ObjCProtocolDecl * lookupProtocolNamed(IdentifierInfo *PName)
Definition: DeclObjC.cpp:1953
hasSuperInitCall
static bool hasSuperInitCall(const ObjCMethodDecl *MD)
Definition: ObjCMT.cpp:1694
versionsMatch
static bool versionsMatch(const VersionTuple &X, const VersionTuple &Y)
Check whether the two versions match.
Definition: ObjCMT.cpp:1071
clang::ObjCCategoryImplDecl
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2495
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2508
llvm::DenseSet
Definition: Sema.h:77
clang::CompilerInstance::getPreprocessor
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Definition: CompilerInstance.h:442
clang::arcmt::ObjCMigrateAction::BeginInvocation
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
Definition: ObjCMT.cpp:209
clang::DeclContextLookupResult::find_first
T * find_first() const
Definition: DeclBase.h:1330
clang::SrcMgr::C_User
@ C_User
Definition: SourceManager.h:80
clang::ObjCMethodDecl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclObjC.cpp:1012
clang::ObjCMethodDecl::getReturnTypeSourceInfo
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:346
rewriteToObjCProperty
static void rewriteToObjCProperty(const ObjCMethodDecl *Getter, const ObjCMethodDecl *Setter, const NSAPI &NS, edit::Commit &commit, unsigned LengthOfPrefix, bool Atomic, bool UseNsIosOnlyMacro, bool AvailabilityArgsMatch)
Definition: ObjCMT.cpp:455
clang::TagDecl::isCompleteDefinition
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3453
clang::ObjCMethodDecl::Optional
@ Optional
Definition: DeclObjC.h:144
clang::FrontendOptions::ObjCMT_AtomicProperty
@ ObjCMT_AtomicProperty
prefer 'atomic' property over 'nonatomic'.
Definition: FrontendOptions.h:393
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
getKind
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1008
clang::Preprocessor::getRawToken
bool getRawToken(SourceLocation Loc, Token &Result, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
Definition: Preprocessor.h:1866
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:940
clang::SourceManager::getDecomposedLoc
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Definition: SourceManager.h:1241
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:558
clang::FrontendOptions::ObjCMT_Annotation
@ ObjCMT_Annotation
Enable annotation of ObjCMethods of all kinds.
Definition: FrontendOptions.h:381
clang::Qualifiers::ObjCLifetime
ObjCLifetime
Definition: Type.h:162
clang::ento::Loc
Definition: SVals.h:326
clang::format::hash_combine
static void hash_combine(std::size_t &seed, const T &v)
Definition: UnwrappedLineParser.cpp:743
clang::FrontendOptions::ObjCMT_PropertyDotSyntax
@ ObjCMT_PropertyDotSyntax
Enable converting setter/getter expressions to property-dot syntx.
Definition: FrontendOptions.h:405
clang::QualType::getUnqualifiedType
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6580
clang::Token::isLiteral
bool isLiteral() const
Return true if this is a "literal", like a numeric constant, string, etc.
Definition: Token.h:114
clang::Token::getLength
unsigned getLength() const
Definition: Token.h:128
clang::FrontendOptions::ObjCMT_ReturnsInnerPointerProperty
@ ObjCMT_ReturnsInnerPointerProperty
annotate property with NS_RETURNS_INNER_POINTER
Definition: FrontendOptions.h:396
clang::Type::isObjCObjectPointerType
bool isObjCObjectPointerType() const
Definition: Type.h:6876
clang::ObjCInterfaceDecl::lookupInheritedClass
ObjCInterfaceDecl * lookupInheritedClass(const IdentifierInfo *ICName)
lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super class whose name is passe...
Definition: DeclObjC.cpp:661
clang::FunctionDecl::hasBody
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3012
clang::ObjCCategoryDecl
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2276
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:998
AuditedType
static bool AuditedType(QualType AT)
AuditedType - This routine audits the type AT and returns false if it is one of known CF object types...
Definition: ObjCMT.cpp:1372
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7310
clang::FileEntryRef::getName
StringRef getName() const
Definition: FileEntry.h:62
clang::Expr::IgnoreParenCasts
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2952
clang::ObjCObjectPointerType
Represents a pointer to an Objective C object.
Definition: Type.h:6148
clang::transformer::remove
ASTEdit remove(RangeSelector S)
Removes the source selected by S.
Definition: RewriteRule.cpp:146
UseNSOptionsMacro
static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx, const EnumDecl *EnumDcl)
Definition: ObjCMT.cpp:790
clang::ParentMap
Definition: ParentMap.h:20
MigrateBlockOrFunctionPointerTypeVariable
static void MigrateBlockOrFunctionPointerTypeVariable(std::string &PropertyString, const std::string &TypeString, const char *name)
Definition: ObjCMT.cpp:398
clang::FunctionDecl::param_const_iterator
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition: Decl.h:2512
clang::ObjCMessageExpr::getSuperLoc
SourceLocation getSuperLoc() const
Retrieve the location of the 'super' keyword for a class or instance message to 'super',...
Definition: ExprObjC.h:1291
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::PPConditionalDirectiveRecord
Records preprocessor conditional directive regions and allows querying in which region source locatio...
Definition: PPConditionalDirectiveRecord.h:25
PPConditionalDirectiveRecord.h
clang::ento::DecRef
@ DecRef
The argument has its reference count decreased by 1.
Definition: RetainSummaryManager.h:65
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6748
clang::Decl::hasAttrs
bool hasAttrs() const
Definition: DeclBase.h:484
clang::TagDecl::getBraceRange
SourceRange getBraceRange() const
Definition: Decl.h:3429
false
#define false
Definition: stdbool.h:22
clang::edit::Commit
Definition: Commit.h:29
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:268
clang::PrintingPolicy::SuppressLifetimeQualifiers
unsigned SuppressLifetimeQualifiers
When true, suppress printing of lifetime qualifier in ARC.
Definition: PrettyPrinter.h:181
append_attr
static void append_attr(std::string &PropertyString, const char *attr, bool &LParenAdded)
Definition: ObjCMT.cpp:386
AttributeLangSupport::ObjC
@ ObjC
Definition: SemaDeclAttr.cpp:57
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:655
clang::ObjCImplDecl
Definition: DeclObjC.h:2421
clang::ASTContext::getPrintingPolicy
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:708
clang::SelectorTable::constructSetterSelector
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
Definition: IdentifierTable.cpp:694
clang::ObjCMessageExpr::getArgs
Expr ** getArgs()
Retrieve the arguments to this message, not including the receiver.
Definition: ExprObjC.h:1376
ARCMTActions.h
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:740
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
PropertyMemoryAttribute
static const char * PropertyMemoryAttribute(ASTContext &Context, QualType ArgType)
Definition: ObjCMT.cpp:429
llvm::ArrayRef< std::string >
CocoaConventions.h
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
clang::SourceManager::getCharacterData
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer.
Definition: SourceManager.cpp:1152
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:732
clang::ento::coreFoundation::isCFObjectRef
bool isCFObjectRef(QualType T)
Definition: CocoaConventions.cpp:57
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang::ObjCMethodDecl::isInstanceMethod
bool isInstanceMethod() const
Definition: DeclObjC.h:431
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:253
clang::ObjCContainerDecl::getMethod
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
Definition: DeclObjC.cpp:92
Commit.h
clang::DiagnosticIDs
Used for handling and querying diagnostic IDs.
Definition: DiagnosticIDs.h:166
clang::Selector::getIdentifierInfoForSlot
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
Definition: IdentifierTable.cpp:503
clang::ObjCInterfaceDecl::getSuperClass
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:351
ASTConsumer.h
clang::PrintingPolicy::SuppressStrongLifetime
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
Definition: PrettyPrinter.h:178
clang::ento::RetainSummary
Summary for a function with respect to ownership changes.
Definition: RetainSummaryManager.h:282
clang::edit::EditedSource::commit
bool commit(const Commit &commit)
Definition: EditedSource.cpp:276
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::TypedefDecl
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3302
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:125
clang::ObjCMessageExpr::isImplicit
bool isImplicit() const
Indicates whether the message send was implicitly generated by the implementation.
Definition: ExprObjC.h:1220
clang::ObjCMessageExpr::getMethodFamily
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1365
clang::arcmt::MigrateSourceAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: ObjCMT.cpp:2009
rewriteToObjCInterfaceDecl
static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl, llvm::SmallVectorImpl< ObjCProtocolDecl * > &ConformingProtocols, const NSAPI &NS, edit::Commit &commit)
Definition: ObjCMT.cpp:662
ReplaceWithInstancetype
static void ReplaceWithInstancetype(ASTContext &Ctx, const ObjCMigrateASTConsumer &ASTC, ObjCMethodDecl *OM)
Definition: ObjCMT.cpp:955
clang::NamedDecl::getNameAsString
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition: Decl.h:290
clang::OMF_new
@ OMF_new
Definition: IdentifierTable.h:702
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:78
clang::Rewriter::getRewriteBufferFor
const RewriteBuffer * getRewriteBufferFor(FileID FID) const
getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
Definition: Rewriter.h:198
clang::ObjCMethodDecl::getBody
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:874
clang::FrontendOptions::ObjCMT_Subscripting
@ ObjCMT_Subscripting
Enable migration to modern ObjC subscripting.
Definition: FrontendOptions.h:369
clang::FrontendOptions::ObjCMT_ReadwriteProperty
@ ObjCMT_ReadwriteProperty
Enable migration to modern ObjC readwrite property.
Definition: FrontendOptions.h:375
std
Definition: Format.h:4296
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
AttributesMatch
static bool AttributesMatch(const Decl *Decl1, const Decl *Decl2, bool &AvailabilityArgsMatch)
AttributesMatch - This routine checks list of attributes for two decls.
Definition: ObjCMT.cpp:1129
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2653
IsCategoryNameWithDeprecatedSuffix
static bool IsCategoryNameWithDeprecatedSuffix(ObjCContainerDecl *D)
Definition: ObjCMT.cpp:565
clang::ObjCImplDecl::FindPropertyImplDecl
ObjCPropertyImplDecl * FindPropertyImplDecl(IdentifierInfo *propertyId, ObjCPropertyQueryKind queryKind) const
FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl added to the list of thos...
Definition: DeclObjC.cpp:2187
clang::ObjCMethodDecl::hasBody
bool hasBody() const override
Determine whether this method has a body.
Definition: DeclObjC.h:527
clang::Qualifiers::OCL_None
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:164
clang::ObjCMethodDecl::param_begin
param_const_iterator param_begin() const
Definition: DeclObjC.h:357
clang::ObjCMessageExpr::Instance
@ Instance
The receiver is an object instance.
Definition: ExprObjC.h:1091
ParentMap.h
clang::DiagnosticsEngine::getCustomDiagID
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:867
clang::ObjCMethodDecl::findPropertyDecl
const ObjCPropertyDecl * findPropertyDecl(bool CheckOverrides=true) const
Returns the property associated with this method's selector.
Definition: DeclObjC.cpp:1343
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:195
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang::FrontendOptions::ObjCMTAllowListPath
std::string ObjCMTAllowListPath
Definition: FrontendOptions.h:416
clang::FrontendOptions::ObjCMT_MigrateDecls
@ ObjCMT_MigrateDecls
Definition: FrontendOptions.h:407
clang
Definition: CalledOnceCheck.h:17
clang::ObjCContainerDecl::getInstanceMethod
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1062
clang::Type::isAnyPointerType
bool isAnyPointerType() const
Definition: Type.h:6752
Text
StringRef Text
Definition: Format.cpp:2552
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
clang::Preprocessor::addPPCallbacks
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
Definition: Preprocessor.h:1092
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1658
clang::ASTContext::ObjCMethodsAreEqual
bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl, const ObjCMethodDecl *MethodImp)
Definition: ASTContext.cpp:11958
clang::RewriteBuffer
RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a...
Definition: RewriteBuffer.h:25
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:752
clang::ento::RetainSummaryManager
Definition: RetainSummaryManager.h:449
clang::ObjCMethodDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclObjC.h:285
clang::ento::ArgEffect::getObjKind
ObjKind getObjKind() const
Definition: RetainSummaryManager.h:126
RecursiveASTVisitor.h
clang::transformer::range
RangeSelector range(RangeSelector Begin, RangeSelector End)
DEPRECATED. Use enclose.
Definition: RangeSelector.h:41
clang::ento::ArgEffect
An ArgEffect summarizes the retain count behavior on an argument or receiver to a function or method.
Definition: RetainSummaryManager.h:118
clang::ObjCListBase::empty
bool empty() const
Definition: DeclObjC.h:72
clang::Rewriter::buffer_iterator
std::map< FileID, RewriteBuffer >::iterator buffer_iterator
Definition: Rewriter.h:65
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
llvm::yaml
Definition: DiagnosticsYaml.h:28
clang::OMF_alloc
@ OMF_alloc
Definition: IdentifierTable.h:698
clang::ast_matchers::match
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
Definition: ASTMatchFinder.h:312
clang::EnumDecl::getIntegerType
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3788
ClassImplementsAllMethodsAndProperties
static bool ClassImplementsAllMethodsAndProperties(ASTContext &Ctx, const ObjCImplementationDecl *ImpDecl, const ObjCInterfaceDecl *IDecl, ObjCProtocolDecl *Protocol)
Definition: ObjCMT.cpp:601
clang::FileEntry::getName
StringRef getName() const
Definition: FileEntry.h:361
clang::ObjCProtocolDecl
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2052
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::edit::Commit::insertBefore
bool insertBefore(SourceLocation loc, StringRef text)
Definition: Commit.h:78
clang::OMF_mutableCopy
@ OMF_mutableCopy
Definition: IdentifierTable.h:701
clang::FileID::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:45
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:41
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6471
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:1035
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:311
clang::Rewriter
Rewriter - This is the main interface to the rewrite buffers.
Definition: Rewriter.h:32
clang::Preprocessor::getLocForEndOfToken
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
Definition: Preprocessor.h:1930
clang::ObjCMessageExpr::getMethodDecl
const ObjCMethodDecl * getMethodDecl() const
Definition: ExprObjC.h:1346
llvm::DenseMapInfo< EditEntry >::getTombstoneKey
static EditEntry getTombstoneKey()
Definition: ObjCMT.cpp:2048
unsigned
clang::Stmt::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
clang::ObjCSubstitutionContext::Property
@ Property
The type of a property.
clang::arcmt::ObjCMigrateAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: ObjCMT.cpp:197
clang::ento::RetEffect
RetEffect summarizes a call's retain/release behavior with respect to its return value.
Definition: RetainSummaryManager.h:139
clang::ObjCInterfaceDecl::protocol_loc_end
protocol_loc_iterator protocol_loc_end() const
Definition: DeclObjC.h:1388
clang::FunctionDecl::param_begin
param_iterator param_begin()
Definition: Decl.h:2515
clang::Decl::getAttrs
AttrVec & getAttrs()
Definition: DeclBase.h:490
clang::Qualifiers::removeObjCLifetime
void removeObjCLifetime()
Definition: Type.h:343
clang::ObjCContainerDecl
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:944
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1301
clang::ObjCContainerDecl::instance_properties
instprop_range instance_properties() const
Definition: DeclObjC.h:978
clang::ObjCMethodDecl::isPropertyAccessor
bool isPropertyAccessor() const
Definition: DeclObjC.h:441
CompilerInstance.h
clang::SourceManager::getFileEntryRefForID
Optional< FileEntryRef > getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
Definition: SourceManager.h:1042
clang::CompilerInstance::getFrontendOpts
FrontendOptions & getFrontendOpts()
Definition: CompilerInstance.h:282
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6500
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4657
clang::ento::RetainSummary::getArg
ArgEffect getArg(unsigned idx) const
getArg - Return the argument effect on the argument specified by idx (starting from 0).
Definition: RetainSummaryManager.h:314
clang::PointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2663
clang::ObjCInterfaceDecl::getSuperClassLoc
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:371
clang::ento::IncRef
@ IncRef
The argument has its reference count increased by 1.
Definition: RetainSummaryManager.h:72
clang::ASTContext::hasSameType
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2524
clang::CompilerInstance::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
Definition: CompilerInstance.h:334
clang::arcmt::MigrateSourceAction::BeginInvocation
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
Definition: ObjCMT.cpp:1984
clang::CompilerInstance::getSourceManager
SourceManager & getSourceManager() const
Return the current source manager.
Definition: CompilerInstance.h:422
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::isUppercase
LLVM_READONLY bool isUppercase(unsigned char c)
Return true if this character is an uppercase ASCII letter: [A-Z].
Definition: CharInfo.h:111
clang::ObjCMessageExpr::getNumArgs
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
Definition: ExprObjC.h:1372
Rewriter.h
FileManager.h
clang::edit::rewriteToObjCLiteralSyntax
bool rewriteToObjCLiteralSyntax(const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit, const ParentMap *PMap)
Definition: RewriteObjCFoundationAPI.cpp:338
clang::WrapperFrontendAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendAction.cpp:1155
clang::edit::rewriteToObjCSubscriptSyntax
bool rewriteToObjCSubscriptSyntax(const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
Definition: RewriteObjCFoundationAPI.cpp:289
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:685
clang::ASTContext::hasSameUnqualifiedType
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2548
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:131
SM
#define SM(sm)
Definition: Cuda.cpp:81
clang::arcmt::ObjCMigrateAction::ObjCMigrateAction
ObjCMigrateAction(std::unique_ptr< FrontendAction > WrappedAction, StringRef migrateDir, unsigned migrateAction)
Definition: ObjCMT.cpp:187
EditedSource.h
clang::transformer::name
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
Definition: RangeSelector.cpp:200
clang::EnumType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4673
clang::OIT_Singleton
@ OIT_Singleton
Definition: IdentifierTable.h:734
clang::isAsciiIdentifierStart
LLVM_READONLY bool isAsciiIdentifierStart(unsigned char c, bool AllowDollar=false)
Returns true if this is a valid first character of a C identifier, which is [a-zA-Z_].
Definition: CharInfo.h:54
RetainSummaryManager.h
clang::diff::Insert
@ Insert
Definition: ASTDiff.h:31
clang::FrontendOptions::ObjCMT_Literals
@ ObjCMT_Literals
Enable migration to modern ObjC literals.
Definition: FrontendOptions.h:366
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:425
clang::FrontendOptions::ObjCMT_DesignatedInitializer
@ ObjCMT_DesignatedInitializer
Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
Definition: FrontendOptions.h:402
clang::DeclContextLookupResult::empty
bool empty() const
Definition: DeclBase.h:1322
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1872
clang::edit::Commit::remove
bool remove(CharSourceRange range)
Definition: Commit.cpp:91
clang::ObjCList< ObjCProtocolDecl >
clang::arcmt::FileRemapper::flushToFile
bool flushToFile(StringRef outputPath, DiagnosticsEngine &Diag)
Definition: FileRemapper.cpp:119
clang::arcmt::FileRemapper::remap
void remap(StringRef filePath, std::unique_ptr< llvm::MemoryBuffer > memBuf)
Definition: FileRemapper.cpp:223
clang::NSAPI::isMacroDefined
bool isMacroDefined(StringRef Id) const
Returns true if Id is currently defined as a macro.
Definition: NSAPI.cpp:541
ReplaceWithClasstype
static void ReplaceWithClasstype(const ObjCMigrateASTConsumer &ASTC, ObjCMethodDecl *OM)
Definition: ObjCMT.cpp:978
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:786
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:47
clang::ASTContext::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: ASTContext.cpp:1499
clang::DiagnosticOptions
Options for controlling the compiler diagnostics engine.
Definition: DiagnosticOptions.h:70
clang::ento::ObjKind::OS
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
clang::ObjCMethodDecl::param_size
unsigned param_size() const
Definition: DeclObjC.h:350
clang::WrapperFrontendAction
A frontend action which simply wraps some other runtime-specified frontend action.
Definition: FrontendAction.h:305
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1536
clang::arcmt::getFileRemappingsFromFileList
bool getFileRemappingsFromFileList(std::vector< std::pair< std::string, std::string > > &remap, ArrayRef< StringRef > remapFiles, DiagnosticConsumer *DiagClient)
Get the set of file remappings from a list of files with remapping info.
Definition: ObjCMT.cpp:2212
clang::OIT_None
@ OIT_None
Definition: IdentifierTable.h:731
clang::FrontendOptions::ObjCMT_NsMacros
@ ObjCMT_NsMacros
Enable migration to NS_ENUM/NS_OPTIONS macros.
Definition: FrontendOptions.h:387
MultiplexConsumer.h
clang::FrontendOptions::ObjCMT_NsAtomicIOSOnlyProperty
@ ObjCMT_NsAtomicIOSOnlyProperty
use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
Definition: FrontendOptions.h:399
clang::DeclContext::decls_begin
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1432
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274