paren_contents.cpp 713 B

12345678910111213141516171819202122
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "executable_semantics/syntax/paren_contents.h"
  5. namespace Carbon {
  6. const Expression* ParenContents::AsExpression(int line_number) const {
  7. if (fields_.size() == 1 && fields_.front().name == "" &&
  8. has_trailing_comma_ == HasTrailingComma::No) {
  9. return new Expression(*fields_.front().expression);
  10. } else {
  11. return AsTuple(line_number);
  12. }
  13. }
  14. const Expression* ParenContents::AsTuple(int line_number) const {
  15. return Expression::MakeTupleLiteral(line_number, fields_);
  16. }
  17. } // namespace Carbon