27 using namespace clang;
31 typedef llvm::DenseMap<const ObjCIvarDecl*,IVarState>
IvarUsageMap;
39 IvarUsageMap::iterator I = M.find(D);
46 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(S)) {
47 Scan(M, BE->getBody());
53 i = POE->semantics_begin(), e = POE->semantics_end(); i != e; ++i) {
56 sub = OVE->getSourceExpr();
60 for (
const Stmt *SubStmt : S->children())
73 IvarUsageMap::iterator I = M.find(ID);
81 Scan(M, I->getBody());
86 for (
const auto *I :
ID->property_impls())
90 for (
const auto *Cat :
ID->getClassInterface()->visible_categories()) {
99 for (
const auto *I : C->
decls())
100 if (
const auto *FD = dyn_cast<FunctionDecl>(I)) {
103 Scan(M, FD->getBody());
115 for (
const auto *Ivar : ID->
ivars()) {
122 Ivar->hasAttr<UnusedAttr>() || Ivar->hasAttr<IBOutletAttr>() ||
123 Ivar->hasAttr<IBOutletCollectionAttr>() ||
124 Ivar->isUnnamedBitfield())
137 bool hasUnused =
false;
138 for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
139 if (I->second ==
Unused) {
156 for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
157 if (I->second ==
Unused) {
159 llvm::raw_string_ostream os(sbuf);
160 os <<
"Instance variable '" << *I->first <<
"' in class '" << *ID
161 <<
"' is never used by the methods in its @implementation "
162 "(although it may be used by category methods).";
166 BR.
EmitBasicReport(D, Checker,
"Unused instance variable",
"Optimization",
176 class ObjCUnusedIvarsChecker :
public Checker<
177 check::ASTDecl<ObjCImplementationDecl> > {
Defines the SourceManager interface.
static void Scan(IvarUsageMap &M, const Stmt *S)
const Expr *const * const_semantics_iterator
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
Represents an ObjC class declaration.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
ID
Defines the set of possible language-specific address spaces.
static void checkObjCUnusedIvar(const ObjCImplementationDecl *D, BugReporter &BR, const CheckerBase *Checker)
Defines the clang::LangOptions interface.
ObjCIvarDecl * getPropertyIvarDecl() const
DeclContext * getDeclContext()
CHECKER * registerChecker()
Used to register checkers.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=None)
const ObjCInterfaceDecl * getClassInterface() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
instmeth_range instance_methods() const
llvm::DenseMap< const ObjCIvarDecl *, IVarState > IvarUsageMap
ObjCIvarRefExpr - A reference to an ObjC instance variable.
SourceManager & getSourceManager()
SourceLocation getLocation() const
This class handles loading and caching of source files into memory.