mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:31:04 +01:00
Fix type errors in function calls (#308)
* Make `field_list` always a list. * Create separate `paren_expression` and `tuple` nonterminals * Rename expression_or_field_list.* to field_list.* Co-authored-by: Jeremy G. Siek <jsiek@indiana.edu>
This commit is contained in:
committed by
GitHub
co-authored by
Jeremy G. Siek
parent
bf6bb800c4
commit
8b3bb7c5e9
@@ -24,9 +24,9 @@ cc_library(
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "expression_or_field_list",
|
||||
srcs = ["expression_or_field_list.cpp"],
|
||||
hdrs = ["expression_or_field_list.h"],
|
||||
name = "field_list",
|
||||
srcs = ["field_list.cpp"],
|
||||
hdrs = ["field_list.h"],
|
||||
deps = [":expression"],
|
||||
)
|
||||
|
||||
|
||||
@@ -1,49 +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
|
||||
|
||||
#include "executable_semantics/ast/expression_or_field_list.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto MakeExp(Expression* exp) -> ExpOrFieldList* {
|
||||
auto e = new ExpOrFieldList();
|
||||
e->tag = ExpOrFieldListKind::Exp;
|
||||
e->u.exp = exp;
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeFieldList(std::list<std::pair<std::string, Expression*>>* fields)
|
||||
-> ExpOrFieldList* {
|
||||
auto e = new ExpOrFieldList();
|
||||
e->tag = ExpOrFieldListKind::FieldList;
|
||||
e->u.fields = fields;
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeConsField(ExpOrFieldList* e1, ExpOrFieldList* e2) -> ExpOrFieldList* {
|
||||
auto fields = new std::list<std::pair<std::string, Expression*>>();
|
||||
switch (e1->tag) {
|
||||
case ExpOrFieldListKind::Exp:
|
||||
fields->push_back(std::make_pair("", e1->u.exp));
|
||||
break;
|
||||
case ExpOrFieldListKind::FieldList:
|
||||
for (auto& field : *e1->u.fields) {
|
||||
fields->push_back(field);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (e2->tag) {
|
||||
case ExpOrFieldListKind::Exp:
|
||||
fields->push_back(std::make_pair("", e2->u.exp));
|
||||
break;
|
||||
case ExpOrFieldListKind::FieldList:
|
||||
for (auto& field : *e2->u.fields) {
|
||||
fields->push_back(field);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return MakeFieldList(fields);
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
@@ -1,32 +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 EXECUTABLE_SEMANTICS_AST_EXPRESSION_OR_FIELD_LIST_H_
|
||||
#define EXECUTABLE_SEMANTICS_AST_EXPRESSION_OR_FIELD_LIST_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
enum class ExpOrFieldListKind { Exp, FieldList };
|
||||
|
||||
// This is used in the parsing of tuples and parenthesized expressions.
|
||||
struct ExpOrFieldList {
|
||||
ExpOrFieldListKind tag;
|
||||
union {
|
||||
Expression* exp;
|
||||
std::list<std::pair<std::string, Expression*>>* fields;
|
||||
} u;
|
||||
};
|
||||
|
||||
auto MakeExp(Expression* exp) -> ExpOrFieldList*;
|
||||
auto MakeFieldList(std::list<std::pair<std::string, Expression*>>* fields)
|
||||
-> ExpOrFieldList*;
|
||||
auto MakeConsField(ExpOrFieldList* e1, ExpOrFieldList* e2) -> ExpOrFieldList*;
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
#endif // EXECUTABLE_SEMANTICS_AST_EXPRESSION_OR_FIELD_LIST_H_
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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
|
||||
|
||||
#include "executable_semantics/ast/field_list.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto MakeFieldList(std::list<std::pair<std::string, Expression*>>* fields)
|
||||
-> FieldList* {
|
||||
auto e = new FieldList();
|
||||
e->fields = fields;
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeConsField(FieldList* e1, FieldList* e2) -> FieldList* {
|
||||
auto fields = new std::list<std::pair<std::string, Expression*>>();
|
||||
for (auto& field : *e1->fields) {
|
||||
fields->push_back(field);
|
||||
}
|
||||
for (auto& field : *e2->fields) {
|
||||
fields->push_back(field);
|
||||
}
|
||||
auto result = MakeFieldList(fields);
|
||||
result->has_explicit_comma = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
@@ -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
|
||||
|
||||
#ifndef EXECUTABLE_SEMANTICS_AST_FIELD_LIST_H_
|
||||
#define EXECUTABLE_SEMANTICS_AST_FIELD_LIST_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
// This is used in the parsing of tuples and parenthesized expressions.
|
||||
struct FieldList {
|
||||
std::list<std::pair<std::string, Expression*>>* fields;
|
||||
bool has_explicit_comma = false;
|
||||
};
|
||||
|
||||
auto MakeFieldList(std::list<std::pair<std::string, Expression*>>* fields)
|
||||
-> FieldList*;
|
||||
auto MakeConsField(FieldList* e1, FieldList* e2) -> FieldList*;
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
#endif // EXECUTABLE_SEMANTICS_AST_FIELD_LIST_H_
|
||||
Reference in New Issue
Block a user