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:
Geoff Romer
2021-07-12 11:24:30 -07:00
committed by GitHub
parent ffcdaf9aff
commit de05711966
6 changed files with 316 additions and 296 deletions
+15
View File
@@ -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);
+1 -14
View File
@@ -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_