Progress towards bootstrap/singleheader generation

I will most likely need to refactor some of the components & dependencies files to get the desired gneration implementation the way I want.

Specficially I want to be able to eliminate macros I'm using for enums and common patterns for implmeentation of the data structures.

When it comes to the cpp files, I may leave those alone as the macros largely help ith readability.
Replacing those macros is expensive and most likely not worth it.

The macros under consideration with replacing using the library bootstrap are:

* Define_Types
* Define_Operators
* Define_Specifiers
* GEN_Define_Attribute_Tokens
* Define_CodeType
* Using_Code
* Define_TokType
* def_constant_spec ?
* Helper Macros for def_**_body functions ?
  * AST unallowed types case macros?
(The last three I'm unsure about as they work fine, and neeeding the debugger steps there is a rare scenario...)

The enums could be manually generated and have its fields derived from a CSV (which is what genc is currently doing).
This would allow the user to specify custom attribute macros as well with greater ease.

I may maually inline ProcessModuleFlags, as its not even necessary as any specific symbol with a module flag will only use the export value. Import is only used on modules themselves (from what I can tell).

The Parser::lex function could be offloaded to its own file in case the user wants to swap the entire thing out.
(Most likely may want to for various purposes)

The problem with extracting any definitions out of a component file currently is that will lead to splintering that componnet to multiple other components.
This is necessary as the proper scanner is not implemented yet (only a reduimentary scan_file proc is made so far).
This commit is contained in:
2023-07-24 22:19:21 -04:00
parent 387787b88d
commit 9c81504178
19 changed files with 450 additions and 106 deletions

6
singleheader/Readme.md Normal file
View File

@ -0,0 +1,6 @@
# Singleheader
`gen.singleheader.cpp` with its own `meson.build` generates the library as a single header `gen.hpp`.
Following the same convention seen in the gb, stb, and zpl libraries.
( Currently WIP )

View File

@ -0,0 +1,11 @@
/*
gencpp: An attempt at "simple" staged metaprogramming for c/c++.
See Readme.md for more information from the project repository.
Public Address:
https://github.com/Ed94/gencpp
*/
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
# error Gen.hpp : GEN_TIME not defined
#endif

View File

@ -2,10 +2,76 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND
#include "gen.cpp"
#include "filesystem/gen.scanner.hpp"
using namespace gen;
bool namespace_by_default = true;
constexpr StrC nspace_default = txt_StrC(R"(
#if defined(GEN_DONT_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
# define GEN_NS_BEGIN
# define GEN_NS_END
#elif ! defined(GEN_NS_BEGIN)
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
#endif
)");
constexpr StrC nspace_non_default = txt_StrC(R"(
#if ! defined(GEN_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
# define GEN_NS_BEGIN
# define GEN_NS_END
#elif ! defined(GEN_NS_BEGIN)
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
#endif
)");
constexpr StrC gen_implementation_guard = txt_StrC(R"(
#pragma region GENCPP IMPLEMENTATION GUARD
#if ! defined(GEN_IMPLEMENTATION)
# define GEN_IMPLEMENTATION
)");
constexpr StrC gen_implementation_end = txt_StrC(R"(
#endif
#pragma endregion GENCPP IMPLEMENTATION GUARD
)");
int gen_main()
{
gen::init();
Code push_ignores = scan_file( "../project/helpers/gen.push_ignores.inline.hpp" );
Code pop_ignores = scan_file( "../project/helpers/gen.pop_ignores.inline.hpp" );
Code header_start = scan_file( "components/gen.header_start.hpp" );
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
Builder gen_header;
gen_header.open( "gencpp.hpp" );
gen_header.print( push_ignores );
// Headers
gen_header.print_fmt("#pragma once\n\n");
gen_header.print( header_start );
gen_header.print( nspace_macro );
gen_header.print_fmt( "GEN_NS_BEGIN\n");
gen_header.print_fmt( "\nGEN_NS_END\n");
// Implementation
gen_header.print_fmt( "%s\n\n", (char const*) gen_implementation_guard );
gen_header.print_fmt( "GEN_NS_BEGIN\n");
gen_header.print_fmt( "\nGEN_NS_END\n");
gen_header.print_fmt( "%s\n", (char const*) gen_implementation_end );
gen_header.print( pop_ignores );
gen_header.write();
gen::deinit();
return 0;
}
}

View File

@ -1,5 +0,0 @@
# Singleheader generator
This will require the scanner to be implemented before it can be done properly.

View File

@ -1,4 +1,4 @@
project( 'gen_singleheader', 'c', 'cpp', default_options : ['buildtype=debug'] )
project( 'gencpp_singleheader', 'c', 'cpp', default_options : ['buildtype=debug'] )
includes = include_directories(
[
@ -15,4 +15,4 @@ endif
add_project_arguments('-DGEN_TIME', language : ['c', 'cpp'])
executable( 'gen_singlehader', sources, include_directories : includes )
executable( 'gencpp_singleheader', sources, include_directories : includes )