aboutsummaryrefslogtreecommitdiff
path: root/source/20-codegen-compiler/main.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-07-07 19:35:40 -0700
committerrtk0c <[email protected]>2022-07-07 19:35:40 -0700
commit8776b737483f579d2d2034bb91efe0794bf67d92 (patch)
treedfefd7f9aa2a5fe00b3089d2435f5e1bc6b9c91e /source/20-codegen-compiler/main.cpp
parenteeed6d84f4324387597be05e6ed1df4b3adfca9c (diff)
Changeset: 81 Replace DeclEnum::underlyingTypeStr with a lookup function from the enumeration value DeclEnum::underlyingType
Diffstat (limited to 'source/20-codegen-compiler/main.cpp')
-rw-r--r--source/20-codegen-compiler/main.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/source/20-codegen-compiler/main.cpp b/source/20-codegen-compiler/main.cpp
index e9a449c..348d60e 100644
--- a/source/20-codegen-compiler/main.cpp
+++ b/source/20-codegen-compiler/main.cpp
@@ -474,7 +474,7 @@ void GenerateForEnum(CodegenOutput& headerOut, CodegenOutput& sourceOut, const D
{
auto& o = lookupTable.text;
// TODO use correct underlying type
- APPEND_FMT_LN(o, "constinit frozen::unordered_map<frozen::string, %s, %" PRId64 "> %s = {", decl.underlyingTypeStr.c_str(), filteredElements.size(), str2ValName);
+ APPEND_FMT_LN(o, "constinit frozen::unordered_map<frozen::string, %s, %" PRId64 "> %s = {", FSTR_LUT_LOOKUP(EnumUnderlyingType, decl.underlyingType), filteredElements.size(), str2ValName);
for (auto& elm : filteredElements) {
APPEND_FMT_LN(o, "{\"%s\", %" PRId64 "},", elm.name.c_str(), elm.value);
}
@@ -878,18 +878,12 @@ void ParseInputFileAndGenerate(AppState& as, CodegenLexer& /*lexingState*/ ls, s
++idx;
// Setting underlying type
- // NOTE: these two variables are only valid if we enter the EUT found branch
- size_t eutClauseBegin = idx + /* The ':' token */ 1;
- size_t eutClauseEnd;
if (auto eut = TryConsumeEnumUnderlyingTypeClause(ls);
eut != EUT_COUNT)
{
- eutClauseEnd = idx;
enumDecl.underlyingType = eut;
- enumDecl.underlyingTypeStr = CombineTokens(std::span(tokens.begin() + eutClauseBegin, eutClauseEnd - eutClauseBegin), " "sv);
} else {
enumDecl.underlyingType = EUT_Int32;
- enumDecl.underlyingTypeStr = "int";
}
int enumClosingBraceCount = 0;
@@ -1372,3 +1366,8 @@ where --output-dir=<path>: the *directory* to write generated contents to. Thi
return 0;
}
+
+// TODO move this function to CodegenDecl.cpp, after making LUT able to cross TUs
+std::string_view DeclEnum::GetUnderlyingTypeName() const {
+ return FSTR_LUT_LOOKUP(EnumUnderlyingType, underlyingType);
+}