clang  3.9.0
Transforms.cpp
Go to the documentation of this file.
1 //===--- Transforms.cpp - Transformations to ARC mode ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "Transforms.h"
11 #include "Internals.h"
12 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/StmtVisitor.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Lex/Lexer.h"
19 #include "clang/Lex/Preprocessor.h"
20 #include "clang/Sema/Sema.h"
22 #include "llvm/ADT/DenseSet.h"
23 #include "llvm/ADT/StringSwitch.h"
24 #include <map>
25 
26 using namespace clang;
27 using namespace arcmt;
28 using namespace trans;
29 
31 
33  if (!EnableCFBridgeFns.hasValue())
34  EnableCFBridgeFns = SemaRef.isKnownName("CFBridgingRetain") &&
35  SemaRef.isKnownName("CFBridgingRelease");
36  return *EnableCFBridgeFns;
37 }
38 
39 //===----------------------------------------------------------------------===//
40 // Helpers.
41 //===----------------------------------------------------------------------===//
42 
44  bool AllowOnUnknownClass) {
45  if (!Ctx.getLangOpts().ObjCWeakRuntime)
46  return false;
47 
48  QualType T = type;
49  if (T.isNull())
50  return false;
51 
52  // iOS is always safe to use 'weak'.
53  if (Ctx.getTargetInfo().getTriple().isiOS() ||
54  Ctx.getTargetInfo().getTriple().isWatchOS())
55  AllowOnUnknownClass = true;
56 
57  while (const PointerType *ptr = T->getAs<PointerType>())
58  T = ptr->getPointeeType();
59  if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
60  ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
61  if (!AllowOnUnknownClass && (!Class || Class->getName() == "NSObject"))
62  return false; // id/NSObject is not safe for weak.
63  if (!AllowOnUnknownClass && !Class->hasDefinition())
64  return false; // forward classes are not verifiable, therefore not safe.
65  if (Class && Class->isArcWeakrefUnavailable())
66  return false;
67  }
68 
69  return true;
70 }
71 
73  if (E->getOpcode() != BO_Assign)
74  return false;
75 
76  return isPlusOne(E->getRHS());
77 }
78 
79 bool trans::isPlusOne(const Expr *E) {
80  if (!E)
81  return false;
82  if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(E))
83  E = EWC->getSubExpr();
84 
85  if (const ObjCMessageExpr *
86  ME = dyn_cast<ObjCMessageExpr>(E->IgnoreParenCasts()))
87  if (ME->getMethodFamily() == OMF_retain)
88  return true;
89 
90  if (const CallExpr *
91  callE = dyn_cast<CallExpr>(E->IgnoreParenCasts())) {
92  if (const FunctionDecl *FD = callE->getDirectCallee()) {
93  if (FD->hasAttr<CFReturnsRetainedAttr>())
94  return true;
95 
96  if (FD->isGlobal() &&
97  FD->getIdentifier() &&
98  FD->getParent()->isTranslationUnit() &&
99  FD->isExternallyVisible() &&
100  ento::cocoa::isRefType(callE->getType(), "CF",
101  FD->getIdentifier()->getName())) {
102  StringRef fname = FD->getIdentifier()->getName();
103  if (fname.endswith("Retain") ||
104  fname.find("Create") != StringRef::npos ||
105  fname.find("Copy") != StringRef::npos) {
106  return true;
107  }
108  }
109  }
110  }
111 
112  const ImplicitCastExpr *implCE = dyn_cast<ImplicitCastExpr>(E);
113  while (implCE && implCE->getCastKind() == CK_BitCast)
114  implCE = dyn_cast<ImplicitCastExpr>(implCE->getSubExpr());
115 
116  return implCE && implCE->getCastKind() == CK_ARCConsumeObject;
117 }
118 
119 /// \brief 'Loc' is the end of a statement range. This returns the location
120 /// immediately after the semicolon following the statement.
121 /// If no semicolon is found or the location is inside a macro, the returned
122 /// source location will be invalid.
124  ASTContext &Ctx, bool IsDecl) {
125  SourceLocation SemiLoc = findSemiAfterLocation(loc, Ctx, IsDecl);
126  if (SemiLoc.isInvalid())
127  return SourceLocation();
128  return SemiLoc.getLocWithOffset(1);
129 }
130 
131 /// \brief \arg Loc is the end of a statement range. This returns the location
132 /// of the semicolon following the statement.
133 /// If no semicolon is found or the location is inside a macro, the returned
134 /// source location will be invalid.
136  ASTContext &Ctx,
137  bool IsDecl) {
139  if (loc.isMacroID()) {
140  if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOpts(), &loc))
141  return SourceLocation();
142  }
143  loc = Lexer::getLocForEndOfToken(loc, /*Offset=*/0, SM, Ctx.getLangOpts());
144 
145  // Break down the source location.
146  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc);
147 
148  // Try to load the file buffer.
149  bool invalidTemp = false;
150  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
151  if (invalidTemp)
152  return SourceLocation();
153 
154  const char *tokenBegin = file.data() + locInfo.second;
155 
156  // Lex from the start of the given location.
157  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
158  Ctx.getLangOpts(),
159  file.begin(), tokenBegin, file.end());
160  Token tok;
161  lexer.LexFromRawLexer(tok);
162  if (tok.isNot(tok::semi)) {
163  if (!IsDecl)
164  return SourceLocation();
165  // Declaration may be followed with other tokens; such as an __attribute,
166  // before ending with a semicolon.
167  return findSemiAfterLocation(tok.getLocation(), Ctx, /*IsDecl*/true);
168  }
169 
170  return tok.getLocation();
171 }
172 
174  if (!E || !E->HasSideEffects(Ctx))
175  return false;
176 
177  E = E->IgnoreParenCasts();
178  ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E);
179  if (!ME)
180  return true;
181  switch (ME->getMethodFamily()) {
182  case OMF_autorelease:
183  case OMF_dealloc:
184  case OMF_release:
185  case OMF_retain:
186  switch (ME->getReceiverKind()) {
188  return false;
190  return hasSideEffects(ME->getInstanceReceiver(), Ctx);
191  default:
192  break;
193  }
194  break;
195  default:
196  break;
197  }
198 
199  return true;
200 }
201 
203  E = E->IgnoreParenCasts();
204  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
205  return DRE->getDecl()->getDeclContext()->isFileContext() &&
206  DRE->getDecl()->isExternallyVisible();
207  if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
208  return isGlobalVar(condOp->getTrueExpr()) &&
209  isGlobalVar(condOp->getFalseExpr());
210 
211  return false;
212 }
213 
215  return Pass.SemaRef.PP.isMacroDefined("nil") ? "nil" : "0";
216 }
217 
218 namespace {
219 
220 class ReferenceClear : public RecursiveASTVisitor<ReferenceClear> {
221  ExprSet &Refs;
222 public:
223  ReferenceClear(ExprSet &refs) : Refs(refs) { }
224  bool VisitDeclRefExpr(DeclRefExpr *E) { Refs.erase(E); return true; }
225 };
226 
227 class ReferenceCollector : public RecursiveASTVisitor<ReferenceCollector> {
228  ValueDecl *Dcl;
229  ExprSet &Refs;
230 
231 public:
232  ReferenceCollector(ValueDecl *D, ExprSet &refs)
233  : Dcl(D), Refs(refs) { }
234 
235  bool VisitDeclRefExpr(DeclRefExpr *E) {
236  if (E->getDecl() == Dcl)
237  Refs.insert(E);
238  return true;
239  }
240 };
241 
242 class RemovablesCollector : public RecursiveASTVisitor<RemovablesCollector> {
243  ExprSet &Removables;
244 
245 public:
246  RemovablesCollector(ExprSet &removables)
247  : Removables(removables) { }
248 
249  bool shouldWalkTypesOfTypeLocs() const { return false; }
250 
251  bool TraverseStmtExpr(StmtExpr *E) {
252  CompoundStmt *S = E->getSubStmt();
254  I = S->body_begin(), E = S->body_end(); I != E; ++I) {
255  if (I != E - 1)
256  mark(*I);
257  TraverseStmt(*I);
258  }
259  return true;
260  }
261 
262  bool VisitCompoundStmt(CompoundStmt *S) {
263  for (auto *I : S->body())
264  mark(I);
265  return true;
266  }
267 
268  bool VisitIfStmt(IfStmt *S) {
269  mark(S->getThen());
270  mark(S->getElse());
271  return true;
272  }
273 
274  bool VisitWhileStmt(WhileStmt *S) {
275  mark(S->getBody());
276  return true;
277  }
278 
279  bool VisitDoStmt(DoStmt *S) {
280  mark(S->getBody());
281  return true;
282  }
283 
284  bool VisitForStmt(ForStmt *S) {
285  mark(S->getInit());
286  mark(S->getInc());
287  mark(S->getBody());
288  return true;
289  }
290 
291 private:
292  void mark(Stmt *S) {
293  if (!S) return;
294 
295  while (LabelStmt *Label = dyn_cast<LabelStmt>(S))
296  S = Label->getSubStmt();
297  S = S->IgnoreImplicit();
298  if (Expr *E = dyn_cast<Expr>(S))
299  Removables.insert(E);
300  }
301 };
302 
303 } // end anonymous namespace
304 
305 void trans::clearRefsIn(Stmt *S, ExprSet &refs) {
306  ReferenceClear(refs).TraverseStmt(S);
307 }
308 
310  ReferenceCollector(D, refs).TraverseStmt(S);
311 }
312 
314  RemovablesCollector(exprs).TraverseStmt(S);
315 }
316 
317 //===----------------------------------------------------------------------===//
318 // MigrationContext
319 //===----------------------------------------------------------------------===//
320 
321 namespace {
322 
323 class ASTTransform : public RecursiveASTVisitor<ASTTransform> {
324  MigrationContext &MigrateCtx;
326 
327 public:
328  ASTTransform(MigrationContext &MigrateCtx) : MigrateCtx(MigrateCtx) { }
329 
330  bool shouldWalkTypesOfTypeLocs() const { return false; }
331 
332  bool TraverseObjCImplementationDecl(ObjCImplementationDecl *D) {
333  ObjCImplementationContext ImplCtx(MigrateCtx, D);
335  I = MigrateCtx.traversers_begin(),
336  E = MigrateCtx.traversers_end(); I != E; ++I)
337  (*I)->traverseObjCImplementation(ImplCtx);
338 
339  return base::TraverseObjCImplementationDecl(D);
340  }
341 
342  bool TraverseStmt(Stmt *rootS) {
343  if (!rootS)
344  return true;
345 
346  BodyContext BodyCtx(MigrateCtx, rootS);
348  I = MigrateCtx.traversers_begin(),
349  E = MigrateCtx.traversers_end(); I != E; ++I)
350  (*I)->traverseBody(BodyCtx);
351 
352  return true;
353  }
354 };
355 
356 }
357 
359  for (traverser_iterator
360  I = traversers_begin(), E = traversers_end(); I != E; ++I)
361  delete *I;
362 }
363 
365  while (!T.isNull()) {
366  if (const AttributedType *AttrT = T->getAs<AttributedType>()) {
367  if (AttrT->getAttrKind() == AttributedType::attr_objc_ownership)
368  return !AttrT->getModifiedType()->isObjCRetainableType();
369  }
370 
371  if (T->isArrayType())
372  T = Pass.Ctx.getBaseElementType(T);
373  else if (const PointerType *PT = T->getAs<PointerType>())
374  T = PT->getPointeeType();
375  else if (const ReferenceType *RT = T->getAs<ReferenceType>())
376  T = RT->getPointeeType();
377  else
378  break;
379  }
380 
381  return false;
382 }
383 
385  StringRef toAttr,
386  SourceLocation atLoc) {
387  if (atLoc.isMacroID())
388  return false;
389 
391 
392  // Break down the source location.
393  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
394 
395  // Try to load the file buffer.
396  bool invalidTemp = false;
397  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
398  if (invalidTemp)
399  return false;
400 
401  const char *tokenBegin = file.data() + locInfo.second;
402 
403  // Lex from the start of the given location.
404  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
405  Pass.Ctx.getLangOpts(),
406  file.begin(), tokenBegin, file.end());
407  Token tok;
408  lexer.LexFromRawLexer(tok);
409  if (tok.isNot(tok::at)) return false;
410  lexer.LexFromRawLexer(tok);
411  if (tok.isNot(tok::raw_identifier)) return false;
412  if (tok.getRawIdentifier() != "property")
413  return false;
414  lexer.LexFromRawLexer(tok);
415  if (tok.isNot(tok::l_paren)) return false;
416 
417  Token BeforeTok = tok;
418  Token AfterTok;
419  AfterTok.startToken();
420  SourceLocation AttrLoc;
421 
422  lexer.LexFromRawLexer(tok);
423  if (tok.is(tok::r_paren))
424  return false;
425 
426  while (1) {
427  if (tok.isNot(tok::raw_identifier)) return false;
428  if (tok.getRawIdentifier() == fromAttr) {
429  if (!toAttr.empty()) {
430  Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
431  return true;
432  }
433  // We want to remove the attribute.
434  AttrLoc = tok.getLocation();
435  }
436 
437  do {
438  lexer.LexFromRawLexer(tok);
439  if (AttrLoc.isValid() && AfterTok.is(tok::unknown))
440  AfterTok = tok;
441  } while (tok.isNot(tok::comma) && tok.isNot(tok::r_paren));
442  if (tok.is(tok::r_paren))
443  break;
444  if (AttrLoc.isInvalid())
445  BeforeTok = tok;
446  lexer.LexFromRawLexer(tok);
447  }
448 
449  if (toAttr.empty() && AttrLoc.isValid() && AfterTok.isNot(tok::unknown)) {
450  // We want to remove the attribute.
451  if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::r_paren)) {
452  Pass.TA.remove(SourceRange(BeforeTok.getLocation(),
453  AfterTok.getLocation()));
454  } else if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::comma)) {
455  Pass.TA.remove(SourceRange(AttrLoc, AfterTok.getLocation()));
456  } else {
457  Pass.TA.remove(SourceRange(BeforeTok.getLocation(), AttrLoc));
458  }
459 
460  return true;
461  }
462 
463  return false;
464 }
465 
467  SourceLocation atLoc) {
468  if (atLoc.isMacroID())
469  return false;
470 
472 
473  // Break down the source location.
474  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
475 
476  // Try to load the file buffer.
477  bool invalidTemp = false;
478  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
479  if (invalidTemp)
480  return false;
481 
482  const char *tokenBegin = file.data() + locInfo.second;
483 
484  // Lex from the start of the given location.
485  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
486  Pass.Ctx.getLangOpts(),
487  file.begin(), tokenBegin, file.end());
488  Token tok;
489  lexer.LexFromRawLexer(tok);
490  if (tok.isNot(tok::at)) return false;
491  lexer.LexFromRawLexer(tok);
492  if (tok.isNot(tok::raw_identifier)) return false;
493  if (tok.getRawIdentifier() != "property")
494  return false;
495  lexer.LexFromRawLexer(tok);
496 
497  if (tok.isNot(tok::l_paren)) {
498  Pass.TA.insert(tok.getLocation(), std::string("(") + attr.str() + ") ");
499  return true;
500  }
501 
502  lexer.LexFromRawLexer(tok);
503  if (tok.is(tok::r_paren)) {
504  Pass.TA.insert(tok.getLocation(), attr);
505  return true;
506  }
507 
508  if (tok.isNot(tok::raw_identifier)) return false;
509 
510  Pass.TA.insert(tok.getLocation(), std::string(attr) + ", ");
511  return true;
512 }
513 
515  for (traverser_iterator
516  I = traversers_begin(), E = traversers_end(); I != E; ++I)
517  (*I)->traverseTU(*this);
518 
519  ASTTransform(*this).TraverseDecl(TU);
520 }
521 
522 static void GCRewriteFinalize(MigrationPass &pass) {
523  ASTContext &Ctx = pass.Ctx;
524  TransformActions &TA = pass.TA;
526  Selector FinalizeSel =
527  Ctx.Selectors.getNullarySelector(&pass.Ctx.Idents.get("finalize"));
528 
530  impl_iterator;
531  for (impl_iterator I = impl_iterator(DC->decls_begin()),
532  E = impl_iterator(DC->decls_end()); I != E; ++I) {
533  for (const auto *MD : I->instance_methods()) {
534  if (!MD->hasBody())
535  continue;
536 
537  if (MD->isInstanceMethod() && MD->getSelector() == FinalizeSel) {
538  const ObjCMethodDecl *FinalizeM = MD;
539  Transaction Trans(TA);
540  TA.insert(FinalizeM->getSourceRange().getBegin(),
541  "#if !__has_feature(objc_arc)\n");
543  const SourceManager &SM = pass.Ctx.getSourceManager();
544  const LangOptions &LangOpts = pass.Ctx.getLangOpts();
545  bool Invalid;
546  std::string str = "\n#endif\n";
547  str += Lexer::getSourceText(
549  SM, LangOpts, &Invalid);
550  TA.insertAfterToken(FinalizeM->getSourceRange().getEnd(), str);
551 
552  break;
553  }
554  }
555  }
556 }
557 
558 //===----------------------------------------------------------------------===//
559 // getAllTransformations.
560 //===----------------------------------------------------------------------===//
561 
562 static void traverseAST(MigrationPass &pass) {
563  MigrationContext MigrateCtx(pass);
564 
565  if (pass.isGCMigration()) {
567  MigrateCtx.addTraverser(new GCAttrsTraverser());
568  }
569  MigrateCtx.addTraverser(new PropertyRewriteTraverser());
570  MigrateCtx.addTraverser(new BlockObjCVariableTraverser());
571  MigrateCtx.addTraverser(new ProtectedScopeTraverser());
572 
573  MigrateCtx.traverse(pass.Ctx.getTranslationUnitDecl());
574 }
575 
581  makeAssignARCSafe(pass);
582  rewriteUnbridgedCasts(pass);
583  checkAPIUses(pass);
584  traverseAST(pass);
585 }
586 
587 std::vector<TransformFn> arcmt::getAllTransformations(
588  LangOptions::GCMode OrigGCMode,
589  bool NoFinalizeRemoval) {
590  std::vector<TransformFn> transforms;
591 
592  if (OrigGCMode == LangOptions::GCOnly && NoFinalizeRemoval)
593  transforms.push_back(GCRewriteFinalize);
594  transforms.push_back(independentTransforms);
595  // This depends on previous transformations removing various expressions.
596  transforms.push_back(removeEmptyStatementsAndDeallocFinalize);
597 
598  return transforms;
599 }
Expr * getInc()
Definition: Stmt.h:1187
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1009
static void independentTransforms(MigrationPass &pass)
Definition: Transforms.cpp:576
bool hasDefinition() const
Determine whether this class has been defined.
Definition: DeclObjC.h:1440
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
CastKind getCastKind() const
Definition: Expr.h:2680
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
The receiver is an object instance.
Definition: ExprObjC.h:1005
body_iterator body_end()
Definition: Stmt.h:583
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:237
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:46
Smart pointer class that efficiently represents Objective-C method names.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2179
A (possibly-)qualified type.
Definition: Type.h:598
bool isMacroID() const
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1270
CompoundStmt * getSubStmt()
Definition: Expr.h:3396
IfStmt - This represents an if/then/else.
Definition: Stmt.h:881
Defines the SourceManager interface.
static CharSourceRange getTokenRange(SourceRange R)
const Stmt * getElse() const
Definition: Stmt.h:921
bool isArcWeakrefUnavailable() const
isArcWeakrefUnavailable - Checks for a class or one of its super classes to be incompatible with __we...
Definition: DeclObjC.cpp:390
traverser_iterator traversers_begin()
Definition: Transforms.h:108
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:2802
bool rewritePropertyAttribute(StringRef fromAttr, StringRef toAttr, SourceLocation atLoc)
Definition: Transforms.cpp:384
void traverse(TranslationUnitDecl *TU)
Definition: Transforms.cpp:514
SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
'Loc' is the end of a statement range.
Definition: Transforms.cpp:135
void makeAssignARCSafe(MigrationPass &pass)
std::vector< ASTTraverser * >::iterator traverser_iterator
Definition: Transforms.h:107
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
bool isGCMigration() const
Definition: Internals.h:166
decl_iterator decls_end() const
Definition: DeclBase.h:1455
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:2936
void clearRefsIn(Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:305
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:789
Stmt * getBody()
Definition: Stmt.h:1123
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:92
bool isGlobalVar(Expr *E)
Definition: Transforms.cpp:202
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
Expr * getSubExpr()
Definition: Expr.h:2684
SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
'Loc' is the end of a statement range.
Definition: Transforms.cpp:123
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
IdentifierTable & Idents
Definition: ASTContext.h:459
Selector getNullarySelector(IdentifierInfo *ID)
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:1153
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:588
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
void removeRetainReleaseDeallocFinalize(MigrationPass &pass)
const LangOptions & getLangOpts() const
Definition: ASTContext.h:604
Stmt * getBody()
Definition: Stmt.h:1188
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:2897
Stmt * getInit()
Definition: Stmt.h:1167
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
Definition: Expr.cpp:2326
void rewriteUnusedInitDelegate(MigrationPass &pass)
Preprocessor & PP
Definition: Sema.h:298
A class that does preordor or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
Definition: DeclObjC.h:1091
bool isPlusOneAssign(const BinaryOperator *E)
Definition: Transforms.cpp:72
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1206
detail::InMemoryDirectory::const_iterator I
bool isInvalid() const
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:3170
StringRef getNilString(MigrationPass &Pass)
Returns "nil" or "0" if 'nil' macro is not actually defined.
Definition: Transforms.cpp:214
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:551
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:415
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:922
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:805
void collectRemovables(Stmt *S, ExprSet &exprs)
Definition: Transforms.cpp:313
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:590
Expr - This represents one expression.
Definition: Expr.h:105
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:761
void insertAfterToken(SourceLocation loc, StringRef text)
void removeEmptyStatementsAndDeallocFinalize(MigrationPass &pass)
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:886
Defines the clang::Preprocessor interface.
Stmt * getBody()
Definition: Stmt.h:1078
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:123
void checkAPIUses(MigrationPass &pass)
bool isNot(tok::TokenKind K) const
Definition: Token.h:95
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:860
bool addPropertyAttribute(StringRef attr, SourceLocation atLoc)
Definition: Transforms.cpp:466
ValueDecl * getDecl()
Definition: Expr.h:1017
const SourceManager & SM
Definition: Format.cpp:1184
bool canApplyWeak(ASTContext &Ctx, QualType type, bool AllowOnUnknownClass=false)
Determine whether we can add weak to the given type.
Definition: Transforms.cpp:43
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:1102
void rewriteUnbridgedCasts(MigrationPass &pass)
SelectorTable & Selectors
Definition: ASTContext.h:460
Encodes a location in the source.
body_range body()
Definition: Stmt.h:581
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
bool isValid() const
Return true if this is a valid SourceLocation object.
traverser_iterator traversers_end()
Definition: Transforms.h:109
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2734
SourceLocation getBegin() const
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:94
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:3380
SourceRange getSourceRange() const override LLVM_READONLY
Definition: DeclObjC.h:293
void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:309
void addTraverser(ASTTraverser *traverser)
Definition: Transforms.h:111
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Definition: ExprObjC.h:1155
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:793
static void traverseAST(MigrationPass &pass)
Definition: Transforms.cpp:562
bool isRefType(QualType RetTy, StringRef Prefix, StringRef Name=StringRef())
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1135
void rewriteAutoreleasePool(MigrationPass &pass)
bool hasSideEffects(Expr *E, ASTContext &Ctx)
Definition: Transforms.cpp:173
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1983
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
Definition: Transforms.cpp:587
static void GCRewriteFinalize(MigrationPass &pass)
Definition: Transforms.cpp:522
bool isPlusOne(const Expr *E)
Definition: Transforms.cpp:79
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
void replaceText(SourceLocation loc, StringRef text, StringRef replacementText)
detail::InMemoryDirectory::const_iterator E
body_iterator body_begin()
Definition: Stmt.h:582
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:1473
const Stmt * getThen() const
Definition: Stmt.h:919
Represents a pointer to an Objective C object.
Definition: Type.h:4991
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2461
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2319
void removeZeroOutPropsInDeallocFinalize(MigrationPass &pass)
SourceManager & getSourceManager()
Definition: ASTContext.h:561
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:3761
TransformActions & TA
Definition: Internals.h:151
void remove(SourceRange range)
Opcode getOpcode() const
Definition: Expr.h:2940
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:1047
bool isArrayType() const
Definition: Type.h:5521
void insert(SourceLocation loc, StringRef text)
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2148
Expr * getRHS() const
Definition: Expr.h:2945
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:80
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:932
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
A trivial tuple used to represent a source range.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:665
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition: ExprObjC.h:1136
This class handles loading and caching of source files into memory.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
void startToken()
Reset all flags to cleared.
Definition: Token.h:168