mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 06:50:09 +01:00
Migrate PrimitiveOperator to value semantics (#606)
* Make PrimitiveOperator.arguments a value. * Make operator factory functions take Expressions by value.
This commit is contained in:
@@ -122,30 +122,27 @@ auto Expression::MakeBool(int line_num, bool b) -> const Expression* {
|
||||
}
|
||||
|
||||
auto Expression::MakeOp(int line_num, enum Operator op,
|
||||
std::vector<const Expression*>* args)
|
||||
-> const Expression* {
|
||||
std::vector<Expression> args) -> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->value = PrimitiveOperator({.op = op, .arguments = args});
|
||||
e->value = PrimitiveOperator({.op = op, .arguments = std::move(args)});
|
||||
return e;
|
||||
}
|
||||
|
||||
auto Expression::MakeUnOp(int line_num, enum Operator op, const Expression* arg)
|
||||
auto Expression::MakeUnOp(int line_num, enum Operator op, Expression arg)
|
||||
-> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->value = PrimitiveOperator(
|
||||
{.op = op, .arguments = new std::vector<const Expression*>{arg}});
|
||||
e->value = PrimitiveOperator({.op = op, .arguments = {std::move(arg)}});
|
||||
return e;
|
||||
}
|
||||
|
||||
auto Expression::MakeBinOp(int line_num, enum Operator op,
|
||||
const Expression* arg1, const Expression* arg2)
|
||||
-> const Expression* {
|
||||
auto Expression::MakeBinOp(int line_num, enum Operator op, Expression arg1,
|
||||
Expression arg2) -> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->value = PrimitiveOperator(
|
||||
{.op = op, .arguments = new std::vector<const Expression*>{arg1, arg2}});
|
||||
{.op = op, .arguments = {std::move(arg1), std::move(arg2)}});
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -265,21 +262,21 @@ void PrintExp(const Expression* e) {
|
||||
case ExpressionKind::PrimitiveOp: {
|
||||
std::cout << "(";
|
||||
PrimitiveOperator op = e->GetPrimitiveOperator();
|
||||
if (op.arguments->size() == 0) {
|
||||
if (op.arguments.size() == 0) {
|
||||
PrintOp(op.op);
|
||||
} else if (op.arguments->size() == 1) {
|
||||
} else if (op.arguments.size() == 1) {
|
||||
PrintOp(op.op);
|
||||
std::cout << " ";
|
||||
auto iter = op.arguments->begin();
|
||||
PrintExp(*iter);
|
||||
} else if (op.arguments->size() == 2) {
|
||||
auto iter = op.arguments->begin();
|
||||
PrintExp(*iter);
|
||||
auto iter = op.arguments.begin();
|
||||
PrintExp(&*iter);
|
||||
} else if (op.arguments.size() == 2) {
|
||||
auto iter = op.arguments.begin();
|
||||
PrintExp(&*iter);
|
||||
std::cout << " ";
|
||||
PrintOp(op.op);
|
||||
std::cout << " ";
|
||||
++iter;
|
||||
PrintExp(*iter);
|
||||
PrintExp(&*iter);
|
||||
}
|
||||
std::cout << ")";
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user