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