From e44bdc6a2a0cf624b08046ecc7e5c5d5d9d2d66c Mon Sep 17 00:00:00 2001 From: _ov4 Date: Fri, 16 Oct 2026 13:21:05 +0000 Subject: fix(compiler): correct CIE semantics and diagnostic locations Use standard WHILE headers and default-public class fields, resolve pseudocode identifiers without case sensitivity, and check signed i64 literal boundaries before conversion. Preserve source locations across recursive emission and function diagnostics. Add 22 regression cases and update compiler examples and documentation. Validated all 69 CTest entries with the original Linux Actions seed and verified the release package's embedded, native and IR output paths. --- include/cps/AST.h | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'include/cps/AST.h') diff --git a/include/cps/AST.h b/include/cps/AST.h index 1afc359..5aadc21 100644 --- a/include/cps/AST.h +++ b/include/cps/AST.h @@ -6,8 +6,18 @@ namespace cps { -class ExprAST { +class SourceLocation { + int SourceLine = 0; public: + explicit SourceLocation(int Line = 0) : SourceLine(Line) {} + virtual ~SourceLocation() = default; + int getLine() const { return SourceLine; } + void setLine(int Line) { SourceLine = Line; } +}; + +class ExprAST : public SourceLocation { +public: + using SourceLocation::SourceLocation; virtual ~ExprAST() = default; }; @@ -56,13 +66,11 @@ public: class ArrayAccessExprAST : public ExprAST { std::string Name; std::vector> Indices; - int Line; public: ArrayAccessExprAST(const std::string &Name, std::vector> Indices, int Line) - : Name(Name), Indices(std::move(Indices)), Line(Line) {} + : ExprAST(Line), Name(Name), Indices(std::move(Indices)) {} const std::string &getName() const { return Name; } const std::vector> &getIndices() const { return Indices; } - int getLine() const { return Line; } }; class UnaryExprAST : public ExprAST { @@ -78,18 +86,17 @@ public: 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, int Line) - : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)), Line(Line) {} + : ExprAST(Line), Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} int getOp() const { return Op; } ExprAST *getLHS() const { return LHS.get(); } ExprAST *getRHS() const { return RHS.get(); } - int getLine() const { return Line; } }; -class StmtAST { +class StmtAST : public SourceLocation { public: + using SourceLocation::SourceLocation; virtual ~StmtAST() = default; }; @@ -154,14 +161,12 @@ 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, int Line) - : Name(Name), Indices(std::move(Indices)), Expr(std::move(Expr)), Line(Line) {} + : StmtAST(Line), Name(Name), Indices(std::move(Indices)), Expr(std::move(Expr)) {} 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