Removed thirdparty dir, updated docs, removed banned.define/undef files

This commit is contained in:
Edward R. Gonzalez 2023-07-12 03:15:52 -04:00
parent 6ae23e4da0
commit b17c094cd2
9 changed files with 90 additions and 21873 deletions

View File

@ -21,21 +21,25 @@ These build up a code AST to then serialize with a file builder.
## Notes ## Notes
This project is not minimum feature complete yet. The project has reached a sort of *alpha* state, all the current functionality works however there is some kinks with the design to iterate on.
Version 1 will have C and a subset of C++ features available to it.
I will generate with this library a C99 or 11 variant when Version 1 is complete. The project has no external dependencies beyond:
A single-header version will also be generated.
The size target is to stay under 5-6k sloc (data & interface code). * `stdarg.h`
With the dependency code being under 10000 sloc. (Containers, Memory, String handling, Language bloat) * `stddef.h`
* `stdio.h`
* `errno.h`
* `unistd.h` (Linux/Mac)
* `intrin.h` (Windows)
* `windows.h` (Windows)
Any dependencies from the zpl library will be exposed manually with using declarations into global scope. Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
They will be removed when the library is feature complete for version 1 (zero dependencies milestone). The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
*Right now the constructors are working to some extent based on testing* When gencpp is in a stable state, I will make a C variant with the same feature set.
A single-header version will also be generated for both.
***The editor and scanner will NOT be implemented by version 1. They require alot code and the focus for version 1 is to have a robust constructor API and builder, witch a wide suite of usage examples in the tests for the project.*** ***The editor and scanner have not been implemented yet. The scanner will come first, then the editor.***
## Usage ## Usage
@ -69,7 +73,7 @@ u32 gen_main()
``` ```
The design uses a constructive builder sort of AST for the code to generate. The design uses a constructive builder API for the code to generate.
The user is given `Code` objects that are used to build up the AST. The user is given `Code` objects that are used to build up the AST.
Example using each construction interface: Example using each construction interface:
@ -80,14 +84,14 @@ Example using each construction interface:
```cpp ```cpp
Code t_uw = def_type( name(uw) ); Code t_uw = def_type( name(uw) );
Code t_allocator = def_type( name(allocator) ); Code t_allocator = def_type( name(allocator) );
Code t_string_cosnt = def_type( name(char), def_specifiers( 2, ESpecifier::Const, ESpecifier::Ptr ) ); Code t_string_cosnt = def_type( name(char), def_specifiers( ESpecifier::Const, ESpecifier::Ptr ) );
Code header; Code header;
{ {
Code num = def_variable( t_uw, name(Num) ); Code num = def_variable( t_uw, name(Num) );
Code cap = def_variable( t_uw, name(Capacity) ); Code cap = def_variable( t_uw, name(Capacity) );
Code mem_alloc = def_variable( t_allocator, name(Allocator) ); Code mem_alloc = def_variable( t_allocator, name(Allocator) );
Code body = make_struct_body( num, cap, mem_alloc ); Code body = def_struct_body( num, cap, mem_alloc );
header = def_struct( name(ArrayHeader), __, __, body ); header = def_struct( name(ArrayHeader), __, __, body );
} }
@ -112,14 +116,14 @@ Parse will automatically generate any types that have not been used previously.
### Untyped ### Untyped
```cpp ```cpp
Code header = untyped_str( R(" Code header = untyped_str( code(
struct ArrayHeader struct ArrayHeader
{ {
uw Num; uw Num;
uw Capacity; uw Capacity;
allocator Allocator; allocator Allocator;
}; };
)"); ));
``` ```
`name` is a helper macro for providing a string literal with its size, intended for the name paraemter of functions. `name` is a helper macro for providing a string literal with its size, intended for the name paraemter of functions.
@ -255,12 +259,12 @@ Data Notes:
* Both AST and Code have member symbols but their data layout is enforced to be POD types. * Both AST and Code have member symbols but their data layout is enforced to be POD types.
* This library treats memory failures as fatal. * This library treats memory failures as fatal.
* Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content. * Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
* `StringArenas`, `StringMap`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators. * `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
* Strings used for seralization and file buffers are not contained by those used for cached strings. * Strings used for seralization and file buffers are not contained by those used for cached strings.
* They are currently using `Memory::GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out). * They are currently using `Memory::GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
* Memory within the buckets is not resused, so its inherently wasteful (most likely will give non-cached strings their own tailored alloator later) * Memory within the buckets is not resused, so its inherently wasteful (most likely will give non-cached strings their own tailored alloator later)
Two generic templated containers throughout the library: Two generic templated containers are used throughout the library:
* `template< class Type> struct Array` * `template< class Type> struct Array`
* `template< class Type> struct HashTable` * `template< class Type> struct HashTable`
@ -335,6 +339,14 @@ Code <name>
``` ```
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
```cpp
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
// instead of:
def_global_body( 3, ht_entry, array_ht_entry, hashtable );
```
### Parse construction ### Parse construction
A string provided to the API is parsed for the intended language construct. A string provided to the API is parsed for the intended language construct.
@ -420,12 +432,13 @@ Code <name> = def_varaible( <type>, <name>, untyped_<function name>(
Template metaprogramming in the traditional sense becomes possible with the use of `token_fmt` and parse constructors: Template metaprogramming in the traditional sense becomes possible with the use of `token_fmt` and parse constructors:
```cpp ```cpp
char const* token_key, token_value, ...; StrC value = txt_StrC("Something");
char const* template_str = txt( char const* template_str = txt(
Code with {key} to replace with token_values Code with <key> to replace with token_values
... ...
); );
char const* gen_code_str = token_fmt( template, num_tokens, { token_key, token_value }, ... ); char const* gen_code_str = token_fmt( "key", value, template_str );
Code <name> = parse_<function name>( gen_code_str ); Code <name> = parse_<function name>( gen_code_str );
``` ```
@ -591,7 +604,6 @@ Names or Content fields are interned strings and thus showed be cached using `ge
* Implement a context stack for the parsing, allows for accurate scope validation for the AST types. * Implement a context stack for the parsing, allows for accurate scope validation for the AST types.
* Make a test suite thats covers some base cases and zpl containers (+ anything else suitable) * Make a test suite thats covers some base cases and zpl containers (+ anything else suitable)
* Finish support for module specifiers and standard/platform attributes. * Finish support for module specifiers and standard/platform attributes.
* Remove full ZPL dependency, move into Bloat header/source only what is used.
* Generate a single-header library. * Generate a single-header library.
* Actually get to version 1. * Improve the allocation strategy for strings in `AST::to_string`, `Parser::lex`, and `token_fmt_va`
* May be in need of a better name, I found a few repos with this same one... * May be in need of a better name, I found a few repos with this same one...

