clang  14.0.0git
Transforms.cpp
Go to the documentation of this file.
1 //===--- Transforms.cpp - Transformations to ARC mode ---------------------===//
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"
10 #include "Internals.h"
11 #include "clang/ARCMigrate/ARCMT.h"
12 #include "clang/AST/ASTContext.h"
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Lex/Lexer.h"
18 #include "clang/Lex/Preprocessor.h"
19 #include "clang/Sema/Sema.h"
20 
21 using namespace clang;
22 using namespace arcmt;
23 using namespace trans;
24 
26 
28  if (!EnableCFBridgeFns.hasValue())
29  EnableCFBridgeFns = SemaRef.isKnownName("CFBridgingRetain") &&
30  SemaRef.isKnownName("CFBridgingRelease");
31  return *EnableCFBridgeFns;
32 }
33 
34 //===----------------------------------------------------------------------===//
35 // Helpers.
36 //===----------------------------------------------------------------------===//
37 
39  bool AllowOnUnknownClass) {
40  if (!Ctx.getLangOpts().ObjCWeakRuntime)
41  return false;
42 
43  QualType T = type;
44  if (T.isNull())
45  return false;
46 
47  // iOS is always safe to use 'weak'.
48  if (Ctx.getTargetInfo().getTriple().isiOS() ||
49  Ctx.getTargetInfo().getTriple().isWatchOS())
50  AllowOnUnknownClass = true;
51 
52  while (const PointerType *ptr = T->getAs<PointerType>())
53  T = ptr->getPointeeType();
54  if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
55  ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
56  if (!AllowOnUnknownClass && (!Class || Class->getName() == "NSObject"))
57  return false; // id/NSObject is not safe for weak.
58  if (!AllowOnUnknownClass && !Class->hasDefinition())
59  return false; // forward classes are not verifiable, therefore not safe.
60  if (Class && Class->isArcWeakrefUnavailable())
61  return false;
62  }
63 
64  return true;
65 }
66 
68  if (E->getOpcode() != BO_Assign)
69  return false;
70 
71  return isPlusOne(E->getRHS());
72 }
73 
74 bool trans::isPlusOne(const Expr *E) {
75  if (!E)
76  return false;
77  if (const FullExpr *FE = dyn_cast<FullExpr>(E))
78  E = FE->getSubExpr();
79 
80  if (const ObjCMessageExpr *
81  ME = dyn_cast<ObjCMessageExpr>(E->IgnoreParenCasts()))
82  if (ME->getMethodFamily() == OMF_retain)
83  return true;
84 
85  if (const CallExpr *
86  callE = dyn_cast<CallExpr>(E->IgnoreParenCasts())) {
87  if (const FunctionDecl *FD = callE->getDirectCallee()) {
88  if (FD->hasAttr<CFReturnsRetainedAttr>())
89  return true;
90 
91  if (FD->isGlobal() &&
92  FD->getIdentifier() &&
93  FD->getParent()->isTranslationUnit() &&
94  FD->isExternallyVisible() &&
95  ento::cocoa::isRefType(callE->getType(), "CF",
96  FD->getIdentifier()->getName())) {
97  StringRef fname = FD->getIdentifier()->getName();
98  if (fname.endswith("Retain") || fname.contains("Create") ||
99  fname.contains("Copy"))
100  return true;
101  }
102  }
103  }
104 
105  const ImplicitCastExpr *implCE = dyn_cast<ImplicitCastExpr>(E);
106  while (implCE && implCE->getCastKind() == CK_BitCast)
107  implCE = dyn_cast<ImplicitCastExpr>(implCE->getSubExpr());
108 
109  return implCE && implCE->getCastKind() == CK_ARCConsumeObject;
110 }
111 
112 /// 'Loc' is the end of a statement range. This returns the location
113 /// immediately after the semicolon following the statement.
114 /// If no semicolon is found or the location is inside a macro, the returned
115 /// source location will be invalid.
117  ASTContext &Ctx, bool IsDecl) {
118  SourceLocation SemiLoc = findSemiAfterLocation(loc, Ctx, IsDecl);
119  if (SemiLoc.isInvalid())
120  return SourceLocation();
121  return SemiLoc.getLocWithOffset(1);
122 }
123 
124 /// \arg Loc is the end of a statement range. This returns the location
125 /// of the semicolon following the statement.
126 /// If no semicolon is found or the location is inside a macro, the returned
127 /// source location will be invalid.
129  ASTContext &Ctx,
130  bool IsDecl) {
132  if (loc.isMacroID()) {
133  if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOpts(), &loc))
134  return SourceLocation();
135  }
136  loc = Lexer::getLocForEndOfToken(loc, /*Offset=*/0, SM, Ctx.getLangOpts());
137 
138  // Break down the source location.
139  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc);
140 
141  // Try to load the file buffer.
142  bool invalidTemp = false;
143  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
144  if (invalidTemp)
145  return SourceLocation();
146 
147  const char *tokenBegin = file.data() + locInfo.second;
148 
149  // Lex from the start of the given location.
150  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
151  Ctx.getLangOpts(),
152  file.begin(), tokenBegin, file.end());
153  Token tok;
154  lexer.LexFromRawLexer(tok);
155  if (tok.isNot(tok::semi)) {
156  if (!IsDecl)
157  return SourceLocation();
158  // Declaration may be followed with other tokens; such as an __attribute,
159  // before ending with a semicolon.
160  return findSemiAfterLocation(tok.getLocation(), Ctx, /*IsDecl*/true);
161  }
162 
163  return tok.getLocation();
164 }
165 
167  if (!E || !E->HasSideEffects(Ctx))
168  return false;
169 
170  E = E->IgnoreParenCasts();
171  ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E);
172  if (!ME)
173  return true;
174  switch (ME->getMethodFamily()) {
175  case OMF_autorelease:
176  case OMF_dealloc:
177  case OMF_release:
178  case OMF_retain:
179  switch (ME->getReceiverKind()) {
181  return false;
183  return hasSideEffects(ME->getInstanceReceiver(), Ctx);
184  default:
185  break;
186  }
187  break;
188  default:
189  break;
190  }
191 
192  return true;
193 }
194 
196  E = E->IgnoreParenCasts();
197  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
198  return DRE->getDecl()->getDeclContext()->isFileContext() &&
199  DRE->getDecl()->isExternallyVisible();
200  if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
201  return isGlobalVar(condOp->getTrueExpr()) &&
202  isGlobalVar(condOp->getFalseExpr());
203 
204  return false;
205 }
206 
208  return Pass.SemaRef.PP.isMacroDefined("nil") ? "nil" : "0";
209 }
210 
211 namespace {
212 
213 class ReferenceClear : public RecursiveASTVisitor<ReferenceClear> {
214  ExprSet &Refs;
215 public:
216  ReferenceClear(ExprSet &refs) : Refs(refs) { }
217  bool VisitDeclRefExpr(DeclRefExpr *E) { Refs.erase(E); return true; }
218 };
219 
220 class ReferenceCollector : public RecursiveASTVisitor<ReferenceCollector> {
221  ValueDecl *Dcl;
222  ExprSet &Refs;
223 
224 public:
225  ReferenceCollector(ValueDecl *D, ExprSet &refs)
226  : Dcl(D), Refs(refs) { }
227 
228  bool VisitDeclRefExpr(DeclRefExpr *E) {
229  if (E->getDecl() == Dcl)
230  Refs.insert(E);
231  return true;
232  }
233 };
234 
235 class RemovablesCollector : public RecursiveASTVisitor<RemovablesCollector> {
236  ExprSet &Removables;
237 
238 public:
239  RemovablesCollector(ExprSet &removables)
240  : Removables(removables) { }
241 
242  bool shouldWalkTypesOfTypeLocs() const { return false; }
243 
244  bool TraverseStmtExpr(StmtExpr *E) {
245  CompoundStmt *S = E->getSubStmt();
247  I = S->body_begin(), E = S->body_end(); I != E; ++I) {
248  if (I != E - 1)
249  mark(*I);
250  TraverseStmt(*I);
251  }
252  return true;
253  }
254 
255  bool VisitCompoundStmt(CompoundStmt *S) {
256  for (auto *I : S->body())
257  mark(I);
258  return true;
259  }
260 
261  bool VisitIfStmt(IfStmt *S) {
262  mark(S->getThen());
263  mark(S->getElse());
264  return true;
265  }
266 
267  bool VisitWhileStmt(WhileStmt *S) {
268  mark(S->getBody());
269  return true;
270  }
271 
272  bool VisitDoStmt(DoStmt *S) {
273  mark(S->getBody());
274  return true;
275  }
276 
277  bool VisitForStmt(ForStmt *S) {
278  mark(S->getInit());
279  mark(S->getInc());
280  mark(S->getBody());
281  return true;
282  }
283 
284 private:
285  void mark(Stmt *S) {
286  if (!S) return;
287 
288  while (auto *Label = dyn_cast<LabelStmt>(S))
289  S = Label->getSubStmt();
290  if (auto *E = dyn_cast<Expr>(S))
291  S = E->IgnoreImplicit();
292  if (auto *E = dyn_cast<Expr>(S))
293  Removables.insert(E);
294  }
295 };
296 
297 } // end anonymous namespace
298 
299 void trans::clearRefsIn(Stmt *S, ExprSet &refs) {
300  ReferenceClear(refs).TraverseStmt(S);
301 }
302 
304  ReferenceCollector(D, refs).TraverseStmt(S);
305 }
306 
308  RemovablesCollector(exprs).TraverseStmt(S);
309 }
310 
311 //===----------------------------------------------------------------------===//
312 // MigrationContext
313 //===----------------------------------------------------------------------===//
314 
315 namespace {
316 
317 class ASTTransform : public RecursiveASTVisitor<ASTTransform> {
318  MigrationContext &MigrateCtx;
320 
321 public:
322  ASTTransform(MigrationContext &MigrateCtx) : MigrateCtx(MigrateCtx) { }
323 
324  bool shouldWalkTypesOfTypeLocs() const { return false; }
325 
326  bool TraverseObjCImplementationDecl(ObjCImplementationDecl *D) {
327  ObjCImplementationContext ImplCtx(MigrateCtx, D);
329  I = MigrateCtx.traversers_begin(),
330  E = MigrateCtx.traversers_end(); I != E; ++I)
331  (*I)->traverseObjCImplementation(ImplCtx);
332 
333  return base::TraverseObjCImplementationDecl(D);
334  }
335 
336  bool TraverseStmt(Stmt *rootS) {
337  if (!rootS)
338  return true;
339 
340  BodyContext BodyCtx(MigrateCtx, rootS);
342  I = MigrateCtx.traversers_begin(),
343  E = MigrateCtx.traversers_end(); I != E; ++I)
344  (*I)->traverseBody(BodyCtx);
345 
346  return true;
347  }
348 };
349 
350 }
351 
353  for (traverser_iterator
354  I = traversers_begin(), E = traversers_end(); I != E; ++I)
355  delete *I;
356 }
357 
359  while (!T.isNull()) {
360  if (const AttributedType *AttrT = T->getAs<AttributedType>()) {
361  if (AttrT->getAttrKind() == attr::ObjCOwnership)
362  return !AttrT->getModifiedType()->isObjCRetainableType();
363  }
364 
365  if (T->isArrayType())
366  T = Pass.Ctx.getBaseElementType(T);
367  else if (const PointerType *PT = T->getAs<PointerType>())
368  T = PT->getPointeeType();
369  else if (const ReferenceType *RT = T->getAs<ReferenceType>())
370  T = RT->getPointeeType();
371  else
372  break;
373  }
374 
375  return false;
376 }
377 
379  StringRef toAttr,
380  SourceLocation atLoc) {
381  if (atLoc.isMacroID())
382  return false;
383 
385 
386  // Break down the source location.
387  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
388 
389  // Try to load the file buffer.
390  bool invalidTemp = false;
391  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
392  if (invalidTemp)
393  return false;
394 
395  const char *tokenBegin = file.data() + locInfo.second;
396 
397  // Lex from the start of the given location.
398  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
399  Pass.Ctx.getLangOpts(),
400  file.begin(), tokenBegin, file.end());
401  Token tok;
402  lexer.LexFromRawLexer(tok);
403  if (tok.isNot(tok::at)) return false;
404  lexer.LexFromRawLexer(tok);
405  if (tok.isNot(tok::raw_identifier)) return false;
406  if (tok.getRawIdentifier() != "property")
407  return false;
408  lexer.LexFromRawLexer(tok);
409  if (tok.isNot(tok::l_paren)) return false;
410 
411  Token BeforeTok = tok;
412  Token AfterTok;
413  AfterTok.startToken();
414  SourceLocation AttrLoc;
415 
416  lexer.LexFromRawLexer(tok);
417  if (tok.is(tok::r_paren))
418  return false;
419 
420  while (1) {
421  if (tok.isNot(tok::raw_identifier)) return false;
422  if (tok.getRawIdentifier() == fromAttr) {
423  if (!toAttr.empty()) {
424  Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
425  return true;
426  }
427  // We want to remove the attribute.
428  AttrLoc = tok.getLocation();
429  }
430 
431  do {
432  lexer.LexFromRawLexer(tok);
433  if (AttrLoc.isValid() && AfterTok.is(tok::unknown))
434  AfterTok = tok;
435  } while (tok.isNot(tok::comma) && tok.isNot(tok::r_paren));
436  if (tok.is(tok::r_paren))
437  break;
438  if (AttrLoc.isInvalid())
439  BeforeTok = tok;
440  lexer.LexFromRawLexer(tok);
441  }
442 
443  if (toAttr.empty() && AttrLoc.isValid() && AfterTok.isNot(tok::unknown)) {
444  // We want to remove the attribute.
445  if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::r_paren)) {
446  Pass.TA.remove(SourceRange(BeforeTok.getLocation(),
447  AfterTok.getLocation()));
448  } else if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::comma)) {
449  Pass.TA.remove(SourceRange(AttrLoc, AfterTok.getLocation()));
450  } else {
451  Pass.TA.remove(SourceRange(BeforeTok.getLocation(), AttrLoc));
452  }
453 
454  return true;
455  }
456 
457  return false;
458 }
459 
461  SourceLocation atLoc) {
462  if (atLoc.isMacroID())
463  return false;
464 
466 
467  // Break down the source location.
468  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
469 
470  // Try to load the file buffer.
471  bool invalidTemp = false;
472  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
473  if (invalidTemp)
474  return false;
475 
476  const char *tokenBegin = file.data() + locInfo.second;
477 
478  // Lex from the start of the given location.
479  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
480  Pass.Ctx.getLangOpts(),
481  file.begin(), tokenBegin, file.end());
482  Token tok;
483  lexer.LexFromRawLexer(tok);
484  if (tok.isNot(tok::at)) return false;
485  lexer.LexFromRawLexer(tok);
486  if (tok.isNot(tok::raw_identifier)) return false;
487  if (tok.getRawIdentifier() != "property")
488  return false;
489  lexer.LexFromRawLexer(tok);
490 
491  if (tok.isNot(tok::l_paren)) {
492  Pass.TA.insert(tok.getLocation(), std::string("(") + attr.str() + ") ");
493  return true;
494  }
495 
496  lexer.LexFromRawLexer(tok);
497  if (tok.is(tok::r_paren)) {
498  Pass.TA.insert(tok.getLocation(), attr);
499  return true;
500  }
501 
502  if (tok.isNot(tok::raw_identifier)) return false;
503 
504  Pass.TA.insert(tok.getLocation(), std::string(attr) + ", ");
505  return true;
506 }
507 
509  for (traverser_iterator
510  I = traversers_begin(), E = traversers_end(); I != E; ++I)
511  (*I)->traverseTU(*this);
512 
513  ASTTransform(*this).TraverseDecl(TU);
514 }
515 
516 static void GCRewriteFinalize(MigrationPass &pass) {
517  ASTContext &Ctx = pass.Ctx;
518  TransformActions &TA = pass.TA;
520  Selector FinalizeSel =
521  Ctx.Selectors.getNullarySelector(&pass.Ctx.Idents.get("finalize"));
522 
524  impl_iterator;
525  for (impl_iterator I = impl_iterator(DC->decls_begin()),
526  E = impl_iterator(DC->decls_end()); I != E; ++I) {
527  for (const auto *MD : I->instance_methods()) {
528  if (!MD->hasBody())
529  continue;
530 
531  if (MD->isInstanceMethod() && MD->getSelector() == FinalizeSel) {
532  const ObjCMethodDecl *FinalizeM = MD;
533  Transaction Trans(TA);
534  TA.insert(FinalizeM->getSourceRange().getBegin(),
535  "#if !__has_feature(objc_arc)\n");
537  const SourceManager &SM = pass.Ctx.getSourceManager();
538  const LangOptions &LangOpts = pass.Ctx.getLangOpts();
539  bool Invalid;
540  std::string str = "\n#endif\n";
541  str += Lexer::getSourceText(
543  SM, LangOpts, &Invalid);
544  TA.insertAfterToken(FinalizeM->getSourceRange().getEnd(), str);
545 
546  break;
547  }
548  }
549  }
550 }
551 
552 //===----------------------------------------------------------------------===//
553 // getAllTransformations.
554 //===----------------------------------------------------------------------===//
555 
556 static void traverseAST(MigrationPass &pass) {
557  MigrationContext MigrateCtx(pass);
558 
559  if (pass.isGCMigration()) {
561  MigrateCtx.addTraverser(new GCAttrsTraverser());
562  }
563  MigrateCtx.addTraverser(new PropertyRewriteTraverser());
564  MigrateCtx.addTraverser(new BlockObjCVariableTraverser());
565  MigrateCtx.addTraverser(new ProtectedScopeTraverser());
566 
567  MigrateCtx.traverse(pass.Ctx.getTranslationUnitDecl());
568 }
569 
575  makeAssignARCSafe(pass);
576  rewriteUnbridgedCasts(pass);
577  checkAPIUses(pass);
578  traverseAST(pass);
579 }
580 
581 std::vector<TransformFn> arcmt::getAllTransformations(
582  LangOptions::GCMode OrigGCMode,
583  bool NoFinalizeRemoval) {
584  std::vector<TransformFn> transforms;
585 
586  if (OrigGCMode == LangOptions::GCOnly && NoFinalizeRemoval)
587  transforms.push_back(GCRewriteFinalize);
588  transforms.push_back(independentTransforms);
589  // This depends on previous transformations removing various expressions.
590  transforms.push_back(removeEmptyStatementsAndDeallocFinalize);
591 
592  return transforms;
593 }
clang::Token::startToken
void startToken()
Reset all flags to cleared.
Definition: Token.h:171
clang::ObjCMessageExpr::SuperInstance
@ SuperInstance
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1097
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1151
clang::Lexer::isAtEndOfMacroExpansion
static bool isAtEndOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroEnd=nullptr)
Returns true if the given MacroID location points at the last token of the macro expansion.
Definition: Lexer.cpp:827
clang::DeclContext::decls_end
decl_iterator decls_end() const
Definition: DeclBase.h:2117
clang::OMF_autorelease
@ OMF_autorelease
Definition: IdentifierTable.h:702
clang::arcmt::TransformActions::insertAfterToken
void insertAfterToken(SourceLocation loc, StringRef text)
Definition: TransformActions.cpp:633
clang::DeclContext::specific_decl_iterator
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2135
type
clang::AttributedType
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4668
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
clang::arcmt::trans::isGlobalVar
bool isGlobalVar(Expr *E)
Definition: Transforms.cpp:195
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::WhileStmt
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2341
clang::arcmt::trans::isPlusOneAssign
bool isPlusOneAssign(const BinaryOperator *E)
Definition: Transforms.cpp:67
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::arcmt::MigrationPass
Definition: Internals.h:146
clang::ObjCImplementationDecl
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2546
Transforms.h
clang::Expr::IgnoreImplicit
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:2907
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:592
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::OMF_release
@ OMF_release
Definition: IdentifierTable.h:705
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:136
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:221
ARCMT.h
TargetInfo.h
clang::arcmt::TransformActions
Definition: Internals.h:49
clang::CastExpr::getSubExpr
Expr * getSubExpr()
Definition: Expr.h:3524
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::ASTContext::getBaseElementType
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Definition: ASTContext.cpp:6297
clang::ast_matchers::type
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchersInternal.cpp:772
clang::arcmt::trans::MigrationContext::isGCOwnedNonObjC
bool isGCOwnedNonObjC(QualType T)
Definition: Transforms.cpp:358
clang::arcmt::trans::makeAssignARCSafe
void makeAssignARCSafe(MigrationPass &pass)
Definition: TransARCAssign.cpp:74
clang::IfStmt
IfStmt - This represents an if/then/else.
Definition: Stmt.h:1904
clang::arcmt::trans::removeEmptyStatementsAndDeallocFinalize
void removeEmptyStatementsAndDeallocFinalize(MigrationPass &pass)
Definition: TransEmptyStatementsAndDealloc.cpp:240
clang::arcmt::trans::collectRemovables
void collectRemovables(Stmt *S, ExprSet &exprs)
Definition: Transforms.cpp:307
clang::StmtExpr::getSubStmt
CompoundStmt * getSubStmt()
Definition: Expr.h:4362
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
Internals.h
clang::Lexer::getSourceText
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
Definition: Lexer.cpp:957
SourceManager.h
clang::arcmt::trans::ASTTraverser::~ASTTraverser
virtual ~ASTTraverser()
Definition: Transforms.cpp:25
clang::LangOptions::GCOnly
@ GCOnly
Definition: LangOptions.h:63
clang::arcmt::trans::collectRefs
void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:303
clang::BinaryOperator::getOpcode
Opcode getOpcode() const
Definition: Expr.h:3847
clang::LangOptions::GCMode
GCMode
Definition: LangOptions.h:63
clang::Lexer::LexFromRawLexer
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
Definition: Lexer.h:198
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::arcmt::MigrationPass::TA
TransformActions & TA
Definition: Internals.h:152
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition: ASTContext.h:695
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1057
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::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::arcmt::MigrationPass::isGCMigration
bool isGCMigration() const
Definition: Internals.h:167
Preprocessor.h
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:76
clang::ConditionalOperator
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4141
clang::FullExpr
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:998
clang::arcmt::trans::GCAttrsTraverser
Definition: Transforms.h:144
clang::arcmt::trans::removeZeroOutPropsInDeallocFinalize
void removeZeroOutPropsInDeallocFinalize(MigrationPass &pass)
Definition: TransZeroOutPropsInDealloc.cpp:221
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:82
clang::ast_matchers::attr
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
Definition: ASTMatchersInternal.cpp:1029
clang::arcmt::TransformActions::replaceText
void replaceText(SourceLocation loc, StringRef text, StringRef replacementText)
Definition: TransformActions.cpp:659
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1399
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::OMF_retain
@ OMF_retain
Definition: IdentifierTable.h:706
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3803
clang::arcmt::Transaction
Definition: Internals.h:124
clang::ASTContext::Selectors
SelectorTable & Selectors
Definition: ASTContext.h:649
clang::arcmt::trans::MigrationContext::~MigrationContext
~MigrationContext()
Definition: Transforms.cpp:352
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:222
clang::arcmt::TransformActions::remove
void remove(SourceRange range)
Definition: TransformActions.cpp:638
clang::OMF_dealloc
@ OMF_dealloc
Definition: IdentifierTable.h:703
clang::arcmt::trans::ProtectedScopeTraverser
Definition: Transforms.h:137
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
clang::arcmt::trans::rewriteUnbridgedCasts
void rewriteUnbridgedCasts(MigrationPass &pass)
Definition: TransUnbridgedCasts.cpp:463
clang::arcmt::trans::MigrationContext
Definition: Transforms.h:80
clang::RecursiveASTVisitor
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Definition: RecursiveASTVisitor.h:164
clang::arcmt::trans::MigrationContext::addPropertyAttribute
bool addPropertyAttribute(StringRef attr, SourceLocation atLoc)
Definition: Transforms.cpp:460
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7161
clang::arcmt::TransformActions::insert
void insert(SourceLocation loc, StringRef text)
Definition: TransformActions.cpp:629
clang::ForStmt
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2534
clang::ento::cocoa::isRefType
bool isRefType(QualType RetTy, StringRef Prefix, StringRef Name=StringRef())
Definition: CocoaConventions.cpp:24
clang::Token::is
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition: Token.h:97
clang::ObjCMessageExpr::getReceiverKind
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition: ExprObjC.h:1224
clang::Preprocessor::isMacroDefined
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:1088
clang::DeclRefExpr::getDecl
ValueDecl * getDecl()
Definition: Expr.h:1289
ASTContext.h
clang::arcmt::trans::MigrationContext::traversers_begin
traverser_iterator traversers_begin()
Definition: Transforms.h:107
clang::arcmt::trans::isPlusOne
bool isPlusOne(const Expr *E)
Definition: Transforms.cpp:74
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
llvm::DenseSet
Definition: Sema.h:78
clang::arcmt::trans::clearRefsIn
void clearRefsIn(Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:299
clang::arcmt::MigrationPass::Ctx
ASTContext & Ctx
Definition: Internals.h:148
Label
std::string Label
Definition: UsingDeclarationsSorter.cpp:69
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:940
Sema.h
clang::CastExpr::getCastKind
CastKind getCastKind() const
Definition: Expr.h:3518
clang::Token::getRawIdentifier
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode),...
Definition: Token.h:205
clang::arcmt::trans::GCCollectableCallsTraverser
Definition: Transforms.h:149
clang::arcmt::trans::hasSideEffects
bool hasSideEffects(Expr *E, ASTContext &Ctx)
Definition: Transforms.cpp:166
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:2924
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1130
clang::ObjCObjectPointerType
Represents a pointer to an Objective C object.
Definition: Type.h:6072
clang::arcmt::MigrationPass::SemaRef
Sema & SemaRef
Definition: Internals.h:151
clang::arcmt::trans::removeRetainReleaseDeallocFinalize
void removeRetainReleaseDeallocFinalize(MigrationPass &pass)
Definition: TransRetainReleaseDealloc.cpp:456
clang::arcmt::trans::MigrationContext::traverse
void traverse(TranslationUnitDecl *TU)
Definition: Transforms.cpp:508
clang::arcmt::trans::checkAPIUses
void checkAPIUses(MigrationPass &pass)
Definition: TransAPIUses.cpp:105
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:676
clang::arcmt::trans::rewriteUnusedInitDelegate
void rewriteUnusedInitDelegate(MigrationPass &pass)
Definition: TransUnusedInitDelegate.cpp:74
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:648
clang::CharSourceRange::getTokenRange
static CharSourceRange getTokenRange(SourceRange R)
Definition: SourceLocation.h:263
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:738
clang::StmtExpr
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4345
Lexer.h
clang::arcmt::trans::MigrationContext::addTraverser
void addTraverser(ASTTraverser *traverser)
Definition: Transforms.h:110
CocoaConventions.h
clang::arcmt::trans::BodyContext
Definition: Transforms.h:45
clang::DoStmt
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2478
clang::arcmt::getAllTransformations
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
Definition: Transforms.cpp:581
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:747
clang::ObjCMessageExpr::getMethodFamily
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1365
clang::SourceLocation::isMacroID
bool isMacroID() const
Definition: SourceLocation.h:105
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:58
traverseAST
static void traverseAST(MigrationPass &pass)
Definition: Transforms.cpp:556
clang::SelectorTable::getNullarySelector
Selector getNullarySelector(IdentifierInfo *ID)
Definition: IdentifierTable.h:913
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2640
clang::arcmt::trans::PropertyRewriteTraverser
Definition: Transforms.h:127
clang::Expr::HasSideEffects
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Definition: Expr.cpp:3383
clang::ObjCMessageExpr::Instance
@ Instance
The receiver is an object instance.
Definition: ExprObjC.h:1091
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:113
clang
Definition: CalledOnceCheck.h:17
GCRewriteFinalize
static void GCRewriteFinalize(MigrationPass &pass)
Definition: Transforms.cpp:516
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:748
clang::Type::isArrayType
bool isArrayType() const
Definition: Type.h:6738
RecursiveASTVisitor.h
clang::arcmt::trans::MigrationContext::Pass
MigrationPass & Pass
Definition: Transforms.h:84
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::BinaryOperator::getRHS
Expr * getRHS() const
Definition: Expr.h:3854
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:112
clang::arcmt::trans::canApplyWeak
bool canApplyWeak(ASTContext &Ctx, QualType type, bool AllowOnUnknownClass=false)
Determine whether we can add weak to the given type.
Definition: Transforms.cpp:38
clang::ObjCMethodDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:287
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3618
clang::arcmt::trans::ObjCImplementationContext
Definition: Transforms.h:59
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2751
clang::Lexer::getLocForEndOfToken
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Definition: Lexer.cpp:783
clang::arcmt::trans::MigrationContext::rewritePropertyAttribute
bool rewritePropertyAttribute(StringRef fromAttr, StringRef toAttr, SourceLocation atLoc)
Definition: Transforms.cpp:378
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::arcmt::MigrationPass::CFBridgingFunctionsDefined
bool CFBridgingFunctionsDefined()
Definition: Transforms.cpp:27
SM
#define SM(sm)
Definition: Cuda.cpp:78
clang::Sema::PP
Preprocessor & PP
Definition: Sema.h:410
clang::arcmt::trans::BlockObjCVariableTraverser
Definition: Transforms.h:132
clang::arcmt::trans::MigrationContext::traverser_iterator
std::vector< ASTTraverser * >::iterator traverser_iterator
Definition: Transforms.h:106
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1217
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1856
clang::arcmt::trans::MigrationContext::traversers_end
traverser_iterator traversers_end()
Definition: Transforms.h:108
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2795
clang::arcmt::trans::getNilString
StringRef getNilString(MigrationPass &Pass)
Returns "nil" or "0" if 'nil' macro is not actually defined.
Definition: Transforms.cpp:207
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:765
clang::arcmt::trans::rewriteAutoreleasePool
void rewriteAutoreleasePool(MigrationPass &pass)
Definition: TransAutoreleasePool.cpp:431
independentTransforms
static void independentTransforms(MigrationPass &pass)
Definition: Transforms.cpp:570
clang::DeclContext::decls_begin
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1419