13using ast_matchers::callee;
19using ast_matchers::ofClass;
20using ast_matchers::parameterCountIs;
23using ast_matchers::returns;
25bool hasSmartPointerClassShape(
const CXXRecordDecl &RD,
bool &HasGet,
29 bool HasArrow =
false;
32 for (
const auto *MD : RD.methods()) {
36 if (!MD->isConst() || MD->getNumParams() != 0)
38 switch (MD->getOverloadedOperator()) {
40 if (MD->getReturnType()->isReferenceType()) {
42 StarReturnType = MD->getReturnType()
43 .getNonReferenceType()
44 ->getCanonicalTypeUnqualified();
48 if (MD->getReturnType()->isPointerType()) {
50 ArrowReturnType = MD->getReturnType()
52 ->getCanonicalTypeUnqualified();
56 IdentifierInfo *II = MD->getIdentifier();
59 if (II->isStr(
"get")) {
60 if (MD->getReturnType()->isPointerType()) {
64 ->getCanonicalTypeUnqualified();
66 }
else if (II->isStr(
"value")) {
67 if (MD->getReturnType()->isReferenceType()) {
69 ValueReturnType = MD->getReturnType()
70 .getNonReferenceType()
71 ->getCanonicalTypeUnqualified();
80 if (!HasStar || !HasArrow || StarReturnType != ArrowReturnType)
83 HasValue = HasValue && (ValueReturnType == StarReturnType);
96 bool HasValue =
false;
97 bool HasStarAndArrow =
98 clang::dataflow::hasSmartPointerClassShape(
Node, HasGet, HasValue);
99 return HasStarAndArrow && HasGet;
104 bool HasValue =
false;
105 bool HasStarAndArrow =
106 clang::dataflow::hasSmartPointerClassShape(
Node, HasGet, HasValue);
107 return HasStarAndArrow && HasValue;
112 bool HasValue =
false;
113 bool HasStarAndArrow =
114 clang::dataflow::hasSmartPointerClassShape(
Node, HasGet, HasValue);
115 return HasStarAndArrow && (HasGet || HasValue);
126 ofClass(smartPointerClassWithGetOrValue()))));
133 ofClass(smartPointerClassWithGetOrValue()))));
138 hasName(
"value"), ofClass(smartPointerClassWithValue()))));
144 ofClass(smartPointerClassWithGet()))));
#define AST_MATCHER(Type, DefineMatcher)
AST_MATCHER(Type, DefineMatcher) { ... } defines a zero parameter function named DefineMatcher() that...
static CanQualType GetReturnType(QualType RetTy)
Returns the "extra-canonicalized" return type, which discards qualifiers on the return type.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines an enumeration for C++ overloaded operators.
Represents a C++ struct/union/class.
const AstTypeMatcher< PointerType > pointerType
Matches pointer types, but does not match Objective-C object pointer types.
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.
internal::PolymorphicMatcher< internal::HasOverloadedOperatorNameMatcher, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl), std::vector< std::string > > hasOverloadedOperatorName(StringRef Name)
Matches overloaded operator names.
const AstTypeMatcher< ReferenceType > referenceType
Matches both lvalue and rvalue reference types.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXMethodDecl > cxxMethodDecl
Matches method declarations.
Dataflow Directional Tag Classes.
ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall()
ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall()
ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow()
ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar()
Matchers: For now, these match on any class with an operator* or operator-> where the return types ha...
@ OO_None
Not an overloaded operator.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.