[PATCH] D125706: [analyzer][NFC] Use idiomatic classof instead of isKind
This revision was automatically updated to reflect the committed changes. Closed by commit rGe37b287998a7: [analyzer][NFC] Use idiomatic classof instead of isKind (authored by steakhal). Changed prior to commit: https://reviews.llvm.org/D125706?vs=429767=432493#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125706/new/ https://reviews.llvm.org/D125706 Files: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h === --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -100,7 +100,7 @@ /// the desired type. template T castAs() const { -assert(T::isKind(*this)); +assert(T::classof(*this)); return *static_cast(this); } @@ -108,7 +108,7 @@ /// not of the desired type. template Optional getAs() const { -if (!T::isKind(*this)) +if (!T::classof(*this)) return None; return *static_cast(this); } @@ -124,13 +124,11 @@ ID.AddPointer(Data); } - bool operator==(const SVal ) const { + bool operator==(SVal R) const { return getRawKind() == R.getRawKind() && Data == R.Data; } - bool operator!=(const SVal ) const { -return !(*this == R); - } + bool operator!=(SVal R) const { return !(*this == R); } bool isUnknown() const { return getRawKind() == UnknownValKind; @@ -221,12 +219,10 @@ public: UndefinedVal() : SVal(UndefinedValKind) {} + static bool classof(SVal V) { return V.getBaseKind() == UndefinedValKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == UndefinedValKind; - } }; class DefinedOrUnknownSVal : public SVal { @@ -236,6 +232,8 @@ bool isUndef() const = delete; bool isValid() const = delete; + static bool classof(SVal V) { return !V.isUndef(); } + protected: DefinedOrUnknownSVal() = default; explicit DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind) @@ -244,22 +242,16 @@ private: friend class SVal; - - static bool isKind(const SVal& V) { -return !V.isUndef(); - } }; class UnknownVal : public DefinedOrUnknownSVal { public: explicit UnknownVal() : DefinedOrUnknownSVal(UnknownValKind) {} + static bool classof(SVal V) { return V.getBaseKind() == UnknownValKind; } + private: friend class SVal; - - static bool isKind(const SVal ) { -return V.getBaseKind() == UnknownValKind; - } }; class DefinedSVal : public DefinedOrUnknownSVal { @@ -270,6 +262,8 @@ bool isUnknownOrUndef() const = delete; bool isValid() const = delete; + static bool classof(SVal V) { return !V.isUnknownOrUndef(); } + protected: DefinedSVal() = default; explicit DefinedSVal(const void *d, bool isLoc, unsigned ValKind) @@ -277,25 +271,17 @@ private: friend class SVal; - - static bool isKind(const SVal& V) { -return !V.isUnknownOrUndef(); - } }; /// Represents an SVal that is guaranteed to not be UnknownVal. class KnownSVal : public SVal { friend class SVal; - KnownSVal() = default; - static bool isKind(const SVal ) { -return !V.isUnknown(); - } - public: KnownSVal(const DefinedSVal ) : SVal(V) {} KnownSVal(const UndefinedVal ) : SVal(V) {} + static bool classof(SVal V) { return !V.isUnknown(); } }; class NonLoc : public DefinedSVal { @@ -312,12 +298,10 @@ T->isAnyComplexType() || T->isVectorType(); } + static bool classof(SVal V) { return V.getBaseKind() == NonLocKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == NonLocKind; - } }; class Loc : public DefinedSVal { @@ -334,12 +318,10 @@ T->isReferenceType() || T->isNullPtrType(); } + static bool classof(SVal V) { return V.getBaseKind() == LocKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == LocKind; - } }; //====// @@ -365,17 +347,14 @@ return !isa(getSymbol()); } -private: - friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == NonLocKind && - V.getSubKind() == SymbolValKind; + static bool classof(SVal V) { +return V.getBaseKind() == NonLocKind && V.getSubKind() == SymbolValKind; } - static bool isKind(const NonLoc& V) { -return V.getSubKind() == SymbolValKind; - } + static bool classof(NonLoc V) { return V.getSubKind() == SymbolValKind; } + +private: + friend class SVal; }; /// Value representing integer constant. @@ -392,19 +371,15 @@ ConcreteInt evalMinus(SValBuilder ) const; + static bool classof(SVal V) { +return V.getBaseKind() == NonLocKind && V.getSubKind() == ConcreteIntKind; + } + + static
[PATCH] D125706: [analyzer][NFC] Use idiomatic classof instead of isKind
martong accepted this revision. martong added a comment. This revision is now accepted and ready to land. LGTM Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125706/new/ https://reviews.llvm.org/D125706 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D125706: [analyzer][NFC] Use idiomatic classof instead of isKind
steakhal created this revision. steakhal added reviewers: NoQ, martong, Szelethus, balazske, ASDenysPetrov, bzcheeseman. Herald added subscribers: manas, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun. Herald added a project: All. steakhal requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. - Rename `isKind()` to `classof()` to follow the llvm style RTTI. - Take SVal by-value instead of reference. - Mark `classof` public. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D125706 Files: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h === --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -100,7 +100,7 @@ /// the desired type. template T castAs() const { -assert(T::isKind(*this)); +assert(T::classof(*this)); return *static_cast(this); } @@ -108,7 +108,7 @@ /// not of the desired type. template Optional getAs() const { -if (!T::isKind(*this)) +if (!T::classof(*this)) return None; return *static_cast(this); } @@ -124,13 +124,11 @@ ID.AddPointer(Data); } - bool operator==(const SVal ) const { + bool operator==(SVal R) const { return getRawKind() == R.getRawKind() && Data == R.Data; } - bool operator!=(const SVal ) const { -return !(*this == R); - } + bool operator!=(SVal R) const { return !(*this == R); } bool isUnknown() const { return getRawKind() == UnknownValKind; @@ -224,12 +222,10 @@ public: UndefinedVal() : SVal(UndefinedValKind) {} + static bool classof(SVal V) { return V.getBaseKind() == UndefinedValKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == UndefinedValKind; - } }; class DefinedOrUnknownSVal : public SVal { @@ -239,6 +235,8 @@ bool isUndef() const = delete; bool isValid() const = delete; + static bool classof(SVal V) { return !V.isUndef(); } + protected: DefinedOrUnknownSVal() = default; explicit DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind) @@ -247,22 +245,16 @@ private: friend class SVal; - - static bool isKind(const SVal& V) { -return !V.isUndef(); - } }; class UnknownVal : public DefinedOrUnknownSVal { public: explicit UnknownVal() : DefinedOrUnknownSVal(UnknownValKind) {} + static bool classof(SVal V) { return V.getBaseKind() == UnknownValKind; } + private: friend class SVal; - - static bool isKind(const SVal ) { -return V.getBaseKind() == UnknownValKind; - } }; class DefinedSVal : public DefinedOrUnknownSVal { @@ -273,6 +265,8 @@ bool isUnknownOrUndef() const = delete; bool isValid() const = delete; + static bool classof(SVal V) { return !V.isUnknownOrUndef(); } + protected: DefinedSVal() = default; explicit DefinedSVal(const void *d, bool isLoc, unsigned ValKind) @@ -280,25 +274,17 @@ private: friend class SVal; - - static bool isKind(const SVal& V) { -return !V.isUnknownOrUndef(); - } }; /// Represents an SVal that is guaranteed to not be UnknownVal. class KnownSVal : public SVal { friend class SVal; - KnownSVal() = default; - static bool isKind(const SVal ) { -return !V.isUnknown(); - } - public: KnownSVal(const DefinedSVal ) : SVal(V) {} KnownSVal(const UndefinedVal ) : SVal(V) {} + static bool classof(SVal V) { return !V.isUnknown(); } }; class NonLoc : public DefinedSVal { @@ -315,12 +301,10 @@ T->isAnyComplexType() || T->isVectorType(); } + static bool classof(SVal V) { return V.getBaseKind() == NonLocKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == NonLocKind; - } }; class Loc : public DefinedSVal { @@ -337,12 +321,10 @@ T->isReferenceType() || T->isNullPtrType(); } + static bool classof(SVal V) { return V.getBaseKind() == LocKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == LocKind; - } }; //====// @@ -368,17 +350,14 @@ return !isa(getSymbol()); } -private: - friend class SVal; - - static bool isKind(const SVal& V) { -return V.getBaseKind() == NonLocKind && - V.getSubKind() == SymbolValKind; + static bool classof(SVal V) { +return V.getBaseKind() == NonLocKind && V.getSubKind() == SymbolValKind; } - static bool isKind(const NonLoc& V) { -return V.getSubKind() == SymbolValKind; - } + static bool classof(NonLoc V) { return V.getSubKind() == SymbolValKind; } + +private: + friend class SVal; }; /// Value representing integer constant. @@