From 9edb2459fd9d2bc7c8869d21ddc8ff20aeb55c39 Mon Sep 17 00:00:00 2001 From: Jon Meow <46229924+jonmeow@users.noreply.github.com> Date: Mon, 20 Sep 2021 13:51:20 -0700 Subject: [PATCH] Remove BisonWrap, which was a Ptr-specific feature (#836) --- executable_semantics/syntax/BUILD | 7 --- executable_semantics/syntax/bison_wrap.h | 44 ----------------- executable_semantics/syntax/parser.ypp | 60 ++++++++++++------------ 3 files changed, 29 insertions(+), 82 deletions(-) delete mode 100644 executable_semantics/syntax/bison_wrap.h diff --git a/executable_semantics/syntax/BUILD b/executable_semantics/syntax/BUILD index adb7a63af58d..ccfb4db827ed 100644 --- a/executable_semantics/syntax/BUILD +++ b/executable_semantics/syntax/BUILD @@ -6,12 +6,6 @@ load("@mypy_integration//:mypy.bzl", "mypy_test") package(default_visibility = ["//executable_semantics:__pkg__"]) -cc_library( - name = "bison_wrap", - hdrs = ["bison_wrap.h"], - deps = ["//common:check"], -) - cc_library( name = "syntax", srcs = [ @@ -33,7 +27,6 @@ cc_library( "-Wno-writable-strings", ], deps = [ - ":bison_wrap", "//common:check", "//common:ostream", "//common:string_helpers", diff --git a/executable_semantics/syntax/bison_wrap.h b/executable_semantics/syntax/bison_wrap.h deleted file mode 100644 index c6917470b775..000000000000 --- a/executable_semantics/syntax/bison_wrap.h +++ /dev/null @@ -1,44 +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_SYNTAX_BISON_WRAP_H_ -#define EXECUTABLE_SEMANTICS_SYNTAX_BISON_WRAP_H_ - -#include - -#include "common/check.h" - -namespace Carbon { - -// Bison requires that types be default initializable for use with its variant -// semantics. This wraps arbitrary types to support a default constructor, while -// still requiring they be properly initialized. -template -class BisonWrap { - public: - // Assigning a value initializes the wrapper. - BisonWrap& operator=(T&& rhs) { - val = std::move(rhs); - return *this; - } - - // Support transparent conversion to the wrapped type. - operator T() { return Release(); } - - // Deliberately releases the contained value. Errors if not initialized. - // Called directly in parser.ypp when releasing pairs. - auto Release() -> T { - CHECK(val.has_value()); - T ret = std::move(*val); - val.reset(); - return ret; - } - - private: - std::optional val; -}; - -} // namespace Carbon - -#endif // EXECUTABLE_SEMANTICS_SYNTAX_BISON_WRAP_H_ diff --git a/executable_semantics/syntax/parser.ypp b/executable_semantics/syntax/parser.ypp index bce5c9de1b51..4f88da2a8019 100644 --- a/executable_semantics/syntax/parser.ypp +++ b/executable_semantics/syntax/parser.ypp @@ -73,7 +73,6 @@ #include "executable_semantics/ast/pattern.h" #include "executable_semantics/common/arena.h" #include "executable_semantics/common/ptr.h" - #include "executable_semantics/syntax/bison_wrap.h" namespace Carbon { class ParseAndLexContext; @@ -98,42 +97,42 @@ %type > import_directives %type optional_library_path %type api_or_impl -%type >> declaration -%type >> function_declaration -%type >> function_definition +%type > declaration +%type > function_declaration +%type > function_definition %type >> declaration_list -%type >> statement -%type >> if_statement +%type > statement +%type > if_statement %type >> optional_else -%type , bool>>> return_expression -%type >> block +%type , bool>> return_expression +%type > block %type >> statement_list -%type >> expression -%type > generic_binding +%type > expression +%type generic_binding %type > deduced_params %type > deduced_param_list -%type >> pattern -%type >> non_expression_pattern -%type , bool>>> return_type -%type >> paren_expression -%type >> tuple +%type > pattern +%type > non_expression_pattern +%type , bool>> return_type +%type > paren_expression +%type > tuple %type > binding_lhs -%type >> variable_declaration -%type >> member +%type > variable_declaration +%type > member %type >> member_list -%type ::Element>> paren_expression_element +%type ::Element> paren_expression_element %type > paren_expression_base %type > paren_expression_contents -%type >> paren_pattern -%type >> tuple_pattern -%type >> maybe_empty_tuple_pattern +%type > paren_pattern +%type > tuple_pattern +%type > maybe_empty_tuple_pattern %type > paren_pattern_base -%type ::Element>> paren_pattern_element +%type ::Element> paren_pattern_element %type > paren_pattern_contents -%type >>> alternative +%type >> alternative %type >>> alternative_list %type >>> alternative_list_contents -%type , Nonnull>>> clause +%type , Nonnull>> clause %type , Nonnull>>> clause_list %token @@ -375,7 +374,7 @@ expression: } | FNTY tuple return_type { - auto [return_exp, is_omitted_exp] = $3.Release(); + auto [return_exp, is_omitted_exp] = $3; $$ = arena->New(context.SourceLoc(), $2, return_exp, is_omitted_exp); } @@ -469,9 +468,8 @@ paren_pattern_contents: | paren_pattern_contents COMMA paren_expression_element { $$ = $1; - auto el = $3.Release(); - $$.elements.push_back({.name = el.name, - .term = arena->New(el.term)}); + $$.elements.push_back({.name = $3.name, + .term = arena->New($3.term)}); } | paren_pattern_contents COMMA paren_pattern_element { @@ -541,7 +539,7 @@ statement: { $$ = arena->New(context.SourceLoc()); } | RETURN return_expression SEMICOLON { - auto [return_exp, is_omitted_exp] = $2.Release(); + auto [return_exp, is_omitted_exp] = $2; $$ = arena->New(context.SourceLoc(), return_exp, is_omitted_exp); } | block @@ -617,7 +615,7 @@ deduced_params: function_definition: FN identifier deduced_params maybe_empty_tuple_pattern return_type block { - auto [return_exp, is_omitted_exp] = $5.Release(); + auto [return_exp, is_omitted_exp] = $5; $$ = arena->New( context.SourceLoc(), $2, $3, $4, arena->New(return_exp), is_omitted_exp, $6); @@ -636,7 +634,7 @@ function_definition: function_declaration: FN identifier deduced_params maybe_empty_tuple_pattern return_type SEMICOLON { - auto [return_exp, is_omitted_exp] = $5.Release(); + auto [return_exp, is_omitted_exp] = $5; $$ = arena->New( context.SourceLoc(), $2, $3, $4, arena->New(return_exp), is_omitted_exp,