#include #include "AST/ExprNode.h" #include "Sema/ASTVisitor.h" ExprNode::ExprNode(const SharedPtr &type) : type(type) {} LiteralExprNode::LiteralExprNode(const SharedPtr &type) : ExprNode(type) {} BooleanLiteralExprNode::BooleanLiteralExprNode(bool literal) : literal(literal), LiteralExprNode(BasicType::BOOLEAN_TYPE) {} void BooleanLiteralExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } IntegerLiteralExprNode::IntegerLiteralExprNode(long literal) : literal(literal), LiteralExprNode(BasicType::INTEGER_TYPE) {} void IntegerLiteralExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } FloatLiteralExprNode::FloatLiteralExprNode(double literal) : literal(literal), LiteralExprNode(BasicType::FLOAT_TYPE) {} void FloatLiteralExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } StringLiteralExprNode::StringLiteralExprNode() : LiteralExprNode(BasicType::STRING_TYPE) {} StringLiteralExprNode::StringLiteralExprNode(String literal) : literal(std::move(literal)), LiteralExprNode(BasicType::STRING_TYPE) {} void StringLiteralExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } ArrayLiteralExprNode::ArrayLiteralExprNode() : LiteralExprNode(BasicType::UNKNOWN_TYPE) {} ArrayLiteralExprNode::ArrayLiteralExprNode(const SharedPtr &type) : LiteralExprNode(type) {} void ArrayLiteralExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } IdentifierExprNode::IdentifierExprNode(String name) : name(std::move(name)) {} void IdentifierExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } CallExprNode::CallExprNode(String calleeName, const SharedPtrVector &args) : calleeName(std::move(calleeName)), args(args) {} void CallExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } void CallExprNode::bindChildrenInversely() { auto self = shared_from_this(); for (const SharedPtr &arg: args) { arg->parent = self; } } UnaryOperatorExprNode::UnaryOperatorExprNode(unsigned int opCode, const SharedPtr &subExpr) : opCode(opCode), subExpr(subExpr) {} void UnaryOperatorExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } void UnaryOperatorExprNode::bindChildrenInversely() { subExpr->parent = shared_from_this(); } BinaryOperatorExprNode::BinaryOperatorExprNode( unsigned int opCode, const SharedPtr &lhs, const SharedPtr &rhs ) : opCode(opCode), lhs(lhs), rhs(rhs) {} void BinaryOperatorExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } void BinaryOperatorExprNode::bindChildrenInversely() { lhs->parent = rhs->parent = shared_from_this(); } void ArraySubscriptExprNode::accept(const SharedPtr &visitor) { visitor->visit(staticPtrCast(shared_from_this())); } ArraySubscriptExprNode::ArraySubscriptExprNode( const SharedPtr &baseExpr, const SharedPtrVector &indexExprs ) : baseExpr(baseExpr), indexExprs(indexExprs) {}