Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
Summary:
Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
This work is to support future changes needed for eachOf/allOf/anyOf matchers. We will add a new type on VariantMatcher.
Reviewers: klimek
CC: cfe-commits, revane
Differential Revision: http://llvm-reviews.chandlerc.com/D1365
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188272 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ASTMatchers/Dynamic/Parser.cpp b/lib/ASTMatchers/Dynamic/Parser.cpp
index 54424ce..37e6c10 100644
--- a/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -311,9 +311,9 @@
NameToken.Text, NameToken.Range);
SourceRange MatcherRange = NameToken.Range;
MatcherRange.End = EndToken.Range.End;
- MatcherList Result = S->actOnMatcherExpression(
+ VariantMatcher Result = S->actOnMatcherExpression(
NameToken.Text, MatcherRange, BindID, Args, Error);
- if (Result.empty()) return false;
+ if (Result.isNull()) return false;
*Value = Result;
return true;
@@ -358,11 +358,11 @@
class RegistrySema : public Parser::Sema {
public:
virtual ~RegistrySema() {}
- MatcherList actOnMatcherExpression(StringRef MatcherName,
- const SourceRange &NameRange,
- StringRef BindID,
- ArrayRef<ParserValue> Args,
- Diagnostics *Error) {
+ VariantMatcher actOnMatcherExpression(StringRef MatcherName,
+ const SourceRange &NameRange,
+ StringRef BindID,
+ ArrayRef<ParserValue> Args,
+ Diagnostics *Error) {
if (BindID.empty()) {
return Registry::constructMatcher(MatcherName, NameRange, Args, Error);
} else {
@@ -402,16 +402,17 @@
VariantValue Value;
if (!parseExpression(Code, S, &Value, Error))
return NULL;
- if (!Value.isMatchers()) {
+ if (!Value.isMatcher()) {
Error->addError(SourceRange(), Error->ET_ParserNotAMatcher);
return NULL;
}
- if (Value.getMatchers().matchers().size() != 1) {
+ const DynTypedMatcher *Result;
+ if (!Value.getMatcher().getSingleMatcher(Result)) {
Error->addError(SourceRange(), Error->ET_ParserOverloadedType)
<< Value.getTypeAsString();
return NULL;
}
- return Value.getMatchers().matchers()[0]->clone();
+ return Result->clone();
}
} // namespace dynamic