Switch the parse tree tests to lit (#2289)

This switch is being done in order to make it easier to update tests when the parse tree structure changes. I've been spending a lot of time doing such updates as part of refactoring the parse tree, and I expect more, so that's really at the root of all the refactoring I've been doing to lit updates.
This commit is contained in:
Jon Ross-Perkins
2022-10-13 15:54:37 -07:00
committed by GitHub
parent a3329cf004
commit bb521fdd5b
58 changed files with 1634 additions and 1649 deletions
-15
View File
@@ -49,27 +49,12 @@ cc_library(
],
)
cc_library(
name = "parse_test_helpers",
testonly = 1,
hdrs = ["parse_test_helpers.h"],
deps = [
":parse_node_kind",
":parse_tree",
"//common:check",
"//toolchain/lexer:tokenized_buffer",
"@com_google_googletest//:gtest",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "parse_tree_test",
size = "small",
srcs = ["parse_tree_test.cpp"],
deps = [
":parse_node_kind",
":parse_test_helpers",
":parse_tree",
"//common:gtest_main",
"//common:ostream",
View File
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""Updates the CHECK: lines in lit tests based on the AUTOUPDATE line."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import os
import sys
from pathlib import Path
def main() -> None:
# Calls the main script with explorer settings. This uses execv in order to
# avoid Python import behaviors.
this_py = Path(__file__).resolve()
actual_py = this_py.parent.parent.parent.joinpath(
"bazel", "testing", "lit_autoupdate_base.py"
)
args = [
sys.argv[0],
# Flags to configure for explorer testing.
"--build_target",
"//toolchain/driver:carbon",
"--line_number_pattern",
r"(?<=\.carbon:)(\d+)(?=(?:\D|$))",
"--testdata",
"toolchain/parser/testdata",
] + sys.argv[1:]
os.execv(actual_py, args)
if __name__ == "__main__":
main()
-346
View File
@@ -1,346 +0,0 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_PARSER_PARSE_TEST_HELPERS_H_
#define CARBON_TOOLCHAIN_PARSER_PARSE_TEST_HELPERS_H_
#include <gmock/gmock.h>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "common/check.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/lexer/tokenized_buffer.h"
#include "toolchain/parser/parse_node_kind.h"
#include "toolchain/parser/parse_tree.h"
namespace Carbon {
// Enable printing a parse tree from Google Mock.
inline void PrintTo(const ParseTree& tree, std::ostream* output) {
std::string text;
llvm::raw_string_ostream text_stream(text);
tree.Print(text_stream);
*output << "\n" << text_stream.str() << "\n";
}
namespace Testing {
// An aggregate used to describe an expected parse tree.
//
// This type is designed to be used via aggregate initialization with designated
// initializers. The latter make it easy to default everything and then override
// the desired aspects when writing an expectation in a test.
struct ExpectedNode {
ParseNodeKind kind = ParseNodeKind::EmptyDeclaration();
std::string text;
bool has_error = false;
bool skip_subtree = false;
std::vector<ExpectedNode> children;
};
// Implementation of a matcher for a parse tree based on a tree of expected
// nodes.
//
// Don't create this directly, instead use `MatchParseTreeNodes` to construct a
// matcher based on this.
class ExpectedNodesMatcher
: public ::testing::MatcherInterface<const ParseTree&> {
public:
explicit ExpectedNodesMatcher(
llvm::SmallVector<ExpectedNode, 0> expected_nodess)
: expected_nodes_(std::move(expected_nodess)) {}
auto MatchAndExplain(const ParseTree& tree,
::testing::MatchResultListener* output_ptr) const
-> bool override;
auto DescribeTo(std::ostream* output_ptr) const -> void override;
private:
auto MatchExpectedNode(const ParseTree& tree, ParseTree::Node n,
int postorder_index, const ExpectedNode& expected_node,
::testing::MatchResultListener& output) const -> bool;
llvm::SmallVector<ExpectedNode, 0> expected_nodes_;
};
// Implementation of the Google Mock interface for matching (and explaining any
// failure).
inline auto ExpectedNodesMatcher::MatchAndExplain(
const ParseTree& tree, ::testing::MatchResultListener* output_ptr) const
-> bool {
auto& output = *output_ptr;
bool matches = true;
const auto rpo = llvm::reverse(tree.postorder());
const auto nodes_begin = rpo.begin();
const auto nodes_end = rpo.end();
auto nodes_it = nodes_begin;
llvm::SmallVector<const ExpectedNode*, 16> expected_node_stack;
for (const ExpectedNode& en : expected_nodes_) {
expected_node_stack.push_back(&en);
}
while (!expected_node_stack.empty()) {
if (nodes_it == nodes_end) {
// We'll check the size outside the loop.
break;
}
ParseTree::Node n = *nodes_it++;
int postorder_index = n.index();
const ExpectedNode& expected_node = *expected_node_stack.pop_back_val();
if (!MatchExpectedNode(tree, n, postorder_index, expected_node, output)) {
matches = false;
}
if (expected_node.skip_subtree) {
CARBON_CHECK(expected_node.children.empty())
<< "Must not skip an expected subtree while specifying expected "
"children!";
nodes_it = llvm::reverse(tree.postorder(n)).end();
continue;
}
// We want to make sure we don't end up with unsynchronized walks, so skip
// 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());
if (num_children != static_cast<int>(expected_node.children.size())) {
output
<< "\nParse node (postorder index #" << postorder_index << ") has "
<< num_children << " children, expected "
<< expected_node.children.size()
<< ". Skipping this subtree to avoid any unsynchronized tree walk.";
matches = false;
nodes_it = llvm::reverse(tree.postorder(n)).end();
continue;
}
// Push the children onto the stack to continue matching. The expectation
// is in preorder, but we visit the parse tree in reverse postorder. This
// causes the siblings to be visited in reverse order from the expected
// list. However, we use a stack which inherently does this reverse for us
// so we simply append to the stack here.
for (const ExpectedNode& child_expected_node : expected_node.children) {
expected_node_stack.push_back(&child_expected_node);
}
}
// We don't directly check the size because we allow expectations to skip
// subtrees. Instead, we need to check that we successfully processed all of
// the actual tree and consumed all of the expected tree.
if (nodes_it != nodes_end) {
CARBON_CHECK(expected_node_stack.empty())
<< "If we have unmatched nodes in the input tree, should only finish "
"having fully processed expected tree.";
output << "\nFinished processing expected nodes and there are still "
<< (nodes_end - nodes_it) << " unexpected nodes.";
matches = false;
} else if (!expected_node_stack.empty()) {
output << "\nProcessed all " << (nodes_end - nodes_begin)
<< " nodes and still have " << expected_node_stack.size()
<< " expected nodes that were unmatched.";
matches = false;
}
return matches;
}
// Implementation of the Google Mock interface for describing the expected node
// tree.
//
// This is designed to describe the expected tree node structure in as similar
// of a format to the parse tree's print format as is reasonable. There is both
// more and less information, so it won't be exact, but should be close enough
// to make it easy to visually compare the two.
inline auto ExpectedNodesMatcher::DescribeTo(std::ostream* output_ptr) const
-> void {
auto& output = *output_ptr;
output << "Matches expected node pattern:\n[\n";
// We want to walk these in RPO instead of in preorder to match the printing
// of the actual parse tree.
llvm::SmallVector<std::pair<const ExpectedNode*, int>, 16>
expected_node_stack;
for (const ExpectedNode& expected_node : llvm::reverse(expected_nodes_)) {
expected_node_stack.push_back({&expected_node, 0});
}
while (!expected_node_stack.empty()) {
const ExpectedNode& expected_node = *expected_node_stack.back().first;
int depth = expected_node_stack.back().second;
expected_node_stack.pop_back();
for (int indent_count = 0; indent_count < depth; ++indent_count) {
output << " ";
}
output << "{kind: '" << expected_node.kind.name().str() << "'";
if (!expected_node.text.empty()) {
output << ", text: '" << expected_node.text << "'";
}
if (expected_node.has_error) {
output << ", has_error: yes";
}
if (expected_node.skip_subtree) {
output << ", skip_subtree: yes";
}
if (!expected_node.children.empty()) {
CARBON_CHECK(!expected_node.skip_subtree)
<< "Must not have children and skip a subtree!";
output << ", children: [\n";
for (const ExpectedNode& child_expected_node :
llvm::reverse(expected_node.children)) {
expected_node_stack.push_back({&child_expected_node, depth + 1});
}
// If we have children, we know we're not popping off.
continue;
}
// If this is some form of leaf we'll at least need to close it. It may also
// be the last sibling of its parent, and we'll need to close any parents as
// we pop up.
output << "}";
if (!expected_node_stack.empty()) {
CARBON_CHECK(depth >= expected_node_stack.back().second)
<< "Cannot have an increase in depth on a leaf node!";
// The distance we need to pop is the difference in depth.
int pop_depth = depth - expected_node_stack.back().second;
for (int pop_count = 0; pop_count < pop_depth; ++pop_count) {
// Close both the children array and the node mapping.
output << "]}";
}
}
output << "\n";
}
output << "]\n";
}
inline auto ExpectedNodesMatcher::MatchExpectedNode(
const ParseTree& tree, ParseTree::Node n, int postorder_index,
const ExpectedNode& expected_node,
::testing::MatchResultListener& output) const -> bool {
bool matches = true;
ParseNodeKind kind = tree.node_kind(n);
if (kind != expected_node.kind) {
output << "\nParse node (postorder index #" << postorder_index << ") is a "
<< kind.name().str() << ", expected a "
<< expected_node.kind.name().str() << ".";
matches = false;
}
if (tree.node_has_error(n) != expected_node.has_error) {
output << "\nParse node (postorder index #" << postorder_index << ") "
<< (tree.node_has_error(n) ? "has an error"
: "does not have an error")
<< ", expected that it "
<< (expected_node.has_error ? "has an error"
: "does not have an error")
<< ".";
matches = false;
}
llvm::StringRef node_text = tree.GetNodeText(n);
if (!expected_node.text.empty() && node_text != expected_node.text) {
output << "\nParse node (postorder index #" << postorder_index
<< ") is spelled '" << node_text.str() << "', expected '"
<< expected_node.text << "'.";
matches = false;
}
return matches;
}
// Creates a matcher for a parse tree using a tree of expected nodes.
//
// This is intended to be used with an braced initializer list style aggregate
// initializer for an argument, allowing it to describe a tree structure via
// nested `ExpectedNode` objects.
inline auto MatchParseTreeNodes(
llvm::SmallVector<ExpectedNode, 0> expected_nodes)
-> ::testing::Matcher<const ParseTree&> {
return ::testing::MakeMatcher(
new ExpectedNodesMatcher(std::move(expected_nodes)));
}
// Matcher argument for a node with errors.
struct HasErrorTag {};
inline constexpr HasErrorTag HasError;
// Matcher argument to skip checking the children of a node.
struct AnyChildrenTag {};
inline constexpr AnyChildrenTag AnyChildren;
// A function to generate ExpectedNodes a little more tersely and readably. The
// meaning of each argument is inferred from its type.
template <typename... Args>
auto MatchNode(Args... args) -> ExpectedNode {
struct ArgHandler {
ExpectedNode expected;
void UpdateExpectationsForArg(ParseNodeKind kind) { expected.kind = kind; }
void UpdateExpectationsForArg(std::string text) {
expected.text = std::move(text);
}
void UpdateExpectationsForArg(HasErrorTag /*tag*/) {
expected.has_error = true;
}
void UpdateExpectationsForArg(AnyChildrenTag /*tag*/) {
expected.skip_subtree = true;
}
void UpdateExpectationsForArg(ExpectedNode node) {
expected.children.push_back(std::move(node));
}
};
ArgHandler handler;
(handler.UpdateExpectationsForArg(args), ...);
return handler.expected;
}
// A MatchFoo function for each parse node Foo. Used to construct ExpectedNodes
// for use in MatchParseTreeNodes. Example:
//
// MatchParseTreeNodes(
// {MatchFunctionDeclaration("fn", MatchIdentifier("F"),
// MatchParameterList(MatchParameterListEnd()),
// MatchDeclarationEnd(";")),
// MatchFileEnd()});
#define CARBON_PARSE_NODE_KIND(kind) \
template <typename... Args> \
auto Match##kind(Args... args)->ExpectedNode { \
return MatchNode(ParseNodeKind::kind(), std::move(args)...); \
}
#include "toolchain/parser/parse_node_kind.def"
// Helper for matching a designator `lhs.rhs`.
inline auto MatchDesignator(ExpectedNode lhs, std::string rhs) -> ExpectedNode {
return MatchDesignatorExpression(std::move(lhs),
MatchDesignatedName(std::move(rhs)));
}
// Helper for matching a function parameter list.
template <typename... Args>
auto MatchParameters(Args... args) -> ExpectedNode {
return MatchParameterList("(", std::move(args)..., MatchParameterListEnd());
}
// Helper for matching the statements in the body of a simple function
// definition with no parameters.
template <typename... Args>
auto MatchFunctionWithBody(Args... args) -> ExpectedNode {
return MatchFunctionDeclaration(
MatchDeclaredName(), MatchParameters(),
MatchCodeBlock(std::move(args)..., MatchCodeBlockEnd()));
}
} // namespace Testing
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_PARSER_PARSE_TEST_HELPERS_H_
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("//bazel/testing:lit.bzl", "glob_lit_tests")
glob_lit_tests(
data = [
"//bazel/testing:merge_output",
"//toolchain/driver:carbon",
"@llvm-project//llvm:FileCheck",
"@llvm-project//llvm:not",
],
driver = "lit.cfg.py",
test_file_exts = ["carbon"],
)
+9
View File
@@ -0,0 +1,9 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 0, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
@@ -0,0 +1,12 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 0, kind: 'EmptyDeclaration', text: ';'},
// CHECK:STDOUT: {node_index: 1, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
;
+39
View File
@@ -0,0 +1,39 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 24, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 25, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 23, kind: 'CodeBlock', text: '{', subtree_size: 21, children: [
// CHECK:STDOUT: {node_index: 21, kind: 'ExpressionStatement', text: ';', subtree_size: 19, children: [
// CHECK:STDOUT: {node_index: 20, kind: 'CallExpression', text: '(', subtree_size: 18, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'DesignatorExpression', text: '.', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'CallExpression', text: '(', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'DesignatorExpression', text: '.', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'DesignatorExpression', text: '.', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'DesignatedName', text: 'b'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'DesignatedName', text: 'f'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'DesignatorExpression', text: '.', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'NameReference', text: 'c'},
// CHECK:STDOUT: {node_index: 9, kind: 'DesignatedName', text: 'd'}]},
// CHECK:STDOUT: {node_index: 11, kind: 'CallExpressionComma', text: ','},
// CHECK:STDOUT: {node_index: 14, kind: 'ParenExpression', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'NameReference', text: 'e'},
// CHECK:STDOUT: {node_index: 13, kind: 'ParenExpressionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 15, kind: 'CallExpressionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 17, kind: 'DesignatedName', text: 'g'}]},
// CHECK:STDOUT: {node_index: 19, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 22, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 25, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// NOTE: Move to its own directory when more tests are added.
fn F() {
a.b.f(c.d, (e)).g();
}
@@ -0,0 +1,35 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 15, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 14, kind: 'CodeBlock', text: '{', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'ExpressionStatement', text: ';', has_error: yes, subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'DesignatorExpression', text: '.', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'}]}]},
// CHECK:STDOUT: {node_index: 9, kind: 'ExpressionStatement', text: ';', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'DesignatorExpression', text: '.', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 7, kind: 'DesignatedName', text: 'fn', has_error: yes}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'ExpressionStatement', text: ';', has_error: yes, subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'DesignatorExpression', text: '.', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'NameReference', text: 'a'}]}]},
// CHECK:STDOUT: {node_index: 13, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 16, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// NOTE: Move to its own directory when more tests are added.
fn F() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/invalid_designators.carbon:[[@LINE+1]]:5: Expected identifier after `.`.
a.;
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/invalid_designators.carbon:[[@LINE+1]]:5: Expected identifier after `.`.
a.fn;
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/invalid_designators.carbon:[[@LINE+1]]:5: Expected identifier after `.`.
a.42;
}
@@ -0,0 +1,13 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 0, kind: 'EmptyDeclaration', text: ';', has_error: yes},
// CHECK:STDOUT: {node_index: 1, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/no_intro_with_semi.carbon:[[@LINE+1]]:1: Unrecognized declaration introducer.
foo;
@@ -0,0 +1,12 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 0, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/no_intro_without_semi.carbon:[[@LINE+1]]:1: Unrecognized declaration introducer.
foo bar baz
+35
View File
@@ -0,0 +1,35 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 3, kind: 'PackageDirective', text: 'package', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'Geometry'},
// CHECK:STDOUT: {node_index: 1, kind: 'PackageApi', text: 'api'},
// CHECK:STDOUT: {node_index: 2, kind: 'PackageEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 7, kind: 'PackageDirective', text: 'package', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'DeclaredName', text: 'Geometry'},
// CHECK:STDOUT: {node_index: 5, kind: 'PackageImpl', text: 'impl'},
// CHECK:STDOUT: {node_index: 6, kind: 'PackageEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 13, kind: 'PackageDirective', text: 'package', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'DeclaredName', text: 'Geometry'},
// CHECK:STDOUT: {node_index: 10, kind: 'PackageLibrary', text: 'library', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'Literal', text: '"Shapes"'}]},
// CHECK:STDOUT: {node_index: 11, kind: 'PackageApi', text: 'api'},
// CHECK:STDOUT: {node_index: 12, kind: 'PackageEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 19, kind: 'PackageDirective', text: 'package', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'DeclaredName', text: 'Geometry'},
// CHECK:STDOUT: {node_index: 16, kind: 'PackageLibrary', text: 'library', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'Literal', text: '"Shapes"'}]},
// CHECK:STDOUT: {node_index: 17, kind: 'PackageImpl', text: 'impl'},
// CHECK:STDOUT: {node_index: 18, kind: 'PackageEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 20, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// NOTE: Move to its own directory when more tests are added.
package Geometry api;
package Geometry impl;
package Geometry library "Shapes" api;
package Geometry library "Shapes" impl;
@@ -0,0 +1,19 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 4, kind: 'VariableDeclaration', text: 'var', has_error: yes, subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'VariableInitializer', text: '=', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'ParenExpression', text: '(', has_error: yes, subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'NameReference', text: 'foo'},
// CHECK:STDOUT: {node_index: 1, kind: 'ParenExpressionEnd', text: ')'}]}]}]},
// CHECK:STDOUT: {node_index: 5, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/paren_match_regression.carbon:[[@LINE+3]]:5: Expected pattern in `var` declaration.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/paren_match_regression.carbon:[[@LINE+2]]:12: Expected `,` or `)`.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/basics/paren_match_regression.carbon:[[@LINE+1]]:15: Expected `;` after expression.
var = (foo {})
+47
View File
@@ -0,0 +1,47 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 13, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 12, kind: 'CodeBlock', text: '{', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'IfStatement', text: 'if', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'c'},
// CHECK:STDOUT: {node_index: 4, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 9, kind: 'CodeBlock', text: '{', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'ReturnStatement', text: 'return', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'StatementEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 8, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 11, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 27, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'DeclaredName', text: 'G'},
// CHECK:STDOUT: {node_index: 19, kind: 'ParameterList', text: '(', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 17, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'DeclaredName', text: 'x'},
// CHECK:STDOUT: {node_index: 16, kind: 'NameReference', text: 'Foo'}]},
// CHECK:STDOUT: {node_index: 18, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 21, kind: 'ReturnType', text: '->', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 20, kind: 'NameReference', text: 'Foo'}]},
// CHECK:STDOUT: {node_index: 26, kind: 'CodeBlock', text: '{', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 24, kind: 'ReturnStatement', text: 'return', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 23, kind: 'StatementEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 25, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 28, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// NOTE: Move to its own directory when more tests are added.
fn F() {
if (c) {
return;
}
}
fn G(x: Foo) -> Foo {
return x;
}
+69
View File
@@ -0,0 +1,69 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 26, kind: 'VariableDeclaration', text: 'var', subtree_size: 27, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'PatternBinding', text: ':', subtree_size: 13, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'x'},
// CHECK:STDOUT: {node_index: 11, kind: 'StructTypeLiteral', text: '{', subtree_size: 11, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'StructFieldType', text: ':', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'StructFieldDesignator', text: '.', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'DesignatedName', text: 'a'}]},
// CHECK:STDOUT: {node_index: 3, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'StructComma', text: ','},
// CHECK:STDOUT: {node_index: 9, kind: 'StructFieldType', text: ':', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'StructFieldDesignator', text: '.', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'DesignatedName', text: 'b'}]},
// CHECK:STDOUT: {node_index: 8, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'StructEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 24, kind: 'VariableInitializer', text: '=', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 23, kind: 'StructLiteral', text: '{', subtree_size: 11, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'StructFieldValue', text: '=', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'StructFieldDesignator', text: '.', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'DesignatedName', text: 'a'}]},
// CHECK:STDOUT: {node_index: 15, kind: 'Literal', text: '1'}]},
// CHECK:STDOUT: {node_index: 17, kind: 'StructComma', text: ','},
// CHECK:STDOUT: {node_index: 21, kind: 'StructFieldValue', text: '=', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 19, kind: 'StructFieldDesignator', text: '.', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'DesignatedName', text: 'b'}]},
// CHECK:STDOUT: {node_index: 20, kind: 'Literal', text: '2'}]},
// CHECK:STDOUT: {node_index: 22, kind: 'StructEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 25, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 35, kind: 'VariableDeclaration', text: 'var', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 30, kind: 'PatternBinding', text: ':', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 27, kind: 'DeclaredName', text: 'y'},
// CHECK:STDOUT: {node_index: 29, kind: 'StructLiteral', text: '{', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 28, kind: 'StructEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 33, kind: 'VariableInitializer', text: '=', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 32, kind: 'StructLiteral', text: '{', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 31, kind: 'StructEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 34, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 54, kind: 'VariableDeclaration', text: 'var', subtree_size: 19, children: [
// CHECK:STDOUT: {node_index: 44, kind: 'PatternBinding', text: ':', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 36, kind: 'DeclaredName', text: 'z'},
// CHECK:STDOUT: {node_index: 43, kind: 'StructTypeLiteral', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 40, kind: 'StructFieldType', text: ':', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 38, kind: 'StructFieldDesignator', text: '.', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 37, kind: 'DesignatedName', text: 'n'}]},
// CHECK:STDOUT: {node_index: 39, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 41, kind: 'StructComma', text: ','},
// CHECK:STDOUT: {node_index: 42, kind: 'StructEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 52, kind: 'VariableInitializer', text: '=', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 51, kind: 'StructLiteral', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 48, kind: 'StructFieldValue', text: '=', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 46, kind: 'StructFieldDesignator', text: '.', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 45, kind: 'DesignatedName', text: 'n'}]},
// CHECK:STDOUT: {node_index: 47, kind: 'Literal', text: '4'}]},
// CHECK:STDOUT: {node_index: 49, kind: 'StructComma', text: ','},
// CHECK:STDOUT: {node_index: 50, kind: 'StructEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 53, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 55, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// NOTE: Move to its own directory when more tests are added.
var x: {.a: i32, .b: i32} = {.a = 1, .b = 2};
var y: {} = {};
var z: {.n: i32,} = {.n = 4,};
+42
View File
@@ -0,0 +1,42 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 14, kind: 'VariableDeclaration', text: 'var', subtree_size: 15, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'PatternBinding', text: ':', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'x'},
// CHECK:STDOUT: {node_index: 5, kind: 'TupleLiteral', text: '(', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'Literal', text: 'i32'},
// CHECK:STDOUT: {node_index: 2, kind: 'TupleLiteralComma', text: ','},
// CHECK:STDOUT: {node_index: 3, kind: 'Literal', text: 'i32'},
// CHECK:STDOUT: {node_index: 4, kind: 'TupleLiteralEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'VariableInitializer', text: '=', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'TupleLiteral', text: '(', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'Literal', text: '1'},
// CHECK:STDOUT: {node_index: 8, kind: 'TupleLiteralComma', text: ','},
// CHECK:STDOUT: {node_index: 9, kind: 'Literal', text: '2'},
// CHECK:STDOUT: {node_index: 10, kind: 'TupleLiteralEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 13, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 28, kind: 'VariableDeclaration', text: 'var', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 26, kind: 'PatternBinding', text: ':', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'DeclaredName', text: 'y'},
// CHECK:STDOUT: {node_index: 25, kind: 'TupleLiteral', text: '(', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 17, kind: 'TupleLiteral', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'TupleLiteralEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 18, kind: 'TupleLiteralComma', text: ','},
// CHECK:STDOUT: {node_index: 20, kind: 'TupleLiteral', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 19, kind: 'TupleLiteralEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 21, kind: 'TupleLiteralComma', text: ','},
// CHECK:STDOUT: {node_index: 23, kind: 'TupleLiteral', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'TupleLiteralEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 24, kind: 'TupleLiteralEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 27, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 29, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// NOTE: Move to its own directory when more tests are added.
var x: (i32, i32) = (1, 2);
var y: ((), (), ());
+41
View File
@@ -0,0 +1,41 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 6, kind: 'VariableDeclaration', text: 'var', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'v'},
// CHECK:STDOUT: {node_index: 1, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'VariableInitializer', text: '=', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'Literal', text: '0'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 11, kind: 'VariableDeclaration', text: 'var', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'DeclaredName', text: 'w'},
// CHECK:STDOUT: {node_index: 8, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 24, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 13, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 14, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 23, kind: 'CodeBlock', text: '{', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 21, kind: 'VariableDeclaration', text: 'var', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 17, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'DeclaredName', text: 's'},
// CHECK:STDOUT: {node_index: 16, kind: 'NameReference', text: 'String'}]},
// CHECK:STDOUT: {node_index: 19, kind: 'VariableInitializer', text: '=', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'Literal', text: '"hello"'}]},
// CHECK:STDOUT: {node_index: 20, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 22, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 25, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// NOTE: Move to its own directory when more tests are added.
var v: i32 = 0;
var w: i32;
fn F() {
var s: String = "hello";
}
@@ -0,0 +1,37 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 20, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 21, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 19, kind: 'CodeBlock', text: '{', subtree_size: 17, children: [
// CHECK:STDOUT: {node_index: 17, kind: 'ForStatement', text: 'for', subtree_size: 15, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'ForHeader', text: '(', has_error: yes, subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'VariableDeclaration', text: 'var', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'DeclaredName', text: 'x'},
// CHECK:STDOUT: {node_index: 4, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 7, kind: 'NameReference', text: 'y'},
// CHECK:STDOUT: {node_index: 8, kind: 'ForHeaderEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 16, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'NameReference', text: 'Print'},
// CHECK:STDOUT: {node_index: 11, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 12, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 15, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 18, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 21, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/for/colon_instead_of_in.carbon:[[@LINE+1]]:19: `:` should be replaced by `in`.
for (var x: i32 : y) {
Print(x);
}
}
+36
View File
@@ -0,0 +1,36 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 19, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 20, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 18, kind: 'CodeBlock', text: '{', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'ForStatement', text: 'for', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'ForHeader', text: '(', has_error: yes, subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'VariableDeclaration', text: 'var', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'DeclaredName', text: 'x'},
// CHECK:STDOUT: {node_index: 4, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 7, kind: 'ForHeaderEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 15, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'NameReference', text: 'Print'},
// CHECK:STDOUT: {node_index: 10, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 11, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 14, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 17, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 20, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/for/missing_in.carbon:[[@LINE+1]]:19: Expected `in` after loop `var` declaration.
for (var x: i32 y) {
Print(x);
}
}
+34
View File
@@ -0,0 +1,34 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 17, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 18, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 16, kind: 'CodeBlock', text: '{', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'ForStatement', text: 'for', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'ForHeader', text: '(', has_error: yes, subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'ForIn', text: 'in'},
// CHECK:STDOUT: {node_index: 4, kind: 'NameReference', text: 'y'},
// CHECK:STDOUT: {node_index: 5, kind: 'ForHeaderEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 13, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'NameReference', text: 'Print'},
// CHECK:STDOUT: {node_index: 8, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 9, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 15, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 18, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/for/missing_var.carbon:[[@LINE+1]]:8: Expected `var` declaration.
for (x: i32 in y) {
Print(x);
}
}
+50
View File
@@ -0,0 +1,50 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 32, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 33, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 31, kind: 'CodeBlock', text: '{', subtree_size: 29, children: [
// CHECK:STDOUT: {node_index: 29, kind: 'ForStatement', text: 'for', subtree_size: 27, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'ForHeader', text: '(', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'VariableDeclaration', text: 'var', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'DeclaredName', text: 'y'},
// CHECK:STDOUT: {node_index: 4, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 7, kind: 'ForIn', text: 'in'},
// CHECK:STDOUT: {node_index: 8, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 9, kind: 'ForHeaderEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 28, kind: 'CodeBlock', text: '{', subtree_size: 18, children: [
// CHECK:STDOUT: {node_index: 26, kind: 'ForStatement', text: 'for', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'ForHeader', text: '(', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'VariableDeclaration', text: 'var', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'DeclaredName', text: 'z'},
// CHECK:STDOUT: {node_index: 12, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 15, kind: 'ForIn', text: 'in'},
// CHECK:STDOUT: {node_index: 16, kind: 'NameReference', text: 'y'},
// CHECK:STDOUT: {node_index: 17, kind: 'ForHeaderEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 25, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 23, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 19, kind: 'NameReference', text: 'Print'},
// CHECK:STDOUT: {node_index: 20, kind: 'NameReference', text: 'z'},
// CHECK:STDOUT: {node_index: 21, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 24, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 27, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 30, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 33, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo() {
for (var y: i32 in x) {
for (var z: i32 in y) {
Print(z);
}
}
}
+37
View File
@@ -0,0 +1,37 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 21, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 22, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 20, kind: 'CodeBlock', text: '{', subtree_size: 18, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'ForStatement', text: 'for', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'ForHeader', text: '(', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'VariableDeclaration', text: 'var', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'DeclaredName', text: 'x'},
// CHECK:STDOUT: {node_index: 4, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 7, kind: 'ForIn', text: 'in'},
// CHECK:STDOUT: {node_index: 8, kind: 'NameReference', text: 'y'},
// CHECK:STDOUT: {node_index: 9, kind: 'ForHeaderEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 17, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'NameReference', text: 'Print'},
// CHECK:STDOUT: {node_index: 12, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 13, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 16, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 19, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 22, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo() {
for (var x: i32 in y) {
Print(x);
}
}
@@ -0,0 +1,16 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 4, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 3, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F();
@@ -0,0 +1,15 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 2, kind: 'FunctionDeclaration', text: 'fn', has_error: yes, subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 1, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 3, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/identifier_instead_of_sig.carbon:[[@LINE+1]]:8: Expected `(` after function name.
fn foo bar;
@@ -0,0 +1,14 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 1, kind: 'FunctionDeclaration', text: 'fn', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 2, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/missing_name.carbon:[[@LINE+1]]:4: Expected function name after `fn` keyword.
fn ();
@@ -0,0 +1,14 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 1, kind: 'FunctionDeclaration', text: 'fn', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'}]},
// CHECK:STDOUT: {node_index: 2, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/no_sig_or_semi.carbon:[[@LINE+1]]:7: Expected `(` after function name.
fn foo
@@ -0,0 +1,14 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 1, kind: 'FunctionDeclaration', text: 'fn', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 2, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/only_fn_and_semi.carbon:[[@LINE+1]]:3: Expected function name after `fn` keyword.
fn;
@@ -0,0 +1,14 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 1, kind: 'FunctionDeclaration', text: 'fn', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 2, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/repeated_fn_and_semi.carbon:[[@LINE+1]]:4: Expected function name after `fn` keyword.
fn fn;
@@ -0,0 +1,21 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 0, kind: 'FunctionDeclaration', text: 'fn', has_error: yes},
// CHECK:STDOUT: {node_index: 5, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 3, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/skip_indented_newline_until_outdent.carbon:[[@LINE+1]]:6: Expected function name after `fn` keyword.
fn (x,
y,
z)
fn F();
@@ -0,0 +1,22 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 1, kind: 'FunctionDeclaration', text: 'fn', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 4, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 7, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/skip_indented_newline_with_semi.carbon:[[@LINE+1]]:4: Expected function name after `fn` keyword.
fn (x,
y,
z);
fn F();
@@ -0,0 +1,21 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 0, kind: 'FunctionDeclaration', text: 'fn', has_error: yes},
// CHECK:STDOUT: {node_index: 5, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 3, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/skip_indented_newline_without_semi.carbon:[[@LINE+1]]:4: Expected function name after `fn` keyword.
fn (x,
y,
z)
fn F();
@@ -0,0 +1,19 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 0, kind: 'FunctionDeclaration', text: 'fn', has_error: yes},
// CHECK:STDOUT: {node_index: 5, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 3, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/skip_to_newline_without_semi.carbon:[[@LINE+1]]:4: Expected function name after `fn` keyword.
fn ()
fn F();
@@ -0,0 +1,18 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 4, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 3, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/skip_without_semi_to_curly.carbon:[[@LINE+1]]:1: Unrecognized declaration introducer.
struct X { fn () }
fn F();
@@ -0,0 +1,17 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 4, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 3, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/with_identifier_as_param.carbon:[[@LINE+1]]:8: Expected parameter declaration.
fn foo(bar);
@@ -0,0 +1,23 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 11, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 9, kind: 'ParameterList', text: '(', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'DeclaredName', text: 'bar'},
// CHECK:STDOUT: {node_index: 2, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'ParameterListComma', text: ','},
// CHECK:STDOUT: {node_index: 7, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'DeclaredName', text: 'baz'},
// CHECK:STDOUT: {node_index: 6, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 8, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 12, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo(bar: i32, baz: i32);
@@ -0,0 +1,18 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 6, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'ReturnType', text: '->', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'Literal', text: 'u32'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 7, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo() -> u32;
@@ -0,0 +1,14 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 1, kind: 'FunctionDeclaration', text: 'fn', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 2, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/declaration/without_name_and_many_tokens_in_params.carbon:[[@LINE+1]]:4: Expected function name after `fn` keyword.
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);
@@ -0,0 +1,18 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 5, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'CodeBlock', text: '{', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 6, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
}
@@ -0,0 +1,23 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 6, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 5, kind: 'CodeBlock', text: '{', has_error: yes, subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'bar'},
// CHECK:STDOUT: {node_index: 4, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 7, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
// Note: this might become valid depending on the expression syntax. This test
// shouldn't be taken as a sign it should remain invalid.
bar
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/function/definition/identifier_in_statements.carbon:[[@LINE+1]]:1: Expected `;` after expression.
}
@@ -0,0 +1,35 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 21, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 22, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 9, kind: 'ParameterList', text: '(', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'DeclaredName', text: 'bar'},
// CHECK:STDOUT: {node_index: 2, kind: 'Literal', text: 'i64'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'ParameterListComma', text: ','},
// CHECK:STDOUT: {node_index: 7, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'DeclaredName', text: 'baz'},
// CHECK:STDOUT: {node_index: 6, kind: 'Literal', text: 'i64'}]},
// CHECK:STDOUT: {node_index: 8, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 20, kind: 'CodeBlock', text: '{', subtree_size: 11, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'ExpressionStatement', text: ';', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 17, kind: 'CallExpression', text: '(', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'NameReference', text: 'foo'},
// CHECK:STDOUT: {node_index: 11, kind: 'NameReference', text: 'baz'},
// CHECK:STDOUT: {node_index: 12, kind: 'CallExpressionComma', text: ','},
// CHECK:STDOUT: {node_index: 15, kind: 'InfixOperator', text: '+', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'NameReference', text: 'bar'},
// CHECK:STDOUT: {node_index: 14, kind: 'NameReference', text: 'baz'}]},
// CHECK:STDOUT: {node_index: 16, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 19, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 22, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo(bar: i64, baz: i64) {
foo(baz, bar + baz);
}
@@ -0,0 +1,24 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 10, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 11, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'foo'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 4, kind: 'ReturnType', text: '->', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'Literal', text: 'f64'}]},
// CHECK:STDOUT: {node_index: 9, kind: 'CodeBlock', text: '{', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'ReturnStatement', text: 'return', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Literal', text: '42'},
// CHECK:STDOUT: {node_index: 6, kind: 'StatementEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 8, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 11, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn foo() -> f64 {
return 42;
}
+45
View File
@@ -0,0 +1,45 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 25, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 26, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 24, kind: 'CodeBlock', text: '{', subtree_size: 22, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'IfStatement', text: 'if', subtree_size: 20, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 21, kind: 'CodeBlock', text: '{', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 19, kind: 'IfStatement', text: 'if', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'b'},
// CHECK:STDOUT: {node_index: 7, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 18, kind: 'CodeBlock', text: '{', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'IfStatement', text: 'if', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'NameReference', text: 'c'},
// CHECK:STDOUT: {node_index: 10, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 15, kind: 'CodeBlock', text: '{', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'NameReference', text: 'd'}]},
// CHECK:STDOUT: {node_index: 14, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 17, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 20, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 23, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 26, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
if (a) {
if (b) {
if (c) {
d;
}
}
}
}
+85
View File
@@ -0,0 +1,85 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 60, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 61, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 59, kind: 'CodeBlock', text: '{', subtree_size: 57, children: [
// CHECK:STDOUT: {node_index: 26, kind: 'IfStatement', text: 'if', subtree_size: 24, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 20, kind: 'CodeBlock', text: '{', subtree_size: 15, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'IfStatement', text: 'if', subtree_size: 13, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'b'},
// CHECK:STDOUT: {node_index: 7, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 12, kind: 'CodeBlock', text: '{', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'NameReference', text: 'c'}]},
// CHECK:STDOUT: {node_index: 11, kind: 'CodeBlockEnd', text: '}'}]},
// CHECK:STDOUT: {node_index: 13, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 17, kind: 'CodeBlock', text: '{', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'NameReference', text: 'd'}]},
// CHECK:STDOUT: {node_index: 16, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 19, kind: 'CodeBlockEnd', text: '}'}]},
// CHECK:STDOUT: {node_index: 21, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 25, kind: 'CodeBlock', text: '{', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 23, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'NameReference', text: 'e'}]},
// CHECK:STDOUT: {node_index: 24, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 57, kind: 'IfStatement', text: 'if', subtree_size: 31, children: [
// CHECK:STDOUT: {node_index: 29, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 27, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 28, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 36, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 34, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 33, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 30, kind: 'NameReference', text: 'G'},
// CHECK:STDOUT: {node_index: 31, kind: 'Literal', text: '1'},
// CHECK:STDOUT: {node_index: 32, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 35, kind: 'CodeBlockEnd', text: '}'}]},
// CHECK:STDOUT: {node_index: 37, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 56, kind: 'IfStatement', text: 'if', subtree_size: 19, children: [
// CHECK:STDOUT: {node_index: 40, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 38, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 39, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 47, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 45, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 44, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 41, kind: 'NameReference', text: 'G'},
// CHECK:STDOUT: {node_index: 42, kind: 'Literal', text: '2'},
// CHECK:STDOUT: {node_index: 43, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 46, kind: 'CodeBlockEnd', text: '}'}]},
// CHECK:STDOUT: {node_index: 48, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 55, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 53, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 52, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 49, kind: 'NameReference', text: 'G'},
// CHECK:STDOUT: {node_index: 50, kind: 'Literal', text: '3'},
// CHECK:STDOUT: {node_index: 51, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 54, kind: 'CodeBlockEnd', text: '}'}]}]}]},
// CHECK:STDOUT: {node_index: 58, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 61, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
if (a) {
if (b) {
c;
} else {
d;
}
} else {
e;
}
if (x) { G(1); }
else if (x) { G(2); }
else { G(3); }
}
+79
View File
@@ -0,0 +1,79 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 52, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 53, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 51, kind: 'CodeBlock', text: '{', subtree_size: 49, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'IfStatement', text: 'if', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 14, kind: 'IfStatement', text: 'if', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'b'},
// CHECK:STDOUT: {node_index: 7, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'NameReference', text: 'c'}]},
// CHECK:STDOUT: {node_index: 11, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 13, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'NameReference', text: 'd'}]}]},
// CHECK:STDOUT: {node_index: 15, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 17, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'NameReference', text: 'e'}]}]},
// CHECK:STDOUT: {node_index: 49, kind: 'IfStatement', text: 'if', subtree_size: 31, children: [
// CHECK:STDOUT: {node_index: 21, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 19, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 20, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 28, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 26, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 25, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'NameReference', text: 'G'},
// CHECK:STDOUT: {node_index: 23, kind: 'Literal', text: '1'},
// CHECK:STDOUT: {node_index: 24, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 27, kind: 'CodeBlockEnd', text: '}'}]},
// CHECK:STDOUT: {node_index: 29, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 48, kind: 'IfStatement', text: 'if', subtree_size: 19, children: [
// CHECK:STDOUT: {node_index: 32, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 30, kind: 'NameReference', text: 'x'},
// CHECK:STDOUT: {node_index: 31, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 39, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 37, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 36, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 33, kind: 'NameReference', text: 'G'},
// CHECK:STDOUT: {node_index: 34, kind: 'Literal', text: '2'},
// CHECK:STDOUT: {node_index: 35, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 38, kind: 'CodeBlockEnd', text: '}'}]},
// CHECK:STDOUT: {node_index: 40, kind: 'IfStatementElse', text: 'else'},
// CHECK:STDOUT: {node_index: 47, kind: 'CodeBlock', text: '{', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 45, kind: 'ExpressionStatement', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 44, kind: 'CallExpression', text: '(', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 41, kind: 'NameReference', text: 'G'},
// CHECK:STDOUT: {node_index: 42, kind: 'Literal', text: '3'},
// CHECK:STDOUT: {node_index: 43, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 46, kind: 'CodeBlockEnd', text: '}'}]}]}]},
// CHECK:STDOUT: {node_index: 50, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 53, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
if (a)
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/else_unbraced.carbon:[[@LINE+1]]:5: Expected braced code block.
if (b)
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/else_unbraced.carbon:[[@LINE+1]]:7: Expected braced code block.
c;
else
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/else_unbraced.carbon:[[@LINE+1]]:7: Expected braced code block.
d;
else
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/else_unbraced.carbon:[[@LINE+1]]:5: Expected braced code block.
e;
if (x) { G(1); }
else if (x) { G(2); }
else { G(3); }
}
+46
View File
@@ -0,0 +1,46 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 24, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 25, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 23, kind: 'CodeBlock', text: '{', subtree_size: 21, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'IfStatement', text: 'if', has_error: yes, subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 5, kind: 'CodeBlock', text: '{', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 11, kind: 'IfStatement', text: 'if', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'Condition', text: '(', has_error: yes, subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'CodeBlock', text: '{', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 17, kind: 'IfStatement', text: 'if', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'Condition', text: '(', has_error: yes, subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'NameReference', text: 'b'},
// CHECK:STDOUT: {node_index: 13, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 16, kind: 'CodeBlock', text: '{', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 21, kind: 'IfStatement', text: 'if', has_error: yes, subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 20, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'NameReference', text: 'd'},
// CHECK:STDOUT: {node_index: 19, kind: 'ConditionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 22, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 25, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/errors.carbon:[[@LINE+1]]:6: Expected `(` after `if`.
if a {}
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/errors.carbon:[[@LINE+1]]:7: Expected expression.
if () {}
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/errors.carbon:[[@LINE+1]]:9: Unexpected tokens before `)`.
if (b c) {}
if (d)
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/errors.carbon:[[@LINE+2]]:1: Expected braced code block.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/errors.carbon:[[@LINE+1]]:1: Expected expression.
}
+40
View File
@@ -0,0 +1,40 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// TODO: This should have an error.
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 19, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 20, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 18, kind: 'CodeBlock', text: '{', subtree_size: 16, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'IfStatement', text: 'if', subtree_size: 14, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 15, kind: 'IfStatement', text: 'if', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'b'},
// CHECK:STDOUT: {node_index: 7, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 14, kind: 'IfStatement', text: 'if', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'NameReference', text: 'c'},
// CHECK:STDOUT: {node_index: 10, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 13, kind: 'ExpressionStatement', text: ';', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'NameReference', text: 'd'}]}]}]}]},
// CHECK:STDOUT: {node_index: 17, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 20, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
if (a)
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/unbraced.carbon:[[@LINE+1]]:5: Expected braced code block.
if (b)
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/unbraced.carbon:[[@LINE+1]]:7: Expected braced code block.
if (c)
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/if/unbraced.carbon:[[@LINE+1]]:9: Expected braced code block.
d;
}
+1
View File
@@ -0,0 +1 @@
../../../bazel/testing/lit.cfg.py
+25
View File
@@ -0,0 +1,25 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 11, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'CodeBlock', text: '{', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'ExpressionStatement', text: ';', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'InfixOperator', text: 'and', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'InfixOperator', text: 'and', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'NameReference', text: 'b'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'c'}]}]},
// CHECK:STDOUT: {node_index: 9, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
a and b and c;
}
+84
View File
@@ -0,0 +1,84 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 64, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 65, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 10, kind: 'ParameterList', text: '(', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'PatternBinding', text: ':', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'DeclaredName', text: 'p'},
// CHECK:STDOUT: {node_index: 3, kind: 'PostfixOperator', text: '*', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 5, kind: 'ParameterListComma', text: ','},
// CHECK:STDOUT: {node_index: 8, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'DeclaredName', text: 'n'},
// CHECK:STDOUT: {node_index: 7, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 9, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 63, kind: 'CodeBlock', text: '{', subtree_size: 53, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'VariableDeclaration', text: 'var', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'PatternBinding', text: ':', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'DeclaredName', text: 'q'},
// CHECK:STDOUT: {node_index: 13, kind: 'PostfixOperator', text: '*', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 12, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 16, kind: 'VariableInitializer', text: '=', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'NameReference', text: 'p'}]},
// CHECK:STDOUT: {node_index: 17, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 26, kind: 'VariableDeclaration', text: 'var', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 21, kind: 'PatternBinding', text: ':', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 19, kind: 'DeclaredName', text: 't'},
// CHECK:STDOUT: {node_index: 20, kind: 'NameReference', text: 'Type'}]},
// CHECK:STDOUT: {node_index: 24, kind: 'VariableInitializer', text: '=', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 23, kind: 'PostfixOperator', text: '*', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'Literal', text: 'i32'}]}]},
// CHECK:STDOUT: {node_index: 25, kind: 'DeclarationEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 32, kind: 'ExpressionStatement', text: ';', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 31, kind: 'InfixOperator', text: '=', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 27, kind: 'NameReference', text: 't'},
// CHECK:STDOUT: {node_index: 30, kind: 'PostfixOperator', text: '*', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 29, kind: 'PostfixOperator', text: '*', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 28, kind: 'NameReference', text: 't'}]}]}]}]},
// CHECK:STDOUT: {node_index: 38, kind: 'ExpressionStatement', text: ';', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 37, kind: 'InfixOperator', text: '=', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 33, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 36, kind: 'InfixOperator', text: '*', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 34, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 35, kind: 'NameReference', text: 'n'}]}]}]},
// CHECK:STDOUT: {node_index: 45, kind: 'ExpressionStatement', text: ';', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 44, kind: 'InfixOperator', text: '=', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 39, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 43, kind: 'InfixOperator', text: '*', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 40, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 42, kind: 'PrefixOperator', text: '*', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 41, kind: 'NameReference', text: 'p'}]}]}]}]},
// CHECK:STDOUT: {node_index: 51, kind: 'ExpressionStatement', text: ';', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 50, kind: 'InfixOperator', text: '=', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 46, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 49, kind: 'InfixOperator', text: '*', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 47, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 48, kind: 'NameReference', text: 'n'}]}]}]},
// CHECK:STDOUT: {node_index: 61, kind: 'ExpressionStatement', text: ';', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 60, kind: 'CallExpression', text: '(', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 52, kind: 'NameReference', text: 'G'},
// CHECK:STDOUT: {node_index: 54, kind: 'PostfixOperator', text: '*', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 53, kind: 'Literal', text: 'i32'}]},
// CHECK:STDOUT: {node_index: 55, kind: 'CallExpressionComma', text: ','},
// CHECK:STDOUT: {node_index: 58, kind: 'InfixOperator', text: '*', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 56, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 57, kind: 'NameReference', text: 'n'}]},
// CHECK:STDOUT: {node_index: 59, kind: 'CallExpressionEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 62, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 65, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F(p: i32*, n: i32) {
var q: i32* = p;
var t: Type = i32*;
t = t**;
n = n * n;
n = n * *p;
n = n*n;
G(i32*, n * n);
}
@@ -0,0 +1,26 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 11, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'CodeBlock', text: '{', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'ExpressionStatement', text: ';', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'InfixOperator', text: 'or', has_error: yes, subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'InfixOperator', text: 'and', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'NameReference', text: 'b'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'c'}]}]},
// CHECK:STDOUT: {node_index: 9, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/missing_precedence_and_or.carbon:[[@LINE+1]]:11: Parentheses are required to disambiguate operator precedence.
a and b or c;
}
@@ -0,0 +1,31 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 14, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 15, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 13, kind: 'CodeBlock', text: '{', subtree_size: 11, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'ExpressionStatement', text: ';', subtree_size: 9, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'InfixOperator', text: 'and', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'InfixOperator', text: 'and', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'PrefixOperator', text: 'not', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'PrefixOperator', text: 'not', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'NameReference', text: 'b'}]}]},
// CHECK:STDOUT: {node_index: 9, kind: 'PrefixOperator', text: 'not', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'NameReference', text: 'c'}]}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 15, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/missing_precedence_not.carbon:[[@LINE+3]]:3: Whitespace is required before this unary operator.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/missing_precedence_not.carbon:[[@LINE+2]]:13: Whitespace is required before this unary operator.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/missing_precedence_not.carbon:[[@LINE+1]]:23: Whitespace is required before this unary operator.
not a and not b and not c;
}
@@ -0,0 +1,26 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 11, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'CodeBlock', text: '{', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'ExpressionStatement', text: ';', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'InfixOperator', text: 'and', has_error: yes, subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'InfixOperator', text: 'or', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'NameReference', text: 'b'}]},
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'c'}]}]},
// CHECK:STDOUT: {node_index: 9, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/missing_precedence_or_and.carbon:[[@LINE+1]]:10: Parentheses are required to disambiguate operator precedence.
a or b and c;
}
@@ -0,0 +1,23 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 9, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 8, kind: 'CodeBlock', text: '{', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'ExpressionStatement', text: ';', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'PostfixOperator', text: '++', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'PostfixOperator', text: '++', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'n'}]}]}]},
// CHECK:STDOUT: {node_index: 7, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 10, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
n++++;
}
+23
View File
@@ -0,0 +1,23 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 9, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 8, kind: 'CodeBlock', text: '{', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'ExpressionStatement', text: ';', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'PrefixOperator', text: '++', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'PrefixOperator', text: '++', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'n'}]}]}]},
// CHECK:STDOUT: {node_index: 7, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 10, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
++++n;
}
+44
View File
@@ -0,0 +1,44 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{not} %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 26, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 27, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 25, kind: 'CodeBlock', text: '{', subtree_size: 23, children: [
// CHECK:STDOUT: {node_index: 23, kind: 'ExpressionStatement', text: ';', subtree_size: 21, children: [
// CHECK:STDOUT: {node_index: 22, kind: 'InfixOperator', text: '=', subtree_size: 20, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'n'},
// CHECK:STDOUT: {node_index: 21, kind: 'InfixOperator', text: '=', subtree_size: 18, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'InfixOperator', text: '+', subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'InfixOperator', text: '*', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 4, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 5, kind: 'NameReference', text: 'b'}]},
// CHECK:STDOUT: {node_index: 9, kind: 'InfixOperator', text: '*', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 7, kind: 'NameReference', text: 'c'},
// CHECK:STDOUT: {node_index: 8, kind: 'NameReference', text: 'd'}]}]},
// CHECK:STDOUT: {node_index: 20, kind: 'InfixOperator', text: '-', has_error: yes, subtree_size: 10, children: [
// CHECK:STDOUT: {node_index: 17, kind: 'InfixOperator', text: '&', has_error: yes, subtree_size: 7, children: [
// CHECK:STDOUT: {node_index: 15, kind: 'InfixOperator', text: '<<', has_error: yes, subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'InfixOperator', text: '*', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 11, kind: 'NameReference', text: 'd'},
// CHECK:STDOUT: {node_index: 12, kind: 'NameReference', text: 'd'}]},
// CHECK:STDOUT: {node_index: 14, kind: 'NameReference', text: 'e'}]},
// CHECK:STDOUT: {node_index: 16, kind: 'NameReference', text: 'f'}]},
// CHECK:STDOUT: {node_index: 19, kind: 'PrefixOperator', text: 'not', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'NameReference', text: 'g'}]}]}]}]}]},
// CHECK:STDOUT: {node_index: 24, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 27, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/variety.carbon:[[@LINE+4]]:29: Parentheses are required to disambiguate operator precedence.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/variety.carbon:[[@LINE+3]]:34: Parentheses are required to disambiguate operator precedence.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/variety.carbon:[[@LINE+2]]:38: Parentheses are required to disambiguate operator precedence.
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/variety.carbon:[[@LINE+1]]:40: Parentheses are required to disambiguate operator precedence.
n = a * b + c * d = d * d << e & f - not g;
}
+48
View File
@@ -0,0 +1,48 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 27, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 28, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 26, kind: 'CodeBlock', text: '{', subtree_size: 24, children: [
// CHECK:STDOUT: {node_index: 24, kind: 'WhileStatement', text: 'while', subtree_size: 22, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 23, kind: 'CodeBlock', text: '{', subtree_size: 18, children: [
// CHECK:STDOUT: {node_index: 13, kind: 'IfStatement', text: 'if', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'NameReference', text: 'b'},
// CHECK:STDOUT: {node_index: 7, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 12, kind: 'CodeBlock', text: '{', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 10, kind: 'BreakStatement', text: 'break', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 9, kind: 'StatementEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 11, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 21, kind: 'IfStatement', text: 'if', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 16, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 14, kind: 'NameReference', text: 'c'},
// CHECK:STDOUT: {node_index: 15, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 20, kind: 'CodeBlock', text: '{', subtree_size: 4, children: [
// CHECK:STDOUT: {node_index: 18, kind: 'ContinueStatement', text: 'continue', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 17, kind: 'StatementEnd', text: ';'}]},
// CHECK:STDOUT: {node_index: 19, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 22, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 25, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 28, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
while (a) {
if (b) {
break;
}
if (c) {
continue;
}
}
}
+28
View File
@@ -0,0 +1,28 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// TODO: This should have an error.
// RUN: %{carbon} dump parse-tree %s | %{FileCheck-strict} %s
// AUTOUPDATE: %{carbon} dump parse-tree %s
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 11, kind: 'FunctionDeclaration', text: 'fn', subtree_size: 12, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 1, kind: 'ParameterListEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 10, kind: 'CodeBlock', text: '{', subtree_size: 8, children: [
// CHECK:STDOUT: {node_index: 8, kind: 'WhileStatement', text: 'while', subtree_size: 6, children: [
// CHECK:STDOUT: {node_index: 5, kind: 'Condition', text: '(', subtree_size: 3, children: [
// CHECK:STDOUT: {node_index: 3, kind: 'NameReference', text: 'a'},
// CHECK:STDOUT: {node_index: 4, kind: 'ConditionEnd', text: ')'}]},
// CHECK:STDOUT: {node_index: 7, kind: 'BreakStatement', text: 'break', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 6, kind: 'StatementEnd', text: ';'}]}]},
// CHECK:STDOUT: {node_index: 9, kind: 'CodeBlockEnd', text: '}'}]}]},
// CHECK:STDOUT: {node_index: 12, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F() {
while (a)
// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/while/unbraced.carbon:[[@LINE+1]]:5: Expected braced code block.
break;
}