aboutsummaryrefslogtreecommitdiff
path: root/source/20-codegen-compiler/CodegenUtils.inl
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-02 21:34:16 -0700
committerrtk0c <[email protected]>2022-06-02 21:34:16 -0700
commitbd07ae3f4e1bcdedc3e373460671ca9713a03de5 (patch)
tree15c897891474a97983f247196923f8e4f2184083 /source/20-codegen-compiler/CodegenUtils.inl
parent8a0f2cd0b398ee0b7740e44a0e5fb2f75d090ccb (diff)
Changeset: 60 Add struct/class scanning to codegen
Diffstat (limited to 'source/20-codegen-compiler/CodegenUtils.inl')
-rw-r--r--source/20-codegen-compiler/CodegenUtils.inl84
1 files changed, 0 insertions, 84 deletions
diff --git a/source/20-codegen-compiler/CodegenUtils.inl b/source/20-codegen-compiler/CodegenUtils.inl
deleted file mode 100644
index dddfe61..0000000
--- a/source/20-codegen-compiler/CodegenUtils.inl
+++ /dev/null
@@ -1,84 +0,0 @@
-#pragma once
-
-#include "CodegenConfig.hpp"
-#include "CodegenMacros.hpp"
-
-#include "CodegenOutput.inl"
-
-#include <Macros.hpp>
-#include <ScopeGuard.hpp>
-
-#include <cstdio>
-#include <cstdlib>
-#include <filesystem>
-
-namespace Utils {
-
-bool WriteOutputFile(const CodegenOutput& output, const char* path) {
- auto outputFile = Utils::OpenCstdioFile(path, Utils::WriteTruncate);
- if (!outputFile) {
- printf("[ERROR] unable to open output file %s\n", path);
- return false;
- }
- DEFER { fclose(outputFile); };
-
- DEBUG_PRINTF("Writing output %s\n", path);
- output.Write(outputFile);
-
- return true;
-}
-
-std::string MakeFullName(std::string_view name, DeclNamespace* ns = nullptr) {
- size_t length = 0;
- std::vector<std::string_view> components;
- if (!name.empty()) {
- components.push_back(name);
- length += name.length();
- }
-
- DeclNamespace* currentNamespace = ns;
- while (currentNamespace) {
- components.push_back(currentNamespace->name);
- length += currentNamespace->name.size() + /*::*/ 2;
- currentNamespace = currentNamespace->container;
- }
-
- std::string fullname;
- fullname.reserve(length);
- for (auto it = components.rbegin(); it != components.rend(); ++it) {
- fullname += *it;
- fullname += "::";
- }
- // Get rid of the last "::"
- fullname.pop_back();
- fullname.pop_back();
-
- return fullname;
-}
-
-void ProduceGeneratedHeader(const char* headerFilename, CodegenOutput& header, const char* sourceFilename, CodegenOutput& source) {
- CodegenOutputThing headerOut;
- headerOut.text += &R"""(
-// This file is generated. Any changes will be overidden when building.
-#pragma once
-
-#include <MetadataBase.hpp>
-
-#include <cstddef>
-#include <cstdint>
-)"""[1];
-
- CodegenOutputThing sourceOut;
- APPEND_LIT_LN(sourceOut.text, "// This file is generated. Any changes will be overidden when building.");
- APPEND_FMT_LN(sourceOut.text, "#include \"%s\"", headerFilename);
- sourceOut.text += &R"""(
-#include <frozen/string.h>
-#include <frozen/unordered_map.h>
-using namespace std::literals;
-)"""[1];
-
- header.AddOutputThing(std::move(headerOut));
- source.AddOutputThing(std::move(sourceOut));
-}
-
-} // namespace Utils