mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:34:45 +01:00
Drop support for named tuple fields (#886)
Rationale: Based on the status of #478 and #505, Carbon won't have this feature for a while, and it will be simpler not to support it on spec in the meantime.
This commit is contained in:
@@ -26,25 +26,12 @@ namespace Carbon {
|
||||
// either `Expression` or `Pattern`.
|
||||
template <typename Term>
|
||||
struct ParenContents {
|
||||
struct Element {
|
||||
std::optional<std::string> name;
|
||||
Nonnull<Term*> term;
|
||||
};
|
||||
|
||||
// If this object represents a single term, with no name and no trailing
|
||||
// comma, this method returns that term. This typically means the parentheses
|
||||
// can be interpreted as grouping.
|
||||
// If this object represents a single term with no trailing comma, this
|
||||
// method returns that term. This typically means the parentheses can be
|
||||
// interpreted as grouping.
|
||||
auto SingleTerm() const -> std::optional<Nonnull<Term*>>;
|
||||
|
||||
// Converts `elements` to std::vector<TupleElement>. TupleElement must
|
||||
// have a constructor that takes a std::string and a Nonnull<Term*>.
|
||||
//
|
||||
// TODO: Find a way to deduce TupleElement from Term.
|
||||
template <typename TupleElement>
|
||||
auto TupleElements(SourceLocation source_loc) const
|
||||
-> std::vector<TupleElement>;
|
||||
|
||||
std::vector<Element> elements;
|
||||
std::vector<Nonnull<Term*>> elements;
|
||||
bool has_trailing_comma;
|
||||
};
|
||||
|
||||
@@ -52,37 +39,13 @@ struct ParenContents {
|
||||
|
||||
template <typename Term>
|
||||
auto ParenContents<Term>::SingleTerm() const -> std::optional<Nonnull<Term*>> {
|
||||
if (elements.size() == 1 && !elements.front().name.has_value() &&
|
||||
!has_trailing_comma) {
|
||||
return elements.front().term;
|
||||
if (elements.size() == 1 && !has_trailing_comma) {
|
||||
return elements.front();
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Term>
|
||||
template <typename TupleElement>
|
||||
auto ParenContents<Term>::TupleElements(SourceLocation source_loc) const
|
||||
-> std::vector<TupleElement> {
|
||||
std::vector<TupleElement> result;
|
||||
int i = 0;
|
||||
bool seen_named_member = false;
|
||||
for (auto element : elements) {
|
||||
if (element.name.has_value()) {
|
||||
seen_named_member = true;
|
||||
result.push_back(TupleElement(*element.name, element.term));
|
||||
} else {
|
||||
if (seen_named_member) {
|
||||
FATAL_PROGRAM_ERROR(source_loc)
|
||||
<< "positional members must come before named members";
|
||||
}
|
||||
result.push_back(TupleElement(std::to_string(i), element.term));
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
#endif // EXECUTABLE_SEMANTICS_AST_PAREN_CONTENTS_H_
|
||||
|
||||
Reference in New Issue
Block a user