mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 18:44:55 +01:00
Support parsing and testing unimplemented expressions (#957)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
be0c1e9da6
commit
dc5e62fc7a
@@ -10,7 +10,9 @@
|
||||
namespace Carbon {
|
||||
namespace TestingInternal {
|
||||
|
||||
auto BlockContentsMatcher::MatchAndExplain(
|
||||
AstNodeMatcherBase::~AstNodeMatcherBase() = default;
|
||||
|
||||
auto BlockContentsMatcher::MatchAndExplainImpl(
|
||||
Nonnull<const AstNode*> node, ::testing::MatchResultListener* out) const
|
||||
-> bool {
|
||||
const auto* block = llvm::dyn_cast<Block>(node);
|
||||
@@ -22,7 +24,7 @@ auto BlockContentsMatcher::MatchAndExplain(
|
||||
return matcher_.MatchAndExplain(block->statements(), out);
|
||||
}
|
||||
|
||||
auto MatchesIntLiteralMatcher::MatchAndExplain(
|
||||
auto MatchesIntLiteralMatcher::MatchAndExplainImpl(
|
||||
const AstNode* node, ::testing::MatchResultListener* listener) const
|
||||
-> bool {
|
||||
const auto* literal = llvm::dyn_cast<IntLiteral>(node);
|
||||
@@ -35,7 +37,7 @@ auto MatchesIntLiteralMatcher::MatchAndExplain(
|
||||
return matched;
|
||||
}
|
||||
|
||||
auto BinaryOperatorExpressionMatcher::MatchAndExplain(
|
||||
auto BinaryOperatorExpressionMatcher::MatchAndExplainImpl(
|
||||
Nonnull<const AstNode*> node, ::testing::MatchResultListener* out) const
|
||||
-> bool {
|
||||
const auto* op = llvm::dyn_cast<PrimitiveOperatorExpression>(node);
|
||||
@@ -70,7 +72,7 @@ void BinaryOperatorExpressionMatcher::DescribeToImpl(std::ostream* out,
|
||||
rhs_.DescribeTo(out);
|
||||
}
|
||||
|
||||
auto MatchesReturnMatcher::MatchAndExplain(
|
||||
auto MatchesReturnMatcher::MatchAndExplainImpl(
|
||||
const AstNode* node, ::testing::MatchResultListener* listener) const
|
||||
-> bool {
|
||||
const auto* ret = llvm::dyn_cast<Return>(node);
|
||||
@@ -135,7 +137,7 @@ class RawListenerOstream : public llvm::raw_ostream {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
auto MatchesFunctionDeclarationMatcher::MatchAndExplain(
|
||||
auto MatchesFunctionDeclarationMatcher::MatchAndExplainImpl(
|
||||
const AstNode* node, ::testing::MatchResultListener* listener) const
|
||||
-> bool {
|
||||
RawListenerOstream out(listener);
|
||||
@@ -185,5 +187,28 @@ void MatchesFunctionDeclarationMatcher::DescribeToImpl(std::ostream* out,
|
||||
}
|
||||
}
|
||||
|
||||
auto MatchesUnimplementedExpressionMatcher::MatchAndExplainImpl(
|
||||
const AstNode* node, ::testing::MatchResultListener* listener) const
|
||||
-> bool {
|
||||
const auto* unimplemented = llvm::dyn_cast<UnimplementedExpression>(node);
|
||||
if (unimplemented == nullptr) {
|
||||
*listener << "is not an UnimplementedExpression";
|
||||
return false;
|
||||
}
|
||||
if (unimplemented->label() != label_) {
|
||||
*listener << "is not labeled " << label_;
|
||||
return false;
|
||||
}
|
||||
*listener << "is an unimplemented " << label_ << " node whose children ";
|
||||
return children_matcher_.MatchAndExplain(unimplemented->children(), listener);
|
||||
}
|
||||
|
||||
void MatchesUnimplementedExpressionMatcher::DescribeToImpl(std::ostream* out,
|
||||
bool negated) const {
|
||||
*out << "is " << (negated ? "not " : "") << "an unimplemented " << label_
|
||||
<< " node whose children ";
|
||||
children_matcher_.DescribeTo(out);
|
||||
}
|
||||
|
||||
} // namespace TestingInternal
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user