mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Similar to #1272, changed the type of alternative signature from generic Expression to TupleLiteral to match the grammar (#1291)
This commit is contained in:
@@ -300,7 +300,7 @@ message ClassDeclaration {
|
||||
|
||||
message AlternativeSignature {
|
||||
optional string name = 1;
|
||||
optional Expression signature = 2;
|
||||
optional TupleLiteralExpression signature = 3;
|
||||
}
|
||||
|
||||
message ChoiceDeclaration {
|
||||
|
||||
@@ -644,7 +644,7 @@ static auto DeclarationToCarbon(const Fuzzing::Declaration& declaration,
|
||||
for (const auto& alternative : choice.alternatives()) {
|
||||
out << sep;
|
||||
IdentifierToCarbon(alternative.name(), out);
|
||||
ExpressionToCarbon(alternative.signature(), out);
|
||||
TupleLiteralExpressionToCarbon(alternative.signature(), out);
|
||||
}
|
||||
out << "}";
|
||||
break;
|
||||
|
||||
@@ -220,7 +220,7 @@ class ClassDeclaration : public Declaration {
|
||||
class AlternativeSignature : public AstNode {
|
||||
public:
|
||||
AlternativeSignature(SourceLocation source_loc, std::string name,
|
||||
Nonnull<Expression*> signature)
|
||||
Nonnull<TupleLiteral*> signature)
|
||||
: AstNode(AstNodeKind::AlternativeSignature, source_loc),
|
||||
name_(std::move(name)),
|
||||
signature_(signature) {}
|
||||
@@ -233,12 +233,12 @@ class AlternativeSignature : public AstNode {
|
||||
}
|
||||
|
||||
auto name() const -> const std::string& { return name_; }
|
||||
auto signature() const -> const Expression& { return *signature_; }
|
||||
auto signature() -> Expression& { return *signature_; }
|
||||
auto signature() const -> const TupleLiteral& { return *signature_; }
|
||||
auto signature() -> TupleLiteral& { return *signature_; }
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
Nonnull<Expression*> signature_;
|
||||
Nonnull<TupleLiteral*> signature_;
|
||||
};
|
||||
|
||||
class ChoiceDeclaration : public Declaration {
|
||||
|
||||
@@ -516,7 +516,7 @@ static auto DeclarationToProto(const Declaration& declaration)
|
||||
auto* alternative_proto = choice_proto->add_alternatives();
|
||||
alternative_proto->set_name(alternative->name());
|
||||
*alternative_proto->mutable_signature() =
|
||||
ExpressionToProto(alternative->signature());
|
||||
TupleLiteralExpressionToProto(alternative->signature());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,482 @@
|
||||
compilation_unit {
|
||||
package_statement {
|
||||
package_name: "ExplorerTest"
|
||||
}
|
||||
is_api: true
|
||||
declarations {
|
||||
choice {
|
||||
name: "Ints"
|
||||
alternatives {
|
||||
name: "None"
|
||||
signature {
|
||||
}
|
||||
}
|
||||
alternatives {
|
||||
name: "One"
|
||||
signature {
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
alternatives {
|
||||
name: "Two"
|
||||
signature {
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
declarations {
|
||||
function {
|
||||
name: "Main"
|
||||
param_pattern {
|
||||
}
|
||||
return_term {
|
||||
kind: Expression
|
||||
type {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
body {
|
||||
statements {
|
||||
variable_definition {
|
||||
pattern {
|
||||
binding_pattern {
|
||||
name: "x"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
init {
|
||||
call {
|
||||
function {
|
||||
field_access {
|
||||
field: "None"
|
||||
aggregate {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
argument {
|
||||
tuple_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
variable_definition {
|
||||
pattern {
|
||||
binding_pattern {
|
||||
name: "y"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
init {
|
||||
call {
|
||||
function {
|
||||
field_access {
|
||||
field: "One"
|
||||
aggregate {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
argument {
|
||||
tuple_literal {
|
||||
fields {
|
||||
int_literal {
|
||||
value: 42
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
variable_definition {
|
||||
pattern {
|
||||
binding_pattern {
|
||||
name: "n"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
init {
|
||||
int_literal {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
match {
|
||||
expression {
|
||||
identifier {
|
||||
name: "y"
|
||||
}
|
||||
}
|
||||
clauses {
|
||||
pattern {
|
||||
expression_pattern {
|
||||
expression {
|
||||
field_access {
|
||||
field: "None"
|
||||
aggregate {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statement {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
primitive_operator {
|
||||
op: Add
|
||||
arguments {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
arguments {
|
||||
int_literal {
|
||||
value: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clauses {
|
||||
pattern {
|
||||
alternative_pattern {
|
||||
choice_type {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
alternative_name: "One"
|
||||
arguments {
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "x"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statement {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
primitive_operator {
|
||||
op: Sub
|
||||
arguments {
|
||||
primitive_operator {
|
||||
op: Add
|
||||
arguments {
|
||||
identifier {
|
||||
name: "x"
|
||||
}
|
||||
}
|
||||
arguments {
|
||||
int_literal {
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
arguments {
|
||||
int_literal {
|
||||
value: 42
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clauses {
|
||||
pattern {
|
||||
alternative_pattern {
|
||||
choice_type {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
alternative_name: "Two"
|
||||
arguments {
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "a"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "b"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statement {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
int_literal {
|
||||
value: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
match {
|
||||
expression {
|
||||
identifier {
|
||||
name: "x"
|
||||
}
|
||||
}
|
||||
clauses {
|
||||
pattern {
|
||||
alternative_pattern {
|
||||
choice_type {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
alternative_name: "One"
|
||||
arguments {
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "x"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statement {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
primitive_operator {
|
||||
op: Add
|
||||
arguments {
|
||||
identifier {
|
||||
name: "x"
|
||||
}
|
||||
}
|
||||
arguments {
|
||||
int_literal {
|
||||
value: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clauses {
|
||||
pattern {
|
||||
expression_pattern {
|
||||
expression {
|
||||
call {
|
||||
function {
|
||||
field_access {
|
||||
field: "None"
|
||||
aggregate {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
argument {
|
||||
tuple_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statement {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
primitive_operator {
|
||||
op: Sub
|
||||
arguments {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
arguments {
|
||||
int_literal {
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clauses {
|
||||
pattern {
|
||||
alternative_pattern {
|
||||
choice_type {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
alternative_name: "Two"
|
||||
arguments {
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "x"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "y"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statement {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
int_literal {
|
||||
value: 5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
return_statement {
|
||||
expression {
|
||||
identifier {
|
||||
name: "n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
declarations {
|
||||
choice {
|
||||
name: "MoreInts"
|
||||
alternatives {
|
||||
name: "None"
|
||||
signature {
|
||||
}
|
||||
}
|
||||
alternatives {
|
||||
name: "One"
|
||||
signature {
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
alternatives {
|
||||
name: "Two"
|
||||
signature {
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
compilation_unit {
|
||||
package_statement {
|
||||
package_name: "ExplorerTest"
|
||||
}
|
||||
is_api: true
|
||||
declarations {
|
||||
choice {
|
||||
name: "Ints"
|
||||
alternatives {
|
||||
name: "None"
|
||||
signature {
|
||||
}
|
||||
}
|
||||
alternatives {
|
||||
name: "One"
|
||||
signature {
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
alternatives {
|
||||
name: "Two"
|
||||
signature {
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
fields {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
declarations {
|
||||
function {
|
||||
name: "Main"
|
||||
param_pattern {
|
||||
}
|
||||
return_term {
|
||||
kind: Expression
|
||||
type {
|
||||
int_type_literal {
|
||||
}
|
||||
}
|
||||
}
|
||||
body {
|
||||
statements {
|
||||
variable_definition {
|
||||
pattern {
|
||||
tuple_pattern {
|
||||
fields {
|
||||
var_pattern {
|
||||
pattern {
|
||||
alternative_pattern {
|
||||
choice_type {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
alternative_name: "Two"
|
||||
arguments {
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "a1"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
var_pattern {
|
||||
pattern {
|
||||
binding_pattern {
|
||||
name: "a2"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
tuple_pattern {
|
||||
fields {
|
||||
tuple_pattern {
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "b"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
var_pattern {
|
||||
pattern {
|
||||
binding_pattern {
|
||||
name: "c"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
var_pattern {
|
||||
pattern {
|
||||
tuple_pattern {
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "d"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
binding_pattern {
|
||||
name: "e"
|
||||
type {
|
||||
auto_pattern {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
init {
|
||||
tuple_literal {
|
||||
fields {
|
||||
call {
|
||||
function {
|
||||
field_access {
|
||||
field: "Two"
|
||||
aggregate {
|
||||
identifier {
|
||||
name: "Ints"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
argument {
|
||||
tuple_literal {
|
||||
fields {
|
||||
int_literal {
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
fields {
|
||||
int_literal {
|
||||
value: 10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
tuple_literal {
|
||||
fields {
|
||||
tuple_literal {
|
||||
fields {
|
||||
int_literal {
|
||||
value: 2
|
||||
}
|
||||
}
|
||||
fields {
|
||||
int_literal {
|
||||
value: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields {
|
||||
tuple_literal {
|
||||
fields {
|
||||
int_literal {
|
||||
value: 4
|
||||
}
|
||||
}
|
||||
fields {
|
||||
int_literal {
|
||||
value: 5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "a1"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
int_literal {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "a2"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
int_literal {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "c"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
int_literal {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "d"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
int_literal {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
assign {
|
||||
lhs {
|
||||
identifier {
|
||||
name: "e"
|
||||
}
|
||||
}
|
||||
rhs {
|
||||
int_literal {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statements {
|
||||
return_statement {
|
||||
expression {
|
||||
int_literal {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
compilation_unit {
|
||||
declarations {
|
||||
choice {
|
||||
alternatives {
|
||||
signature {
|
||||
fields {
|
||||
primitive_operator {
|
||||
arguments {
|
||||
intrinsic {
|
||||
argument {
|
||||
fields {
|
||||
primitive_operator {
|
||||
arguments {
|
||||
identifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
compilation_unit {
|
||||
declarations {
|
||||
choice {
|
||||
alternatives {
|
||||
signature {
|
||||
primitive_operator {
|
||||
arguments {
|
||||
intrinsic {
|
||||
argument {
|
||||
fields {
|
||||
primitive_operator {
|
||||
arguments {
|
||||
identifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user