clang 10.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/AST/ASTContext.h"
12 #include "clang/AST/RecursiveASTVisitor.h"
13 #include "clang/Analysis/DomainSpecific/CocoaConventions.h"
14 #include "clang/Basic/SourceManager.h"
15 #include "clang/Basic/TargetInfo.h"
16 #include "clang/Lex/Lexer.h"
17 #include "clang/Lex/Preprocessor.h"
18 #include "clang/Sema/Sema.h"
19
20 using namespace clang;
21 using namespace arcmt;
22 using namespace trans;
23
24 ASTTraverser::~ASTTraverser() { }
25
26 bool MigrationPass::CFBridgingFunctionsDefined() {
27 if (!EnableCFBridgeFns.hasValue())
28 EnableCFBridgeFns = SemaRef.isKnownName("CFBridgingRetain") &&
29 SemaRef.isKnownName("CFBridgingRelease");
30 return *EnableCFBridgeFns;
31 }
32
33 //===----------------------------------------------------------------------===//
34 // Helpers.
35 //===----------------------------------------------------------------------===//
36
37 bool trans::canApplyWeak(ASTContext &Ctx, QualType type,
38 bool AllowOnUnknownClass) {
39 if (!Ctx.getLangOpts().ObjCWeakRuntime)
40 return false;
41
42 QualType T = type;
43 if (T.isNull())
44 return false;
45
46 // iOS is always safe to use 'weak'.
47 if (Ctx.getTargetInfo().getTriple().isiOS() ||
48 Ctx.getTargetInfo().getTriple().isWatchOS())
49 AllowOnUnknownClass = true;
50
51 while (const PointerType *ptr = T->getAs<PointerType>())
52 T = ptr->getPointeeType();
53 if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
54 ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
55 if (!AllowOnUnknownClass && (!Class || Class->getName() == "NSObject"))
56 return false; // id/NSObject is not safe for weak.
57 if (!AllowOnUnknownClass && !Class->hasDefinition())
58 return false; // forward classes are not verifiable, therefore not safe.
59 if (Class && Class->isArcWeakrefUnavailable())
60 return false;
61 }
62
63 return true;
64 }
65
66 bool trans::isPlusOneAssign(const BinaryOperator *E) {
67 if (E->getOpcode() != BO_Assign)
68 return false;
69
70 return isPlusOne(E->getRHS());
71 }
72
73 bool trans::isPlusOne(const Expr *E) {
74 if (!E)
75 return false;
76 if (const FullExpr *FE = dyn_cast<FullExpr>(E))
77 E = FE->getSubExpr();
78
79 if (const ObjCMessageExpr *
80 ME = dyn_cast<ObjCMessageExpr>(E->IgnoreParenCasts()))
81 if (ME->getMethodFamily() == OMF_retain)
82 return true;
83
84 if (const CallExpr *
85 callE = dyn_cast<CallExpr>(E->IgnoreParenCasts())) {
86 if (const FunctionDecl *FD = callE->getDirectCallee()) {
87 if (FD->hasAttr<CFReturnsRetainedAttr>())
88 return true;
89
90 if (FD->isGlobal() &&
91 FD->getIdentifier() &&
92 FD->getParent()->isTranslationUnit() &&
93 FD->isExternallyVisible() &&
94 ento::cocoa::isRefType(callE->getType(), "CF",
95 FD->getIdentifier()->getName())) {
96 StringRef fname = FD->getIdentifier()->getName();
97 if (fname.endswith("Retain") ||
98 fname.find("Create") != StringRef::npos ||
99 fname.find("Copy") != StringRef::npos) {
100 return true;
101 }
102 }
103 }
104 }
105
106 const ImplicitCastExpr *implCE = dyn_cast<ImplicitCastExpr>(E);
107 while (implCE && implCE->getCastKind() == CK_BitCast)
108 implCE = dyn_cast<ImplicitCastExpr>(implCE->getSubExpr());
109
110 return implCE && implCE->getCastKind() == CK_ARCConsumeObject;
111 }
112
113 /// 'Loc' is the end of a statement range. This returns the location
114 /// immediately after the semicolon following the statement.
115 /// If no semicolon is found or the location is inside a macro, the returned
116 /// source location will be invalid.
117 SourceLocation trans::findLocationAfterSemi(SourceLocation loc,
118 ASTContext &Ctx, bool IsDecl) {
119 SourceLocation SemiLoc = findSemiAfterLocation(loc, Ctx, IsDecl);
120 if (SemiLoc.isInvalid())
121 return SourceLocation();
122 return SemiLoc.getLocWithOffset(1);
123 }
124
125 /// \arg Loc is the end of a statement range. This returns the location
126 /// of the semicolon following the statement.
127 /// If no semicolon is found or the location is inside a macro, the returned
128 /// source location will be invalid.
129 SourceLocation trans::findSemiAfterLocation(SourceLocation loc,
130 ASTContext &Ctx,
131 bool IsDecl) {
132 SourceManager &SM = Ctx.getSourceManager();
133 if (loc.isMacroID()) {
134 if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOpts(), &loc))
135 return SourceLocation();
136 }
137 loc = Lexer::getLocForEndOfToken(loc, /*Offset=*/0, SM, Ctx.getLangOpts());
138
139 // Break down the source location.
140 std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc);
141
142 // Try to load the file buffer.
143 bool invalidTemp = false;
144 StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
145 if (invalidTemp)
146 return SourceLocation();
147
148 const char *tokenBegin = file.data() + locInfo.second;
149
150 // Lex from the start of the given location.
151 Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
152 Ctx.getLangOpts(),
153 file.begin(), tokenBegin, file.end());
154 Token tok;
155 lexer.LexFromRawLexer(tok);
156 if (tok.isNot(tok::semi)) {
157 if (!IsDecl)
158 return SourceLocation();
159 // Declaration may be followed with other tokens; such as an __attribute,
160 // before ending with a semicolon.
161 return findSemiAfterLocation(tok.getLocation(), Ctx, /*IsDecl*/true);
162 }
163
164 return tok.getLocation();
165 }
166
167 bool trans::hasSideEffects(Expr *E, ASTContext &Ctx) {
168 if (!E || !E->HasSideEffects(Ctx))
169 return false;
170
171 E = E->IgnoreParenCasts();
172 ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E);
173 if (!ME)
174 return true;
175 switch (ME->getMethodFamily()) {
176 case OMF_autorelease:
177 case OMF_dealloc:
178 case OMF_release:
179 case OMF_retain:
180 switch (ME->getReceiverKind()) {
181 case ObjCMessageExpr::SuperInstance:
182 return false;
183 case ObjCMessageExpr::Instance:
184 return hasSideEffects(ME->getInstanceReceiver(), Ctx);
185 default:
186 break;
187 }
188 break;
189 default:
190 break;
191 }
192
193 return true;
194 }
195
196 bool trans::isGlobalVar(Expr *E) {
197 E = E->IgnoreParenCasts();
198 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
199 return DRE->getDecl()->getDeclContext()->isFileContext() &&
200 DRE->getDecl()->isExternallyVisible();
201 if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
202 return isGlobalVar(condOp->getTrueExpr()) &&
203 isGlobalVar(condOp->getFalseExpr());
204
205 return false;
206 }
207
208 StringRef trans::getNilString(MigrationPass &Pass) {
209 return Pass.SemaRef.PP.isMacroDefined("nil") ? "nil" : "0";
210 }
211
212 namespace {
213
214 class ReferenceClear : public RecursiveASTVisitor<ReferenceClear> {
215 ExprSet &Refs;
216 public:
217 ReferenceClear(ExprSet &refs) : Refs(refs) { }
218 bool VisitDeclRefExpr(DeclRefExpr *E) { Refs.erase(E); return true; }
219 };
220
221 class ReferenceCollector : public RecursiveASTVisitor<ReferenceCollector> {
222 ValueDecl *Dcl;
223 ExprSet &Refs;
224
225 public:
226 ReferenceCollector(ValueDecl *D, ExprSet &refs)
227 : Dcl(D), Refs(refs) { }
228
229 bool VisitDeclRefExpr(DeclRefExpr *E) {
230 if (E->getDecl() == Dcl)
231 Refs.insert(E);
232 return true;
233 }
234 };
235
236 class RemovablesCollector : public RecursiveASTVisitor<RemovablesCollector> {
237 ExprSet &Removables;
238
239 public:
240 RemovablesCollector(ExprSet &removables)
241 : Removables(removables) { }
242
243 bool shouldWalkTypesOfTypeLocs() const { return false; }
244
245 bool TraverseStmtExpr(StmtExpr *E) {
246 CompoundStmt *S = E->getSubStmt();
247 for (CompoundStmt::body_iterator
248 I = S->body_begin(), E = S->body_end(); I != E; ++I) {
249 if (I != E - 1)
250 mark(*I);
251 TraverseStmt(*I);
252 }
253 return true;
254 }
255
256 bool VisitCompoundStmt(CompoundStmt *S) {
257 for (auto *I : S->body())
258 mark(I);
259 return true;
260 }
261
262 bool VisitIfStmt(IfStmt *S) {
263 mark(S->getThen());
264 mark(S->getElse());
265 return true;
266 }
267
268 bool VisitWhileStmt(WhileStmt *S) {
269 mark(S->getBody());
270 return true;
271 }
272
273 bool VisitDoStmt(DoStmt *S) {
274 mark(S->getBody());
275 return true;
276 }
277
278 bool VisitForStmt(ForStmt *S) {
279 mark(S->getInit());
280 mark(S->getInc());
281 mark(S->getBody());
282 return true;
283 }
284
285 private:
286 void mark(Stmt *S) {
287 if (!S) return;
288
289 while (auto *Label = dyn_cast<LabelStmt>(S))
290 S = Label->getSubStmt();
291 if (auto *E = dyn_cast<Expr>(S))
292 S = E->IgnoreImplicit();
293 if (auto *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
304 void trans::collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs) {
305 ReferenceCollector(D, refs).TraverseStmt(S);
306 }
307
308 void trans::collectRemovables(Stmt *S, ExprSet &exprs) {
309 RemovablesCollector(exprs).TraverseStmt(S);
310 }
311
312 //===----------------------------------------------------------------------===//
313 // MigrationContext
314 //===----------------------------------------------------------------------===//
315
316 namespace {
317
318 class ASTTransform : public RecursiveASTVisitor<ASTTransform> {
319 MigrationContext &MigrateCtx;
320 typedef RecursiveASTVisitor<ASTTransform> base;
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);
329 for (MigrationContext::traverser_iterator
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);
342 for (MigrationContext::traverser_iterator
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
353 MigrationContext::~MigrationContext() {
354 for (traverser_iterator
355 I = traversers_begin(), E = traversers_end(); I != E; ++I)
356 delete *I;
357 }
358
359 bool MigrationContext::isGCOwnedNonObjC(QualType T) {
360 while (!T.isNull()) {
361 if (const AttributedType *AttrT = T->getAs<AttributedType>()) {
362 if (AttrT->getAttrKind() == attr::ObjCOwnership)
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
379 bool MigrationContext::rewritePropertyAttribute(StringRef fromAttr,
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
461 bool MigrationContext::addPropertyAttribute(StringRef attr,
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
509 void MigrationContext::traverse(TranslationUnitDecl *TU) {
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;
520 DeclContext *DC = Ctx.getTranslationUnitDecl();
521 Selector FinalizeSel =
522 Ctx.Selectors.getNullarySelector(&pass.Ctx.Idents.get("finalize"));
523
524 typedef DeclContext::specific_decl_iterator<ObjCImplementationDecl>
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");
537 CharSourceRange::getTokenRange(FinalizeM->getSourceRange());
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(
543 CharSourceRange::getTokenRange(FinalizeM->getSourceRange()),
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()) {
561 MigrateCtx.addTraverser(new GCCollectableCallsTraverser);
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
571 static void independentTransforms(MigrationPass &pass) {
572 rewriteAutoreleasePool(pass);
573 removeRetainReleaseDeallocFinalize(pass);
574 rewriteUnusedInitDelegate(pass);
575 removeZeroOutPropsInDeallocFinalize(pass);
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 }
clang::ForStmt::getInc
Expr * getInc()
Definition: Stmt.h:2443
CocoaConventions.h
clang::SourceManager::getLocForStartOfFile
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
Definition: SourceManager.h:1109
clang::ObjCMessageExpr::SuperInstance
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1107
independentTransforms
static void independentTransforms(MigrationPass &pass)
Definition: Transforms.cpp:571
clang::ast_matchers::type
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchersInternal.cpp:638
ASTContext.h
Defines the clang::ASTContext interface.
clang::ObjCInterfaceDecl::hasDefinition
bool hasDefinition() const
Determine whether this class has been defined.
Definition: DeclObjC.h:1549
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1783
clang::ObjCMessageExpr::Instance
The receiver is an object instance.
Definition: ExprObjC.h:1101
clang::CompoundStmt::body_end
body_iterator body_end()
Definition: Stmt.h:1367
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:76
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:132
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:685
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2614
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:654
clang::Type::isArrayType
bool isArrayType() const
Definition: Type.h:6570
clang::arcmt::trans::MigrationContext::isGCOwnedNonObjC
bool isGCOwnedNonObjC(QualType T)
Definition: Transforms.cpp:359
clang::StmtExpr::getSubStmt
CompoundStmt * getSubStmt()
Definition: Expr.h:3970
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::IfStmt
IfStmt - This represents an if/then/else.
Definition: Stmt.h:1834
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:557
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:994
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
SourceManager.h
Defines the SourceManager interface.
clang::CharSourceRange::getTokenRange
static CharSourceRange getTokenRange(SourceRange R)
Definition: SourceLocation.h:258
llvm::DenseSet
Definition: Sema.h:71
clang::BinaryOperator::getOpcode
Opcode getOpcode() const
Definition: Expr.h:3469
clang::arcmt::MigrationPass
Definition: Internals.h:144
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:707
clang::LangOptions::GCMode
GCMode
Definition: LangOptions.h:57
Internals.h
clang::arcmt::trans::ProtectedScopeTraverser
Definition: Transforms.h:137
clang::arcmt::trans::MigrationContext::traversers_begin
traverser_iterator traversers_begin()
Definition: Transforms.h:107
clang::SourceManager::getBufferData
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
Definition: SourceManager.cpp:702
clang::arcmt::trans::MigrationContext::rewritePropertyAttribute
bool rewritePropertyAttribute(StringRef fromAttr, StringRef toAttr, SourceLocation atLoc)
Definition: Transforms.cpp:379
clang::arcmt::trans::MigrationContext::traverse
void traverse(TranslationUnitDecl *TU)
Definition: Transforms.cpp:509
clang::arcmt::trans::findSemiAfterLocation
SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
&#39;Loc&#39; is the end of a statement range.
Definition: Transforms.cpp:129
Sema.h
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:7002
clang::arcmt::trans::makeAssignARCSafe
void makeAssignARCSafe(MigrationPass &pass)
Definition: TransARCAssign.cpp:74
clang::arcmt::trans::MigrationContext::traverser_iterator
std::vector< ASTTraverser * >::iterator traverser_iterator
Definition: Transforms.h:106
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:138
clang::IfStmt::getThen
Stmt * getThen()
Definition: Stmt.h:1921
clang::arcmt::trans::BlockObjCVariableTraverser
Definition: Transforms.h:132
clang::arcmt::trans::clearRefsIn
void clearRefsIn(Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:300
clang::DoStmt::getBody
Stmt * getBody()
Definition: Stmt.h:2379
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:168
clang::FullExpr
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:950
clang::arcmt::trans::isGlobalVar
bool isGlobalVar(Expr *E)
Definition: Transforms.cpp:196
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::CastExpr::getSubExpr
Expr * getSubExpr()
Definition: Expr.h:3202
clang::arcmt::trans::findLocationAfterSemi
SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
&#39;Loc&#39; is the end of a statement range.
Definition: Transforms.cpp:117
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:53
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:580
clang::SelectorTable::getNullarySelector
Selector getNullarySelector(IdentifierInfo *ID)
Definition: IdentifierTable.h:850
clang::ForStmt
ForStmt - This represents a &#39;for (init;cond;inc)&#39; stmt.
Definition: Stmt.h:2410
clang::arcmt::trans::removeRetainReleaseDeallocFinalize
void removeRetainReleaseDeallocFinalize(MigrationPass &pass)
Definition: TransRetainReleaseDealloc.cpp:456
clang::ForStmt::getBody
Stmt * getBody()
Definition: Stmt.h:2444
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3434
clang::ForStmt::getInit
Stmt * getInit()
Definition: Stmt.h:2423
clang::arcmt::MigrationPass::Ctx
ASTContext & Ctx
Definition: Internals.h:146
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:2995
clang::arcmt::trans::rewriteUnusedInitDelegate
void rewriteUnusedInitDelegate(MigrationPass &pass)
Definition: TransUnusedInitDelegate.cpp:74
clang::Sema::PP
Preprocessor & PP
Definition: Sema.h:384
clang::LangOptions::GCOnly
Definition: LangOptions.h:57
clang::RecursiveASTVisitor
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Definition: RecursiveASTVisitor.h:151
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1186
clang::arcmt::trans::isPlusOneAssign
bool isPlusOneAssign(const BinaryOperator *E)
Definition: Transforms.cpp:66
clang::ConditionalOperator
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:3732
clang::arcmt::trans::getNilString
StringRef getNilString(MigrationPass &Pass)
Returns "nil" or "0" if &#39;nil&#39; macro is not actually defined.
Definition: Transforms.cpp:208
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1332
clang::arcmt::Transaction
Definition: Internals.h:122
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:939
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:3396
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:822
clang::arcmt::trans::collectRemovables
void collectRemovables(Stmt *S, ExprSet &exprs)
Definition: Transforms.cpp:308
clang::arcmt::trans::ObjCImplementationContext
Definition: Transforms.h:59
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:619
clang::Expr
This represents one expression.
Definition: Expr.h:108
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:778
Label
std::string Label
Definition: UsingDeclarationsSorter.cpp:69
clang::arcmt::trans::GCAttrsTraverser
Definition: Transforms.h:144
clang::arcmt::trans::GCCollectableCallsTraverser
Definition: Transforms.h:149
clang::arcmt::MigrationPass::CFBridgingFunctionsDefined
bool CFBridgingFunctionsDefined()
Definition: Transforms.cpp:26
clang::arcmt::TransformActions::insertAfterToken
void insertAfterToken(SourceLocation loc, StringRef text)
Definition: TransformActions.cpp:633
clang::OMF_retain
Definition: IdentifierTable.h:643
clang::arcmt::trans::removeEmptyStatementsAndDeallocFinalize
void removeEmptyStatementsAndDeallocFinalize(MigrationPass &pass)
Definition: TransEmptyStatementsAndDealloc.cpp:240
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:126
Preprocessor.h
Defines the clang::Preprocessor interface.
clang::OMF_dealloc
Definition: IdentifierTable.h:640
clang::WhileStmt::getBody
Stmt * getBody()
Definition: Stmt.h:2287
Lexer.h
clang::OMF_release
Definition: IdentifierTable.h:642
clang::arcmt::trans::checkAPIUses
void checkAPIUses(MigrationPass &pass)
Definition: TransAPIUses.cpp:105
clang::arcmt::trans::BodyContext
Definition: Transforms.h:45
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:950
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:217
clang::ObjCMessageExpr::getReceiverKind
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition: ExprObjC.h:1234
clang::arcmt::trans::MigrationContext::addPropertyAttribute
bool addPropertyAttribute(StringRef attr, SourceLocation atLoc)
Definition: Transforms.cpp:461
clang::DeclRefExpr::getDecl
ValueDecl * getDecl()
Definition: Expr.h:1247
Transforms.h
RecursiveASTVisitor.h
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
SM
const SourceManager & SM
Definition: Format.cpp:1685
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:37
clang::DoStmt
DoStmt - This represents a &#39;do/while&#39; stmt.
Definition: Stmt.h:2354
clang::arcmt::trans::rewriteUnbridgedCasts
void rewriteUnbridgedCasts(MigrationPass &pass)
Definition: TransUnbridgedCasts.cpp:463
clang::arcmt::TransformActions
Definition: Internals.h:47
clang::ASTContext::Selectors
SelectorTable & Selectors
Definition: ASTContext.h:581
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::CompoundStmt::body
body_range body()
Definition: Stmt.h:1365
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:529
clang::DeclContext::decls_begin
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1388
clang::CastExpr::getCastKind
CastKind getCastKind() const
Definition: Expr.h:3196
clang::ObjCMessageExpr::getMethodFamily
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1375
clang::IfStmt::getElse
Stmt * getElse()
Definition: Stmt.h:1930
clang::arcmt::trans::MigrationContext::traversers_end
traverser_iterator traversers_end()
Definition: Transforms.h:108
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3274
clang::StmtExpr
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:3954
clang::ObjCMethodDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclObjC.h:286
clang::arcmt::trans::collectRefs
void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs)
Definition: Transforms.cpp:304
clang::arcmt::trans::MigrationContext::addTraverser
void addTraverser(ASTTraverser *traverser)
Definition: Transforms.h:110
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:1260
clang::Preprocessor::isMacroDefined
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:1020
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
traverseAST
static void traverseAST(MigrationPass &pass)
Definition: Transforms.cpp:557
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::ento::cocoa::isRefType
bool isRefType(QualType RetTy, StringRef Prefix, StringRef Name=StringRef())
Definition: CocoaConventions.cpp:24
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:106
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
clang::arcmt::trans::rewriteAutoreleasePool
void rewriteAutoreleasePool(MigrationPass &pass)
Definition: TransAutoreleasePool.cpp:431
clang::arcmt::trans::hasSideEffects
bool hasSideEffects(Expr *E, ASTContext &Ctx)
Definition: Transforms.cpp:167
clang::arcmt::MigrationPass::SemaRef
Sema & SemaRef
Definition: Internals.h:149
clang::arcmt::getAllTransformations
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
Definition: Transforms.cpp:582
GCRewriteFinalize
static void GCRewriteFinalize(MigrationPass &pass)
Definition: Transforms.cpp:517
type
clang::arcmt::trans::isPlusOne
bool isPlusOne(const Expr *E)
Definition: Transforms.cpp:73
clang::CompoundStmt::body_begin
body_iterator body_begin()
Definition: Stmt.h:1366
clang::DeclContext::specific_decl_iterator
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:2053
clang::SourceLocation::isMacroID
bool isMacroID() const
Definition: SourceLocation.h:99
clang::arcmt::trans::MigrationContext
Definition: Transforms.h:80
clang::ObjCObjectPointerType
Represents a pointer to an Objective C object.
Definition: Type.h:5951
clang::ObjCImplementationDecl
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2566
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:2978
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2750
clang::arcmt::trans::removeZeroOutPropsInDeallocFinalize
void removeZeroOutPropsInDeallocFinalize(MigrationPass &pass)
Definition: TransZeroOutPropsInDealloc.cpp:223
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition: ASTContext.h:679
clang::arcmt::trans::MigrationContext::~MigrationContext
~MigrationContext()
Definition: Transforms.cpp:353
clang::AttributedType
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4550
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1009
clang::arcmt::MigrationPass::TA
TransformActions & TA
Definition: Internals.h:150
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:107
clang::WhileStmt
WhileStmt - This represents a &#39;while&#39; stmt.
Definition: Stmt.h:2226
clang::arcmt::TransformActions::insert
void insert(SourceLocation loc, StringRef text)
Definition: TransformActions.cpp:629
TargetInfo.h
Defines the clang::TargetInfo interface.
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2546
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:250
clang::arcmt::trans::ASTTraverser::~ASTTraverser
virtual ~ASTTraverser()
Definition: Transforms.cpp:24
clang::ObjCInterfaceDecl::isArcWeakrefUnavailable
bool isArcWeakrefUnavailable() const
isArcWeakrefUnavailable - Checks for a class or one of its super classes to be incompatible with __we...
Definition: DeclObjC.cpp:412
clang::arcmt::trans::PropertyRewriteTraverser
Definition: Transforms.h:127
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:82
clang::arcmt::MigrationPass::isGCMigration
bool isGCMigration() const
Definition: Internals.h:165
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1171
clang::BinaryOperator::getRHS
Expr * getRHS() const
Definition: Expr.h:3476
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:207
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:216
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:724
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:596
clang::Token::startToken
void startToken()
Reset all flags to cleared.
Definition: Token.h:171
clang::SourceManager::getDecomposedLoc
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Definition: SourceManager.h:1238
clang::DeclContext::decls_end
decl_iterator decls_end() const
Definition: DeclBase.h:2035
clang::OMF_autorelease
Definition: IdentifierTable.h:639