mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Implement IndirectValue (#588)
Also updates `FieldAccess` to use `IndirectValue`, as an example.
This commit is contained in:
@@ -25,6 +25,7 @@ cc_library(
|
||||
name = "expression",
|
||||
srcs = ["expression.cpp"],
|
||||
hdrs = ["expression.h"],
|
||||
deps = ["//common:indirect_value"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user