Files
carbon-lang/executable_semantics/syntax/paren_contents.cpp
T
Jeremy G. Siek 8924f5620b Private unions (#492)
* changed union of Statement to be private

* changed the union in Expression to be private

* changed union in Value to be private

* changed AST constructors to be static methods

* updates to syntax unit tests
2021-04-27 14:29:13 -04:00

24 lines
755 B
C++

// 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/syntax/paren_contents.h"
namespace Carbon {
const Expression* ParenContents::AsExpression(int line_number) const {
if (fields_.size() == 1 && fields_.front().name == "" &&
has_trailing_comma_ == HasTrailingComma::No) {
return fields_.front().expression;
} else {
return AsTuple(line_number);
}
}
const Expression* ParenContents::AsTuple(int line_number) const {
return Expression::MakeTuple(line_number,
new std::vector<FieldInitializer>(fields_));
}
} // namespace Carbon