19 using namespace clang;
20 using namespace arcmt;
21 using namespace trans;
25 class ZeroOutInDeallocRemover :
31 llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*> SynthesizedProperties;
37 ZeroOutInDeallocRemover(
MigrationPass &pass) : Pass(pass), SelfD(nullptr) {
53 if (!refE || refE->
getDecl() != SelfD)
56 bool BackedBySynthesizeSetter =
false;
57 for (llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*>::iterator
58 P = SynthesizedProperties.begin(),
59 E = SynthesizedProperties.end();
P != E; ++
P) {
62 BackedBySynthesizeSetter =
true;
66 if (!BackedBySynthesizeSetter)
75 if (RHSIsNull && isRemovable(ME))
82 if (isZeroingPropIvar(POE) && isRemovable(POE)) {
91 if (isZeroingPropIvar(BOE) && isRemovable(BOE)) {
116 if (PID->getPropertyImplementation() ==
120 if (!(setterM && setterM->
isDefined())) {
127 SynthesizedProperties[PD] = PID;
133 base::TraverseObjCMethodDecl(D);
136 SynthesizedProperties.clear();
142 bool TraverseFunctionDecl(
FunctionDecl *D) {
return true; }
143 bool TraverseBlockDecl(
BlockDecl *block) {
return true; }
144 bool TraverseBlockExpr(
BlockExpr *block) {
return true; }
147 bool isRemovable(
Expr *E)
const {
148 return Removables.count(E);
151 bool isZeroingPropIvar(
Expr *E) {
154 return isZeroingPropIvar(BO);
156 return isZeroingPropIvar(PO);
162 return isZeroingPropIvar(BOE->
getLHS()) &&
163 isZeroingPropIvar(BOE->
getRHS());
173 bool IvarBacksPropertySynthesis =
false;
174 for (llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*>::iterator
175 P = SynthesizedProperties.begin(),
176 E = SynthesizedProperties.end();
P != E; ++
P) {
179 IvarBacksPropertySynthesis =
true;
183 if (!IvarBacksPropertySynthesis)
189 return isZero(BOE->
getRHS());
194 if (!BO)
return false;
195 if (BO->
getOpcode() != BO_Assign)
return false;
199 if (!PropRefExp)
return false;
206 if (!SynthesizedProperties.count(PDecl))
210 return isZero(cast<OpaqueValueExpr>(BO->
getRHS())->getSourceExpr());
213 bool isZero(
Expr *E) {
217 return isZeroingPropIvar(E);
224 ZeroOutInDeallocRemover trans(pass);
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
The receiver is an object instance.
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Smart pointer class that efficiently represents Objective-C method names.
Selector getSelector() const
ObjCIvarDecl * getPropertyIvarDecl() const
ObjCMethodDecl - Represents an instance or class method declaration.
ObjCPropertyDecl * getExplicitProperty() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ObjCMethodDecl * getSetterMethodDecl() const
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Selector getNullarySelector(IdentifierInfo *ID)
PropertyAttributeKind getPropertyAttributes() const
A builtin binary operation expression such as "x + y" or "x <= y".
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
void collectRemovables(Stmt *S, ExprSet &exprs)
Represents a block literal declaration, which is like an unnamed FunctionDecl.
This represents one expression.
Selector getSetterName() const
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
DeclContext * getDeclContext()
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
propimpl_range property_impls() const
An expression that sends a message to the given Objective-C object or class.
bool isInstanceMethod() const
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Selector getSelector() const
ImplicitParamDecl * getSelfDecl() const
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
SelectorTable & Selectors
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
bool isImplicitProperty() const
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
bool isObjCObjectPointerType() const
Represents one property declaration in an Objective-C interface.
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Dataflow Directional Tag Classes.
bool hasBody() const override
Determine whether this method has a body.
void removeZeroOutPropsInDeallocFinalize(MigrationPass &pass)
ObjCIvarRefExpr - A reference to an ObjC instance variable.
TranslationUnitDecl * getTranslationUnitDecl() const
ObjCIvarDecl - Represents an ObjC instance variable.
A reference to a declared variable, function, enum, etc.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...