aboutsummaryrefslogtreecommitdiff
path: root/buildtools/codegen/CodegenDecl.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-05-29 16:14:26 -0700
committerrtk0c <[email protected]>2022-05-29 16:14:26 -0700
commit66b63ae887f553e1cac813546a6b827a9c85d80c (patch)
treec404dd9cc6a74853f8ea409cdeeb1419b04cef44 /buildtools/codegen/CodegenDecl.hpp
parent1a6f1ea3b76c3ed4cad5aba5502af390ce50a2c0 (diff)
Changeset: 43 Add tostring code gen for enums
Diffstat (limited to 'buildtools/codegen/CodegenDecl.hpp')
-rw-r--r--buildtools/codegen/CodegenDecl.hpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/buildtools/codegen/CodegenDecl.hpp b/buildtools/codegen/CodegenDecl.hpp
index 3414d80..c2d8dbb 100644
--- a/buildtools/codegen/CodegenDecl.hpp
+++ b/buildtools/codegen/CodegenDecl.hpp
@@ -20,8 +20,22 @@ enum EnumUnderlyingType {
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;
};
@@ -29,4 +43,23 @@ struct DeclEnum {
std::string name;
std::vector<DeclEnumElement> elements;
EnumUnderlyingType underlyingType;
+ // Start with invalid value, calculate on demand
+ EnumValuePattern pattern = EVP_COUNT;
+
+ EnumValuePattern CalcPattern() const;
+ void CalcPatternIfNecessary();
+};
+
+struct DeclFunctionArgument {
+ std::string type;
+ std::string name;
+};
+
+struct DeclFunction {
+ // Things like extern, static, etc. that gets written before the function return type
+ std::string prefix;
+ std::string name;
+ std::string returnType;
+ std::vector<DeclFunctionArgument> arguments;
+ std::string body;
};