14using ast_matchers::callee;
18using ast_matchers::hasCanonicalType;
21using ast_matchers::ofClass;
22using ast_matchers::parameterCountIs;
25using ast_matchers::returns;
28 if (!RT.isNull() && RT->isPointerType()) {
29 return RT->getPointeeType()->getCanonicalTypeUnqualified();
35 if (!RT.isNull() && RT->isReferenceType()) {
36 return RT.getNonReferenceType()->getCanonicalTypeUnqualified();
41CanQualType pointerLikeReturnType(
const CXXRecordDecl &RD) {
45 for (
const auto *MD : RD.methods()) {
49 if (!MD->isConst() || MD->getNumParams() != 0)
51 switch (MD->getOverloadedOperator()) {
53 StarReturnType = valueLikeReturnType(MD->getReturnType());
56 ArrowReturnType = getLikeReturnType(MD->getReturnType());
62 if (!StarReturnType.isNull() && !ArrowReturnType.isNull() &&
63 StarReturnType == ArrowReturnType)
64 return StarReturnType;
69QualType findReturnType(
const CXXRecordDecl &RD, StringRef MethodName) {
70 for (
const auto *MD : RD.methods()) {
74 if (!MD->isConst() || MD->getNumParams() != 0 ||
75 MD->getOverloadedOperator() !=
OO_None)
77 clang::IdentifierInfo *II = MD->getIdentifier();
78 if (II && II->
isStr(MethodName))
79 return MD->getReturnType();
91using clang::dataflow::findReturnType;
92using clang::dataflow::getLikeReturnType;
93using clang::dataflow::pointerLikeReturnType;
94using clang::dataflow::valueLikeReturnType;
97 clang::StringRef, MethodName) {
98 auto RT = pointerLikeReturnType(Node);
101 return getLikeReturnType(findReturnType(Node, MethodName)) == RT;
105 clang::StringRef, MethodName) {
106 auto RT = pointerLikeReturnType(Node);
109 return valueLikeReturnType(findReturnType(Node, MethodName)) == RT;
113 auto RT = pointerLikeReturnType(Node);
116 return getLikeReturnType(findReturnType(Node,
"get")) == RT ||
117 valueLikeReturnType(findReturnType(Node,
"value")) == RT;
121 return !pointerLikeReturnType(Node).isNull();
133 ofClass(smartPointerClassWithGetOrValue()))));
141 ofClass(smartPointerClassWithGetOrValue()))));
149 ofClass(pointerClass()))));
157 ofClass(pointerClass()))));
163 parameterCountIs(0), returns(hasCanonicalType(
referenceType())),
165 ofClass(smartPointerClassWithValueLike(MethodName)))));
171 parameterCountIs(0), returns(hasCanonicalType(
pointerType())),
172 hasName(MethodName), ofClass(smartPointerClassWithGetLike(MethodName)))));
180 if (Callee ==
nullptr)
185 for (
const auto *MD : RD->
methods()) {
186 if (MD->getOverloadedOperator() == OO_Star && MD->isConst() &&
187 MD->getNumParams() == 0 && MD->getReturnType()->isReferenceType()) {
188 CanonicalCallee = MD;
192 return CanonicalCallee;
#define AST_MATCHER(Type, DefineMatcher)
AST_MATCHER(Type, DefineMatcher) { ... } defines a zero parameter function named DefineMatcher() that...
#define AST_MATCHER_P(Type, DefineMatcher, ParamType, Param)
AST_MATCHER_P(Type, DefineMatcher, ParamType, Param) { ... } defines a single-parameter function name...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines an enumeration for C++ overloaded operators.
C Language Family Type Representation.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
method_range methods() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Represents a function declaration or definition.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
internal::Matcher< NamedDecl > hasName(StringRef Name)
Matches NamedDecl nodes that have the specified name.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXMemberCallExpr > cxxMemberCallExpr
Matches member call expressions.
internal::Matcher< Stmt > StatementMatcher
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXOperatorCallExpr > cxxOperatorCallExpr
Matches overloaded operator calls.
const AstTypeMatcher< PointerType > pointerType
internal::PolymorphicMatcher< internal::HasOverloadedOperatorNameMatcher, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl), std::vector< std::string > > hasOverloadedOperatorName(StringRef Name)
Matches overloaded operator names.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXMethodDecl > cxxMethodDecl
Matches method declarations.
const AstTypeMatcher< ReferenceType > referenceType
Dataflow Directional Tag Classes.
ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall(clang::StringRef MethodName="value")
ast_matchers::StatementMatcher isPointerLikeOperatorStar()
Matchers: For now, these match on any class with an operator* or operator-> where the return types ha...
internal::Matcher< NamedDecl > hasName(StringRef Name)
Matches NamedDecl nodes that have the specified name.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXMemberCallExpr > cxxMemberCallExpr
Matches member call expressions.
ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow()
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXOperatorCallExpr > cxxOperatorCallExpr
Matches overloaded operator calls.
const AstTypeMatcher< PointerType > pointerType
internal::PolymorphicMatcher< internal::HasOverloadedOperatorNameMatcher, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl), std::vector< std::string > > hasOverloadedOperatorName(StringRef Name)
Matches overloaded operator names.
const FunctionDecl * getCanonicalSmartPointerLikeOperatorCallee(const CallExpr *CE)
Returns the "canonical" callee for smart pointer operators (* and ->) as a key for caching.
ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar()
const internal::VariadicDynCastAllOfMatcher< Decl, CXXMethodDecl > cxxMethodDecl
Matches method declarations.
ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall(clang::StringRef MethodName="get")
ast_matchers::StatementMatcher isPointerLikeOperatorArrow()
const AstTypeMatcher< ReferenceType > referenceType
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ OO_None
Not an overloaded operator.