Implement IndirectValue (#588)

Also updates `FieldAccess` to use `IndirectValue`, as an example.
This commit is contained in:
Geoff Romer
2021-06-24 11:26:28 -07:00
committed by GitHub
parent 85cfb3b930
commit 6ca6822157
8 changed files with 265 additions and 7 deletions
+1
View File
@@ -25,6 +25,7 @@ cc_library(
name = "expression",
srcs = ["expression.cpp"],
hdrs = ["expression.h"],
deps = ["//common:indirect_value"],
)
cc_library(
+2 -2
View File
@@ -162,7 +162,7 @@ auto Expression::MakeGetField(int line_num, const Expression* exp,
std::string field) -> const Expression* {
auto* e = new Expression();
e->line_num = line_num;
e->value = FieldAccess({.aggregate = exp, .field = std::move(field)});
e->value = FieldAccess({.aggregate = *exp, .field = std::move(field)});
return e;
}
@@ -258,7 +258,7 @@ void PrintExp(const Expression* e) {
std::cout << "]";
break;
case ExpressionKind::GetField:
PrintExp(e->GetFieldAccess().aggregate);
PrintExp(e->GetFieldAccess().aggregate.GetPointer());
std::cout << ".";
std::cout << e->GetFieldAccess().field;
break;
+3 -1
View File
@@ -9,6 +9,8 @@
#include <variant>
#include <vector>
#include "common/indirect_value.h"
namespace Carbon {
struct Expression;
@@ -62,7 +64,7 @@ struct Variable {
struct FieldAccess {
static constexpr ExpressionKind Kind = ExpressionKind::GetField;
const Expression* aggregate;
IndirectValue<Expression> aggregate;
std::string field;
};