diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-16 13:21:05 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-16 13:21:05 +0000 |
| commit | e44bdc6a2a0cf624b08046ecc7e5c5d5d9d2d66c (patch) | |
| tree | f5276cc0dd2f34e4d30a58f80223912265a1c5a0 /lib/Lexer | |
| parent | e1e789ac0249149a4aa1671f5f9260d488cb617a (diff) | |
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.
Diffstat (limited to 'lib/Lexer')
| -rw-r--r-- | lib/Lexer/Lexer.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Lexer/Lexer.cc b/lib/Lexer/Lexer.cc index 59247cf..9203db1 100644 --- a/lib/Lexer/Lexer.cc +++ b/lib/Lexer/Lexer.cc @@ -1,5 +1,7 @@ #include "cps/Lexer.h" #include <algorithm> +#include <charconv> +#include <limits> #include <cctype> #include <cstdio> #include <cstdlib> @@ -104,7 +106,6 @@ int Lexer::readToken() { if (IdentifierStr == "THROW") return tok_throw; if (IdentifierStr == "WHILE") return tok_while; - if (IdentifierStr == "DO") return tok_do; if (IdentifierStr == "ENDWHILE") return tok_endwhile; if (IdentifierStr == "REPEAT") return tok_repeat; @@ -175,7 +176,13 @@ int Lexer::readToken() { return tok_number_real; } - NumVal = strtoll(NumStr.c_str(), nullptr, 10); + auto Parsed = std::from_chars(NumStr.data(), NumStr.data() + NumStr.size(), NumVal); + if (Parsed.ec != std::errc{} || + NumVal > uint64_t(std::numeric_limits<int64_t>::max()) + 1) { + fprintf(stderr, "error: Integer literal is outside the i64 range at line %d\n", TokenLine); + HadError = true; + NumVal = 0; + } return tok_number_int; } |
