Use string values instead of string pointers in Expression. (#591)

This commit is contained in:
Geoff Romer
2021-06-24 11:01:13 -07:00
committed by GitHub
parent 9bdabda851
commit 85cfb3b930
4 changed files with 32 additions and 35 deletions
+6 -8
View File
@@ -96,7 +96,7 @@ auto Expression::MakeFunType(int line_num, const Expression* param,
auto Expression::MakeVar(int line_num, std::string var) -> const Expression* {
auto* v = new Expression();
v->line_num = line_num;
v->value = Variable({.name = new std::string(std::move(var))});
v->value = Variable({.name = std::move(var)});
return v;
}
@@ -104,8 +104,7 @@ auto Expression::MakeVarPat(int line_num, std::string var,
const Expression* type) -> const Expression* {
auto* v = new Expression();
v->line_num = line_num;
v->value =
PatternVariable({.name = new std::string(std::move(var)), .type = type});
v->value = PatternVariable({.name = std::move(var), .type = type});
return v;
}
@@ -163,8 +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 = new std::string(std::move(field))});
e->value = FieldAccess({.aggregate = exp, .field = std::move(field)});
return e;
}
@@ -262,7 +260,7 @@ void PrintExp(const Expression* e) {
case ExpressionKind::GetField:
PrintExp(e->GetFieldAccess().aggregate);
std::cout << ".";
std::cout << *e->GetFieldAccess().field;
std::cout << e->GetFieldAccess().field;
break;
case ExpressionKind::Tuple:
std::cout << "(";
@@ -299,12 +297,12 @@ void PrintExp(const Expression* e) {
break;
}
case ExpressionKind::Variable:
std::cout << *e->GetVariable().name;
std::cout << e->GetVariable().name;
break;
case ExpressionKind::PatternVariable:
PrintExp(e->GetPatternVariable().type);
std::cout << ": ";
std::cout << *e->GetPatternVariable().name;
std::cout << e->GetPatternVariable().name;
break;
case ExpressionKind::Call:
PrintExp(e->GetCall().function);