View File

@ -1,35 +0,0 @@
// Standard Allocation
#define new static_assert( false, "Banned keyword used: new" )
#define delete static_assert( false, "Banned keyword used: delete" )
// Standard Coroutines
#define co_await static_assert( false, "Banned keyword used: co_await" )
#define co_return static_assert( false, "Banned keyword used: co_return" )
#define co_yield static_assert( false, "Banned keyword used: co_yield" )
// Standard Exceptions
#define atomic_cancel static_assert( false, "Banned keyword used: atomic_cancel" )
#define atomic_commit static_assert( false, "Banned keyword used: atomic_commit" )
#define atomic_noexcept static_assert( false, "Banned keyword used: atomic_noexcept" )
#define catch static_assert( false, "Banned keyword used: catch" )
#define noexcept static_assert( false, "Banned keyword used: noexcept" )
#define throw static_assert( false, "Banned keyword used: throw" )
#define try static_assert( false, "Banned keyword used: try" )
// Standard RTTI
#define decltype static_assert( false, "Banned keyword used: decltype" )
#define reflexpr static_assert( false, "Banned keyword used: reflexpr" )
#define typeid static_assert( false, "Banned keyword used: typeid" )
// Object-Oriented Dynamic Dispatch
#define final static_assert( false, "Banned keyword used: final" )
#define override static_assert( false, "Banned keyword used: override" )
#define virtual static_assert( false, "Banned keyword used: virtual" )
// Private Access Specifier
#define private static_assert( false, "Banned keyword used: private" )
// Template Meta-programming
#define concept static_assert( false, "Banned keyword used: concept" )
#define requires static_assert( false, "Banned keyword used: requires" )
#define template static_assert( false, "Banned keyword used: template" )

View File

@ -1,35 +0,0 @@
// Standard Allocation
#undef new
#undef delete
// Standard Coroutines
#undef co_await
#undef co_return
#undef co_yield
// Standard Exceptions
#undef atomic_cancel
#undef atomic_commit
#undef atomic_noexcept
#undef catch
#undef noexcept
#undef throw
#undef try
// Standard RTTI
#undef decltype
#undef reflexpr
#undef typeid
// Object-Oriented Dynamic Dispatch
#undef final
#undef override
#undef virtual
// Private Access Specifier
#undef private
// Template Meta-programming
#undef concept
#undef requires
#undef template

View File

