[PATCH] D94880: Add clang-query support for mapAnyOf
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 17 10:10:23 PST 2021
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94880
Files:
clang/lib/ASTMatchers/Dynamic/Marshallers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -102,6 +102,9 @@
// Other:
// equalsNode
+ registerMatcher("mapAnyOf",
+ std::make_unique<internal::MapAnyOfBuilderDescriptor>());
+
REGISTER_OVERLOADED_2(callee);
REGISTER_OVERLOADED_2(hasAnyCapture);
REGISTER_OVERLOADED_2(hasPrefix);
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===================================================================
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -1057,6 +1057,55 @@
ASTNodeKind nodeMatcherType() const override { return ASTNodeKind(); }
};
+class MapAnyOfBuilderDescriptor : public MatcherDescriptor {
+public:
+ VariantMatcher create(SourceRange NameRange, ArrayRef<ParserValue> Args,
+ Diagnostics *Error) const override {
+ return {};
+ }
+
+ bool isBuilderMatcher() const override { return true; }
+
+ std::unique_ptr<MatcherDescriptor>
+ buildMatcherCtor(SourceRange NameRange, ArrayRef<ParserValue> Args,
+ Diagnostics *Error) const override {
+
+ std::vector<ASTNodeKind> NodeKinds;
+ for (auto Arg : Args) {
+ if (!Arg.Value.isNodeKind())
+ return {};
+ NodeKinds.push_back(Arg.Value.getNodeKind());
+ }
+
+ if (NodeKinds.empty()) {
+ // Set error
+ return {};
+ }
+
+ ASTNodeKind CladeNodeKind = NodeKinds.front().getCladeKind();
+
+ return std::make_unique<MapAnyOfMatcherDescriptor>(CladeNodeKind,
+ NodeKinds);
+ }
+
+ bool isVariadic() const override { return false; }
+
+ unsigned getNumArgs() const override { return 0; }
+
+ void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
+ std::vector<ArgKind> &ArgKinds) const override {
+ return;
+ }
+ bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity = nullptr,
+ ASTNodeKind *LeastDerivedKind = nullptr) const override {
+ return false;
+ }
+
+ bool isPolymorphic() const override { return false; }
+
+ ASTNodeKind nodeMatcherType() const override { return ASTNodeKind(); }
+};
+
/// Helper functions to select the appropriate marshaller functions.
/// They detect the number of arguments, arguments types and return type.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94880.317229.patch
Type: text/x-patch
Size: 2471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210117/91beff83/attachment.bin>
More information about the cfe-commits
mailing list