forked from Mirrors/openclonk
Aul: Split assignment op from standard BinOp
Assignment was special-cased everywhere, so it can just as well get a separate AST node.directional-lights
parent
daf3424e63
commit
43c6f946dd
|
@ -37,6 +37,7 @@ namespace aul { namespace ast {
|
||||||
class VarExpr;
|
class VarExpr;
|
||||||
class UnOpExpr;
|
class UnOpExpr;
|
||||||
class BinOpExpr;
|
class BinOpExpr;
|
||||||
|
class AssignmentExpr;
|
||||||
class SubscriptExpr;
|
class SubscriptExpr;
|
||||||
class SliceExpr;
|
class SliceExpr;
|
||||||
class CallExpr;
|
class CallExpr;
|
||||||
|
@ -75,6 +76,7 @@ public:
|
||||||
virtual void visit(const ::aul::ast::VarExpr *n) {}
|
virtual void visit(const ::aul::ast::VarExpr *n) {}
|
||||||
virtual void visit(const ::aul::ast::UnOpExpr *) {}
|
virtual void visit(const ::aul::ast::UnOpExpr *) {}
|
||||||
virtual void visit(const ::aul::ast::BinOpExpr *) {}
|
virtual void visit(const ::aul::ast::BinOpExpr *) {}
|
||||||
|
virtual void visit(const ::aul::ast::AssignmentExpr *) {}
|
||||||
virtual void visit(const ::aul::ast::SubscriptExpr *) {}
|
virtual void visit(const ::aul::ast::SubscriptExpr *) {}
|
||||||
virtual void visit(const ::aul::ast::SliceExpr *) {}
|
virtual void visit(const ::aul::ast::SliceExpr *) {}
|
||||||
virtual void visit(const ::aul::ast::CallExpr *) {}
|
virtual void visit(const ::aul::ast::CallExpr *) {}
|
||||||
|
@ -224,9 +226,14 @@ public:
|
||||||
BinOpExpr(int op, ExprPtr &&lhs, ExprPtr &&rhs) : op(op), lhs(std::move(lhs)), rhs(std::move(rhs)) {}
|
BinOpExpr(int op, ExprPtr &&lhs, ExprPtr &&rhs) : op(op), lhs(std::move(lhs)), rhs(std::move(rhs)) {}
|
||||||
ExprPtr lhs, rhs;
|
ExprPtr lhs, rhs;
|
||||||
int op; // TODO: Make this a proper operator type
|
int op; // TODO: Make this a proper operator type
|
||||||
|
};
|
||||||
|
|
||||||
// Marker for '='
|
class AssignmentExpr : public Expr
|
||||||
enum { AssignmentOp = -1 };
|
{
|
||||||
|
AST_NODE(AssignmentExpr);
|
||||||
|
public:
|
||||||
|
AssignmentExpr(ExprPtr &&lhs, ExprPtr &&rhs) : lhs(std::move(lhs)), rhs(std::move(rhs)) {}
|
||||||
|
ExprPtr lhs, rhs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SubscriptExpr : public Expr
|
class SubscriptExpr : public Expr
|
||||||
|
@ -456,6 +463,11 @@ public:
|
||||||
n->lhs->accept(this);
|
n->lhs->accept(this);
|
||||||
n->rhs->accept(this);
|
n->rhs->accept(this);
|
||||||
}
|
}
|
||||||
|
virtual void visit(const ::aul::ast::AssignmentExpr *n) override
|
||||||
|
{
|
||||||
|
n->lhs->accept(this);
|
||||||
|
n->rhs->accept(this);
|
||||||
|
}
|
||||||
virtual void visit(const ::aul::ast::SubscriptExpr *n) override
|
virtual void visit(const ::aul::ast::SubscriptExpr *n) override
|
||||||
{
|
{
|
||||||
n->object->accept(this);
|
n->object->accept(this);
|
||||||
|
|
|
@ -228,6 +228,7 @@ public:
|
||||||
virtual void visit(const ::aul::ast::VarExpr *n) override;
|
virtual void visit(const ::aul::ast::VarExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::UnOpExpr *n) override;
|
virtual void visit(const ::aul::ast::UnOpExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::BinOpExpr *n) override;
|
virtual void visit(const ::aul::ast::BinOpExpr *n) override;
|
||||||
|
virtual void visit(const ::aul::ast::AssignmentExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::SubscriptExpr *n) override;
|
virtual void visit(const ::aul::ast::SubscriptExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::SliceExpr *n) override;
|
virtual void visit(const ::aul::ast::SliceExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::CallExpr *n) override;
|
virtual void visit(const ::aul::ast::CallExpr *n) override;
|
||||||
|
@ -315,6 +316,7 @@ public:
|
||||||
virtual void visit(const ::aul::ast::VarExpr *n) override;
|
virtual void visit(const ::aul::ast::VarExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::UnOpExpr *n) override;
|
virtual void visit(const ::aul::ast::UnOpExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::BinOpExpr *n) override;
|
virtual void visit(const ::aul::ast::BinOpExpr *n) override;
|
||||||
|
virtual void visit(const ::aul::ast::AssignmentExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::SubscriptExpr *n) override;
|
virtual void visit(const ::aul::ast::SubscriptExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::SliceExpr *n) override;
|
virtual void visit(const ::aul::ast::SliceExpr *n) override;
|
||||||
virtual void visit(const ::aul::ast::CallExpr *n) override;
|
virtual void visit(const ::aul::ast::CallExpr *n) override;
|
||||||
|
@ -985,14 +987,6 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::BinOpExpr *n)
|
||||||
{
|
{
|
||||||
n->lhs->accept(this);
|
n->lhs->accept(this);
|
||||||
|
|
||||||
if (n->op == ::aul::ast::BinOpExpr::AssignmentOp)
|
|
||||||
{
|
|
||||||
C4AulBCC setter = MakeSetter(n->loc, false);
|
|
||||||
n->rhs->accept(this);
|
|
||||||
AddBCC(n->loc, setter);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &op = C4ScriptOpMap[n->op];
|
const auto &op = C4ScriptOpMap[n->op];
|
||||||
if (op.Code == AB_JUMPAND || op.Code == AB_JUMPOR || op.Code == AB_JUMPNNIL)
|
if (op.Code == AB_JUMPAND || op.Code == AB_JUMPOR || op.Code == AB_JUMPNNIL)
|
||||||
{
|
{
|
||||||
|
@ -1017,6 +1011,14 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::BinOpExpr *n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::AssignmentExpr *n)
|
||||||
|
{
|
||||||
|
n->lhs->accept(this);
|
||||||
|
C4AulBCC setter = MakeSetter(n->loc, false);
|
||||||
|
n->rhs->accept(this);
|
||||||
|
AddBCC(n->loc, setter);
|
||||||
|
}
|
||||||
|
|
||||||
void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::SubscriptExpr *n)
|
void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::SubscriptExpr *n)
|
||||||
{
|
{
|
||||||
n->object->accept(this);
|
n->object->accept(this);
|
||||||
|
@ -1588,9 +1590,6 @@ void C4AulCompiler::ConstexprEvaluator::visit(const ::aul::ast::UnOpExpr *n)
|
||||||
|
|
||||||
void C4AulCompiler::ConstexprEvaluator::visit(const ::aul::ast::BinOpExpr *n)
|
void C4AulCompiler::ConstexprEvaluator::visit(const ::aul::ast::BinOpExpr *n)
|
||||||
{
|
{
|
||||||
if (n->op == ::aul::ast::BinOpExpr::AssignmentOp)
|
|
||||||
nonconst(n);
|
|
||||||
|
|
||||||
assert(n->op > 0);
|
assert(n->op > 0);
|
||||||
const auto &op = C4ScriptOpMap[n->op];
|
const auto &op = C4ScriptOpMap[n->op];
|
||||||
if (op.Changer)
|
if (op.Changer)
|
||||||
|
@ -1662,6 +1661,11 @@ void C4AulCompiler::ConstexprEvaluator::visit(const ::aul::ast::BinOpExpr *n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void C4AulCompiler::ConstexprEvaluator::visit(const ::aul::ast::AssignmentExpr *n)
|
||||||
|
{
|
||||||
|
nonconst(n);
|
||||||
|
}
|
||||||
|
|
||||||
void C4AulCompiler::ConstexprEvaluator::visit(const ::aul::ast::SubscriptExpr *n)
|
void C4AulCompiler::ConstexprEvaluator::visit(const ::aul::ast::SubscriptExpr *n)
|
||||||
{
|
{
|
||||||
n->object->accept(this);
|
n->object->accept(this);
|
||||||
|
|
|
@ -1460,7 +1460,7 @@ std::unique_ptr<::aul::ast::Expr> C4AulParse::Parse_Expression(int iParentPrio)
|
||||||
if (iParentPrio > 1)
|
if (iParentPrio > 1)
|
||||||
return expr;
|
return expr;
|
||||||
Shift();
|
Shift();
|
||||||
expr = ::aul::ast::BinOpExpr::New(NodeStart, ::aul::ast::BinOpExpr::AssignmentOp, std::move(expr), Parse_Expression(1));
|
expr = ::aul::ast::AssignmentExpr::New(NodeStart, std::move(expr), Parse_Expression(1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ATT_OPERATOR:
|
case ATT_OPERATOR:
|
||||||
|
|
Loading…
Reference in New Issue