@ -32,6 +32,7 @@ While getting fleshed out, all feature macros are defined on the top of the head
These macros are: These macros are:
* `GENCPP_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
* `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage * `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage
* `GEN_FEATURE_PARSING` : Defines the parse constructors * `GEN_FEATURE_PARSING` : Defines the parse constructors
* `GEN_FEATURE_EDITOR` : Defines the file editing features for changing definitions based on ASTs * `GEN_FEATURE_EDITOR` : Defines the file editing features for changing definitions based on ASTs
@ -44,6 +45,8 @@ This can be used to auto-queue generation of dependent definitions for the symbo
### Organization ### Organization
Dependencies : Mostly from the c-zpl library.
log_failure definition : based on whether to always use fatal on all errors log_failure definition : based on whether to always use fatal on all errors
Major enum definitions and their associated functions used with the AST data Major enum definitions and their associated functions used with the AST data
@ -86,6 +89,7 @@ Inlined functions related to the AST datatype that required forwards for gen int
## gen.cpp ## gen.cpp
* Dependencies
* Static data * Static data
* AST Body case macros are next. * AST Body case macros are next.
* AST implementation * AST implementation

View File

@ -5,45 +5,46 @@
#pragma region GENCPP DEPENDENCIES #pragma region GENCPP DEPENDENCIES
//! If its desired to roll your own dependencies, define GENCPP_PROVIDE_DEPENDENCIES before including this file. //! If its desired to roll your own dependencies, define GENCPP_PROVIDE_DEPENDENCIES before including this file.
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
#ifndef GENCPP_PROVIDE_DEPENDENCIES #ifndef GENCPP_PROVIDE_DEPENDENCIES
#pragma region Macros
# include <stdio.h>
// NOTE: Ensure we use standard methods for these calls if we use GEN_PICO // NOTE: Ensure we use standard methods for these calls if we use GEN_PICO
# if ! defined( GEN_PICO_CUSTOM_ROUTINES ) #pragma region Macros
# if ! defined( GEN_MODULE_CORE ) # include <stdio.h>
# define _strlen strlen # if ! defined( GEN_PICO_CUSTOM_ROUTINES )
# define _printf_err( fmt, ... ) fprintf( stderr, fmt, __VA_ARGS__ ) # if ! defined( GEN_MODULE_CORE )
# define _printf_err_va( fmt, va ) vfprintf( stderr, fmt, va ) # define _strlen strlen
# else # define _printf_err( fmt, ... ) fprintf( stderr, fmt, __VA_ARGS__ )
# define _strlen str_len # define _printf_err_va( fmt, va ) vfprintf( stderr, fmt, va )
# define _printf_err( fmt, ... ) str_fmt_out_err( fmt, __VA_ARGS__ ) # else
# define _printf_err_va( fmt, va ) str_fmt_out_err_va( fmt, va ) # define _strlen str_len
# endif # define _printf_err( fmt, ... ) str_fmt_out_err( fmt, __VA_ARGS__ )
# define _printf_err_va( fmt, va ) str_fmt_out_err_va( fmt, va )
# endif # endif
# endif
# include <errno.h> #
# include <errno.h>
# if defined( GEN_SYSTEM_UNIX ) || defined( GEN_SYSTEM_MACOS ) #
# include <unistd.h> # if defined( GEN_SYSTEM_UNIX ) || defined( GEN_SYSTEM_MACOS )
# elif defined( GEN_SYSTEM_WINDOWS ) # include <unistd.h>
# if ! defined( GEN_NO_WINDOWS_H ) # elif defined( GEN_SYSTEM_WINDOWS )
# ifndef WIN32_LEAN_AND_MEAN # if ! defined( GEN_NO_WINDOWS_H )
# ifndef NOMINMAX # ifndef WIN32_LEAN_AND_MEAN
# define NOMINMAX # ifndef NOMINMAX
# endif # define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# define WIN32_MEAN_AND_LEAN
# define VC_EXTRALEAN
# endif # endif
# include <windows.h> #
# undef NOMINMAX # define WIN32_LEAN_AND_MEAN
# undef WIN32_LEAN_AND_MEAN # define WIN32_MEAN_AND_LEAN
# undef WIN32_MEAN_AND_LEAN # define VC_EXTRALEAN
# undef VC_EXTRALEAN
# endif # endif
# include <windows.h>
# undef NOMINMAX
# undef WIN32_LEAN_AND_MEAN
# undef WIN32_MEAN_AND_LEAN
# undef VC_EXTRALEAN
# endif # endif
# endif
#pragma endregion Macros #pragma endregion Macros
namespace gen namespace gen

View File

@ -11,7 +11,8 @@
#ifdef gen_time #ifdef gen_time
#pragma region GENCPP DEPENDENCIES #pragma region GENCPP DEPENDENCIES
//! If its desired to roll your own dependencies, define GENCPP_PROVIDE_DEPENDENCIES before including this file. //! If its desired to roll your own dependencies, define GENCPP_PROVIDE_DEPENDENCIES before including this file.
#ifndef GENCPP_PROVIDE_DEPENDENCIES // Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
#ifndef GENCPP_ROLL_OWN_DEPENDENCIES
#if __clang__ #if __clang__
# pragma clang diagnostic ignored "-Wunused-const-variable" # pragma clang diagnostic ignored "-Wunused-const-variable"
@ -116,19 +117,19 @@
# error Unknown compiler # error Unknown compiler
#endif #endif
# ifndef GEN_DEF_INLINE #ifndef GEN_DEF_INLINE
# if defined( GEN_STATIC ) # if defined( GEN_STATIC )
# define GEN_DEF_INLINE # define GEN_DEF_INLINE
# define GEN_IMPL_INLINE # define GEN_IMPL_INLINE
# else # else
# define GEN_DEF_INLINE static # define GEN_DEF_INLINE static
# define GEN_IMPL_INLINE static inline # define GEN_IMPL_INLINE static inline
# endif
# endif # endif
#endif
# if defined( GEN_ALWAYS_INLINE ) #if defined( GEN_ALWAYS_INLINE )
# undef GEN_ALWAYS_INLINE # undef GEN_ALWAYS_INLINE
# endif #endif
#ifdef GEN_COMPILER_MSVC #ifdef GEN_COMPILER_MSVC
# define forceinline __forceinline # define forceinline __forceinline
@ -144,7 +145,6 @@
# define forceinline inline # define forceinline inline
#endif #endif
#ifdef GEN_COMPILER_MSVC #ifdef GEN_COMPILER_MSVC
# define neverinline __declspec( noinline ) # define neverinline __declspec( noinline )
#elif defined(GEN_COMPILER_GCC) #elif defined(GEN_COMPILER_GCC)
@ -278,8 +278,6 @@ while(0);
# endif # endif
#pragma endregion Mandatory Includes #pragma endregion Mandatory Includes
// #include "Banned.define.hpp"
namespace gen namespace gen
{ {
constexpr constexpr
@ -3075,6 +3073,9 @@ namespace gen
Code def_specifiers ( s32 num, SpecifierT* specs ); Code def_specifiers ( s32 num, SpecifierT* specs );
Code def_struct_body ( s32 num, Code* codes ); Code def_struct_body ( s32 num, Code* codes );
Code def_union_body ( s32 num, Code* codes ); Code def_union_body ( s32 num, Code* codes );
// Use this to manually populate the entries on demand (will not be checked for validity).
Code def_empty_body( CodeT body_type );
# pragma endregion Upfront # pragma endregion Upfront
# pragma region Parsing # pragma region Parsing
@ -3105,7 +3106,7 @@ namespace gen
//! Do not use directly. Use the token_fmt macro instead. //! Do not use directly. Use the token_fmt macro instead.
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string. // Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
inline inline
StrC _token_fmt( sw num, ... ) StrC token_fmt_impl( sw num, ... )
{ {
local_persist thread_local local_persist thread_local
char buf[GEN_PRINTF_MAXLEN] = { 0 }; char buf[GEN_PRINTF_MAXLEN] = { 0 };
@ -3260,7 +3261,7 @@ namespace gen
# define args( ... ) macro_num_args( __VA_ARGS__ ), __VA_ARGS__ # define args( ... ) macro_num_args( __VA_ARGS__ ), __VA_ARGS__
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string. // Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
# define token_fmt( ... ) _token_fmt( (macro_num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ ) # define token_fmt( ... ) token_fmt_impl( (macro_num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
#pragma endregion Macros #pragma endregion Macros
#pragma region Constants #pragma region Constants

View File

@ -17,12 +17,5 @@
#undef gigabytes #undef gigabytes
#undef terabytes #undef terabytes
#undef global
#undef internal
#undef local_persist
#undef forceinline
#undef txt
// gen_time // gen_time
#endif #endif

View File

@ -275,7 +275,7 @@ Code gen__hashtable( StrC type )
) )
)); ));
return def_global_body( 3, ht_entry, array_ht_entry, hashtable ); return def_global_body( args( ht_entry, array_ht_entry, hashtable ));
} }
struct GenHashTableRequest struct GenHashTableRequest

21724
thirdparty/zpl.h vendored

File diff suppressed because it is too large Load Diff