From 62b605c6c0ea13e9763c0a0115464007b13a8831 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 20 Oct 2026 11:57:16 +0000 Subject: refactor(strings): replace compiler builtins with the STRING library Construct literals as STRING values and route string operations through ordinary library functions and operators. Preserve value ownership in records, arrays, constants and file I/O. Co-Authored-By: Claude Opus 5.5 --- include/cps/CodeGen.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'include/cps/CodeGen.h') diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 30f4135..e6281c5 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -11,8 +11,6 @@ #include "cps/TypeSystem.h" #include "cps/ArithmeticHandler.h" -#include "cps/StringHandler.h" -#include "cps/StringConversionHandler.h" #include #include @@ -93,6 +91,12 @@ class CodeGen { bool prepareSymbolDeclaration(const std::string &Name, bool IsConstant = false); bool requireWritable(const SymbolInfo &Info, const std::string &Name); void emitConstantStmt(ConstantStmtAST *Stmt); + std::map StringConstants; + const TypeInfo *requireStringType(); + llvm::Value *emitStringFromCString(llvm::Value *Text); + llvm::Value *emitStringCString(llvm::Value *Value); + llvm::Value *emitCStringExpr(ExprAST *Expr); + bool containsString(const TypeInfo *Type) const; std::unique_ptr Types; std::unique_ptr Arrays; @@ -101,14 +105,11 @@ class CodeGen { std::unique_ptr FuncGen; std::unique_ptr ArithHandler; - std::unique_ptr StrHandler; - std::unique_ptr StrConvHandler; std::unique_ptr Files; std::unique_ptr Memory; llvm::FunctionCallee PrintfFunc; llvm::FunctionCallee ScanfFunc; - llvm::FunctionCallee MallocFunc; llvm::Value *PrintfFormatStr; // %lld\n llvm::Value *PrintfFloatFormatStr; // %f\n @@ -117,7 +118,6 @@ class CodeGen { llvm::Value *ScanfFormatStr; // %lld llvm::Value *ScanfFloatFormatStr; // %lf - llvm::Value *ScanfStringFormatStr; // %s llvm::Value *TrueStr; // "TRUE" llvm::Value *FalseStr; // "FALSE" @@ -157,7 +157,7 @@ class CodeGen { // Resolves a variable / array element / field chain / deref to an address // (emitting index and null-pointer checks along the way). bool emitLValue(ExprAST *E, LValueInfo &Out); - // The rvalue read: load + the STRING null->"" guard. + // Read a value from resolved storage. llvm::Value *loadFromLValue(const LValueInfo &LV); llvm::Value *emitAllocationSize(ExprAST *Expr); llvm::Value *emitCall(const std::string &Callee, @@ -209,7 +209,7 @@ public: llvm::Value *emitExpr(ExprAST *Expr); void emitStmt(StmtAST *Stmt); - // STRING slots zero-init to null; normalize null to "" at load/print sites. + // Normalize a raw C string pointer to "" when explicitly casting it to STRING. llvm::Value *emitStringNullGuard(llvm::Value *StrVal); // Name-level admission gate for Enum/Record/Pointer plus the existing -- cgit v1.3.1-4-g156e