20 using namespace clang;
21 using namespace arcmt;
22 using namespace trans;
26 class ZeroOutInDeallocRemover :
32 llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*> SynthesizedProperties;
38 ZeroOutInDeallocRemover(
MigrationPass &pass) : Pass(pass), SelfD(nullptr) {
54 if (!refE || refE->
getDecl() != SelfD)
57 bool BackedBySynthesizeSetter =
false;
58 for (llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*>::iterator
59 P = SynthesizedProperties.begin(),
60 E = SynthesizedProperties.end();
P != E; ++
P) {
63 BackedBySynthesizeSetter =
true;
67 if (!BackedBySynthesizeSetter)
76 if (RHSIsNull && isRemovable(ME))
83 if (isZeroingPropIvar(POE) && isRemovable(POE)) {
92 if (isZeroingPropIvar(BOE) && isRemovable(BOE)) {
117 if (PID->getPropertyImplementation() ==
121 if (!(setterM && setterM->
isDefined())) {
128 SynthesizedProperties[PD] = PID;
134 base::TraverseObjCMethodDecl(D);
137 SynthesizedProperties.clear();
143 bool TraverseFunctionDecl(
FunctionDecl *D) {
return true; }
144 bool TraverseBlockDecl(
BlockDecl *block) {
return true; }
145 bool TraverseBlockExpr(
BlockExpr *block) {
return true; }
148 bool isRemovable(
Expr *E)
const {
149 return Removables.count(E);
152 bool isZeroingPropIvar(
Expr *E) {
155 return isZeroingPropIvar(BO);
157 return isZeroingPropIvar(PO);
163 return isZeroingPropIvar(BOE->
getLHS()) &&
164 isZeroingPropIvar(BOE->
getRHS());
174 bool IvarBacksPropertySynthesis =
false;
175 for (llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*>::iterator
176 P = SynthesizedProperties.begin(),
177 E = SynthesizedProperties.end();
P != E; ++
P) {
180 IvarBacksPropertySynthesis =
true;
184 if (!IvarBacksPropertySynthesis)
190 return isZero(BOE->
getRHS());
195 if (!BO)
return false;
196 if (BO->
getOpcode() != BO_Assign)
return false;
200 if (!PropRefExp)
return false;
207 if (!SynthesizedProperties.count(PDecl))
211 return isZero(cast<OpaqueValueExpr>(BO->
getRHS())->getSourceExpr());
214 bool isZero(
Expr *E) {
218 return isZeroingPropIvar(E);
225 ZeroOutInDeallocRemover trans(pass);
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Defines the clang::ASTContext interface.
An instance of this class is created to represent 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
IgnoreParenCasts - Ignore parentheses and casts.
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)
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Expr - 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
IgnoreParens - Ignore parentheses.