mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Restructure handling of paren expressions (#417)
* Move nontrivial logic out of `parser.ypp` into `FieldList`, rename it to `ParenContents`, make it a class, and add tests * Use a `FieldInitializer` struct instead of `std::pair<std::string, Expression*>` to represent the fields of a tuple
This commit is contained in:
@@ -27,13 +27,6 @@ cc_library(
|
||||
hdrs = ["expression.h"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "field_list",
|
||||
srcs = ["field_list.cpp"],
|
||||
hdrs = ["field_list.h"],
|
||||
deps = [":expression"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "function_definition",
|
||||
srcs = ["function_definition.cpp"],
|
||||
|
||||
@@ -1,29 +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/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
|
||||
@@ -1,26 +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_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