mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Use a lambda for tag's visit (#645)
Also shifts declaration order a little for [style](https://google.github.io/styleguide/cppguide.html#Declaration_Order); moving line_num down (data members after methods) and tag() down (factory functions before instance members).
This commit is contained in:
@@ -17,21 +17,6 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
namespace {
|
||||
|
||||
struct TagVisitor {
|
||||
template <typename Alternative>
|
||||
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});
|
||||
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
@@ -12,19 +12,6 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
namespace {
|
||||
|
||||
struct TagVisitor {
|
||||
template <typename Alternative>
|
||||
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<IntValue>(value).value;
|
||||
}
|
||||
|
||||
@@ -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<IntValue, FunctionValue, PointerValue, BoolValue, StructValue,
|
||||
AlternativeValue, TupleValue, IntType, BoolType, TypeType,
|
||||
|
||||
Reference in New Issue
Block a user