From 8776b737483f579d2d2034bb91efe0794bf67d92 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 7 Jul 2022 19:35:40 -0700 Subject: Changeset: 81 Replace DeclEnum::underlyingTypeStr with a lookup function from the enumeration value DeclEnum::underlyingType --- source/20-codegen-compiler/main.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source/20-codegen-compiler/main.cpp') 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 %s = {", decl.underlyingTypeStr.c_str(), filteredElements.size(), str2ValName); + APPEND_FMT_LN(o, "constinit frozen::unordered_map %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=: 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); +} -- cgit v1.2.3-70-g09d2