Make it possible to store NodeKinds in ArgKind

This commit is contained in:
Stephen Kelly 2021-02-06 23:28:50 +00:00
parent 79fedadd6a
commit e12d827991
2 changed files with 19 additions and 2 deletions

View File

@ -35,6 +35,7 @@ class ArgKind {
public:
enum Kind {
AK_Matcher,
AK_Node,
AK_Boolean,
AK_Double,
AK_Unsigned,
@ -48,11 +49,19 @@ class ArgKind {
return ArgKind{AK_Matcher, MatcherKind};
}
static ArgKind MakeNodeArg(ASTNodeKind MatcherKind) {
return ArgKind{AK_Node, MatcherKind};
}
Kind getArgKind() const { return K; }
ASTNodeKind getMatcherKind() const {
assert(K == AK_Matcher);
return NodeKind;
}
ASTNodeKind getNodeKind() const {
assert(K == AK_Node);
return NodeKind;
}
/// Determines if this type can be converted to \p To.
///
@ -63,7 +72,8 @@ class ArgKind {
bool isConvertibleTo(ArgKind To, unsigned *Specificity) const;
bool operator<(const ArgKind &Other) const {
if (K == AK_Matcher && Other.K == AK_Matcher)
if ((K == AK_Matcher && Other.K == AK_Matcher) ||
(K == AK_Node && Other.K == AK_Node))
return NodeKind < Other.NodeKind;
return K < Other.K;
}

View File

@ -23,6 +23,8 @@ std::string ArgKind::asString() const {
switch (getArgKind()) {
case AK_Matcher:
return (Twine("Matcher<") + NodeKind.asStringRef() + ">").str();
case AK_Node:
return NodeKind.asStringRef().str();
case AK_Boolean:
return "boolean";
case AK_Double:
@ -38,7 +40,7 @@ std::string ArgKind::asString() const {
bool ArgKind::isConvertibleTo(ArgKind To, unsigned *Specificity) const {
if (K != To.K)
return false;
if (K != AK_Matcher) {
if (K != AK_Matcher && K != AK_Node) {
if (Specificity)
*Specificity = 1;
return true;
@ -443,6 +445,11 @@ bool VariantValue::isConvertibleTo(ArgKind Kind, unsigned *Specificity) const {
*Specificity = 1;
return true;
case ArgKind::AK_Node:
if (!isNodeKind())
return false;
return getMatcher().isConvertibleTo(Kind.getNodeKind(), Specificity);
case ArgKind::AK_Matcher:
if (!isMatcher())
return false;