aboutsummaryrefslogtreecommitdiff
path: root/src/brussel.codegen.comp/CodegenDecl.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2023-10-19 22:50:07 -0700
committerrtk0c <[email protected]>2023-10-19 22:50:07 -0700
commit2c92e07f337e42cf58970443f9de678f85a9b2a4 (patch)
tree075d5407e1e12a9d35cbee6e4c20ad34e0765c42 /src/brussel.codegen.comp/CodegenDecl.hpp
parent615809c036f604bce4582cea8ad49c64693f4f45 (diff)
The great renaming: switch to "module style"
Diffstat (limited to 'src/brussel.codegen.comp/CodegenDecl.hpp')
-rw-r--r--src/brussel.codegen.comp/CodegenDecl.hpp154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/brussel.codegen.comp/CodegenDecl.hpp b/src/brussel.codegen.comp/CodegenDecl.hpp
new file mode 100644
index 0000000..f1ac5b1
--- /dev/null
+++ b/src/brussel.codegen.comp/CodegenDecl.hpp
@@ -0,0 +1,154 @@
+#pragma once
+
+#include "CodegenOutput.hpp"
+
+#include <string>
+#include <vector>
+
+// TODO replace std::string name with std::string_view into the token storage?
+
+struct SourceFile {
+ std::string filename;
+ CodegenOutput preHeaderOutput;
+ CodegenOutput postHeaderOutput;
+ CodegenOutput postSourceOutput;
+ CodegenOutput tuOutput; // "tu" = Translation Unit, produces a separately compiled .cpp file
+ bool header = false;
+ /// Whether this file is being reprocessed in this invocation of codegen.exe or not.
+ bool reprocessing = false;
+};
+
+struct DeclNamespace {
+ // NOTE: namespace doesn't have a source file field, because the same namespace can be "reopened" in multipled files
+
+ DeclNamespace* container = nullptr;
+ std::string name;
+ const std::string* fullname = nullptr; // View into storage map key
+};
+
+struct DeclStruct;
+struct DeclMemberVariable {
+ DeclStruct* containerStruct = nullptr;
+ std::string name;
+ std::string type;
+ std::string getterName;
+ std::string setterName;
+ bool isGetterGenerated = false;
+ bool isSetterGenerated = false;
+};
+struct DeclMemberFunction {
+ DeclStruct* containerStruct = nullptr;
+ // TODO
+};
+
+// Structs or classes
+struct DeclStruct {
+ SourceFile* sourceFile = nullptr;
+ DeclNamespace* container = nullptr;
+ std::vector<const DeclStruct*> baseClasses;
+ std::vector<DeclMemberVariable> memberVariables;
+ std::vector<DeclMemberVariable> generatedVariables;
+ std::vector<DeclMemberFunction> memberFunctions;
+ std::vector<DeclMemberFunction> generatedFunctions;
+ std::string name;
+ mutable std::string mangledName;
+ const std::string* fullname = nullptr; // View into storage map key
+
+ // Scanned generation options
+ bool generating : 1 = false;
+ bool generatingInheritanceHiearchy : 1 = false;
+
+ const std::string& GetName() const { return name; }
+ const std::string& GetFullName() const { return *fullname; }
+ const std::string& GetMangledName() const;
+};
+
+struct DeclXGlobalVar {
+ std::string name;
+ bool hasCtor = false;
+ bool hasDtor = false;
+
+ static std::string MangleCtorName(std::string_view targetName);
+ std::string GetMangledCtorName() const { return MangleCtorName(name); }
+ static std::string MangleDtorName(std::string_view targetName);
+ std::string GetMangledDtorName() const { return MangleDtorName(name); }
+};
+
+enum EnumUnderlyingType {
+ EUT_Int8,
+ EUT_Int16,
+ EUT_Int32,
+ EUT_Int64,
+ EUT_Uint8,
+ EUT_Uint16,
+ EUT_Uint32,
+ EUT_Uint64,
+ EUT_COUNT,
+};
+
+enum EnumValuePattern {
+ // The numbers cover n..m with no gaps
+ EVP_Continuous,
+ // The numbers cover for i in n..m, 1 << i
+ // e.g. [0] = 1 << 0,
+ // [1] = 1 << 1.
+ // [2] = 1 << 2. etc.
+ EVP_Bits,
+ // The numbesr don't have a particular pattern
+ EVP_Random,
+ EVP_COUNT,
+};
+
+struct DeclEnumElement {
+ std::string name;
+ // TODO support int64_t, etc. enum underlying types
+ uint64_t value;
+};
+
+struct DeclEnum {
+ SourceFile* sourceFile = nullptr;
+ DeclNamespace* container = nullptr;
+ std::string name;
+ mutable std::string mangledName;
+ const std::string* fullname = nullptr; // View into storage map key
+ std::vector<DeclEnumElement> elements;
+ EnumUnderlyingType underlyingType;
+ // Start with invalid value, calculate on demand
+ mutable EnumValuePattern pattern = EVP_COUNT;
+
+ // TODO replace this with a regex?
+ std::string generateRemovingPrefix;
+ std::string generatingAddingPrefix;
+ // NOTE: this flag acts as a gate for every specific generating option, must be enabled for them to work
+ bool generating : 1 = false;
+ bool generateToString : 1 = false;
+ bool generateFromString : 1 = false;
+ // NOTE: see GenerateForEnum() for the exact heuristics
+ bool generateExcludeUseHeuristics : 1 = false;
+
+ const std::string& GetName() const { return name; }
+ const std::string& GetFullName() const { return *fullname; }
+ const std::string& GetMangledName() const;
+
+ std::string_view GetUnderlyingTypeName() const;
+
+ EnumValuePattern CalcPattern() const;
+ EnumValuePattern GetPattern() const;
+};
+
+struct DeclFunctionArgument {
+ std::string type;
+ std::string name;
+};
+
+struct DeclFunction {
+ SourceFile* sourceFile = nullptr;
+ DeclNamespace* container = nullptr;
+ // Things like extern, static, etc. that gets written before the function return type
+ std::string prefix;
+ std::string name;
+ const std::string* fullname = nullptr; // View into storage map key
+ std::string returnType;
+ std::vector<DeclFunctionArgument> arguments;
+ std::string body;
+};