mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Accessor renames on parser (#1135)
This commit is contained in:
@@ -152,7 +152,7 @@ auto Driver::RunDumpParseTreeSubcommand(llvm::ArrayRef<llvm::StringRef> args)
|
||||
auto parse_tree =
|
||||
ParseTree::Parse(tokenized_source, ConsoleDiagnosticConsumer());
|
||||
parse_tree.Print(output_stream_);
|
||||
return !tokenized_source.has_errors() && !parse_tree.HasErrors();
|
||||
return !tokenized_source.has_errors() && !parse_tree.has_errors();
|
||||
}
|
||||
|
||||
auto Driver::ReportExtraArgs(llvm::StringRef subcommand_text,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto ParseNodeKind::GetName() const -> llvm::StringRef {
|
||||
auto ParseNodeKind::name() const -> llvm::StringRef {
|
||||
static constexpr llvm::StringLiteral Names[] = {
|
||||
#define CARBON_PARSE_NODE_KIND(Name) #Name,
|
||||
#include "toolchain/parser/parse_node_kind.def"
|
||||
|
||||
@@ -52,7 +52,7 @@ class ParseNodeKind {
|
||||
}
|
||||
|
||||
// Gets a friendly name for the token for logging or debugging.
|
||||
[[nodiscard]] auto GetName() const -> llvm::StringRef;
|
||||
[[nodiscard]] auto name() const -> llvm::StringRef;
|
||||
|
||||
// Enable conversion to our private enum, including in a `constexpr` context,
|
||||
// to enable usage in `switch` and `case`. The enum remains private and
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace {
|
||||
|
||||
// Not much to test here, so just verify that the API compiles and returns the
|
||||
// data in the `.def` file.
|
||||
#define CARBON_PARSE_NODE_KIND(Name) \
|
||||
TEST(ParseNodeKindTest, Name) { \
|
||||
EXPECT_EQ(#Name, ParseNodeKind::Name().GetName()); \
|
||||
#define CARBON_PARSE_NODE_KIND(Name) \
|
||||
TEST(ParseNodeKindTest, Name) { \
|
||||
EXPECT_EQ(#Name, ParseNodeKind::Name().name()); \
|
||||
}
|
||||
#include "toolchain/parser/parse_node_kind.def"
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ inline auto ExpectedNodesMatcher::MatchAndExplain(
|
||||
-> bool {
|
||||
auto& output = *output_ptr;
|
||||
bool matches = true;
|
||||
const auto rpo = llvm::reverse(tree.Postorder());
|
||||
const auto rpo = llvm::reverse(tree.postorder());
|
||||
const auto nodes_begin = rpo.begin();
|
||||
const auto nodes_end = rpo.end();
|
||||
auto nodes_it = nodes_begin;
|
||||
@@ -92,7 +92,7 @@ inline auto ExpectedNodesMatcher::MatchAndExplain(
|
||||
}
|
||||
|
||||
ParseTree::Node n = *nodes_it++;
|
||||
int postorder_index = n.GetIndex();
|
||||
int postorder_index = n.index();
|
||||
|
||||
const ExpectedNode& expected_node = *expected_node_stack.pop_back_val();
|
||||
|
||||
@@ -104,7 +104,7 @@ inline auto ExpectedNodesMatcher::MatchAndExplain(
|
||||
CHECK(expected_node.children.empty())
|
||||
<< "Must not skip an expected subtree while specifying expected "
|
||||
"children!";
|
||||
nodes_it = llvm::reverse(tree.Postorder(n)).end();
|
||||
nodes_it = llvm::reverse(tree.postorder(n)).end();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ inline auto ExpectedNodesMatcher::MatchAndExplain(
|
||||
// ahead in the tree to ensure that the number of children of this node and
|
||||
// the expected number of children match.
|
||||
int num_children =
|
||||
std::distance(tree.Children(n).begin(), tree.Children(n).end());
|
||||
std::distance(tree.children(n).begin(), tree.children(n).end());
|
||||
if (num_children != static_cast<int>(expected_node.children.size())) {
|
||||
output
|
||||
<< "\nParse node (postorder index #" << postorder_index << ") has "
|
||||
@@ -120,7 +120,7 @@ inline auto ExpectedNodesMatcher::MatchAndExplain(
|
||||
<< expected_node.children.size()
|
||||
<< ". Skipping this subtree to avoid any unsynchronized tree walk.";
|
||||
matches = false;
|
||||
nodes_it = llvm::reverse(tree.Postorder(n)).end();
|
||||
nodes_it = llvm::reverse(tree.postorder(n)).end();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ inline auto ExpectedNodesMatcher::DescribeTo(std::ostream* output_ptr) const
|
||||
for (int indent_count = 0; indent_count < depth; ++indent_count) {
|
||||
output << " ";
|
||||
}
|
||||
output << "{kind: '" << expected_node.kind.GetName().str() << "'";
|
||||
output << "{kind: '" << expected_node.kind.name().str() << "'";
|
||||
if (!expected_node.text.empty()) {
|
||||
output << ", text: '" << expected_node.text << "'";
|
||||
}
|
||||
@@ -229,17 +229,17 @@ inline auto ExpectedNodesMatcher::MatchExpectedNode(
|
||||
::testing::MatchResultListener& output) const -> bool {
|
||||
bool matches = true;
|
||||
|
||||
ParseNodeKind kind = tree.GetNodeKind(n);
|
||||
ParseNodeKind kind = tree.node_kind(n);
|
||||
if (kind != expected_node.kind) {
|
||||
output << "\nParse node (postorder index #" << postorder_index << ") is a "
|
||||
<< kind.GetName().str() << ", expected a "
|
||||
<< expected_node.kind.GetName().str() << ".";
|
||||
<< kind.name().str() << ", expected a "
|
||||
<< expected_node.kind.name().str() << ".";
|
||||
matches = false;
|
||||
}
|
||||
|
||||
if (tree.HasErrorInNode(n) != expected_node.has_error) {
|
||||
if (tree.node_has_error(n) != expected_node.has_error) {
|
||||
output << "\nParse node (postorder index #" << postorder_index << ") "
|
||||
<< (tree.HasErrorInNode(n) ? "has an error"
|
||||
<< (tree.node_has_error(n) ? "has an error"
|
||||
: "does not have an error")
|
||||
<< ", expected that it "
|
||||
<< (expected_node.has_error ? "has an error"
|
||||
|
||||
@@ -30,12 +30,12 @@ auto ParseTree::Parse(TokenizedBuffer& tokens, DiagnosticConsumer& consumer)
|
||||
return Parser::Parse(tokens, emitter);
|
||||
}
|
||||
|
||||
auto ParseTree::Postorder() const -> llvm::iterator_range<PostorderIterator> {
|
||||
auto ParseTree::postorder() const -> llvm::iterator_range<PostorderIterator> {
|
||||
return {PostorderIterator(Node(0)),
|
||||
PostorderIterator(Node(node_impls_.size()))};
|
||||
}
|
||||
|
||||
auto ParseTree::Postorder(Node n) const
|
||||
auto ParseTree::postorder(Node n) const
|
||||
-> llvm::iterator_range<PostorderIterator> {
|
||||
// The postorder ends after this node, the root, and begins at the start of
|
||||
// its subtree.
|
||||
@@ -45,28 +45,28 @@ auto ParseTree::Postorder(Node n) const
|
||||
PostorderIterator(Node(end_index))};
|
||||
}
|
||||
|
||||
auto ParseTree::Children(Node n) const
|
||||
auto ParseTree::children(Node n) const
|
||||
-> llvm::iterator_range<SiblingIterator> {
|
||||
int end_index = n.index_ - node_impls_[n.index_].subtree_size;
|
||||
return {SiblingIterator(*this, Node(n.index_ - 1)),
|
||||
SiblingIterator(*this, Node(end_index))};
|
||||
}
|
||||
|
||||
auto ParseTree::Roots() const -> llvm::iterator_range<SiblingIterator> {
|
||||
auto ParseTree::roots() const -> llvm::iterator_range<SiblingIterator> {
|
||||
return {
|
||||
SiblingIterator(*this, Node(static_cast<int>(node_impls_.size()) - 1)),
|
||||
SiblingIterator(*this, Node(-1))};
|
||||
}
|
||||
|
||||
auto ParseTree::HasErrorInNode(Node n) const -> bool {
|
||||
auto ParseTree::node_has_error(Node n) const -> bool {
|
||||
return node_impls_[n.index_].has_error;
|
||||
}
|
||||
|
||||
auto ParseTree::GetNodeKind(Node n) const -> ParseNodeKind {
|
||||
auto ParseTree::node_kind(Node n) const -> ParseNodeKind {
|
||||
return node_impls_[n.index_].kind;
|
||||
}
|
||||
|
||||
auto ParseTree::GetNodeToken(Node n) const -> TokenizedBuffer::Token {
|
||||
auto ParseTree::node_token(Node n) const -> TokenizedBuffer::Token {
|
||||
return node_impls_[n.index_].token;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ auto ParseTree::Print(llvm::raw_ostream& output) const -> void {
|
||||
// The roots, like siblings, are in RPO (so reversed), but we add them in
|
||||
// order here because we'll pop off the stack effectively reversing then.
|
||||
llvm::SmallVector<std::pair<Node, int>, 16> node_stack;
|
||||
for (Node n : Roots()) {
|
||||
for (Node n : roots()) {
|
||||
node_stack.push_back({n, 0});
|
||||
}
|
||||
|
||||
@@ -93,16 +93,15 @@ auto ParseTree::Print(llvm::raw_ostream& output) const -> void {
|
||||
Node n;
|
||||
int depth;
|
||||
std::tie(n, depth) = node_stack.pop_back_val();
|
||||
auto& n_impl = node_impls_[n.GetIndex()];
|
||||
auto& n_impl = node_impls_[n.index()];
|
||||
|
||||
for (int unused_indent : llvm::seq(0, depth)) {
|
||||
(void)unused_indent;
|
||||
output << " ";
|
||||
}
|
||||
|
||||
output << "{node_index: " << n.index_ << ", kind: '"
|
||||
<< n_impl.kind.GetName() << "', text: '"
|
||||
<< tokens_->GetTokenText(n_impl.token) << "'";
|
||||
output << "{node_index: " << n.index_ << ", kind: '" << n_impl.kind.name()
|
||||
<< "', text: '" << tokens_->GetTokenText(n_impl.token) << "'";
|
||||
|
||||
if (n_impl.has_error) {
|
||||
output << ", has_error: yes";
|
||||
@@ -114,7 +113,7 @@ auto ParseTree::Print(llvm::raw_ostream& output) const -> void {
|
||||
output << ", children: [\n";
|
||||
// We append the children in order here as well because they will get
|
||||
// reversed when popped off the stack.
|
||||
for (Node sibling_n : Children(n)) {
|
||||
for (Node sibling_n : children(n)) {
|
||||
node_stack.push_back({sibling_n, depth + 1});
|
||||
}
|
||||
continue;
|
||||
@@ -142,12 +141,12 @@ auto ParseTree::Print(llvm::raw_ostream& output) const -> void {
|
||||
auto ParseTree::Verify() const -> bool {
|
||||
// Verify basic tree structure invariants.
|
||||
llvm::SmallVector<ParseTree::Node, 16> ancestors;
|
||||
for (Node n : llvm::reverse(Postorder())) {
|
||||
auto& n_impl = node_impls_[n.GetIndex()];
|
||||
for (Node n : llvm::reverse(postorder())) {
|
||||
auto& n_impl = node_impls_[n.index()];
|
||||
|
||||
if (n_impl.has_error && !has_errors_) {
|
||||
llvm::errs()
|
||||
<< "Node #" << n.GetIndex()
|
||||
<< "Node #" << n.index()
|
||||
<< " has errors, but the tree is not marked as having any.\n";
|
||||
return false;
|
||||
}
|
||||
@@ -155,14 +154,14 @@ auto ParseTree::Verify() const -> bool {
|
||||
if (n_impl.subtree_size > 1) {
|
||||
if (!ancestors.empty()) {
|
||||
auto parent_n = ancestors.back();
|
||||
auto& parent_n_impl = node_impls_[parent_n.GetIndex()];
|
||||
int end_index = n.GetIndex() - n_impl.subtree_size;
|
||||
int parent_end_index = parent_n.GetIndex() - parent_n_impl.subtree_size;
|
||||
auto& parent_n_impl = node_impls_[parent_n.index()];
|
||||
int end_index = n.index() - n_impl.subtree_size;
|
||||
int parent_end_index = parent_n.index() - parent_n_impl.subtree_size;
|
||||
if (parent_end_index > end_index) {
|
||||
llvm::errs() << "Node #" << n.GetIndex() << " has a subtree size of "
|
||||
llvm::errs() << "Node #" << n.index() << " has a subtree size of "
|
||||
<< n_impl.subtree_size
|
||||
<< " which extends beyond its parent's (node #"
|
||||
<< parent_n.GetIndex() << ") subtree (size "
|
||||
<< parent_n.index() << ") subtree (size "
|
||||
<< parent_n_impl.subtree_size << ")\n";
|
||||
return false;
|
||||
}
|
||||
@@ -173,7 +172,7 @@ auto ParseTree::Verify() const -> bool {
|
||||
}
|
||||
|
||||
if (n_impl.subtree_size < 1) {
|
||||
llvm::errs() << "Node #" << n.GetIndex()
|
||||
llvm::errs() << "Node #" << n.index()
|
||||
<< " has an invalid subtree size of " << n_impl.subtree_size
|
||||
<< "!\n";
|
||||
return false;
|
||||
@@ -181,11 +180,11 @@ auto ParseTree::Verify() const -> bool {
|
||||
|
||||
// We're going to pop off some levels of the tree. Check each ancestor to
|
||||
// make sure the offsets are correct.
|
||||
int next_index = n.GetIndex() - 1;
|
||||
int next_index = n.index() - 1;
|
||||
while (!ancestors.empty()) {
|
||||
ParseTree::Node parent_n = ancestors.back();
|
||||
if ((parent_n.GetIndex() -
|
||||
node_impls_[parent_n.GetIndex()].subtree_size) != next_index) {
|
||||
if ((parent_n.index() - node_impls_[parent_n.index()].subtree_size) !=
|
||||
next_index) {
|
||||
break;
|
||||
}
|
||||
ancestors.pop_back();
|
||||
@@ -195,7 +194,7 @@ auto ParseTree::Verify() const -> bool {
|
||||
llvm::errs()
|
||||
<< "Finished walking the parse tree and there are still ancestors:\n";
|
||||
for (Node ancestor_n : ancestors) {
|
||||
llvm::errs() << " Node #" << ancestor_n.GetIndex() << "\n";
|
||||
llvm::errs() << " Node #" << ancestor_n.index() << "\n";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -204,17 +203,17 @@ auto ParseTree::Verify() const -> bool {
|
||||
}
|
||||
|
||||
auto ParseTree::Node::Print(llvm::raw_ostream& output) const -> void {
|
||||
output << GetIndex();
|
||||
output << index();
|
||||
}
|
||||
|
||||
auto ParseTree::PostorderIterator::Print(llvm::raw_ostream& output) const
|
||||
-> void {
|
||||
output << node_.GetIndex();
|
||||
output << node_.index();
|
||||
}
|
||||
|
||||
auto ParseTree::SiblingIterator::Print(llvm::raw_ostream& output) const
|
||||
-> void {
|
||||
output << node_.GetIndex();
|
||||
output << node_.index();
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
@@ -58,41 +58,41 @@ class ParseTree {
|
||||
-> ParseTree;
|
||||
|
||||
// Tests whether there are any errors in the parse tree.
|
||||
[[nodiscard]] auto HasErrors() const -> bool { return has_errors_; }
|
||||
[[nodiscard]] auto has_errors() const -> bool { return has_errors_; }
|
||||
|
||||
// Returns the number of nodes in this parse tree.
|
||||
[[nodiscard]] auto Size() const -> int { return node_impls_.size(); }
|
||||
[[nodiscard]] auto size() const -> int { return node_impls_.size(); }
|
||||
|
||||
// Returns an iterable range over the parse tree nodes in depth-first
|
||||
// postorder.
|
||||
[[nodiscard]] auto Postorder() const
|
||||
[[nodiscard]] auto postorder() const
|
||||
-> llvm::iterator_range<PostorderIterator>;
|
||||
|
||||
// Returns an iterable range over the parse tree node and all of its
|
||||
// descendants in depth-first postorder.
|
||||
[[nodiscard]] auto Postorder(Node n) const
|
||||
[[nodiscard]] auto postorder(Node n) const
|
||||
-> llvm::iterator_range<PostorderIterator>;
|
||||
|
||||
// Returns an iterable range over the direct children of a node in the parse
|
||||
// tree. This is a forward range, but is constant time to increment. The order
|
||||
// of children is the same as would be found in a reverse postorder traversal.
|
||||
[[nodiscard]] auto Children(Node n) const
|
||||
[[nodiscard]] auto children(Node n) const
|
||||
-> llvm::iterator_range<SiblingIterator>;
|
||||
|
||||
// Returns an iterable range over the roots of the parse tree. This is a
|
||||
// forward range, but is constant time to increment. The order of roots is the
|
||||
// same as would be found in a reverse postorder traversal.
|
||||
[[nodiscard]] auto Roots() const -> llvm::iterator_range<SiblingIterator>;
|
||||
[[nodiscard]] auto roots() const -> llvm::iterator_range<SiblingIterator>;
|
||||
|
||||
// Tests whether a particular node contains an error and may not match the
|
||||
// full expected structure of the grammar.
|
||||
[[nodiscard]] auto HasErrorInNode(Node n) const -> bool;
|
||||
[[nodiscard]] auto node_has_error(Node n) const -> bool;
|
||||
|
||||
// Returns the kind of the given parse tree node.
|
||||
[[nodiscard]] auto GetNodeKind(Node n) const -> ParseNodeKind;
|
||||
[[nodiscard]] auto node_kind(Node n) const -> ParseNodeKind;
|
||||
|
||||
// Returns the token the given parse tree node models.
|
||||
[[nodiscard]] auto GetNodeToken(Node n) const -> TokenizedBuffer::Token;
|
||||
[[nodiscard]] auto node_token(Node n) const -> TokenizedBuffer::Token;
|
||||
|
||||
// Returns the text backing the token for the given node.
|
||||
//
|
||||
@@ -254,7 +254,7 @@ class ParseTree::Node {
|
||||
// should not expect any particular semantics from this value.
|
||||
//
|
||||
// FIXME: Maybe we can switch to stream operator overloads?
|
||||
[[nodiscard]] auto GetIndex() const -> int { return index_; }
|
||||
[[nodiscard]] auto index() const -> int { return index_; }
|
||||
|
||||
// Prints the node index.
|
||||
auto Print(llvm::raw_ostream& output) const -> void;
|
||||
|
||||
@@ -36,13 +36,13 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
|
||||
// Now parse it into a tree. Note that parsing will (when asserts are enabled)
|
||||
// walk the entire tree to verify it so we don't have to do that here.
|
||||
ParseTree tree = ParseTree::Parse(tokens, NullDiagnosticConsumer());
|
||||
if (tree.HasErrors()) {
|
||||
if (tree.has_errors()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// In the absence of parse errors, we should have exactly as many nodes as
|
||||
// tokens.
|
||||
CHECK(tree.Size() == tokens.size()) << "Unexpected number of tree nodes!";
|
||||
CHECK(tree.size() == tokens.size()) << "Unexpected number of tree nodes!";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -51,16 +51,16 @@ class ParseTreeTest : public ::testing::Test {
|
||||
TEST_F(ParseTreeTest, Empty) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchFileEnd()}));
|
||||
}
|
||||
|
||||
TEST_F(ParseTreeTest, EmptyDeclaration) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer(";");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
auto it = tree.Postorder().begin();
|
||||
auto end = tree.Postorder().end();
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
auto it = tree.postorder().begin();
|
||||
auto end = tree.postorder().end();
|
||||
ASSERT_THAT(it, Ne(end));
|
||||
ParseTree::Node n = *it++;
|
||||
ASSERT_THAT(it, Ne(end));
|
||||
@@ -69,28 +69,28 @@ TEST_F(ParseTreeTest, EmptyDeclaration) {
|
||||
|
||||
// Directly test the main API so that we get easier to understand errors in
|
||||
// simple cases than what the custom matcher will produce.
|
||||
EXPECT_FALSE(tree.HasErrorInNode(n));
|
||||
EXPECT_FALSE(tree.HasErrorInNode(eof));
|
||||
EXPECT_THAT(tree.GetNodeKind(n), Eq(ParseNodeKind::EmptyDeclaration()));
|
||||
EXPECT_THAT(tree.GetNodeKind(eof), Eq(ParseNodeKind::FileEnd()));
|
||||
EXPECT_FALSE(tree.node_has_error(n));
|
||||
EXPECT_FALSE(tree.node_has_error(eof));
|
||||
EXPECT_THAT(tree.node_kind(n), Eq(ParseNodeKind::EmptyDeclaration()));
|
||||
EXPECT_THAT(tree.node_kind(eof), Eq(ParseNodeKind::FileEnd()));
|
||||
|
||||
auto t = tree.GetNodeToken(n);
|
||||
auto t = tree.node_token(n);
|
||||
ASSERT_THAT(tokens.tokens().begin(), Ne(tokens.tokens().end()));
|
||||
EXPECT_THAT(t, Eq(*tokens.tokens().begin()));
|
||||
EXPECT_THAT(tokens.GetTokenText(t), Eq(";"));
|
||||
|
||||
EXPECT_THAT(tree.Children(n).begin(), Eq(tree.Children(n).end()));
|
||||
EXPECT_THAT(tree.Children(eof).begin(), Eq(tree.Children(eof).end()));
|
||||
EXPECT_THAT(tree.children(n).begin(), Eq(tree.children(n).end()));
|
||||
EXPECT_THAT(tree.children(eof).begin(), Eq(tree.children(eof).end()));
|
||||
|
||||
EXPECT_THAT(tree.Postorder().begin(), Eq(tree.Postorder(n).begin()));
|
||||
EXPECT_THAT(tree.Postorder(n).end(), Eq(tree.Postorder(eof).begin()));
|
||||
EXPECT_THAT(tree.Postorder(eof).end(), Eq(tree.Postorder().end()));
|
||||
EXPECT_THAT(tree.postorder().begin(), Eq(tree.postorder(n).begin()));
|
||||
EXPECT_THAT(tree.postorder(n).end(), Eq(tree.postorder(eof).begin()));
|
||||
EXPECT_THAT(tree.postorder(eof).end(), Eq(tree.postorder().end()));
|
||||
}
|
||||
|
||||
TEST_F(ParseTreeTest, BasicFunctionDeclaration) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes(
|
||||
{MatchFunctionDeclaration("fn", MatchDeclaredName("F"),
|
||||
MatchParameters(),
|
||||
@@ -101,14 +101,14 @@ TEST_F(ParseTreeTest, BasicFunctionDeclaration) {
|
||||
TEST_F(ParseTreeTest, NoDeclarationIntroducerOrSemi) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("foo bar baz");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchFileEnd()}));
|
||||
}
|
||||
|
||||
TEST_F(ParseTreeTest, NoDeclarationIntroducerWithSemi) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("foo;");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchEmptyDeclaration(";", HasError),
|
||||
MatchFileEnd()}));
|
||||
}
|
||||
@@ -116,7 +116,7 @@ TEST_F(ParseTreeTest, NoDeclarationIntroducerWithSemi) {
|
||||
TEST_F(ParseTreeTest, JustFunctionIntroducerAndSemi) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn;");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchFunctionDeclaration(
|
||||
HasError, MatchDeclarationEnd()),
|
||||
MatchFileEnd()}));
|
||||
@@ -125,7 +125,7 @@ TEST_F(ParseTreeTest, JustFunctionIntroducerAndSemi) {
|
||||
TEST_F(ParseTreeTest, RepeatedFunctionIntroducerAndSemi) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn fn;");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchFunctionDeclaration(
|
||||
HasError, MatchDeclarationEnd()),
|
||||
MatchFileEnd()}));
|
||||
@@ -134,7 +134,7 @@ TEST_F(ParseTreeTest, RepeatedFunctionIntroducerAndSemi) {
|
||||
TEST_F(ParseTreeTest, FunctionDeclarationWithNoSignatureOrSemi) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn foo");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree,
|
||||
MatchParseTreeNodes(
|
||||
{MatchFunctionDeclaration(HasError, MatchDeclaredName("foo")),
|
||||
@@ -145,7 +145,7 @@ TEST_F(ParseTreeTest,
|
||||
FunctionDeclarationWithIdentifierInsteadOfSignatureAndSemi) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn foo bar;");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchFunctionDeclaration(
|
||||
HasError, MatchDeclaredName("foo"),
|
||||
MatchDeclarationEnd()),
|
||||
@@ -155,7 +155,7 @@ TEST_F(ParseTreeTest,
|
||||
TEST_F(ParseTreeTest, FunctionDeclarationWithParameterList) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn foo(bar: i32, baz: i32);");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
MatchParseTreeNodes(
|
||||
@@ -177,7 +177,7 @@ TEST_F(ParseTreeTest, FunctionDefinitionWithParameterList) {
|
||||
" foo(baz, bar + baz);\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
MatchParseTreeNodes(
|
||||
@@ -203,7 +203,7 @@ TEST_F(ParseTreeTest, FunctionDefinitionWithParameterList) {
|
||||
TEST_F(ParseTreeTest, FunctionDeclarationWithReturnType) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn foo() -> u32;");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
MatchParseTreeNodes(
|
||||
@@ -219,7 +219,7 @@ TEST_F(ParseTreeTest, FunctionDefinitionWithReturnType) {
|
||||
" return 42;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_THAT(tree,
|
||||
MatchParseTreeNodes(
|
||||
{MatchFunctionDeclaration(
|
||||
@@ -236,7 +236,7 @@ TEST_F(ParseTreeTest, FunctionDeclarationWithSingleIdentifierParameterList) {
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
// Note: this might become valid depending on the parameter syntax, this test
|
||||
// shouldn't be taken as a sign it should remain invalid.
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree,
|
||||
MatchParseTreeNodes(
|
||||
{MatchFunctionDeclaration(
|
||||
@@ -249,7 +249,7 @@ TEST_F(ParseTreeTest, FunctionDeclarationWithSingleIdentifierParameterList) {
|
||||
TEST_F(ParseTreeTest, FunctionDeclarationWithoutName) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn ();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchFunctionDeclaration(
|
||||
HasError, MatchDeclarationEnd()),
|
||||
MatchFileEnd()}));
|
||||
@@ -260,7 +260,7 @@ TEST_F(ParseTreeTest,
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer(
|
||||
"fn (a tokens c d e f g h i j k l m n o p q r s t u v w x y z);");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes({MatchFunctionDeclaration(
|
||||
HasError, MatchDeclarationEnd()),
|
||||
MatchFileEnd()}));
|
||||
@@ -271,7 +271,7 @@ TEST_F(ParseTreeTest, FunctionDeclarationSkipToNewlineWithoutSemi) {
|
||||
"fn ()\n"
|
||||
"fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree, MatchParseTreeNodes({MatchFunctionDeclaration(HasError),
|
||||
MatchFunctionDeclaration(
|
||||
@@ -287,7 +287,7 @@ TEST_F(ParseTreeTest, FunctionDeclarationSkipIndentedNewlineWithSemi) {
|
||||
" z);\n"
|
||||
"fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
MatchParseTreeNodes(
|
||||
@@ -304,7 +304,7 @@ TEST_F(ParseTreeTest, FunctionDeclarationSkipIndentedNewlineWithoutSemi) {
|
||||
" z)\n"
|
||||
"fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree, MatchParseTreeNodes({MatchFunctionDeclaration(HasError),
|
||||
MatchFunctionDeclaration(
|
||||
@@ -320,7 +320,7 @@ TEST_F(ParseTreeTest, FunctionDeclarationSkipIndentedNewlineUntilOutdent) {
|
||||
" z)\n"
|
||||
"fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree, MatchParseTreeNodes({MatchFunctionDeclaration(HasError),
|
||||
MatchFunctionDeclaration(
|
||||
@@ -339,7 +339,7 @@ TEST_F(ParseTreeTest, FunctionDeclarationSkipWithoutSemiToCurly) {
|
||||
"struct X { fn () }\n"
|
||||
"fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
}
|
||||
|
||||
TEST_F(ParseTreeTest, BasicFunctionDefinition) {
|
||||
@@ -347,7 +347,7 @@ TEST_F(ParseTreeTest, BasicFunctionDefinition) {
|
||||
"fn F() {\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes(
|
||||
{MatchFunctionDeclaration(
|
||||
MatchDeclaredName("F"), MatchParameters(),
|
||||
@@ -363,7 +363,7 @@ TEST_F(ParseTreeTest, FunctionDefinitionWithIdenifierInStatements) {
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
// Note: this might become valid depending on the expression syntax. This test
|
||||
// shouldn't be taken as a sign it should remain invalid.
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes(
|
||||
{MatchFunctionDeclaration(
|
||||
MatchDeclaredName("F"), MatchParameters(),
|
||||
@@ -378,7 +378,7 @@ TEST_F(ParseTreeTest, FunctionDefinitionWithFunctionCall) {
|
||||
" a.b.f(c.d, (e)).g();\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
ExpectedNode call_to_f = MatchCallExpression(
|
||||
MatchDesignator(MatchDesignator(MatchNameReference("a"), "b"), "f"),
|
||||
@@ -400,7 +400,7 @@ TEST_F(ParseTreeTest, InvalidDesignators) {
|
||||
" a.42;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(tree, MatchParseTreeNodes(
|
||||
{MatchFunctionWithBody(
|
||||
@@ -426,7 +426,7 @@ TEST_F(ParseTreeTest, Operators) {
|
||||
" n = a * b + c * d = d * d << e & f - not g;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -462,7 +462,7 @@ TEST_F(ParseTreeTest, OperatorsPrefixUnary) {
|
||||
" ++++n;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -478,7 +478,7 @@ TEST_F(ParseTreeTest, OperatorsPostfixUnary) {
|
||||
" n++++;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -494,7 +494,7 @@ TEST_F(ParseTreeTest, OperatorsAssociative) {
|
||||
" a and b and c;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -512,7 +512,7 @@ TEST_F(ParseTreeTest, OperatorsMissingPrecedence1) {
|
||||
" a and b or c;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -531,7 +531,7 @@ TEST_F(ParseTreeTest, OperatorsMissingPrecedence2) {
|
||||
" a or b and c;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -550,7 +550,7 @@ TEST_F(ParseTreeTest, OperatorsMissingPrecedenceForNot) {
|
||||
" not a and not b and not c;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -575,7 +575,7 @@ TEST_F(ParseTreeTest, OperatorFixity) {
|
||||
" G(i32*, n * n);\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -671,7 +671,7 @@ TEST_F(ParseTreeTest, OperatorWhitespaceErrors) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer(input);
|
||||
ErrorTrackingDiagnosticConsumer error_tracker(consumer);
|
||||
ParseTree tree = ParseTree::Parse(tokens, error_tracker);
|
||||
EXPECT_THAT(tree.HasErrors(), Eq(kind == Failed)) << input;
|
||||
EXPECT_THAT(tree.has_errors(), Eq(kind == Failed)) << input;
|
||||
EXPECT_THAT(error_tracker.SeenError(), Eq(kind != Valid)) << input;
|
||||
}
|
||||
}
|
||||
@@ -684,7 +684,7 @@ TEST_F(ParseTreeTest, VariableDeclarations) {
|
||||
" var s: String = \"hello\";\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(tree,
|
||||
MatchParseTreeNodes(
|
||||
@@ -718,7 +718,7 @@ TEST_F(ParseTreeTest, IfNoElse) {
|
||||
"}");
|
||||
ErrorTrackingDiagnosticConsumer error_tracker(consumer);
|
||||
ParseTree tree = ParseTree::Parse(tokens, error_tracker);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_FALSE(error_tracker.SeenError());
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -753,7 +753,7 @@ TEST_F(ParseTreeTest, IfNoElseUnbraced) {
|
||||
ErrorTrackingDiagnosticConsumer error_tracker(consumer);
|
||||
ParseTree tree = ParseTree::Parse(tokens, error_tracker);
|
||||
// The missing braces are invalid, but we should be able to recover.
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_TRUE(error_tracker.SeenError());
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -788,7 +788,7 @@ TEST_F(ParseTreeTest, IfElse) {
|
||||
"}");
|
||||
ErrorTrackingDiagnosticConsumer error_tracker(consumer);
|
||||
ParseTree tree = ParseTree::Parse(tokens, error_tracker);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_FALSE(error_tracker.SeenError());
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -855,7 +855,7 @@ TEST_F(ParseTreeTest, IfElseUnbraced) {
|
||||
ErrorTrackingDiagnosticConsumer error_tracker(consumer);
|
||||
ParseTree tree = ParseTree::Parse(tokens, error_tracker);
|
||||
// The missing braces are invalid, but we should be able to recover.
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_TRUE(error_tracker.SeenError());
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -906,7 +906,7 @@ TEST_F(ParseTreeTest, IfError) {
|
||||
" if (d)\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -939,7 +939,7 @@ TEST_F(ParseTreeTest, WhileBreakContinue) {
|
||||
"}");
|
||||
ErrorTrackingDiagnosticConsumer error_tracker(consumer);
|
||||
ParseTree tree = ParseTree::Parse(tokens, error_tracker);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_FALSE(error_tracker.SeenError());
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -970,7 +970,7 @@ TEST_F(ParseTreeTest, WhileUnbraced) {
|
||||
"}");
|
||||
ErrorTrackingDiagnosticConsumer error_tracker(consumer);
|
||||
ParseTree tree = ParseTree::Parse(tokens, error_tracker);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
EXPECT_TRUE(error_tracker.SeenError());
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -993,7 +993,7 @@ TEST_F(ParseTreeTest, Return) {
|
||||
" return x;\n"
|
||||
"}");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -1019,7 +1019,7 @@ TEST_F(ParseTreeTest, Tuples) {
|
||||
var y: ((), (), ());
|
||||
)");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
auto empty_tuple = MatchTupleLiteral(MatchTupleLiteralEnd());
|
||||
|
||||
@@ -1053,7 +1053,7 @@ TEST_F(ParseTreeTest, Structs) {
|
||||
var z: {.n: i32,} = {.n = 4,};
|
||||
)");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
|
||||
EXPECT_THAT(
|
||||
tree,
|
||||
@@ -1146,7 +1146,7 @@ TEST_F(ParseTreeTest, StructErrors) {
|
||||
Testing::MockDiagnosticConsumer consumer;
|
||||
EXPECT_CALL(consumer, HandleDiagnostic(testcase.diag_matcher));
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1166,7 +1166,7 @@ auto GetAndDropLine(llvm::StringRef& s) -> std::string {
|
||||
TEST_F(ParseTreeTest, Printing) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
std::string print_storage;
|
||||
llvm::raw_string_ostream print_stream(print_storage);
|
||||
tree.Print(print_stream);
|
||||
@@ -1194,7 +1194,7 @@ TEST_F(ParseTreeTest, Printing) {
|
||||
TEST_F(ParseTreeTest, PrintingAsYAML) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("fn F();");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_FALSE(tree.HasErrors());
|
||||
EXPECT_FALSE(tree.has_errors());
|
||||
std::string print_output;
|
||||
llvm::raw_string_ostream print_stream(print_output);
|
||||
tree.Print(print_stream);
|
||||
@@ -1235,7 +1235,7 @@ TEST_F(ParseTreeTest, ParenMatchRegression) {
|
||||
// the closing `}` when it skips over the nested scope.
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer("var = (foo {})");
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
EXPECT_THAT(
|
||||
tree, MatchParseTreeNodes(
|
||||
{MatchVariableDeclaration(
|
||||
@@ -1263,7 +1263,7 @@ TEST_F(ParseTreeTest, RecursionLimit) {
|
||||
"Exceeded recursion limit ({0})", ParseTree::StackDepthLimit))))
|
||||
.Times(AtLeast(1));
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
}
|
||||
|
||||
TEST_F(ParseTreeTest, ParsePostfixExpressionRegression) {
|
||||
@@ -1277,7 +1277,7 @@ TEST_F(ParseTreeTest, ParsePostfixExpressionRegression) {
|
||||
TokenizedBuffer tokens = GetTokenizedBuffer(code);
|
||||
ASSERT_FALSE(tokens.has_errors());
|
||||
ParseTree tree = ParseTree::Parse(tokens, consumer);
|
||||
EXPECT_TRUE(tree.HasErrors());
|
||||
EXPECT_TRUE(tree.has_errors());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class ParseTreeTest : public ::testing::Test {
|
||||
TEST_F(ParseTreeTest, Empty) {
|
||||
// TODO: Validate the returned Semantics object.
|
||||
Analyze("");
|
||||
ASSERT_FALSE(parse_tree->HasErrors());
|
||||
ASSERT_FALSE(parse_tree->has_errors());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user