From 766a4b8e5236bffb40984439a79186c5ee823ff8 Mon Sep 17 00:00:00 2001 From: ov-4 Date: Fri, 30 Jan 2026 02:06:37 +0000 Subject: Added runtime check for array index and division --- include/cps/AST.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'include/cps/AST.h') diff --git a/include/cps/AST.h b/include/cps/AST.h index aaf81cb..a0c0ace 100644 --- a/include/cps/AST.h +++ b/include/cps/AST.h @@ -27,22 +27,26 @@ public: class ArrayAccessExprAST : public ExprAST { std::string Name; std::vector> Indices; + int Line; public: - ArrayAccessExprAST(const std::string &Name, std::vector> Indices) - : Name(Name), Indices(std::move(Indices)) {} + ArrayAccessExprAST(const std::string &Name, std::vector> Indices, int Line) + : Name(Name), Indices(std::move(Indices)), Line(Line) {} const std::string &getName() const { return Name; } const std::vector> &getIndices() const { return Indices; } + int getLine() const { return Line; } }; class BinaryExprAST : public ExprAST { int Op; std::unique_ptr LHS, RHS; + int Line; public: - BinaryExprAST(int Op, std::unique_ptr LHS, std::unique_ptr RHS) - : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + BinaryExprAST(int Op, std::unique_ptr LHS, std::unique_ptr RHS, int Line) + : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)), Line(Line) {} int getOp() const { return Op; } ExprAST *getLHS() const { return LHS.get(); } ExprAST *getRHS() const { return RHS.get(); } + int getLine() const { return Line; } }; class StmtAST { @@ -86,12 +90,14 @@ class ArrayAssignStmtAST : public StmtAST { std::string Name; std::vector> Indices; std::unique_ptr Expr; + int Line; public: - ArrayAssignStmtAST(const std::string &Name, std::vector> Indices, std::unique_ptr Expr) - : Name(Name), Indices(std::move(Indices)), Expr(std::move(Expr)) {} + ArrayAssignStmtAST(const std::string &Name, std::vector> Indices, std::unique_ptr Expr, int Line) + : Name(Name), Indices(std::move(Indices)), Expr(std::move(Expr)), Line(Line) {} const std::string &getName() const { return Name; } const std::vector> &getIndices() const { return Indices; } ExprAST *getExpr() const { return Expr.get(); } + int getLine() const { return Line; } }; class InputStmtAST : public StmtAST { -- cgit v1.3.1-4-g156e