2024-11-30 13:50:53 -08:00
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
|
|
|
#define GEN_EXPOSE_BACKEND
|
2024-11-30 20:38:27 -08:00
|
|
|
#include "../project/gen.cpp"
|
2024-11-30 13:50:53 -08:00
|
|
|
|
|
|
|
#include "helpers/push_ignores.inline.hpp"
|
|
|
|
#include "helpers/helper.hpp"
|
|
|
|
|
|
|
|
GEN_NS_BEGIN
|
2024-12-05 14:48:24 -08:00
|
|
|
#include "helpers/push_container_defines.inline.hpp"
|
2024-11-30 13:50:53 -08:00
|
|
|
#include "dependencies/parsing.cpp"
|
2024-12-05 14:48:24 -08:00
|
|
|
#include "helpers/pop_container_defines.inline.hpp"
|
2024-11-30 13:50:53 -08:00
|
|
|
GEN_NS_END
|
|
|
|
|
|
|
|
#include "auxillary/builder.hpp"
|
|
|
|
#include "auxillary/builder.cpp"
|
|
|
|
#include "auxillary/scanner.hpp"
|
|
|
|
|
|
|
|
#include <cstdlib> // for system()
|
|
|
|
|
2024-11-30 20:48:14 -08:00
|
|
|
#include "components/memory.fixed_arena.hpp"
|
2024-11-30 20:38:27 -08:00
|
|
|
#include "components/misc.hpp"
|
2024-11-30 22:40:31 -08:00
|
|
|
#include "components/containers.array.hpp"
|
|
|
|
#include "components/containers.hashtable.hpp"
|
2024-11-30 20:38:27 -08:00
|
|
|
|
2024-11-30 13:50:53 -08:00
|
|
|
using namespace gen;
|
|
|
|
|
2024-11-30 15:54:19 -08:00
|
|
|
constexpr char const* generation_notice =
|
2024-12-04 23:53:14 -08:00
|
|
|
"// This file was generated automatially by gencpp's c_library.cpp "
|
2024-11-30 15:54:19 -08:00
|
|
|
"(See: https://github.com/Ed94/gencpp)\n\n";
|
|
|
|
|
|
|
|
constexpr StrC roll_own_dependencies_guard_start = txt(R"(
|
|
|
|
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
|
|
|
// Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
|
|
|
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
|
|
|
)");
|
|
|
|
|
|
|
|
constexpr StrC roll_own_dependencies_guard_end = txt(R"(
|
|
|
|
// GEN_ROLL_OWN_DEPENDENCIES
|
|
|
|
#endif
|
|
|
|
)");
|
|
|
|
|
|
|
|
constexpr StrC implementation_guard_start = txt(R"(
|
|
|
|
#pragma region GENCPP IMPLEMENTATION GUARD
|
|
|
|
#if defined(GEN_IMPLEMENTATION) && ! defined(GEN_IMPLEMENTED)
|
|
|
|
# define GEN_IMPLEMENTED
|
|
|
|
)");
|
|
|
|
|
|
|
|
constexpr StrC implementation_guard_end = txt(R"(
|
|
|
|
#endif
|
|
|
|
#pragma endregion GENCPP IMPLEMENTATION GUARD
|
|
|
|
)");
|
|
|
|
|
2024-11-30 13:54:03 -08:00
|
|
|
void format_file( char const* path )
|
|
|
|
{
|
2024-12-04 08:30:54 -08:00
|
|
|
String resolved_path = String::make(GlobalAllocator, to_strc_from_c_str(path));
|
2024-11-30 13:50:53 -08:00
|
|
|
|
2024-11-30 13:54:03 -08:00
|
|
|
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
|
|
|
|
style_arg.append("../scripts/.clang-format ");
|
|
|
|
|
|
|
|
// Need to execute clang format on the generated file to get it to match the original.
|
|
|
|
#define clang_format "clang-format "
|
|
|
|
#define cf_format_inplace "-i "
|
|
|
|
#define cf_verbose "-verbose "
|
|
|
|
String command = String::make( GlobalAllocator, clang_format );
|
|
|
|
command.append( cf_format_inplace );
|
|
|
|
command.append( cf_verbose );
|
|
|
|
command.append( style_arg );
|
|
|
|
command.append( resolved_path );
|
|
|
|
log_fmt("\tRunning clang-format on file:\n");
|
|
|
|
system( command );
|
|
|
|
log_fmt("\tclang-format finished reformatting.\n");
|
|
|
|
#undef cf_cmd
|
|
|
|
#undef cf_format_inplace
|
|
|
|
#undef cf_style
|
|
|
|
#undef cf_verbse
|
|
|
|
}
|
|
|
|
|
|
|
|
Code dump_to_scratch_and_retireve( Code code )
|
|
|
|
{
|
|
|
|
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
|
|
|
|
ecode_file_temp.print(code);
|
|
|
|
ecode_file_temp.write();
|
|
|
|
format_file("gen/scratch.hpp");
|
|
|
|
Code result = scan_file( "gen/scratch.hpp" );
|
|
|
|
remove("gen/scratch.hpp");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-11-30 20:38:27 -08:00
|
|
|
CodeBody parse_file( const char* path )
|
|
|
|
{
|
|
|
|
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
|
|
|
CodeBody code = parse_global_body( { file.size, (char const*)file.data } );
|
2024-12-01 09:48:58 -08:00
|
|
|
log_fmt("\nParsed: %s\n", path);
|
2024-11-30 20:38:27 -08:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
constexpr bool helper_use_c_definition = true;
|
|
|
|
|
2024-11-30 13:54:03 -08:00
|
|
|
int gen_main()
|
|
|
|
{
|
|
|
|
#define project_dir "../project/"
|
|
|
|
gen::init();
|
|
|
|
|
2024-12-04 12:00:37 -08:00
|
|
|
PreprocessorDefines.append(txt("GEN_API_C_BEGIN"));
|
|
|
|
PreprocessorDefines.append(txt("GEN_API_C_END"));
|
2024-12-05 00:41:08 -08:00
|
|
|
PreprocessorDefines.append(txt("HashTable("));
|
2024-12-06 02:29:36 -08:00
|
|
|
PreprocessorDefines.append(txt("GEN_NS_PARSER"));
|
|
|
|
PreprocessorDefines.append(txt("GEN_NS_PARSER_BEGIN"));
|
|
|
|
PreprocessorDefines.append(txt("GEN_NS_PARSER_END"));
|
2024-12-07 16:44:58 -08:00
|
|
|
PreprocessorDefines.append(txt("Using_Code("));
|
|
|
|
PreprocessorDefines.append(txt("Using_CodeOps("));
|
|
|
|
PreprocessorDefines.append(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN"));
|
|
|
|
PreprocessorDefines.append(txt("GEN_OPITMIZE_MAPPINGS_END"));
|
2024-12-06 02:29:36 -08:00
|
|
|
//PreprocessorDefines.append(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"));
|
2024-12-04 12:00:37 -08:00
|
|
|
|
2024-11-30 20:38:27 -08:00
|
|
|
Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" );
|
|
|
|
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
|
|
|
Code c_library_header_start = scan_file( "components/header_start.hpp" );
|
2024-11-30 15:54:19 -08:00
|
|
|
|
|
|
|
Builder
|
2024-11-30 20:38:27 -08:00
|
|
|
header = Builder::open( "gen/gen.h" );
|
2024-11-30 15:54:19 -08:00
|
|
|
header.print_fmt( generation_notice );
|
|
|
|
header.print_fmt("#pragma once\n\n");
|
|
|
|
header.print( push_ignores );
|
|
|
|
|
|
|
|
// Headers
|
|
|
|
{
|
2024-11-30 20:38:27 -08:00
|
|
|
header.print( c_library_header_start );
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
#pragma region Scan, Parse, and Generate Components
|
2024-12-07 16:44:58 -08:00
|
|
|
// Only has operator overload definitions that C doesn't need.
|
|
|
|
// CodeBody ast_inlines = gen_ast_inlines();
|
|
|
|
|
|
|
|
Code interface = scan_file( project_dir "components/interface.hpp" );
|
|
|
|
Code inlines = scan_file( project_dir "components/inlines.hpp" );
|
|
|
|
Code header_end = scan_file( project_dir "components/header_end.hpp" );
|
|
|
|
|
|
|
|
CodeBody ecode = gen_ecode ( project_dir "enums/ECodeTypes.csv", helper_use_c_definition );
|
|
|
|
CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv", helper_use_c_definition );
|
|
|
|
CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv", helper_use_c_definition );
|
|
|
|
|
2024-12-06 02:29:36 -08:00
|
|
|
CodeBody parsed_types = parse_file( project_dir "components/types.hpp" );
|
|
|
|
CodeBody types = def_body(CT_Global_Body);
|
|
|
|
for ( Code entry = parsed_types.begin(); entry != parsed_types.end(); ++ entry )
|
|
|
|
{
|
|
|
|
switch(entry->Type)
|
|
|
|
{
|
|
|
|
case CT_Using:
|
|
|
|
{
|
|
|
|
CodeUsing using_ver = cast(CodeUsing, entry);
|
|
|
|
|
|
|
|
if (using_ver->UnderlyingType->ReturnType)
|
|
|
|
{
|
|
|
|
CodeTypename type = using_ver->UnderlyingType;
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeTypedef typedef_ver = parse_typedef(token_fmt(
|
2024-12-06 02:29:36 -08:00
|
|
|
"ReturnType", to_string(type->ReturnType).to_strc()
|
|
|
|
, "Name" , using_ver->Name
|
|
|
|
, "Parameters", to_string(type->Params).to_strc()
|
|
|
|
, stringize(
|
|
|
|
typedef <ReturnType>( * <Name>)(<Parameters>);
|
|
|
|
)));
|
|
|
|
types.append(typedef_ver);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType);
|
|
|
|
types.append(typedef_ver);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Enum:
|
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
log_fmt("Detected ENUM: %S", entry->Name);
|
|
|
|
convert_cpp_enum_to_c(cast(CodeEnum, entry), types);
|
2024-12-06 02:29:36 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-12-07 14:17:02 -08:00
|
|
|
|
|
|
|
default:
|
|
|
|
types.append(entry);
|
|
|
|
break;
|
2024-12-06 02:29:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CodeBody parsed_ast = parse_file( project_dir "components/ast.hpp" );
|
|
|
|
CodeBody ast = def_body(CT_Global_Body);
|
|
|
|
for ( Code entry = parsed_ast.begin(); entry != parsed_ast.end(); ++ entry )
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
|
|
|
case CT_Preprocess_If:
|
|
|
|
{
|
|
|
|
CodePreprocessCond cond = cast(CodePreprocessCond, entry);
|
|
|
|
if (cond->Content.contains(txt("GEN_COMPILER_C")))
|
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
//++ entry; //
|
2024-12-06 02:29:36 -08:00
|
|
|
//ast.append(entry) // typedef
|
|
|
|
//for ( ; entry != parsed_ast.end() && entry->Type != CT_Preprocess_EndIf; ++ entry) {}
|
|
|
|
//++ entry; // Consume endif
|
|
|
|
}
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_ast, ast);
|
2024-12-06 02:29:36 -08:00
|
|
|
if (found) break;
|
|
|
|
|
|
|
|
ast.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Struct_Fwd:
|
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeStruct fwd = cast(CodeStruct, entry);
|
|
|
|
CodeTypedef tdef = parse_typedef(token_fmt("name", fwd->Name, stringize( typedef struct <name> <name>; )));
|
|
|
|
ast.append(fwd);
|
|
|
|
ast.append(tdef);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Struct:
|
|
|
|
{
|
|
|
|
CodeStruct struct_def = cast(CodeStruct, entry);
|
|
|
|
ast.append(struct_def);
|
|
|
|
if ( ! entry->Name.is_equal(txt("AST")))
|
|
|
|
{
|
|
|
|
CodeTypedef tdef = parse_typedef(token_fmt("name", struct_def->Name, stringize( typedef struct <name> <name>; )));
|
|
|
|
ast.append(tdef);
|
2024-12-06 02:29:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Variable:
|
|
|
|
{
|
|
|
|
CodeVar var = cast(CodeVar, entry);
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
s32 constexpr_found = var->Specs ? var->Specs.remove( Spec_Constexpr ) : - 1;
|
2024-12-06 02:29:36 -08:00
|
|
|
if (constexpr_found > -1) {
|
|
|
|
log_fmt("Found constexpr: %S\n", entry.to_string());
|
|
|
|
if (var->Name.contains(txt("AST_ArrSpecs_Cap")))
|
|
|
|
{
|
|
|
|
Code def = untyped_str(txt(
|
|
|
|
R"(#define AST_ArrSpecs_Cap \
|
|
|
|
( \
|
|
|
|
AST_POD_Size \
|
|
|
|
- sizeof(AST*) * 3 \
|
|
|
|
- sizeof(Token*) \
|
|
|
|
- sizeof(AST*) \
|
|
|
|
- sizeof(StringCached) \
|
|
|
|
- sizeof(CodeType) \
|
|
|
|
- sizeof(ModuleFlag) \
|
|
|
|
- sizeof(int) \
|
|
|
|
) \
|
|
|
|
/ sizeof(int) - 1
|
|
|
|
)"
|
|
|
|
));
|
|
|
|
ast.append(def);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CodeDefine def = def_define(var->Name, var->Value.to_string());
|
|
|
|
ast.append(def);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast.append(var);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ast.append(entry);
|
|
|
|
break;
|
|
|
|
}
|
2024-12-07 16:44:58 -08:00
|
|
|
CodeBody parsed_code_types = parse_file( project_dir "components/code_types.hpp" );
|
|
|
|
CodeBody code_types = def_body(CT_Global_Body);
|
|
|
|
for ( Code entry = parsed_code_types.begin(); entry != parsed_code_types.end(); ++ entry ) switch( entry->Type )
|
|
|
|
{
|
|
|
|
case CT_Preprocess_If:
|
|
|
|
case CT_Preprocess_IfDef:
|
|
|
|
{
|
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_code_types, code_types );
|
|
|
|
if (found) {
|
|
|
|
++ entry;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
|
|
|
|
if (found) break;
|
|
|
|
|
|
|
|
code_types.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
code_types.append(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CodeBody parsed_ast_types = parse_file( project_dir "components/ast_types.hpp" );
|
|
|
|
CodeBody ast_types = def_body(CT_Global_Body);
|
|
|
|
for ( Code entry = parsed_ast_types.begin(); entry != parsed_ast_types.end(); ++ entry ) switch( entry->Type )
|
|
|
|
{
|
|
|
|
case CT_Preprocess_If:
|
|
|
|
case CT_Preprocess_IfDef:
|
|
|
|
{
|
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
|
|
|
|
if (found) break;
|
|
|
|
|
|
|
|
ast_types.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Struct:
|
|
|
|
{
|
|
|
|
CodeStruct struct_def = cast(CodeStruct, entry);
|
|
|
|
CodeTypedef tdef = parse_typedef(token_fmt("name", struct_def->Name, stringize( typedef struct <name> <name>; )));
|
|
|
|
ast_types.append(struct_def);
|
|
|
|
ast_types.append(tdef);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ast_types.append(entry);
|
|
|
|
break;
|
|
|
|
}
|
2024-12-05 14:04:17 -08:00
|
|
|
#pragma endregion Scan, Parse, and Generate Components
|
|
|
|
|
|
|
|
#pragma region Scan, Parse, and Generate Dependencies
|
2024-11-30 20:38:27 -08:00
|
|
|
Code platform = scan_file( project_dir "dependencies/platform.hpp" );
|
|
|
|
Code macros = scan_file( project_dir "dependencies/macros.hpp" );
|
|
|
|
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
|
|
|
Code debug = scan_file( project_dir "dependencies/debug.hpp" );
|
2024-12-05 14:04:17 -08:00
|
|
|
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
|
|
|
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
|
|
|
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
2024-11-30 22:40:31 -08:00
|
|
|
|
2024-11-30 20:38:27 -08:00
|
|
|
CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" );
|
2024-12-03 17:21:08 -08:00
|
|
|
CodeBody memory = def_body(CT_Global_Body);
|
2024-11-30 20:38:27 -08:00
|
|
|
for ( Code entry = parsed_memory.begin(); entry != parsed_memory.end(); ++ entry )
|
|
|
|
{
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Using:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
2024-12-04 12:00:37 -08:00
|
|
|
log_fmt("REPLACE THIS MANUALLY: %SC\n", entry->Name);
|
2024-12-01 23:38:55 -08:00
|
|
|
CodeUsing using_ver = cast(CodeUsing, entry);
|
2024-11-30 20:38:27 -08:00
|
|
|
CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType);
|
|
|
|
|
|
|
|
memory.append(typedef_ver);
|
|
|
|
}
|
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Function_Fwd:
|
2024-12-01 18:59:43 -08:00
|
|
|
{
|
2024-12-01 23:38:55 -08:00
|
|
|
CodeFn fn = cast(CodeFn, entry);
|
2024-12-04 08:01:53 -08:00
|
|
|
// for ( StrC id : to_rename ) if (fn->Name.is_equal(id)) {
|
|
|
|
// rename_function_to_unique_symbol(fn);
|
|
|
|
// }
|
|
|
|
memory.append(fn);
|
2024-12-01 18:59:43 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Function:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
2024-12-01 23:38:55 -08:00
|
|
|
CodeFn fn = cast(CodeFn, entry);
|
2024-12-06 21:21:09 -08:00
|
|
|
if (fn->Specs) {
|
|
|
|
s32 constexpr_found = fn->Specs.remove( Spec_Constexpr );
|
|
|
|
if (constexpr_found > -1) {
|
|
|
|
log_fmt("Found constexpr: %S\n", entry.to_string());
|
|
|
|
fn->Specs.append(Spec_Inline);
|
|
|
|
}
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
2024-12-04 08:01:53 -08:00
|
|
|
memory.append(fn);
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Template:
|
2024-12-01 09:48:58 -08:00
|
|
|
{
|
2024-12-01 23:38:55 -08:00
|
|
|
CodeTemplate tmpl = cast(CodeTemplate, entry);
|
2024-12-01 09:48:58 -08:00
|
|
|
if ( tmpl->Declaration->Name.contains(txt("swap")))
|
|
|
|
{
|
|
|
|
CodeBody macro_swap = parse_global_body( txt(R"(
|
|
|
|
#define swap( a, b ) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
typeof( a ) temp = ( a ); \
|
|
|
|
( a ) = ( b ); \
|
|
|
|
( b ) = temp; \
|
|
|
|
} while ( 0 )
|
|
|
|
)"
|
|
|
|
));
|
|
|
|
memory.append(macro_swap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2024-12-07 14:17:02 -08:00
|
|
|
case CT_Enum:
|
|
|
|
{
|
|
|
|
convert_cpp_enum_to_c(cast(CodeEnum, entry), memory);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CT_Struct_Fwd:
|
|
|
|
{
|
|
|
|
CodeTypedef tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct <name> <name>; )));
|
|
|
|
memory.append(entry);
|
|
|
|
memory.append(tdef);
|
|
|
|
}
|
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Class:
|
|
|
|
case CT_Struct:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
2024-12-02 17:20:30 -08:00
|
|
|
CodeBody body = cast(CodeBody, entry->Body);
|
2024-11-30 20:38:27 -08:00
|
|
|
CodeBody new_body = def_body( entry->Body->Type );
|
|
|
|
for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch
|
|
|
|
(body_entry->Type) {
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_If:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
2024-12-07 14:58:56 -08:00
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), body_entry, body, new_body );
|
|
|
|
if (found) break;
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
new_body.append(body_entry);
|
|
|
|
break;
|
|
|
|
}
|
2024-12-02 17:20:30 -08:00
|
|
|
entry->Body = new_body;
|
2024-12-07 14:17:02 -08:00
|
|
|
|
|
|
|
CodeTypedef tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct <name> <name>; )));
|
2024-11-30 20:38:27 -08:00
|
|
|
memory.append(entry);
|
2024-12-07 14:17:02 -08:00
|
|
|
memory.append(tdef);
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_If:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
b32 found = ignore_preprocess_cond_block(txt("! GEN_C_LIKE_CPP"), entry, parsed_memory, memory );
|
2024-12-04 08:01:53 -08:00
|
|
|
if (found) break;
|
|
|
|
|
2024-12-01 09:48:58 -08:00
|
|
|
memory.append(entry);
|
2024-11-30 22:40:31 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_IfDef:
|
2024-11-30 22:40:31 -08:00
|
|
|
{
|
2024-12-04 23:53:14 -08:00
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_memory, memory );
|
2024-12-01 09:48:58 -08:00
|
|
|
if (found) break;
|
|
|
|
|
|
|
|
memory.append(entry);
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_Pragma:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
2024-12-04 08:01:53 -08:00
|
|
|
CodePragma pragma = cast(CodePragma, entry);
|
|
|
|
// if (pragma->Content.starts_with(txt("region Memory"))) {
|
|
|
|
// memory.append(generic_test);
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
2024-12-01 09:48:58 -08:00
|
|
|
b32 found = swap_pragma_region_implementation( txt("FixedArena"), gen_fixed_arenas, entry, memory);
|
|
|
|
if (found) break;
|
|
|
|
|
|
|
|
memory.append(entry);
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
memory.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-12-04 08:01:53 -08:00
|
|
|
|
2024-11-30 22:40:31 -08:00
|
|
|
CodeBody printing_parsed = parse_file( project_dir "dependencies/printing.hpp" );
|
2024-12-03 17:21:08 -08:00
|
|
|
CodeBody printing = def_body(CT_Global_Body);
|
2024-11-30 22:40:31 -08:00
|
|
|
for ( Code entry = printing_parsed.begin(); entry != printing_parsed.end(); ++ entry )
|
|
|
|
{
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_IfDef:
|
2024-11-30 22:40:31 -08:00
|
|
|
{
|
2024-12-04 23:53:14 -08:00
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, printing_parsed, printing );
|
2024-12-01 09:48:58 -08:00
|
|
|
if (found) break;
|
|
|
|
|
|
|
|
printing.append(entry);
|
2024-11-30 22:40:31 -08:00
|
|
|
}
|
2024-12-01 09:48:58 -08:00
|
|
|
break;
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Variable:
|
2024-12-01 09:48:58 -08:00
|
|
|
{
|
2024-12-04 08:30:54 -08:00
|
|
|
if ( strc_contains(entry->Name, txt("Msg_Invalid_Value")))
|
2024-12-01 09:48:58 -08:00
|
|
|
{
|
|
|
|
CodeDefine define = def_define(entry->Name, entry->Value->Content);
|
|
|
|
printing.append(define);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printing.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printing.append(entry);
|
|
|
|
break;
|
2024-11-30 22:40:31 -08:00
|
|
|
}
|
2024-12-01 09:48:58 -08:00
|
|
|
}
|
2024-11-30 22:40:31 -08:00
|
|
|
|
2024-12-01 09:48:58 -08:00
|
|
|
CodeBody parsed_strings = parse_file( project_dir "dependencies/strings.hpp" );
|
2024-12-03 17:21:08 -08:00
|
|
|
CodeBody strings = def_body(CT_Global_Body);
|
2024-12-07 14:17:02 -08:00
|
|
|
for ( Code entry = parsed_strings.begin(); entry != parsed_strings.end(); ++ entry ) switch (entry->Type)
|
2024-11-30 22:40:31 -08:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
case CT_Preprocess_If:
|
2024-11-30 22:40:31 -08:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
CodePreprocessCond cond = cast(CodePreprocessCond, entry);
|
|
|
|
if (cond->Content.is_equal(txt("GEN_COMPILER_C")))
|
2024-12-01 10:29:16 -08:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
++ entry; // Remove #if GEN_COMPILER_C
|
|
|
|
for ( ; entry->Type != CT_Preprocess_Else
|
|
|
|
&& entry->Type != CT_Preprocess_EndIf; ++ entry ) {
|
|
|
|
strings.append(entry); // Preserve content
|
2024-12-04 08:01:53 -08:00
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
for ( ; entry->Type != CT_Preprocess_EndIf; ++ entry ) {} // Discard C++
|
|
|
|
// #endif discarded by for loop
|
|
|
|
break;
|
|
|
|
}
|
2024-12-04 08:01:53 -08:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
bool found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_strings, strings);
|
|
|
|
if (found) break;
|
2024-12-04 08:01:53 -08:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), entry, parsed_strings, strings);
|
|
|
|
if (found) break;
|
|
|
|
}
|
|
|
|
break;
|
2024-12-01 10:29:16 -08:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
case CT_Preprocess_IfDef:
|
|
|
|
{
|
|
|
|
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_strings, strings );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Preprocess_IfNotDef:
|
|
|
|
{
|
|
|
|
log_fmt("\nIFNDEF: %SC\n", entry->Content);
|
|
|
|
strings.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Struct_Fwd:
|
|
|
|
{
|
|
|
|
if ( entry->Name.is_equal(txt("String")) )
|
2024-11-30 22:40:31 -08:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeTypedef c_def = parse_typedef(code( typedef char* String; ));
|
|
|
|
strings.append(c_def);
|
|
|
|
strings.append(fmt_newline);
|
|
|
|
++ entry;
|
|
|
|
continue;
|
2024-11-30 22:40:31 -08:00
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
else
|
2024-12-01 10:29:16 -08:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeTypedef c_def = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct <name> <name>; )));
|
|
|
|
strings.append(c_def);
|
2024-12-01 10:29:16 -08:00
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
strings.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
2024-12-01 10:29:16 -08:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
case CT_Struct:
|
|
|
|
{
|
|
|
|
CodeBody body = cast(CodeBody, entry->Body);
|
|
|
|
CodeBody new_body = def_body( entry->Body->Type );
|
|
|
|
for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch
|
|
|
|
(body_entry->Type) {
|
|
|
|
case CT_Preprocess_If:
|
|
|
|
{
|
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), body_entry, body, new_body );
|
|
|
|
if (found) break;
|
2024-12-01 18:59:43 -08:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
new_body.append(body_entry);
|
2024-12-01 18:59:43 -08:00
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new_body.append(body_entry);
|
|
|
|
break;
|
2024-12-01 18:59:43 -08:00
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
entry->Body = new_body;
|
|
|
|
strings.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
2024-12-01 18:59:43 -08:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
case CT_Typedef:
|
|
|
|
{
|
|
|
|
StrC name_string_table = txt("StringTable");
|
2024-12-05 00:41:08 -08:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeTypedef td = cast(CodeTypedef, entry);
|
|
|
|
if (td->Name.contains(name_string_table))
|
|
|
|
{
|
|
|
|
CodeBody ht = gen_hashtable(txt("StrC"), name_string_table);
|
|
|
|
strings.append(ht);
|
|
|
|
break;
|
2024-12-05 00:41:08 -08:00
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
strings.append(td);
|
2024-11-30 22:40:31 -08:00
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
strings.append(entry);
|
|
|
|
break;
|
2024-11-30 22:40:31 -08:00
|
|
|
}
|
|
|
|
|
2024-12-05 21:33:58 -08:00
|
|
|
CodeBody parsed_filesystem = parse_file( project_dir "dependencies/filesystem.hpp" );
|
|
|
|
CodeBody filesystem = def_body(CT_Global_Body);
|
|
|
|
for ( Code entry = parsed_filesystem.begin(); entry != parsed_filesystem.end(); ++ entry )
|
|
|
|
{
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
|
|
|
case CT_Preprocess_IfDef:
|
|
|
|
{
|
|
|
|
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_filesystem, filesystem );
|
|
|
|
if (found) break;
|
|
|
|
|
|
|
|
filesystem.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
2024-12-07 14:17:02 -08:00
|
|
|
|
|
|
|
case CT_Enum:
|
2024-12-07 14:58:56 -08:00
|
|
|
{
|
|
|
|
if (entry->Name.is_equal(txt("FileOperations")))
|
|
|
|
continue;
|
|
|
|
convert_cpp_enum_to_c(cast(CodeEnum, entry), filesystem);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
case CT_Enum_Fwd:
|
|
|
|
case CT_Struct_Fwd:
|
|
|
|
case CT_Struct:
|
|
|
|
case CT_Union:
|
|
|
|
case CT_Union_Fwd:
|
|
|
|
{
|
2024-12-07 14:58:56 -08:00
|
|
|
StrC type_str = codetype_to_keyword_str(entry->Type);
|
|
|
|
StrC formated_tmpl = token_fmt_impl( 3,
|
|
|
|
"type", type_str
|
|
|
|
, "name", entry->Name,
|
|
|
|
stringize(
|
|
|
|
typedef <type> <name> <name>;
|
|
|
|
));
|
|
|
|
CodeTypedef tdef = parse_typedef(formated_tmpl);
|
|
|
|
filesystem.append(entry);
|
|
|
|
filesystem.append(tdef);
|
2024-12-07 14:17:02 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-05 21:33:58 -08:00
|
|
|
case CT_Variable:
|
|
|
|
{
|
|
|
|
CodeVar var = cast(CodeVar, entry);
|
|
|
|
if (var->Specs.has(Spec_Constexpr) > -1)
|
|
|
|
{
|
|
|
|
CodeDefine define = def_define(entry->Name, entry->Value->Content);
|
|
|
|
filesystem.append(define);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//if ( strc_contains(entry->Name, txt("Msg_Invalid_Value")))
|
|
|
|
//{
|
|
|
|
// CodeDefine define = def_define(entry->Name, entry->Value->Content);
|
|
|
|
// printing.append(define);
|
|
|
|
// continue;
|
|
|
|
//}
|
|
|
|
filesystem.append(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
filesystem.append(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
CodeBody containers = def_body(CT_Global_Body);
|
|
|
|
{
|
|
|
|
CodeBody array_ssize = gen_array(txt("ssize"), txt("Array_ssize"));
|
|
|
|
|
|
|
|
containers.append( def_pragma(code(region Containers)));
|
|
|
|
|
|
|
|
// At this point all arrays required should have been defined so its safe to generate the generic selectors.
|
|
|
|
containers.append( gen_array_base() );
|
|
|
|
containers.append( gen_array_generic_selection_interface());
|
|
|
|
containers.append( gen_hashtable_base() );
|
|
|
|
containers.append(fmt_newline);
|
2024-12-05 20:02:26 -08:00
|
|
|
containers.append( gen_hashtable_generic_selection_interface());
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
containers.append(array_ssize);
|
|
|
|
|
|
|
|
containers.append( def_pragma(code(endregion Containers)));
|
|
|
|
containers.append(fmt_newline);
|
|
|
|
}
|
|
|
|
#pragma endregion Scan, Parse, and Generate Dependencies
|
|
|
|
|
|
|
|
#pragma region Print Dependencies
|
|
|
|
header.print_fmt( roll_own_dependencies_guard_start );
|
|
|
|
header.print( platform );
|
|
|
|
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
|
|
|
|
|
|
|
header.print( macros );
|
|
|
|
header.print( basic_types );
|
|
|
|
header.print( debug );
|
|
|
|
header.print( dump_to_scratch_and_retireve(memory) );
|
|
|
|
header.print( dump_to_scratch_and_retireve(printing));
|
|
|
|
header.print( string_ops );
|
|
|
|
header.print( dump_to_scratch_and_retireve(containers));
|
|
|
|
header.print( hashing );
|
|
|
|
header.print( dump_to_scratch_and_retireve(strings));
|
2024-12-05 21:33:58 -08:00
|
|
|
header.print( dump_to_scratch_and_retireve(filesystem));
|
|
|
|
header.print( timing );
|
2024-12-01 10:29:16 -08:00
|
|
|
header.print_fmt( "\nGEN_NS_END\n" );
|
2024-12-01 09:48:58 -08:00
|
|
|
header.print_fmt( roll_own_dependencies_guard_end );
|
2024-12-05 14:04:17 -08:00
|
|
|
#pragma endregion Print Dependencies
|
2024-12-01 10:29:16 -08:00
|
|
|
|
2024-12-06 02:29:36 -08:00
|
|
|
header.print(fmt_newline);
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
#pragma region region Print Components
|
|
|
|
header.print_fmt( "GEN_NS_BEGIN\n" );
|
|
|
|
header.print_fmt( "GEN_API_C_BEGIN\n\n" );
|
2024-12-01 10:29:16 -08:00
|
|
|
|
|
|
|
header.print_fmt("#pragma region Types\n");
|
2024-12-06 02:29:36 -08:00
|
|
|
header.print( dump_to_scratch_and_retireve(types) );
|
2024-12-01 10:29:16 -08:00
|
|
|
header.print( fmt_newline );
|
|
|
|
header.print( dump_to_scratch_and_retireve( ecode ));
|
|
|
|
header.print( fmt_newline );
|
|
|
|
header.print( dump_to_scratch_and_retireve( eoperator ));
|
|
|
|
header.print( fmt_newline );
|
|
|
|
header.print( dump_to_scratch_and_retireve( especifier ));
|
|
|
|
header.print_fmt("#pragma endregion Types\n\n");
|
2024-12-06 02:29:36 -08:00
|
|
|
|
|
|
|
header.print_fmt("#pragma region AST\n");
|
|
|
|
header.print( dump_to_scratch_and_retireve(ast) );
|
2024-12-07 16:44:58 -08:00
|
|
|
header.print( dump_to_scratch_and_retireve(code_types) );
|
|
|
|
header.print( dump_to_scratch_and_retireve(ast_types) );
|
2024-12-06 02:29:36 -08:00
|
|
|
header.print_fmt("\n#pragma endregion AST\n");
|
|
|
|
|
|
|
|
header.print_fmt( "\nGEN_API_C_END\n" );
|
|
|
|
|
|
|
|
header.print_fmt( "GEN_NS_END\n\n" );
|
2024-12-05 14:04:17 -08:00
|
|
|
#pragma endregion Print Compoennts
|
|
|
|
#endif
|
2024-11-30 15:54:19 -08:00
|
|
|
}
|
2024-11-30 13:54:03 -08:00
|
|
|
|
2024-11-30 20:38:27 -08:00
|
|
|
header.print( pop_ignores );
|
|
|
|
header.write();
|
|
|
|
|
2024-12-01 09:48:58 -08:00
|
|
|
// format_file( "gen/gen.h" );
|
2024-11-30 20:38:27 -08:00
|
|
|
|
2024-11-30 13:54:03 -08:00
|
|
|
gen::deinit();
|
|
|
|
return 0;
|
|
|
|
#undef project_dir
|
|
|
|
}
|