aboutsummaryrefslogtreecommitdiff
path: root/include/cps
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-14 03:31:47 +0000
committer_ov4 <ov4@ov4.org>2026-10-14 03:31:47 +0000
commit2147449f4d6f37b4624990ff26bce58ebf3cfb4b (patch)
treebbf09cea539b8ea01ee3d392ec828067552fa4b7 /include/cps
parent699e18b65b07af73ccd14b28f83572b1843c7d37 (diff)
feat(parser): add explicit parenthesized type casts
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'include/cps')
-rw-r--r--include/cps/CodeGen.h4
-rw-r--r--include/cps/Parser.h5
-rw-r--r--include/cps/TypeAST.h10
3 files changed, 19 insertions, 0 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index acd6cb2..5043417 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -20,6 +20,7 @@ namespace cps {
class ArrayHandler;
class FileHandler;
class ExceptionHandler;
+class CastExprAST;
class CodeGen {
std::unique_ptr<llvm::LLVMContext> TheContext;
@@ -66,6 +67,9 @@ class CodeGen {
bool isWholeArrayVar(ExprAST *Expr) const;
const TypeInfo *getExprTypeInfo(ExprAST *Expr) const;
llvm::Value *coerceValueToType(llvm::Value *Val, const TypeInfo *TargetInfo);
+ llvm::Value *convertNumericValue(llvm::Value *Val, const TypeInfo *Source,
+ const TypeInfo *Target);
+ llvm::Value *emitCast(CastExprAST *Cast);
// TYPE-system helpers (Designator.cc).
void runTypePrePass(const std::vector<std::unique_ptr<StmtAST>> &Statements);
diff --git a/include/cps/Parser.h b/include/cps/Parser.h
index 49a9791..5713587 100644
--- a/include/cps/Parser.h
+++ b/include/cps/Parser.h
@@ -10,6 +10,7 @@
#include <map>
#include <optional>
#include <string>
+#include <set>
namespace cps {
@@ -20,6 +21,10 @@ class Parser {
unsigned BlockDepth = 0; // ParseBlock nesting; 1 = top level
std::map<int, int> BinopPrecedence;
+ std::set<std::string> TypeNames = {
+ "INTEGER", "REAL", "BOOLEAN", "STRING", "CHAR", "VOID",
+ "C_INT", "C_CHAR", "C_STRING", "C_DOUBLE"
+ };
int getNextToken();
int GetTokPrecedence();
diff --git a/include/cps/TypeAST.h b/include/cps/TypeAST.h
index 95c1d6d..873ca4a 100644
--- a/include/cps/TypeAST.h
+++ b/include/cps/TypeAST.h
@@ -8,6 +8,16 @@
namespace cps {
+class CastExprAST : public ExprAST {
+ std::string TypeName;
+ std::unique_ptr<ExprAST> Operand;
+public:
+ CastExprAST(std::string TypeName, std::unique_ptr<ExprAST> Operand)
+ : TypeName(std::move(TypeName)), Operand(std::move(Operand)) {}
+ const std::string &getTypeName() const { return TypeName; }
+ ExprAST *getOperand() const { return Operand.get(); }
+};
+
// TYPE <name> = C_TYPE("<C type expression>")
class CTypeDeclAST : public StmtAST {
std::string Name;