From f5a2541ed3faf9a942b867e2d54577352153afce Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 13:40:57 +0000 Subject: Refactor record fields to preserve visibility and share parsing Co-Authored-By: Claude Fable 5.1 --- lib/CodeGen/Designator.cc | 5 +---- lib/CodeGen/TypeSystem.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/Designator.cc b/lib/CodeGen/Designator.cc index ad0cc49..640ca0b 100644 --- a/lib/CodeGen/Designator.cc +++ b/lib/CodeGen/Designator.cc @@ -58,10 +58,7 @@ void CodeGen::runTypePrePass(const std::vector> &Statem } else if (auto *P = dynamic_cast(S.get())) { Ok = Types->definePointer(P->getName(), P->getPointeeTypeName(), Err); } else if (auto *R = dynamic_cast(S.get())) { - std::vector> Fields; - for (const RecordFieldDecl &F : R->getFields()) - Fields.emplace_back(F.Name, F.TypeName); - Ok = Types->defineRecord(R->getName(), Fields, Err); + Ok = Types->defineRecord(R->getName(), R->getFields(), Err); } if (!Ok) reportError("%s", Err.c_str()); } diff --git a/lib/CodeGen/TypeSystem.cc b/lib/CodeGen/TypeSystem.cc index c170be8..f693ba1 100644 --- a/lib/CodeGen/TypeSystem.cc +++ b/lib/CodeGen/TypeSystem.cc @@ -1,4 +1,5 @@ #include "cps/TypeSystem.h" +#include "cps/TypeAST.h" #include "llvm/IR/Constants.h" #include @@ -185,7 +186,7 @@ bool TypeSystem::defineEnum(const std::string &Name, } bool TypeSystem::defineRecord(const std::string &Name, - const std::vector> &Fields, + const std::vector &Fields, std::string &Err) { auto It = Types.find(Name); if (It == Types.end() || It->second.Kind != TypeKind::Record) { @@ -195,7 +196,9 @@ bool TypeSystem::defineRecord(const std::string &Name, std::vector FieldTypes; RecordPayload Payload; - for (const auto &[FieldName, FieldTypeName] : Fields) { + for (const RecordFieldDecl &Field : Fields) { + const std::string &FieldName = Field.Name; + const std::string &FieldTypeName = Field.TypeName; if (Payload.findField(FieldName)) { Err = "Duplicate field '" + FieldName + "' in record " + Name; return false; @@ -222,6 +225,7 @@ bool TypeSystem::defineRecord(const std::string &Name, RecordFieldInfo FI; FI.TypeName = FieldInfo->Name; FI.Index = static_cast(FieldTypes.size()); + FI.IsPublic = Field.IsPublic; Payload.Fields.emplace_back(FieldName, FI); FieldTypes.push_back(FieldInfo->LLVMType); } -- cgit v1.3.1-4-g156e