clang  6.0.0svn
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"
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 ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(E))
78  E = EWC->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") ||
99  fname.find("Create") != StringRef::npos ||
100  fname.find("Copy") != StringRef::npos) {
101  return true;
102  }
103  }
104  }
105  }
106 
107  const ImplicitCastExpr *implCE = dyn_cast<ImplicitCastExpr>(E);
108  while (implCE && implCE->getCastKind() == CK_BitCast)
109  implCE = dyn_cast<ImplicitCastExpr>(implCE->getSubExpr());
110 
111  return implCE && implCE->getCastKind() == CK_ARCConsumeObject;
112 }
113 
114 /// \brief 'Loc' is the end of a statement range. This returns the location
115 /// immediately after the semicolon following the statement.
116 /// If no semicolon is found or the location is inside a macro, the returned
117 /// source location will be invalid.
119  ASTContext &Ctx, bool IsDecl) {
120  SourceLocation SemiLoc = findSemiAfterLocation(loc, Ctx, IsDecl);
121  if (SemiLoc.isInvalid())
122  return SourceLocation();
123  return SemiLoc.getLocWithOffset(1);
124 }
125 
126 /// \brief \arg Loc is the end of a statement range. This returns the location
127 /// of the semicolon following the statement.
128 /// If no semicolon is found or the location is inside a macro, the returned
129 /// source location will be invalid.
131  ASTContext &Ctx,
132  bool IsDecl) {
134  if (loc.isMacroID()) {
135  if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOpts(), &loc))
136  return SourceLocation();
137  }
138  loc = Lexer::getLocForEndOfToken(loc, /*Offset=*/0, SM, Ctx.getLangOpts());
139 
140  // Break down the source location.
141  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc);
142 
143  // Try to load the file buffer.
144  bool invalidTemp = false;
145  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
146  if (invalidTemp)
147  return SourceLocation();
148 
149  const char *tokenBegin = file.data() + locInfo.second;
150 
151  // Lex from the start of the given location.
152  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
153  Ctx.getLangOpts(),
154  file.begin(), tokenBegin, file.end());
155  Token tok;
156  lexer.LexFromRawLexer(tok);
157  if (tok.isNot(tok::semi)) {
158  if (!IsDecl)
159  return SourceLocation();
160  // Declaration may be followed with other tokens; such as an __attribute,
161  // before ending with a semicolon.
162  return findSemiAfterLocation(tok.getLocation(), Ctx, /*IsDecl*/true);
163  }
164 
165  return tok.getLocation();
166 }
167 
169  if (!E || !E->HasSideEffects(Ctx))
170  return false;
171 
172  E = E->IgnoreParenCasts();
173  ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E);
174  if (!ME)
175  return true;
176  switch (ME->getMethodFamily()) {
177  case OMF_autorelease:
178  case OMF_dealloc:
179  case OMF_release:
180  case OMF_retain:
181  switch (ME->getReceiverKind()) {
183  return false;
185  return hasSideEffects(ME->getInstanceReceiver(), Ctx);
186  default:
187  break;
188  }
189  break;
190  default:
191  break;
192  }
193 
194  return true;
195 }
196 
198  E = E->IgnoreParenCasts();
199  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
200  return DRE->getDecl()->getDeclContext()->isFileContext() &&
201  DRE->getDecl()->isExternallyVisible();
202  if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
203  return isGlobalVar(condOp->getTrueExpr()) &&
204  isGlobalVar(condOp->getFalseExpr());
205 
206  return false;
207 }
208 
210  return Pass.SemaRef.PP.isMacroDefined("nil") ? "nil" : "0";
211 }
212 
213 namespace {
214 
215 class ReferenceClear : public RecursiveASTVisitor<ReferenceClear> {
216  ExprSet &Refs;
217 public:
218  ReferenceClear(ExprSet &refs) : Refs(refs) { }
219  bool VisitDeclRefExpr(DeclRefExpr *E) { Refs.erase(E); return true; }
220 };
221 
222 class ReferenceCollector : public RecursiveASTVisitor<ReferenceCollector> {
223  ValueDecl *Dcl;
224  ExprSet &Refs;
225 
226 public:
227  ReferenceCollector(ValueDecl *D, ExprSet &refs)
228  : Dcl(D), Refs(refs) { }
229 
230  bool VisitDeclRefExpr(DeclRefExpr *E) {
231  if (E->getDecl() == Dcl)
232  Refs.insert(E);
233  return true;
234  }
235 };
236 
237 class RemovablesCollector : public RecursiveASTVisitor<RemovablesCollector> {
238  ExprSet &Removables;
239 
240 public:
241  RemovablesCollector(ExprSet &removables)
242  : Removables(removables) { }
243 
244  bool shouldWalkTypesOfTypeLocs() const { return false; }
245 
246  bool TraverseStmtExpr(StmtExpr *E) {
247  CompoundStmt *S = E->getSubStmt();
249  I = S->body_begin(), E = S->body_end(); I != E; ++I) {
250  if (I != E - 1)
251  mark(*I);
252  TraverseStmt(*I);
253  }
254  return true;
255  }
256 
257  bool VisitCompoundStmt(CompoundStmt *S) {
258  for (auto *I : S->body())
259  mark(I);
260  return true;
261  }
262 
263  bool VisitIfStmt(IfStmt *S) {
264  mark(S->getThen());
265  mark(S->getElse());
266  return true;
267  }
268 
269  bool VisitWhileStmt(WhileStmt *S) {
270  mark(S->getBody());
271  return true;
272  }
273 
274  bool VisitDoStmt(DoStmt *S) {
275  mark(S->getBody());
276  return true;
277  }
278 
279  bool VisitForStmt(ForStmt *S) {
280  mark(S->getInit());
281  mark(S->getInc());
282  mark(S->getBody());
283  return true;
284  }
285 
286 private:
287  void mark(Stmt *S) {
288  if (!S) return;
289 
290  while (LabelStmt *Label = dyn_cast<LabelStmt>(S))
291  S = Label->getSubStmt();
292  S = S->IgnoreImplicit();
293  if (Expr *E = dyn_cast<Expr>(S))
294  Removables.insert(E);
295  }
296 };
297 
298 } // end anonymous namespace
299 
300 void trans::clearRefsIn(Stmt *S, ExprSet &refs) {
301  ReferenceClear(refs).TraverseStmt(S);
302 }
303 
305  ReferenceCollector(D, refs).TraverseStmt(S);
306 }
307 
309  RemovablesCollector(exprs).TraverseStmt(S);
310 }
311 
312 //===----------------------------------------------------------------------===//
313 // MigrationContext
314 //===----------------------------------------------------------------------===//
315 
316 namespace {
317 
318 class ASTTransform : public RecursiveASTVisitor<ASTTransform> {
319  MigrationContext &MigrateCtx;
321 
322 public:
323  ASTTransform(MigrationContext &MigrateCtx) : MigrateCtx(MigrateCtx) { }
324 
325  bool shouldWalkTypesOfTypeLocs() const { return false; }
326 
327  bool TraverseObjCImplementationDecl(ObjCImplementationDecl *D) {
328  ObjCImplementationContext ImplCtx(MigrateCtx, D);
330  I = MigrateCtx.traversers_begin(),
331  E = MigrateCtx.traversers_end(); I != E; ++I)
332  (*I)->traverseObjCImplementation(ImplCtx);
333 
334  return base::TraverseObjCImplementationDecl(D);
335  }
336 
337  bool TraverseStmt(Stmt *rootS) {
338  if (!rootS)
339  return true;
340 
341  BodyContext BodyCtx(MigrateCtx, rootS);
343  I = MigrateCtx.traversers_begin(),
344  E = MigrateCtx.traversers_end(); I != E; ++I)
345  (*I)->traverseBody(BodyCtx);
346 
347  return true;
348  }
349 };
350 
351 }
352 
354  for (traverser_iterator
355  I = traversers_begin(), E = traversers_end(); I != E; ++I)
356  delete *I;
357 }
358 
360  while (!T.isNull()) {
361  if (const AttributedType *AttrT = T->getAs<AttributedType>()) {
362  if (AttrT->getAttrKind() == AttributedType::attr_objc_ownership)
363  return !AttrT->getModifiedType()->isObjCRetainableType();
364  }
365 
366  if (T->isArrayType())
367  T = Pass.Ctx.getBaseElementType(T);
368  else if (const PointerType *PT = T->getAs<PointerType>())
369  T = PT->getPointeeType();
370  else if (const ReferenceType *RT = T->getAs<ReferenceType>())
371  T = RT->getPointeeType();
372  else
373  break;
374  }
375 
376  return false;
377 }
378 
380  StringRef toAttr,
381  SourceLocation atLoc) {
382  if (atLoc.isMacroID())
383  return false;
384 
385  SourceManager &SM = Pass.Ctx.getSourceManager();
386 
387  // Break down the source location.
388  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
389 
390  // Try to load the file buffer.
391  bool invalidTemp = false;
392  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
393  if (invalidTemp)
394  return false;
395 
396  const char *tokenBegin = file.data() + locInfo.second;
397 
398  // Lex from the start of the given location.
399  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
400  Pass.Ctx.getLangOpts(),
401  file.begin(), tokenBegin, file.end());
402  Token tok;
403  lexer.LexFromRawLexer(tok);
404  if (tok.isNot(tok::at)) return false;
405  lexer.LexFromRawLexer(tok);
406  if (tok.isNot(tok::raw_identifier)) return false;
407  if (tok.getRawIdentifier() != "property")
408  return false;
409  lexer.LexFromRawLexer(tok);
410  if (tok.isNot(tok::l_paren)) return false;
411 
412  Token BeforeTok = tok;
413  Token AfterTok;
414  AfterTok.startToken();
415  SourceLocation AttrLoc;
416 
417  lexer.LexFromRawLexer(tok);
418  if (tok.is(tok::r_paren))
419  return false;
420 
421  while (1) {
422  if (tok.isNot(tok::raw_identifier)) return false;
423  if (tok.getRawIdentifier() == fromAttr) {
424  if (!toAttr.empty()) {
425  Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
426  return true;
427  }
428  // We want to remove the attribute.
429  AttrLoc = tok.getLocation();
430  }
431 
432  do {
433  lexer.LexFromRawLexer(tok);
434  if (AttrLoc.isValid() && AfterTok.is(tok::unknown))
435  AfterTok = tok;
436  } while (tok.isNot(tok::comma) && tok.isNot(tok::r_paren));
437  if (tok.is(tok::r_paren))
438  break;
439  if (AttrLoc.isInvalid())
440  BeforeTok = tok;
441  lexer.LexFromRawLexer(tok);
442  }
443 
444  if (toAttr.empty() && AttrLoc.isValid() && AfterTok.isNot(tok::unknown)) {
445  // We want to remove the attribute.
446  if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::r_paren)) {
447  Pass.TA.remove(SourceRange(BeforeTok.getLocation(),
448  AfterTok.getLocation()));
449  } else if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::comma)) {
450  Pass.TA.remove(SourceRange(AttrLoc, AfterTok.getLocation()));
451  } else {
452  Pass.TA.remove(SourceRange(BeforeTok.getLocation(), AttrLoc));
453  }
454 
455  return true;
456  }
457 
458  return false;
459 }
460 
462  SourceLocation atLoc) {
463  if (atLoc.isMacroID())
464  return false;
465 
466  SourceManager &SM = Pass.Ctx.getSourceManager();
467 
468  // Break down the source location.
469  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
470 
471  // Try to load the file buffer.
472  bool invalidTemp = false;
473  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
474  if (invalidTemp)
475  return false;
476 
477  const char *tokenBegin = file.data() + locInfo.second;
478 
479  // Lex from the start of the given location.
480  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
481  Pass.Ctx.getLangOpts(),
482  file.begin(), tokenBegin, file.end());
483  Token tok;
484  lexer.LexFromRawLexer(tok);
485  if (tok.isNot(tok::at)) return false;
486  lexer.LexFromRawLexer(tok);
487  if (tok.isNot(tok::raw_identifier)) return false;
488  if (tok.getRawIdentifier() != "property")
489  return false;
490  lexer.LexFromRawLexer(tok);
491 
492  if (tok.isNot(tok::l_paren)) {
493  Pass.TA.insert(tok.getLocation(), std::string("(") + attr.str() + ") ");
494  return true;
495  }
496 
497  lexer.LexFromRawLexer(tok);
498  if (tok.is(tok::r_paren)) {
499  Pass.TA.insert(tok.getLocation(), attr);
500  return true;
501  }
502 
503  if (tok.isNot(tok::raw_identifier)) return false;
504 
505  Pass.TA.insert(tok.getLocation(), std::string(attr) + ", ");
506  return true;
507 }
508 
510  for (traverser_iterator
511  I = traversers_begin(), E = traversers_end(); I != E; ++I)
512  (*I)->traverseTU(*this);
513 
514  ASTTransform(*this).TraverseDecl(TU);
515 }
516 
517 static void GCRewriteFinalize(MigrationPass &pass) {
518  ASTContext &Ctx = pass.Ctx;
519  TransformActions &TA = pass.TA;
521  Selector FinalizeSel =
522  Ctx.Selectors.getNullarySelector(&pass.Ctx.Idents.get("finalize"));
523 
525  impl_iterator;
526  for (impl_iterator I = impl_iterator(DC->decls_begin()),
527  E = impl_iterator(DC->decls_end()); I != E; ++I) {
528  for (const auto *MD : I->instance_methods()) {
529  if (!MD->hasBody())
530  continue;
531 
532  if (MD->isInstanceMethod() && MD->getSelector() == FinalizeSel) {
533  const ObjCMethodDecl *FinalizeM = MD;
534  Transaction Trans(TA);
535  TA.insert(FinalizeM->getSourceRange().getBegin(),
536  "#if !__has_feature(objc_arc)\n");
538  const SourceManager &SM = pass.Ctx.getSourceManager();
539  const LangOptions &LangOpts = pass.Ctx.getLangOpts();
540  bool Invalid;
541  std::string str = "\n#endif\n";
542  str += Lexer::getSourceText(
544  SM, LangOpts, &Invalid);
545  TA.insertAfterToken(FinalizeM->getSourceRange().getEnd(), str);
546 
547  break;
548  }
549  }
550  }
551 }
552 
553 //===----------------------------------------------------------------------===//
554 // getAllTransformations.
555 //===----------------------------------------------------------------------===//
556 
557 static void traverseAST(MigrationPass &pass) {
558  MigrationContext MigrateCtx(pass);
559 
560  if (pass.isGCMigration()) {
562  MigrateCtx.addTraverser(new GCAttrsTraverser());
563  }
564  MigrateCtx.addTraverser(new PropertyRewriteTraverser());
565  MigrateCtx.addTraverser(new BlockObjCVariableTraverser());
566  MigrateCtx.addTraverser(new ProtectedScopeTraverser());
567 
568  MigrateCtx.traverse(pass.Ctx.getTranslationUnitDecl());
569 }
570 
576  makeAssignARCSafe(pass);
577  rewriteUnbridgedCasts(pass);
578  checkAPIUses(pass);
579  traverseAST(pass);
580 }
581 
582 std::vector<TransformFn> arcmt::getAllTransformations(
583  LangOptions::GCMode OrigGCMode,
584  bool NoFinalizeRemoval) {
585  std::vector<TransformFn> transforms;
586 
587  if (OrigGCMode == LangOptions::GCOnly && NoFinalizeRemoval)
588  transforms.push_back(GCRewriteFinalize);
589  transforms.push_back(independentTransforms);
590  // This depends on previous transformations removing various expressions.
591  transforms.push_back(removeEmptyStatementsAndDeallocFinalize);
592 
593  return transforms;
594 }
Expr * getInc()
Definition: Stmt.h:1237
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1060
static void independentTransforms(MigrationPass &pass)
Definition: Transforms.cpp:571
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
bool hasDefinition() const
Determine whether this class has been defined.
Definition: DeclObjC.h:1554
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
The receiver is an object instance.
Definition: ExprObjC.h:1054
const Stmt * getElse() const
Definition: Stmt.h:969
body_iterator body_end()
Definition: Stmt.h:626
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:77
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Smart pointer class that efficiently represents Objective-C method names.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2285
A (possibly-)qualified type.
Definition: Type.h:653
bool isArrayType() const
Definition: Type.h:5993
CompoundStmt * getSubStmt()
Definition: Expr.h:3504
Stmt - This represents one statement.
Definition: Stmt.h:66
IfStmt - This represents an if/then/else.
Definition: Stmt.h:929
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:456
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:790
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:95
Defines the SourceManager interface.
static CharSourceRange getTokenRange(SourceRange R)
Opcode getOpcode() const
Definition: Expr.h:3026
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:671
Stmt * IgnoreImplicit()
Skip past any implicit AST nodes which might surround this statement, such as ExprWithCleanups or Imp...
Definition: Stmt.cpp:112
traverser_iterator traversers_begin()
Definition: Transforms.h:108
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
bool rewritePropertyAttribute(StringRef fromAttr, StringRef toAttr, SourceLocation atLoc)
Definition: Transforms.cpp:379
void traverse(TranslationUnitDecl *TU)
Definition: Transforms.cpp:509
SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
&#39;Loc&#39; is the end of a statement range.
Definition: Transforms.cpp:130
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6307
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:139
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Definition: ExprCXX.h:3000
void clearRefsIn(Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:300
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:839
Stmt * getBody()
Definition: Stmt.h:1175
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
bool isGlobalVar(Expr *E)
Definition: Transforms.cpp:197
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
Expr * getSubExpr()
Definition: Expr.h:2761
SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
&#39;Loc&#39; is the end of a statement range.
Definition: Transforms.cpp:118
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:537
Selector getNullarySelector(IdentifierInfo *ID)
ForStmt - This represents a &#39;for (init;cond;inc)&#39; stmt.
Definition: Stmt.h:1203
void removeRetainReleaseDeallocFinalize(MigrationPass &pass)
Stmt * getBody()
Definition: Stmt.h:1238
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:2985
Stmt * getInit()
Definition: Stmt.h:1217
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
Definition: Expr.cpp:2463
void rewriteUnusedInitDelegate(MigrationPass &pass)
Preprocessor & PP
Definition: Sema.h:315
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
Definition: DeclObjC.h:1191
bool isPlusOneAssign(const BinaryOperator *E)
Definition: Transforms.cpp:67
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:3269
StringRef getNilString(MigrationPass &Pass)
Returns "nil" or "0" if &#39;nil&#39; macro is not actually defined.
Definition: Transforms.cpp:209
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:595
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:934
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:2940
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:817
void collectRemovables(Stmt *S, ExprSet &exprs)
Definition: Transforms.cpp:308
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:628
Expr - This represents one expression.
Definition: Expr.h:106
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:773
std::string Label
const FunctionProtoType * T
void insertAfterToken(SourceLocation loc, StringRef text)
const Stmt * getThen() const
Definition: Stmt.h:967
void removeEmptyStatementsAndDeallocFinalize(MigrationPass &pass)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
Defines the clang::Preprocessor interface.
Stmt * getBody()
Definition: Stmt.h:1130
void checkAPIUses(MigrationPass &pass)
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:903
SourceLocation getEnd() const
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition: ExprObjC.h:1187
bool addPropertyAttribute(StringRef attr, SourceLocation atLoc)
Definition: Transforms.cpp:461
ValueDecl * getDecl()
Definition: Expr.h:1041
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
const SourceManager & SM
Definition: Format.cpp:1337
bool canApplyWeak(ASTContext &Ctx, QualType type, bool AllowOnUnknownClass=false)
Determine whether we can add weak to the given type.
Definition: Transforms.cpp:38
DoStmt - This represents a &#39;do/while&#39; stmt.
Definition: Stmt.h:1154
void rewriteUnbridgedCasts(MigrationPass &pass)
SelectorTable & Selectors
Definition: ASTContext.h:538
Encodes a location in the source.
body_range body()
Definition: Stmt.h:624
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1320
CastKind getCastKind() const
Definition: Expr.h:2757
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1321
traverser_iterator traversers_end()
Definition: Transforms.h:109
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2822
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:3488
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:323
void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:304
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:1206
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:916
bool isNot(tok::TokenKind K) const
Definition: Token.h:96
static void traverseAST(MigrationPass &pass)
Definition: Transforms.cpp:557
Dataflow Directional Tag Classes.
bool isRefType(QualType RetTy, StringRef Prefix, StringRef Name=StringRef())
bool isValid() const
Return true if this is a valid SourceLocation object.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
void rewriteAutoreleasePool(MigrationPass &pass)
bool hasSideEffects(Expr *E, ASTContext &Ctx)
Definition: Transforms.cpp:168
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
Definition: Transforms.cpp:582
static void GCRewriteFinalize(MigrationPass &pass)
Definition: Transforms.cpp:517
bool isPlusOne(const Expr *E)
Definition: Transforms.cpp:74
body_iterator body_begin()
Definition: Stmt.h:625
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:1596
bool isMacroID() const
Represents a pointer to an Objective C object.
Definition: Type.h:5442
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2571
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2421
void removeZeroOutPropsInDeallocFinalize(MigrationPass &pass)
SourceManager & getSourceManager()
Definition: ASTContext.h:643
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4033
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:989
TransformActions & TA
Definition: Internals.h:151
WhileStmt - This represents a &#39;while&#39; stmt.
Definition: Stmt.h:1098
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:2209
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:270
bool isArcWeakrefUnavailable() const
isArcWeakrefUnavailable - Checks for a class or one of its super classes to be incompatible with __we...
Definition: DeclObjC.cpp:405
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:107
bool isGCMigration() const
Definition: Internals.h:166
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:956
Expr * getRHS() const
Definition: Expr.h:3031
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
Definition: ASTContext.h:688
This class handles loading and caching of source files into memory.
void startToken()
Reset all flags to cleared.
Definition: Token.h:169
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
decl_iterator decls_end() const
Definition: DeclBase.h:1578