2023-07-24 15:56:15 -07:00
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
|
|
|
#define GEN_EXPOSE_BACKEND
|
2024-12-01 23:11:49 -08:00
|
|
|
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 1
|
|
|
|
#define GEN_SUPPORT_CPP_REFERENCES 0
|
2023-07-24 15:56:15 -07:00
|
|
|
#include "gen.cpp"
|
2023-08-03 20:18:33 -07:00
|
|
|
|
2023-08-09 15:47:59 -07:00
|
|
|
#include "helpers/push_ignores.inline.hpp"
|
2023-07-29 09:25:38 -07:00
|
|
|
#include "helpers/helper.hpp"
|
2023-07-24 15:56:15 -07:00
|
|
|
|
2023-08-03 20:18:33 -07:00
|
|
|
GEN_NS_BEGIN
|
|
|
|
#include "dependencies/parsing.cpp"
|
|
|
|
GEN_NS_END
|
|
|
|
|
2023-08-09 15:47:59 -07:00
|
|
|
#include "auxillary/builder.hpp"
|
|
|
|
#include "auxillary/builder.cpp"
|
|
|
|
#include "auxillary/scanner.hpp"
|
2023-08-03 20:18:33 -07:00
|
|
|
|
2024-10-27 18:38:02 -07:00
|
|
|
#include <cstdlib> // for system()
|
|
|
|
|
2023-07-24 15:56:15 -07:00
|
|
|
using namespace gen;
|
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
constexpr char const* generation_notice =
|
2023-08-22 21:05:58 -07:00
|
|
|
"// This file was generated automatially by gencpp's singleheader.cpp"
|
2023-08-03 08:01:43 -07:00
|
|
|
"(See: https://github.com/Ed94/gencpp)\n\n";
|
2023-07-24 19:19:21 -07:00
|
|
|
|
2023-08-09 15:47:59 -07:00
|
|
|
constexpr StrC implementation_guard_start = txt(R"(
|
2023-07-24 19:19:21 -07:00
|
|
|
#pragma region GENCPP IMPLEMENTATION GUARD
|
2023-07-25 14:46:00 -07:00
|
|
|
#if defined(GEN_IMPLEMENTATION) && ! defined(GEN_IMPLEMENTED)
|
|
|
|
# define GEN_IMPLEMENTED
|
2023-07-24 19:19:21 -07:00
|
|
|
)");
|
|
|
|
|
2023-08-09 15:47:59 -07:00
|
|
|
constexpr StrC implementation_guard_end = txt(R"(
|
2023-07-24 19:19:21 -07:00
|
|
|
#endif
|
|
|
|
#pragma endregion GENCPP IMPLEMENTATION GUARD
|
|
|
|
)");
|
|
|
|
|
2023-08-09 15:47:59 -07:00
|
|
|
constexpr StrC roll_own_dependencies_guard_start = txt(R"(
|
2023-07-25 12:12:51 -07:00
|
|
|
//! 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
|
|
|
|
)");
|
|
|
|
|
2023-08-09 15:47:59 -07:00
|
|
|
constexpr StrC roll_own_dependencies_guard_end = txt(R"(
|
2023-07-25 12:12:51 -07:00
|
|
|
// GEN_ROLL_OWN_DEPENDENCIES
|
|
|
|
#endif
|
|
|
|
)");
|
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
global bool generate_gen_dep = true;
|
|
|
|
global bool generate_builder = true;
|
|
|
|
global bool generate_editor = true;
|
|
|
|
global bool generate_scanner = true;
|
|
|
|
|
2024-10-27 17:01:54 -07:00
|
|
|
void format_file( char const* path )
|
|
|
|
{
|
|
|
|
String resolved_path = String::make(GlobalAllocator, to_str(path));
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-07-24 15:56:15 -07:00
|
|
|
int gen_main()
|
|
|
|
{
|
2023-07-25 12:12:51 -07:00
|
|
|
#define project_dir "../project/"
|
2023-08-03 20:18:33 -07:00
|
|
|
gen::init();
|
2023-07-25 12:12:51 -07:00
|
|
|
|
2023-08-03 20:18:33 -07: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" );
|
2023-08-28 20:52:44 -07:00
|
|
|
Code single_header_start = scan_file( "components/header_start.hpp" );
|
2023-07-24 19:19:21 -07:00
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
Builder
|
2023-08-03 08:01:43 -07:00
|
|
|
header = Builder::open( "gen/gen.hpp" );
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print_fmt( generation_notice );
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print_fmt("#pragma once\n\n");
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print( push_ignores );
|
2023-07-24 19:19:21 -07:00
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
// Headers
|
|
|
|
{
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print( single_header_start );
|
2023-07-25 12:12:51 -07:00
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
if ( generate_gen_dep )
|
2023-07-25 12:12:51 -07:00
|
|
|
{
|
2024-10-27 15:58:37 -07:00
|
|
|
Code platform = scan_file( project_dir "dependencies/platform.hpp" );
|
2023-08-09 15:47:59 -07:00
|
|
|
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" );
|
|
|
|
Code memory = scan_file( project_dir "dependencies/memory.hpp" );
|
|
|
|
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
|
|
|
Code printing = scan_file( project_dir "dependencies/printing.hpp" );
|
|
|
|
Code containers = scan_file( project_dir "dependencies/containers.hpp" );
|
|
|
|
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
|
|
|
Code strings = scan_file( project_dir "dependencies/strings.hpp" );
|
|
|
|
Code filesystem = scan_file( project_dir "dependencies/filesystem.hpp" );
|
|
|
|
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
2023-07-25 12:12:51 -07:00
|
|
|
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print_fmt( roll_own_dependencies_guard_start );
|
2024-10-27 15:58:37 -07:00
|
|
|
header.print( platform );
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
2023-08-03 20:18:33 -07:00
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( macros );
|
|
|
|
header.print( basic_types );
|
|
|
|
header.print( debug );
|
|
|
|
header.print( memory );
|
|
|
|
header.print( string_ops );
|
|
|
|
header.print( printing );
|
|
|
|
header.print( containers );
|
2023-07-26 11:21:20 -07:00
|
|
|
header.print( hashing );
|
2023-08-09 15:47:59 -07:00
|
|
|
header.print( strings );
|
|
|
|
header.print( filesystem );
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( timing );
|
|
|
|
|
2023-08-03 20:18:33 -07:00
|
|
|
if ( generate_scanner )
|
|
|
|
{
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "\n#pragma region Parsing\n" );
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print( scan_file( project_dir "dependencies/parsing.hpp" ) );
|
2023-08-04 13:12:13 -07:00
|
|
|
header.print_fmt( "#pragma endregion Parsing\n\n" );
|
2023-08-03 20:18:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
header.print_fmt( "GEN_NS_END\n" );
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print_fmt( roll_own_dependencies_guard_end );
|
2023-08-09 15:47:59 -07:00
|
|
|
header.print( fmt_newline );
|
2023-07-25 12:12:51 -07:00
|
|
|
}
|
|
|
|
|
2023-08-06 11:58:43 -07:00
|
|
|
Code types = scan_file( project_dir "components/types.hpp" );
|
|
|
|
Code ast = scan_file( project_dir "components/ast.hpp" );
|
|
|
|
Code ast_types = scan_file( project_dir "components/ast_types.hpp" );
|
2023-11-21 17:07:49 -08:00
|
|
|
Code code_types = scan_file( project_dir "components/code_types.hpp" );
|
2023-08-06 11:58:43 -07:00
|
|
|
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/ECode.csv" );
|
|
|
|
CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" );
|
|
|
|
CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" );
|
|
|
|
CodeBody ast_inlines = gen_ast_inlines();
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print_fmt( "GEN_NS_BEGIN\n\n" );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt("#pragma region Types\n");
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( types );
|
2024-10-27 17:01:54 -07: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_newline );
|
2023-07-27 14:12:58 -07:00
|
|
|
header.print_fmt("#pragma endregion Types\n\n");
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt("#pragma region AST\n");
|
2023-08-03 08:01:43 -07:00
|
|
|
header.print( ast );
|
2023-11-21 17:07:49 -08:00
|
|
|
header.print( code_types );
|
2023-08-03 08:01:43 -07:00
|
|
|
header.print( ast_types );
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt("\n#pragma endregion AST\n");
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( interface );
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "\n#pragma region Inlines\n" );
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print( inlines );
|
2024-10-27 17:01:54 -07:00
|
|
|
header.print( dump_to_scratch_and_retireve( ast_inlines ));
|
|
|
|
header.print( fmt_newline );
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "#pragma endregion Inlines\n" );
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( header_end );
|
2023-08-03 20:18:33 -07:00
|
|
|
|
|
|
|
if ( generate_builder )
|
|
|
|
{
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "\n#pragma region Builder\n" );
|
2023-08-21 20:28:39 -07:00
|
|
|
header.print( scan_file( project_dir "auxillary/builder.hpp" ) );
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "#pragma endregion Builder\n" );
|
2023-08-03 20:18:33 -07:00
|
|
|
}
|
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print_fmt( "GEN_NS_END\n" );
|
|
|
|
}
|
2023-07-24 19:19:21 -07:00
|
|
|
|
|
|
|
// Implementation
|
2023-07-25 12:12:51 -07:00
|
|
|
{
|
|
|
|
header.print_fmt( "%s\n", (char const*) implementation_guard_start );
|
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
if ( generate_gen_dep )
|
|
|
|
{
|
2023-08-09 15:47:59 -07:00
|
|
|
Code impl_start = scan_file( project_dir "dependencies/src_start.cpp" );
|
|
|
|
Code debug = scan_file( project_dir "dependencies/debug.cpp" );
|
|
|
|
Code string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
|
|
|
Code printing = scan_file( project_dir "dependencies/printing.cpp" );
|
|
|
|
Code memory = scan_file( project_dir "dependencies/memory.cpp" );
|
|
|
|
Code hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
|
|
|
Code strings = scan_file( project_dir "dependencies/strings.cpp" );
|
|
|
|
Code filesystem = scan_file( project_dir "dependencies/filesystem.cpp" );
|
|
|
|
Code timing = scan_file( project_dir "dependencies/timing.cpp" );
|
2023-07-25 14:46:00 -07:00
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
header.print_fmt( roll_own_dependencies_guard_start );
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( impl_start );
|
|
|
|
header.print( debug );
|
|
|
|
header.print( string_ops );
|
|
|
|
header.print( printing );
|
|
|
|
header.print( memory );
|
|
|
|
header.print( hashing );
|
2023-08-09 15:47:59 -07:00
|
|
|
header.print( strings );
|
|
|
|
header.print( filesystem );
|
2023-08-03 08:01:43 -07:00
|
|
|
header.print( timing );
|
2023-07-25 14:46:00 -07:00
|
|
|
|
2023-08-03 20:18:33 -07:00
|
|
|
if ( generate_scanner )
|
|
|
|
{
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "\n#pragma region Parsing\n" );
|
2023-11-20 12:09:01 -08:00
|
|
|
header.print( scan_file( project_dir "dependencies/parsing.cpp" ) );
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print_fmt( "#pragma endregion Parsing\n\n" );
|
|
|
|
}
|
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print_fmt( "GEN_NS_END\n");
|
|
|
|
header.print_fmt( roll_own_dependencies_guard_end );
|
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Code static_data = scan_file( project_dir "components/static_data.cpp" );
|
|
|
|
Code ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" );
|
|
|
|
Code ast = scan_file( project_dir "components/ast.cpp" );
|
|
|
|
Code code = scan_file( project_dir "components/code_serialization.cpp" );
|
|
|
|
Code interface = scan_file( project_dir "components/interface.cpp" );
|
|
|
|
Code upfront = scan_file( project_dir "components/interface.upfront.cpp" );
|
|
|
|
Code lexer = scan_file( project_dir "components/lexer.cpp" );
|
|
|
|
Code parser = scan_file( project_dir "components/parser.cpp" );
|
|
|
|
Code parsing_interface = scan_file( project_dir "components/interface.parsing.cpp" );
|
|
|
|
Code untyped = scan_file( project_dir "components/interface.untyped.cpp" );
|
2023-07-25 12:12:51 -07:00
|
|
|
|
2023-09-08 12:14:43 -07:00
|
|
|
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv" );
|
2024-10-26 15:42:23 -07:00
|
|
|
CodeNS parser_nspace = def_namespace( name(parser), def_namespace_body( args(etoktype)) );
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2023-08-21 23:09:20 -07:00
|
|
|
header.print_fmt( "\nGEN_NS_BEGIN\n");
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print( static_data );
|
|
|
|
|
|
|
|
header.print_fmt( "#pragma region AST\n\n" );
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( ast_case_macros );
|
|
|
|
header.print( ast );
|
2023-11-19 17:34:46 -08:00
|
|
|
header.print( code );
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print_fmt( "#pragma endregion AST\n\n" );
|
|
|
|
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "#pragma region Interface\n" );
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( interface );
|
|
|
|
header.print( upfront );
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "\n#pragma region Parsing\n\n" );
|
2024-10-27 17:01:54 -07:00
|
|
|
header.print( dump_to_scratch_and_retireve(parser_nspace) );
|
2023-11-20 12:09:01 -08:00
|
|
|
header.print( lexer );
|
|
|
|
header.print( parser );
|
|
|
|
header.print( parsing_interface );
|
2023-08-21 23:09:20 -07:00
|
|
|
header.print_fmt( "\n#pragma endregion Parsing\n" );
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print( untyped );
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "\n#pragma endregion Interface\n\n");
|
2023-08-03 20:18:33 -07:00
|
|
|
|
|
|
|
if ( generate_builder )
|
|
|
|
{
|
2023-08-21 22:51:59 -07:00
|
|
|
header.print_fmt( "#pragma region Builder\n" );
|
2023-08-21 20:28:39 -07:00
|
|
|
header.print( scan_file( project_dir "auxillary/builder.cpp" ) );
|
2023-08-21 23:09:20 -07:00
|
|
|
header.print_fmt( "\n#pragma endregion Builder\n\n" );
|
2023-08-03 20:18:33 -07:00
|
|
|
}
|
|
|
|
|
2023-09-08 12:14:43 -07:00
|
|
|
// Scanner header depends on implementation
|
|
|
|
if ( generate_scanner )
|
|
|
|
{
|
|
|
|
header.print_fmt( "\n#pragma region Scanner\n" );
|
|
|
|
header.print( scan_file( project_dir "auxillary/scanner.hpp" ) );
|
|
|
|
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
|
|
|
}
|
|
|
|
|
2023-08-03 20:18:33 -07:00
|
|
|
#if 0
|
|
|
|
if ( generate_scanner )
|
|
|
|
{
|
|
|
|
header.print_fmt( "#pragma region Scanner\n\n" );
|
2023-08-21 20:28:39 -07:00
|
|
|
header.print( scan_file( project_dir "auxillary/scanner.cpp" ) );
|
2023-08-03 20:18:33 -07:00
|
|
|
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-07-25 12:12:51 -07:00
|
|
|
header.print_fmt( "GEN_NS_END\n");
|
|
|
|
|
|
|
|
header.print_fmt( "%s\n", (char const*) implementation_guard_end );
|
|
|
|
}
|
|
|
|
|
|
|
|
header.print( pop_ignores );
|
|
|
|
header.write();
|
2023-07-24 19:19:21 -07:00
|
|
|
|
|
|
|
gen::deinit();
|
2023-07-24 15:56:15 -07:00
|
|
|
return 0;
|
2023-08-03 20:18:33 -07:00
|
|
|
#undef project_dir
|
2023-07-24 19:19:21 -07:00
|
|
|
}
|