27 using namespace clang;
31 typedef llvm::DenseMap<const ObjCIvarDecl*,IVarState>
IvarUsageMap;
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())
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;
153 Scan(M, D->getDeclContext(), SM.
getFileID(D->getLocation()), SM);
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> > {
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Defines the SourceManager interface.
static void Scan(IvarUsageMap &M, const Stmt *S)
const Expr *const * const_semantics_iterator
ObjCContainerDecl - Represents a container for method declarations.
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
Represents an ObjC class declaration.
detail::InMemoryDirectory::const_iterator I
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
static void checkObjCUnusedIvar(const ObjCImplementationDecl *D, BugReporter &BR, const CheckerBase *Checker)
Expr - This represents one expression.
Defines the clang::LangOptions interface.
ObjCIvarDecl * getPropertyIvarDecl() const
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BugReporter is a utility class for generating PathDiagnostics for analysis.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
CHECKER * registerChecker()
Used to register checkers.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Encodes a location in the source.
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=None)
const TemplateArgument * iterator
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
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
detail::InMemoryDirectory::const_iterator E
llvm::DenseMap< const ObjCIvarDecl *, IVarState > IvarUsageMap
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
ObjCIvarRefExpr - A reference to an ObjC instance variable.
SourceManager & getSourceManager()
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
This class handles loading and caching of source files into memory.