diff options
Diffstat (limited to 'lib/CodeGen')
| -rw-r--r-- | lib/CodeGen/Designator.cc | 5 | ||||
| -rw-r--r-- | lib/CodeGen/TypeSystem.cc | 8 |
2 files changed, 7 insertions, 6 deletions
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<std::unique_ptr<StmtAST>> &Statem } else if (auto *P = dynamic_cast<PointerTypeDeclAST*>(S.get())) { Ok = Types->definePointer(P->getName(), P->getPointeeTypeName(), Err); } else if (auto *R = dynamic_cast<RecordTypeDeclAST*>(S.get())) { - std::vector<std::pair<std::string, std::string>> 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 <utility> @@ -185,7 +186,7 @@ bool TypeSystem::defineEnum(const std::string &Name, } bool TypeSystem::defineRecord(const std::string &Name, - const std::vector<std::pair<std::string, std::string>> &Fields, + const std::vector<RecordFieldDecl> &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<Type*> 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<unsigned>(FieldTypes.size()); + FI.IsPublic = Field.IsPublic; Payload.Fields.emplace_back(FieldName, FI); FieldTypes.push_back(FieldInfo->LLVMType); } |
