mirror of
https://github.com/Ed94/gencpp.git
synced 2024-11-10 02:54:53 -08:00
Removed thirdparty dir, updated docs, removed banned.define/undef files
This commit is contained in:
parent
6ae23e4da0
commit
b17c094cd2
56
Readme.md
56
Readme.md
@ -21,21 +21,25 @@ These build up a code AST to then serialize with a file builder.
|
||||
|
||||
## Notes
|
||||
|
||||
This project is not minimum feature complete yet.
|
||||
Version 1 will have C and a subset of C++ features available to it.
|
||||
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.
|
||||
|
||||
I will generate with this library a C99 or 11 variant when Version 1 is complete.
|
||||
A single-header version will also be generated.
|
||||
The project has no external dependencies beyond:
|
||||
|
||||
The size target is to stay under 5-6k sloc (data & interface code).
|
||||
With the dependency code being under 10000 sloc. (Containers, Memory, String handling, Language bloat)
|
||||
* `stdarg.h`
|
||||
* `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.
|
||||
They will be removed when the library is feature complete for version 1 (zero dependencies milestone).
|
||||
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
|
||||
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
|
||||
|
||||
@ -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.
|
||||
|
||||
Example using each construction interface:
|
||||
@ -80,14 +84,14 @@ Example using each construction interface:
|
||||
```cpp
|
||||
Code t_uw = def_type( name(uw) );
|
||||
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 num = def_variable( t_uw, name(Num) );
|
||||
Code cap = def_variable( t_uw, name(Capacity) );
|
||||
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 );
|
||||
}
|
||||
@ -112,14 +116,14 @@ Parse will automatically generate any types that have not been used previously.
|
||||
### Untyped
|
||||
|
||||
```cpp
|
||||
Code header = untyped_str( R("
|
||||
Code header = untyped_str( code(
|
||||
struct ArrayHeader
|
||||
{
|
||||
uw Num;
|
||||
uw Capacity;
|
||||
allocator Allocator;
|
||||
};
|
||||
)");
|
||||
));
|
||||
```
|
||||
|
||||
`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.
|
||||
* 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.
|
||||
* `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.
|
||||
* 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)
|
||||
|
||||
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 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
|
||||
|
||||
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:
|
||||
|
||||
```cpp
|
||||
char const* token_key, token_value, ...;
|
||||
StrC value = txt_StrC("Something");
|
||||
|
||||
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 );
|
||||
```
|
||||
|
||||
@ -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.
|
||||
* Make a test suite thats covers some base cases and zpl containers (+ anything else suitable)
|
||||
* 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.
|
||||
* 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...
|
||||
|
@ -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" )
|
@ -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
|
@ -32,6 +32,7 @@ While getting fleshed out, all feature macros are defined on the top of the head
|
||||
|
||||
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_FEATURE_PARSING` : Defines the parse constructors
|
||||
* `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
|
||||
|
||||
Dependencies : Mostly from the c-zpl library.
|
||||
|
||||
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
|
||||
@ -86,6 +89,7 @@ Inlined functions related to the AST datatype that required forwards for gen int
|
||||
|
||||
## gen.cpp
|
||||
|
||||
* Dependencies
|
||||
* Static data
|
||||
* AST Body case macros are next.
|
||||
* AST implementation
|
||||
|
@ -5,11 +5,12 @@
|
||||
|
||||
#pragma region GENCPP DEPENDENCIES
|
||||
//! 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
|
||||
|
||||
// NOTE: Ensure we use standard methods for these calls if we use GEN_PICO
|
||||
#pragma region Macros
|
||||
# include <stdio.h>
|
||||
// NOTE: Ensure we use standard methods for these calls if we use GEN_PICO
|
||||
# if ! defined( GEN_PICO_CUSTOM_ROUTINES )
|
||||
# if ! defined( GEN_MODULE_CORE )
|
||||
# define _strlen strlen
|
||||
@ -21,9 +22,9 @@
|
||||
# define _printf_err_va( fmt, va ) str_fmt_out_err_va( fmt, va )
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#
|
||||
# include <errno.h>
|
||||
|
||||
#
|
||||
# if defined( GEN_SYSTEM_UNIX ) || defined( GEN_SYSTEM_MACOS )
|
||||
# include <unistd.h>
|
||||
# elif defined( GEN_SYSTEM_WINDOWS )
|
||||
@ -32,7 +33,7 @@
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
|
||||
#
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_MEAN_AND_LEAN
|
||||
# define VC_EXTRALEAN
|
||||
|
@ -11,7 +11,8 @@
|
||||
#ifdef gen_time
|
||||
#pragma region GENCPP DEPENDENCIES
|
||||
//! 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__
|
||||
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||
@ -116,7 +117,7 @@
|
||||
# error Unknown compiler
|
||||
#endif
|
||||
|
||||
# ifndef GEN_DEF_INLINE
|
||||
#ifndef GEN_DEF_INLINE
|
||||
# if defined( GEN_STATIC )
|
||||
# define GEN_DEF_INLINE
|
||||
# define GEN_IMPL_INLINE
|
||||
@ -124,11 +125,11 @@
|
||||
# define GEN_DEF_INLINE static
|
||||
# define GEN_IMPL_INLINE static inline
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
# if defined( GEN_ALWAYS_INLINE )
|
||||
#if defined( GEN_ALWAYS_INLINE )
|
||||
# undef GEN_ALWAYS_INLINE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef GEN_COMPILER_MSVC
|
||||
# define forceinline __forceinline
|
||||
@ -144,7 +145,6 @@
|
||||
# define forceinline inline
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef GEN_COMPILER_MSVC
|
||||
# define neverinline __declspec( noinline )
|
||||
#elif defined(GEN_COMPILER_GCC)
|
||||
@ -278,8 +278,6 @@ while(0);
|
||||
# endif
|
||||
#pragma endregion Mandatory Includes
|
||||
|
||||
// #include "Banned.define.hpp"
|
||||
|
||||
namespace gen
|
||||
{
|
||||
constexpr
|
||||
@ -3075,6 +3073,9 @@ namespace gen
|
||||
Code def_specifiers ( s32 num, SpecifierT* specs );
|
||||
Code def_struct_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 region Parsing
|
||||
@ -3105,7 +3106,7 @@ namespace gen
|
||||
//! 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.
|
||||
inline
|
||||
StrC _token_fmt( sw num, ... )
|
||||
StrC token_fmt_impl( sw num, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
@ -3260,7 +3261,7 @@ namespace gen
|
||||
# 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.
|
||||
# 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 region Constants
|
||||
|
@ -17,12 +17,5 @@
|
||||
#undef gigabytes
|
||||
#undef terabytes
|
||||
|
||||
#undef global
|
||||
#undef internal
|
||||
#undef local_persist
|
||||
#undef forceinline
|
||||
|
||||
#undef txt
|
||||
|
||||
// gen_time
|
||||
#endif
|
||||
|
@ -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
|
||||
|
21724
thirdparty/zpl.h
vendored
21724
thirdparty/zpl.h
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user