mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Revert to handling Expression by const pointer (#616)
This reverts the bulk of #606, #607, and #611, as well as parts of #588, #605, and #614.
This commit is contained in:
@@ -33,7 +33,7 @@ TEST(ParenContentsTest, UnaryNoCommaAsExpression) {
|
||||
// )
|
||||
// ```
|
||||
ParenContents contents(
|
||||
{{.expression = *Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
{{.expression = Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
ParenContents::HasTrailingComma::No);
|
||||
|
||||
const Expression* expression = contents.AsExpression(/*line_num=*/1);
|
||||
@@ -43,7 +43,7 @@ TEST(ParenContentsTest, UnaryNoCommaAsExpression) {
|
||||
|
||||
TEST(ParenContentsTest, UnaryNoCommaAsTuple) {
|
||||
ParenContents contents(
|
||||
{{.expression = *Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
{{.expression = Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
ParenContents::HasTrailingComma::No);
|
||||
|
||||
const Expression* tuple = contents.AsTuple(/*line_num=*/1);
|
||||
@@ -56,7 +56,7 @@ TEST(ParenContentsTest, UnaryNoCommaAsTuple) {
|
||||
|
||||
TEST(ParenContentsTest, UnaryWithCommaAsExpression) {
|
||||
ParenContents contents(
|
||||
{{.expression = *Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
{{.expression = Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
ParenContents::HasTrailingComma::Yes);
|
||||
|
||||
const Expression* expression = contents.AsExpression(/*line_num=*/1);
|
||||
@@ -69,7 +69,7 @@ TEST(ParenContentsTest, UnaryWithCommaAsExpression) {
|
||||
|
||||
TEST(ParenContentsTest, UnaryWithCommaAsTuple) {
|
||||
ParenContents contents(
|
||||
{{.expression = *Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
{{.expression = Expression::MakeInt(/*line_num=*/2, 42)}},
|
||||
ParenContents::HasTrailingComma::Yes);
|
||||
|
||||
const Expression* tuple = contents.AsTuple(/*line_num=*/1);
|
||||
@@ -82,8 +82,8 @@ TEST(ParenContentsTest, UnaryWithCommaAsTuple) {
|
||||
|
||||
TEST(ParenContentsTest, BinaryAsExpression) {
|
||||
ParenContents contents(
|
||||
{{.expression = *Expression::MakeInt(/*line_num=*/2, 42)},
|
||||
{.expression = *Expression::MakeInt(/*line_num=*/3, 42)}},
|
||||
{{.expression = Expression::MakeInt(/*line_num=*/2, 42)},
|
||||
{.expression = Expression::MakeInt(/*line_num=*/3, 42)}},
|
||||
ParenContents::HasTrailingComma::Yes);
|
||||
|
||||
const Expression* expression = contents.AsExpression(/*line_num=*/1);
|
||||
@@ -97,8 +97,8 @@ TEST(ParenContentsTest, BinaryAsExpression) {
|
||||
|
||||
TEST(ParenContentsTest, BinaryAsTuple) {
|
||||
ParenContents contents(
|
||||
{{.expression = *Expression::MakeInt(/*line_num=*/2, 42)},
|
||||
{.expression = *Expression::MakeInt(/*line_num=*/3, 42)}},
|
||||
{{.expression = Expression::MakeInt(/*line_num=*/2, 42)},
|
||||
{.expression = Expression::MakeInt(/*line_num=*/3, 42)}},
|
||||
ParenContents::HasTrailingComma::Yes);
|
||||
|
||||
const Expression* tuple = contents.AsTuple(/*line_num=*/1);
|
||||
|
||||
@@ -110,8 +110,8 @@ void yy::parser::error(
|
||||
%type <Carbon::FieldInitializer> field_initializer
|
||||
%type <Carbon::ParenContents> paren_contents
|
||||
%type <std::vector<Carbon::FieldInitializer>> paren_contents_without_trailing_comma
|
||||
%type <std::pair<std::string, Carbon::Expression>> alternative
|
||||
%type <std::list<std::pair<std::string, Carbon::Expression>>> alternative_list
|
||||
%type <std::pair<std::string, const Carbon::Expression*>> alternative
|
||||
%type <std::list<std::pair<std::string, const Carbon::Expression*>>> alternative_list
|
||||
%type <std::pair<const Carbon::Expression*, const Carbon::Statement*>*> clause
|
||||
%type <std::list<std::pair<const Carbon::Expression*, const Carbon::Statement*>>*> clause_list
|
||||
%token END_OF_FILE 0
|
||||
@@ -205,9 +205,9 @@ expression:
|
||||
| expression designator
|
||||
{ $$ = Carbon::Expression::MakeGetField(yylineno, $1, $2); }
|
||||
| expression "[" expression "]"
|
||||
{ $$ = Carbon::Expression::MakeIndex(yylineno, *$1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeIndex(yylineno, $1, $3); }
|
||||
| identifier ":" expression
|
||||
{ $$ = Carbon::Expression::MakeVarPat(yylineno, $1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeVarPat(yylineno, $1, $3); }
|
||||
| integer_literal
|
||||
{ $$ = Carbon::Expression::MakeInt(yylineno, $1); }
|
||||
| TRUE
|
||||
@@ -226,33 +226,33 @@ expression:
|
||||
{ $$ = Carbon::Expression::MakeContinuationType(yylineno); }
|
||||
| paren_expression { $$ = $1; }
|
||||
| expression EQUAL_EQUAL expression
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Eq, *$1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Eq, $1, $3); }
|
||||
| expression "+" expression
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Add, *$1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Add, $1, $3); }
|
||||
| expression "-" expression
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Sub, *$1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Sub, $1, $3); }
|
||||
| expression BINARY_STAR expression
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Mul, *$1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Mul, $1, $3); }
|
||||
| expression AND expression
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::And, *$1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::And, $1, $3); }
|
||||
| expression OR expression
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Or, *$1, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeBinOp(yylineno, Carbon::Operator::Or, $1, $3); }
|
||||
| NOT expression
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Not, *$2); }
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Not, $2); }
|
||||
| "-" expression %prec UNARY_MINUS
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Neg, *$2); }
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Neg, $2); }
|
||||
| PREFIX_STAR expression
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Deref, *$2); }
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Deref, $2); }
|
||||
| UNARY_STAR expression %prec PREFIX_STAR
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Deref, *$2); }
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Deref, $2); }
|
||||
| expression tuple
|
||||
{ $$ = Carbon::Expression::MakeCall(yylineno, *$1, *$2); }
|
||||
{ $$ = Carbon::Expression::MakeCall(yylineno, $1, $2); }
|
||||
| expression POSTFIX_STAR
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Ptr, *$1); }
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Ptr, $1); }
|
||||
| expression UNARY_STAR
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Ptr, *$1); }
|
||||
{ $$ = Carbon::Expression::MakeUnOp(yylineno, Carbon::Operator::Ptr, $1); }
|
||||
| FNTY tuple return_type
|
||||
{ $$ = Carbon::Expression::MakeFunType(yylineno, *$2, *$3); }
|
||||
{ $$ = Carbon::Expression::MakeFunType(yylineno, $2, $3); }
|
||||
;
|
||||
designator: "." identifier { $$ = $2; }
|
||||
;
|
||||
@@ -264,9 +264,9 @@ tuple: "(" paren_contents ")"
|
||||
;
|
||||
field_initializer:
|
||||
pattern
|
||||
{ $$ = Carbon::FieldInitializer({"", *$1}); }
|
||||
{ $$ = Carbon::FieldInitializer({"", $1}); }
|
||||
| designator "=" pattern
|
||||
{ $$ = Carbon::FieldInitializer({$1, *$3}); }
|
||||
{ $$ = Carbon::FieldInitializer({$1, $3}); }
|
||||
;
|
||||
paren_contents:
|
||||
// Empty
|
||||
@@ -297,7 +297,7 @@ clause:
|
||||
| DEFAULT DBLARROW statement
|
||||
{
|
||||
auto vp = Carbon::Expression::MakeVarPat(yylineno, "_",
|
||||
*Carbon::Expression::MakeAutoType(yylineno));
|
||||
Carbon::Expression::MakeAutoType(yylineno));
|
||||
$$ = new std::pair<const Carbon::Expression*, const Carbon::Statement*>(vp, $3);
|
||||
}
|
||||
;
|
||||
@@ -311,29 +311,29 @@ clause_list:
|
||||
;
|
||||
statement:
|
||||
expression "=" expression ";"
|
||||
{ $$ = Carbon::Statement::MakeAssign(yylineno, *$1, *$3); }
|
||||
{ $$ = Carbon::Statement::MakeAssign(yylineno, $1, $3); }
|
||||
| VAR pattern "=" expression ";"
|
||||
{ $$ = Carbon::Statement::MakeVarDef(yylineno, *$2, *$4); }
|
||||
{ $$ = Carbon::Statement::MakeVarDef(yylineno, $2, $4); }
|
||||
| expression ";"
|
||||
{ $$ = Carbon::Statement::MakeExpStmt(yylineno, *$1); }
|
||||
{ $$ = Carbon::Statement::MakeExpStmt(yylineno, $1); }
|
||||
| IF "(" expression ")" statement optional_else
|
||||
{ $$ = Carbon::Statement::MakeIf(yylineno, *$3, $5, $6); }
|
||||
{ $$ = Carbon::Statement::MakeIf(yylineno, $3, $5, $6); }
|
||||
| WHILE "(" expression ")" statement
|
||||
{ $$ = Carbon::Statement::MakeWhile(yylineno, *$3, $5); }
|
||||
{ $$ = Carbon::Statement::MakeWhile(yylineno, $3, $5); }
|
||||
| BREAK ";"
|
||||
{ $$ = Carbon::Statement::MakeBreak(yylineno); }
|
||||
| CONTINUE ";"
|
||||
{ $$ = Carbon::Statement::MakeContinue(yylineno); }
|
||||
| RETURN expression ";"
|
||||
{ $$ = Carbon::Statement::MakeReturn(yylineno, *$2); }
|
||||
{ $$ = Carbon::Statement::MakeReturn(yylineno, $2); }
|
||||
| "{" statement_list "}"
|
||||
{ $$ = Carbon::Statement::MakeBlock(yylineno, $2); }
|
||||
| MATCH "(" expression ")" "{" clause_list "}"
|
||||
{ $$ = Carbon::Statement::MakeMatch(yylineno, *$3, $6); }
|
||||
{ $$ = Carbon::Statement::MakeMatch(yylineno, $3, $6); }
|
||||
| CONTINUATION identifier statement
|
||||
{ $$ = Carbon::Statement::MakeContinuation(yylineno, $2, $3); }
|
||||
| RUN expression ";"
|
||||
{ $$ = Carbon::Statement::MakeRun(yylineno, *$2); }
|
||||
{ $$ = Carbon::Statement::MakeRun(yylineno, $2); }
|
||||
| AWAIT ";"
|
||||
{ $$ = Carbon::Statement::MakeAwait(yylineno); }
|
||||
;
|
||||
@@ -356,16 +356,16 @@ return_type:
|
||||
;
|
||||
function_definition:
|
||||
FN identifier tuple return_type "{" statement_list "}"
|
||||
{ $$ = MakeFunDef(yylineno, $2, *$4, *$3, $6); }
|
||||
{ $$ = MakeFunDef(yylineno, $2, $4, $3, $6); }
|
||||
| FN identifier tuple DBLARROW expression ";"
|
||||
{
|
||||
$$ = Carbon::MakeFunDef(yylineno, $2, *Carbon::Expression::MakeAutoType(yylineno), *$3,
|
||||
Carbon::Statement::MakeReturn(yylineno, *$5));
|
||||
$$ = Carbon::MakeFunDef(yylineno, $2, Carbon::Expression::MakeAutoType(yylineno), $3,
|
||||
Carbon::Statement::MakeReturn(yylineno, $5));
|
||||
}
|
||||
;
|
||||
function_declaration:
|
||||
FN identifier tuple return_type ";"
|
||||
{ $$ = MakeFunDef(yylineno, $2, *$4, *$3, 0); }
|
||||
{ $$ = MakeFunDef(yylineno, $2, $4, $3, 0); }
|
||||
;
|
||||
variable_declaration: identifier ":" expression
|
||||
{ $$ = MakeField(yylineno, $1, $3); }
|
||||
@@ -381,19 +381,19 @@ member_list:
|
||||
;
|
||||
alternative:
|
||||
identifier tuple
|
||||
{ $$ = std::pair<std::string, Carbon::Expression>($1, *$2); }
|
||||
{ $$ = std::pair<std::string, const Carbon::Expression*>($1, $2); }
|
||||
| identifier
|
||||
{
|
||||
$$ = std::pair<std::string, Carbon::Expression>(
|
||||
$1, *Carbon::Expression::MakeTuple(yylineno, {}));
|
||||
$$ = std::pair<std::string, const Carbon::Expression*>(
|
||||
$1, Carbon::Expression::MakeTuple(yylineno, {}));
|
||||
}
|
||||
;
|
||||
alternative_list:
|
||||
// Empty
|
||||
{ $$ = std::list<std::pair<std::string, Carbon::Expression>>(); }
|
||||
{ $$ = std::list<std::pair<std::string, const Carbon::Expression*>>(); }
|
||||
| alternative
|
||||
{
|
||||
$$ = std::list<std::pair<std::string, Carbon::Expression>>();
|
||||
$$ = std::list<std::pair<std::string, const Carbon::Expression*>>();
|
||||
$$.push_front($1);
|
||||
}
|
||||
| alternative "," alternative_list
|
||||
|
||||
Reference in New Issue
Block a user