#pragma once #include "CodegenDecl.hpp" #include "CodegenMacros.hpp" #include #include #include #include #include // A generic "thing" (could be anything, comments, string-concated functionsm, etc.) to spit into the output file struct CodegenOutputThing { std::string text; }; class CodegenOutput { private: std::vector mOutThings; std::vector mOutStructs; std::vector mOutEnums; std::vector mOutFunctions; public: std::string optionOutPrefix; // Whether to add prefixes mOutPrefix to all global names or not bool optionAutoAddPrefix : 1 = false; public: void AddOutputThing(CodegenOutputThing thing) { mOutThings.push_back(std::move(thing)); } void 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 Write(FILE* file) { for (auto& thing : mOutThings) { WRITE_LIT(file, "// Output thing\n"); fwrite(thing.text.c_str(), sizeof(char), thing.text.size(), file); WRITE_LIT(file, "\n"); } for (auto& declStruct : mOutStructs) { WRITE_FMT(file, "struct %s {\n", declStruct.name.c_str()); // TODO WRITE_LIT(file, "}\n"); } for (auto& declEnum : mOutEnums) { // TODO } for (auto& declFunc : mOutFunctions) { // TODO } } };