mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Migrate Value to std::variant (#635)
Also: - Switch data members, and associated parameters and return types to be values/references rather than pointers, where applicable. - Move Expression's TagVisitor to anonymous namespace, to avoid name collision. - Switch to trailing return syntax (per style guide).
This commit is contained in:
@@ -8,6 +8,21 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
namespace {
|
||||
|
||||
struct TagVisitor {
|
||||
template <typename Alternative>
|
||||
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<IdentifierExpression>(value);
|
||||
|
||||
@@ -135,7 +135,7 @@ struct TypeTypeLiteral {
|
||||
|
||||
struct Expression {
|
||||
int line_num;
|
||||
inline auto tag() const -> ExpressionKind;
|
||||
auto tag() const -> ExpressionKind;
|
||||
|
||||
static auto MakeIdentifierExpression(int line_num, std::string var)
|
||||
-> const Expression*;
|
||||
@@ -187,19 +187,6 @@ struct Expression {
|
||||
|
||||
void PrintExp(const Expression* exp);
|
||||
|
||||
// Implementation details only beyond this point
|
||||
|
||||
struct TagVisitor {
|
||||
template <typename Alternative>
|
||||
auto operator()(const Alternative&) -> ExpressionKind {
|
||||
return Alternative::Kind;
|
||||
}
|
||||
};
|
||||
|
||||
auto Expression::tag() const -> ExpressionKind {
|
||||
return std::visit(TagVisitor(), value);
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
#endif // EXECUTABLE_SEMANTICS_AST_EXPRESSION_H_
|
||||
|
||||
Reference in New Issue
Block a user