From bd07ae3f4e1bcdedc3e373460671ca9713a03de5 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 2 Jun 2022 21:34:16 -0700 Subject: Changeset: 60 Add struct/class scanning to codegen --- source/20-codegen-compiler/CodegenOutput.cpp | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 source/20-codegen-compiler/CodegenOutput.cpp (limited to 'source/20-codegen-compiler/CodegenOutput.cpp') diff --git a/source/20-codegen-compiler/CodegenOutput.cpp b/source/20-codegen-compiler/CodegenOutput.cpp new file mode 100644 index 0000000..ccd163c --- /dev/null +++ b/source/20-codegen-compiler/CodegenOutput.cpp @@ -0,0 +1,46 @@ +#include "CodegenOutput.hpp" + +#include "CodegenUtils.hpp" + +void CodegenOutput::AddRequestInclude(std::string_view include) { + if (!mRequestIncludes.contains(include)) { + mRequestIncludes.insert(std::string(include)); + } +} + +void CodegenOutput::AddOutputThing(CodegenOutputThing thing) { + mOutThings.push_back(std::move(thing)); +} + +void CodegenOutput::MergeContents(CodegenOutput other) { + std::move(other.mOutThings.begin(), other.mOutThings.end(), std::back_inserter(this->mOutThings)); + std::move(other.mOutStructs.begin(), other.mOutStructs.end(), std::back_inserter(this->mOutStructs)); + std::move(other.mOutEnums.begin(), other.mOutEnums.end(), std::back_inserter(this->mOutEnums)); + std::move(other.mOutFunctions.begin(), other.mOutFunctions.end(), std::back_inserter(this->mOutFunctions)); +} + +void CodegenOutput::Write(FILE* file) const { + for (auto& include : mRequestIncludes) { + // TODO how to resolve to the correct include paths? + WRITE_FMT_LN(file, "#include <%s>", include.c_str()); + } + + for (auto& thing : mOutThings) { + fwrite(thing.text.c_str(), sizeof(char), thing.text.size(), file); + WRITE_LIT(file, "\n"); + } + + for (auto& declStruct : mOutStructs) { + WRITE_FMT_LN(file, "struct %s {", declStruct.name.c_str()); + // TODO + WRITE_LIT_LN(file, "};"); + } + + for (auto& declEnum : mOutEnums) { + // TODO + } + + for (auto& declFunc : mOutFunctions) { + // TODO + } +} -- cgit v1.2.3-70-g09d2