aboutsummaryrefslogtreecommitdiff
path: root/source/20-codegen-compiler/main.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-24 17:34:56 -0700
committerrtk0c <[email protected]>2022-06-24 17:34:56 -0700
commitfd66e74445f50426aa8a137b0a9cfa6d088b953c (patch)
tree6e5d2557f567a7e11a7cc83612af482f27481a3a /source/20-codegen-compiler/main.cpp
parent4386c02d61b37c0d5c508895df2f028b8ea2057c (diff)
Changeset: 75 Add feature to delete entries from the database that belong to currently processed files
Diffstat (limited to 'source/20-codegen-compiler/main.cpp')
-rw-r--r--source/20-codegen-compiler/main.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/source/20-codegen-compiler/main.cpp b/source/20-codegen-compiler/main.cpp
index 5a59b5d..c393fb0 100644
--- a/source/20-codegen-compiler/main.cpp
+++ b/source/20-codegen-compiler/main.cpp
@@ -30,8 +30,22 @@ namespace fs = std::filesystem;
struct AppState {
/*nullable*/ CodegenModelArchive* modelArchive = nullptr;
+ robin_hood::unordered_map<std::string, SourceFile, StringHash, StringEqual> sourceFiles;
std::string_view outputDir;
std::string_view databaseFilePath;
+
+ SourceFile& GetOrCreateSourceFile(std::string_view filename) {
+ auto iter = sourceFiles.find(filename);
+ if (iter != sourceFiles.end()) {
+ return iter->second;
+ } else {
+ auto [iter, success] = sourceFiles.try_emplace(std::string(filename), SourceFile{});
+ auto& filename = iter->first; // NOTE: shadows the parameter `filename`
+ auto& sourceFile = iter->second;
+ sourceFile.filename = filename;
+ return sourceFile;
+ }
+ }
};
FSTR_LUT_DECL(ClexNames, CLEX_eof, CLEX_ext_COUNT) {
@@ -85,21 +99,28 @@ RSTR_LUT_DECL(EnumUnderlyingType, 0, EUT_COUNT) {
RSTR_LUT_MAP_FOR(EnumUnderlyingType);
// Platform-dependent types
- // TODO all of these can be suffixde with "int"
RSTR_LUT_MAP(EUT_Int16, "short");
+ RSTR_LUT_MAP(EUT_Int16, "short int");
RSTR_LUT_MAP(EUT_Uint16, "unsigned short");
+ RSTR_LUT_MAP(EUT_Uint16, "unsigned short int");
RSTR_LUT_MAP(EUT_Int32, "int");
RSTR_LUT_MAP(EUT_Uint32, "unsigned");
RSTR_LUT_MAP(EUT_Uint32, "unsigned int");
#ifdef _WIN32
RSTR_LUT_MAP(EUT_Int32, "long");
+ RSTR_LUT_MAP(EUT_Int32, "long int");
RSTR_LUT_MAP(EUT_Uint32, "unsigned long");
+ RSTR_LUT_MAP(EUT_Uint32, "unsigned long int");
#else
RSTR_LUT_MAP(EUT_Int64, "long");
+ RSTR_LUT_MAP(EUT_Int64, "long int");
RSTR_LUT_MAP(EUT_Uint64, "unsigned long");
+ RSTR_LUT_MAP(EUT_Uint64, "unsigned long int");
#endif
RSTR_LUT_MAP(EUT_Int64, "long long");
+ RSTR_LUT_MAP(EUT_Int64, "long long int");
RSTR_LUT_MAP(EUT_Uint64, "unsigned long long");
+ RSTR_LUT_MAP(EUT_Uint64, "unsigned long long int");
// Sized types
RSTR_LUT_MAP(EUT_Int8, "int8_t");
@@ -279,7 +300,6 @@ found:
}
enum StructMetaGenOptions {
- // TODO how tf do we implement this one: needs full source scanning
SMGO_InheritanceHiearchy,
SMGO_COUNT,
};
@@ -618,6 +638,10 @@ void HandleInputFile(AppState& as, std::string_view filenameStem, std::string_vi
printf("END tokens\n");
#endif
+ auto& sourceFile = as.GetOrCreateSourceFile(filenameStem);
+ sourceFile.header = true;
+ sourceFile.reprocessing = true;
+
ParserState ps;
{
INPLACE_FMT(hpp, "%.*s.gh.inl", PRINTF_STRING_VIEW(filenameStem));
@@ -707,6 +731,7 @@ void HandleInputFile(AppState& as, std::string_view filenameStem, std::string_vi
auto& name = idenTok.text;
auto fullname = Utils::MakeFullName(name, ps.currentNamespace);
DeclStruct structDecl;
+ structDecl.sourceFile = &sourceFile;
structDecl.container = ps.currentNamespace;
structDecl.name = name;
@@ -781,6 +806,7 @@ void HandleInputFile(AppState& as, std::string_view filenameStem, std::string_vi
auto& name = tokens[idx].text;
auto fullname = Utils::MakeFullName(name, ps.currentNamespace);
DeclEnum enumDecl;
+ enumDecl.sourceFile = &sourceFile;
enumDecl.container = ps.currentNamespace;
enumDecl.underlyingType = EUT_Int32; // TODO
enumDecl.underlyingTypeStr = "int";
@@ -1070,6 +1096,7 @@ void HandleInputFile(AppState& as, std::string_view filenameStem, std::string_vi
Utils::WriteOutputFile(ps.standaloneSourceOutput, generatedCppName);
if (as.modelArchive) {
+ as.modelArchive->DeleteDeclsRelatedToFile(filenameStem);
as.modelArchive->Store(ps.model);
}
}
@@ -1189,6 +1216,7 @@ where --output-dir=<path>: the *directory* to write generated contents to. Thi
<opcode> is one of:
"single" process this <input path> file only
"rec" starting at the given directory <input path>, recursively process all .h .hpp files
+ "fileList" read <input path> as a text file, and process each line as a separate file path
)"""[1]);
return -1;
}
@@ -1227,7 +1255,6 @@ where --output-dir=<path>: the *directory* to write generated contents to. Thi
DEBUG_PRINTF("Outputting to directory %.*s.\n", PRINTF_STRING_VIEW(as.outputDir));
DEBUG_PRINTF("Databse file: %.*s.\n", PRINTF_STRING_VIEW(as.databaseFilePath));
- // TODO model archive is broken right now, see each TODO in CodegenModel.cpp
CodegenModelArchive archive(as.databaseFilePath);
as.modelArchive = &archive;