diff --git a/executable_semantics/ast/expression.cpp b/executable_semantics/ast/expression.cpp index 32748860246c..43f727bdf2da 100644 --- a/executable_semantics/ast/expression.cpp +++ b/executable_semantics/ast/expression.cpp @@ -8,21 +8,6 @@ namespace Carbon { -namespace { - -struct TagVisitor { - template - auto operator()(const Alternative&) -> ExpressionKind { - return Alternative::Kind; - } -}; - -} // namespace - -auto Expression::tag() const -> ExpressionKind { - return std::visit(TagVisitor(), value); -} - auto Expression::GetIdentifierExpression() const -> const IdentifierExpression& { return std::get(value); diff --git a/executable_semantics/ast/expression.h b/executable_semantics/ast/expression.h index 2a703b3640bc..aad8e406cdaa 100644 --- a/executable_semantics/ast/expression.h +++ b/executable_semantics/ast/expression.h @@ -134,9 +134,6 @@ struct TypeTypeLiteral { }; struct Expression { - int line_num; - auto tag() const -> ExpressionKind; - static auto MakeIdentifierExpression(int line_num, std::string var) -> const Expression*; static auto MakeBindingExpression(int line_num, std::string var, @@ -176,6 +173,12 @@ struct Expression { auto GetCallExpression() const -> const CallExpression&; auto GetFunctionTypeLiteral() const -> const FunctionTypeLiteral&; + inline auto tag() const -> ExpressionKind { + return std::visit([](const auto& t) { return t.Kind; }, value); + } + + int line_num; + private: std::variant - auto operator()(const Alternative&) -> ActionKind { - return Alternative::Kind; - } -}; - -} // namespace - -auto Action::tag() const -> ActionKind { - return std::visit(TagVisitor(), value); -} - auto Action::MakeLValAction(const Expression* e) -> Action* { auto* act = new Action(); act->value = LValAction({.exp = e}); diff --git a/executable_semantics/interpreter/action.h b/executable_semantics/interpreter/action.h index 62f79379e956..6d18d8513a03 100644 --- a/executable_semantics/interpreter/action.h +++ b/executable_semantics/interpreter/action.h @@ -43,8 +43,6 @@ struct ValAction { }; struct Action { - auto tag() const -> ActionKind; - static auto MakeLValAction(const Expression* e) -> Action*; static auto MakeExpressionAction(const Expression* e) -> Action*; static auto MakeStatementAction(const Statement* s) -> Action*; @@ -59,6 +57,10 @@ struct Action { void Print(std::ostream& out); + inline auto tag() const -> ActionKind { + return std::visit([](const auto& t) { return t.Kind; }, value); + } + // The position or state of the action. Starts at 0 and goes up to the number // of subexpressions. // diff --git a/executable_semantics/interpreter/value.cpp b/executable_semantics/interpreter/value.cpp index 528d04771c1e..a5f01c09f7bf 100644 --- a/executable_semantics/interpreter/value.cpp +++ b/executable_semantics/interpreter/value.cpp @@ -12,19 +12,6 @@ namespace Carbon { -namespace { - -struct TagVisitor { - template - auto operator()(const Alternative&) -> ValKind { - return Alternative::Kind; - } -}; - -} // namespace - -auto Value::tag() const -> ValKind { return std::visit(TagVisitor(), value); } - auto Value::GetIntValue() const -> int { return std::get(value).value; } diff --git a/executable_semantics/interpreter/value.h b/executable_semantics/interpreter/value.h index 6caf48497fd3..82c03d0e6368 100644 --- a/executable_semantics/interpreter/value.h +++ b/executable_semantics/interpreter/value.h @@ -163,8 +163,6 @@ struct ContinuationValue { }; struct Value { - auto tag() const -> ValKind; - // Constructors // Return a first-class continuation represented by the @@ -216,6 +214,10 @@ struct Value { auto GetChoiceType() const -> const ChoiceType&; auto GetContinuationValue() const -> const ContinuationValue&; + inline auto tag() const -> ValKind { + return std::visit([](const auto& t) { return t.Kind; }, value); + } + private: std::variant