19#include "llvm/ADT/ArrayRef.h"
32 return RequiredParams;
40 MaybeCount RequiredArgs ,
41 MaybeCount RequiredParams )
42 : RequiredArgs(RequiredArgs),
45 assert(!QualifiedName.empty());
46 this->QualifiedName.reserve(QualifiedName.size());
47 llvm::transform(QualifiedName, std::back_inserter(this->QualifiedName),
48 [](StringRef From) {
return From.str(); });
53 MaybeCount RequiredArgs ,
54 MaybeCount RequiredParams )
62 const auto *FD = dyn_cast_or_null<FunctionDecl>(Call.getDecl());
66 return matchesImpl(FD, Call.getNumArgs(), Call.parameters().size());
70 const auto *FD = dyn_cast_or_null<FunctionDecl>(CE.
getCalleeDecl());
74 return matchesImpl(FD, CE.
getNumArgs(), FD->param_size());
77bool ento::CallDescription::matchesImpl(
const FunctionDecl *Callee,
79 size_t ParamCount)
const {
80 const auto *FD = Callee;
86 (!RequiredArgs || *RequiredArgs <= ArgCount) &&
87 (!RequiredParams || *RequiredParams <= ParamCount);
91 II = &FD->getASTContext().Idents.get(getFunctionName());
94 const auto MatchNameOnly = [](
const CallDescription &CD,
97 if (
const auto *II = Name.getAsIdentifierInfo())
104 return Name.getAsString() == CD.getFunctionName();
107 const auto ExactMatchArgAndParamCounts =
108 [](
size_t ArgCount,
size_t ParamCount,
109 const CallDescription &CD) ->
bool {
110 const bool ArgsMatch = !CD.RequiredArgs || *CD.RequiredArgs == ArgCount;
111 const bool ParamsMatch =
112 !CD.RequiredParams || *CD.RequiredParams == ParamCount;
113 return ArgsMatch && ParamsMatch;
116 const auto MatchQualifiedNameParts = [](
const CallDescription &CD,
117 const Decl *D) ->
bool {
118 const auto FindNextNamespaceOrRecord =
120 while (Ctx && !isa<NamespaceDecl, RecordDecl>(Ctx))
125 auto QualifierPartsIt = CD.begin_qualified_name_parts();
126 const auto QualifierPartsEndIt = CD.end_qualified_name_parts();
130 const DeclContext *Ctx = FindNextNamespaceOrRecord(D->getDeclContext());
131 for (; Ctx && QualifierPartsIt != QualifierPartsEndIt;
132 Ctx = FindNextNamespaceOrRecord(Ctx->
getParent())) {
134 if (cast<NamedDecl>(Ctx)->getName() != *QualifierPartsIt)
140 return QualifierPartsIt == QualifierPartsEndIt;
144 if (!ExactMatchArgAndParamCounts(ArgCount, ParamCount, *
this))
147 if (!MatchNameOnly(*
this, FD))
150 if (!hasQualifiedNameParts())
153 return MatchQualifiedNameParts(*
this, FD);
157 std::initializer_list<CallDescription> &&List) {
158 Impl.LinearMap.reserve(List.size());
160 Impl.LinearMap.push_back({CD,
true});
164 return static_cast<bool>(Impl.lookup(Call));
168 return static_cast<bool>(Impl.lookupAsWritten(CE));
static MaybeCount readRequiredParams(MaybeCount RequiredArgs, MaybeCount RequiredParams)
std::optional< unsigned > MaybeCount
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Decl - This represents one declaration (or definition), e.g.
The name of a declaration.
Represents a function declaration or definition.
This represents a decl that may have a name.
CallDescriptionSet(std::initializer_list< CallDescription > &&List)
bool containsAsWritten(const CallExpr &CE) const
When available, always prefer lookup with a CallEvent! This function exists only when that is not ava...
bool contains(const CallEvent &Call) const
This class represents a description of a function call using the number of arguments and the name of ...
bool matches(const CallEvent &Call) const
Returns true if the CallEvent is a call to a function that matches the CallDescription.
bool matchesAsWritten(const CallExpr &CE) const
Returns true if the CallExpr is a call to a function that matches the CallDescription.
CallDescription(CallDescriptionFlags Flags, ArrayRef< StringRef > QualifiedName, MaybeCount RequiredArgs=std::nullopt, MaybeCount RequiredParams=std::nullopt)
Constructs a CallDescription object.
Represents an abstract call to a function or method along a particular path.
static bool isCLibraryFunction(const FunctionDecl *FD, StringRef Name=StringRef())
Returns true if the callee is an externally-visible function in the top-level namespace,...
@ CDF_MaybeBuiltin
Describes a C standard function that is sometimes implemented as a macro that expands to a compiler b...
YAML serialization mapping.