From 7d8bca09b3c4bf1418e758bd3bd0d6f85672153e Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 30 May 2022 15:52:19 -0700 Subject: Changeset: 52 Add support for namespaced enums --- buildtools/codegen/CodegenUtils.inl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'buildtools/codegen/CodegenUtils.inl') diff --git a/buildtools/codegen/CodegenUtils.inl b/buildtools/codegen/CodegenUtils.inl index ea46ac1..f9d913e 100644 --- a/buildtools/codegen/CodegenUtils.inl +++ b/buildtools/codegen/CodegenUtils.inl @@ -46,6 +46,34 @@ bool WriteOutputFile(const CodegenOutput& output, std::string_view dir, std::str return true; } +std::string MakeFullName(std::string_view name, DeclNamespace* ns = nullptr) { + size_t length = 0; + std::vector 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 ProduceGeneratedHeaderFileHeader(CodegenOutput& output) { output.AddOutputThing(CodegenOutputThing{ .text = &R"""( @@ -53,6 +81,9 @@ void ProduceGeneratedHeaderFileHeader(CodegenOutput& output) { #pragma once #include + +#include +#include )"""[1], }); } @@ -63,6 +94,8 @@ void ProduceGeneratedSourceFileHeader(CodegenOutput& output) { // This file is generated. Any changes will be overidden when building. #include "GeneratedCode.hpp" +#include +#include #include #include using namespace std::literals; -- cgit v1.2.3-70-g09d2