mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Updates to readme, small fixes to code and organizational refactors
This commit is contained in:
parent
4e61fefc55
commit
30381648b2
@ -311,6 +311,7 @@ Interface :``
|
|||||||
|
|
||||||
Bodies:
|
Bodies:
|
||||||
|
|
||||||
|
* def_body
|
||||||
* def_class_body
|
* def_class_body
|
||||||
* def_enum_body
|
* def_enum_body
|
||||||
* def_export_body
|
* def_export_body
|
||||||
@ -322,8 +323,6 @@ Bodies:
|
|||||||
* def_struct_body
|
* def_struct_body
|
||||||
* def_union_body
|
* def_union_body
|
||||||
|
|
||||||
* def_body
|
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
# Documentation
|
# Documentation
|
||||||
|
|
||||||
This library is currently in a bootstrapping phase.
|
|
||||||
|
|
||||||
Eventually it will have zero dependencies and have its code size severely constricted.
|
|
||||||
|
|
||||||
All dependencies are currently held within `Bloat.hpp` and `Bloat.cpp`
|
|
||||||
|
|
||||||
All the library code is contained in two files: `gen.hpp` and `gen.cpp`
|
All the library code is contained in two files: `gen.hpp` and `gen.cpp`
|
||||||
|
|
||||||
## gen.hpp
|
## gen.hpp
|
||||||
|
|
||||||
While getting fleshed out, all feature macros are defined on the top of the header.
|
Feature Macros:
|
||||||
|
|
||||||
These macros are:
|
|
||||||
|
|
||||||
* `GENCPP_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
|
* `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
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#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
|
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||||
#ifndef GENCPP_PROVIDE_DEPENDENCIES
|
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||||
|
|
||||||
// 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
|
||||||
#pragma region Macros
|
#pragma region Macros
|
||||||
|
111
project/gen.hpp
111
project/gen.hpp
@ -12,7 +12,7 @@
|
|||||||
#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
|
// Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||||
#ifndef GENCPP_ROLL_OWN_DEPENDENCIES
|
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||||
|
|
||||||
#if __clang__
|
#if __clang__
|
||||||
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||||
@ -23,14 +23,8 @@
|
|||||||
# pragma clang diagnostic ignored "-Wunused-function"
|
# pragma clang diagnostic ignored "-Wunused-function"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( GEN_HAS_ATTRIBUTE )
|
|
||||||
# undef GEN_HAS_ATTRIBUTE
|
#pragma region Platform Detection
|
||||||
#endif
|
|
||||||
#if defined( __has_attribute )
|
|
||||||
# define GEN_HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
|
|
||||||
#else
|
|
||||||
# define GEN_HAS_ATTRIBUTE( attribute ) ( 0 )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Platform architecture */
|
/* Platform architecture */
|
||||||
|
|
||||||
@ -117,6 +111,15 @@
|
|||||||
# error Unknown compiler
|
# error Unknown compiler
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined( GEN_HAS_ATTRIBUTE )
|
||||||
|
# undef GEN_HAS_ATTRIBUTE
|
||||||
|
#endif
|
||||||
|
#if defined( __has_attribute )
|
||||||
|
# define GEN_HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
|
||||||
|
#else
|
||||||
|
# define GEN_HAS_ATTRIBUTE( attribute ) ( 0 )
|
||||||
|
#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
|
||||||
@ -159,48 +162,13 @@
|
|||||||
# define forceinline inline
|
# define forceinline inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef count_of
|
#pragma endregion Platform Detection
|
||||||
# define count_of( x ) ( ( size_of( x ) / size_of( 0 [ x ] ) ) / ( ( sw )( ! ( size_of( x ) % size_of( 0 [ x ] ) ) ) ) )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef is_between
|
|
||||||
# define is_between( x, lower, upper ) ( ( ( lower ) <= ( x ) ) && ( ( x ) <= ( upper ) ) )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef min
|
|
||||||
# define min( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef size_of
|
|
||||||
# define size_of( x ) ( sw )( sizeof( x ) )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef swap
|
|
||||||
# define swap( Type, a, b ) \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
Type tmp = ( a ); \
|
|
||||||
( a ) = ( b ); \
|
|
||||||
( b ) = tmp; \
|
|
||||||
} while ( 0 )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef zpl_cast
|
#ifndef zpl_cast
|
||||||
# define zpl_cast( Type ) ( Type )
|
# define zpl_cast( Type ) ( Type )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef global
|
// num_args macro
|
||||||
# define global static // Global variables
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef internal
|
|
||||||
# define internal static // Internal linkage
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef local_persist
|
|
||||||
# define local_persist static // Local Persisting variables
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
// Supports 0-10 arguments
|
// Supports 0-10 arguments
|
||||||
#define macro_num_args_impl( _0, \
|
#define macro_num_args_impl( _0, \
|
||||||
@ -237,14 +205,27 @@
|
|||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Bits
|
||||||
|
|
||||||
#define bit( Value_ ) ( 1 << Value_ )
|
#define bit( Value_ ) ( 1 << Value_ )
|
||||||
#define bitfield_is_equal( Type_, Field_, Mask_ ) ( (Type_(Mask_) & Type_(Field_)) == Type_(Mask_) )
|
#define bitfield_is_equal( Type_, Field_, Mask_ ) ( (Type_(Mask_) & Type_(Field_)) == Type_(Mask_) )
|
||||||
|
|
||||||
|
// Casting
|
||||||
#define ccast( Type_, Value_ ) * const_cast< Type_* >( & (Value_) )
|
#define ccast( Type_, Value_ ) * const_cast< Type_* >( & (Value_) )
|
||||||
#define scast( Type_, Value_ ) static_cast< Type_ >( Value_ )
|
|
||||||
#define rcast( Type_, Value_ ) reinterpret_cast< Type_ >( Value_ )
|
#define rcast( Type_, Value_ ) reinterpret_cast< Type_ >( Value_ )
|
||||||
|
#define scast( Type_, Value_ ) static_cast< Type_ >( Value_ )
|
||||||
#define pcast( Type_, Value_ ) ( * (Type_*)( & (Value_) ) )
|
#define pcast( Type_, Value_ ) ( * (Type_*)( & (Value_) ) )
|
||||||
|
|
||||||
|
// Keywords
|
||||||
|
|
||||||
|
#define global static // Global variables
|
||||||
|
#define internal static // Internal linkage
|
||||||
|
#define local_persist static // Local Persisting variables
|
||||||
|
|
||||||
#define stringize_va( ... ) #__VA_ARGS__
|
#define stringize_va( ... ) #__VA_ARGS__
|
||||||
#define stringize( ... ) stringize_va( __VA_ARGS__ )
|
#define stringize( ... ) stringize_va( __VA_ARGS__ )
|
||||||
|
|
||||||
#define do_once() \
|
#define do_once() \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
@ -280,8 +261,31 @@ while(0);
|
|||||||
|
|
||||||
namespace gen
|
namespace gen
|
||||||
{
|
{
|
||||||
constexpr
|
#ifndef count_of
|
||||||
char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
|
# define count_of( x ) ( ( size_of( x ) / size_of( 0 [ x ] ) ) / ( ( sw )( ! ( size_of( x ) % size_of( 0 [ x ] ) ) ) ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef is_between
|
||||||
|
# define is_between( x, lower, upper ) ( ( ( lower ) <= ( x ) ) && ( ( x ) <= ( upper ) ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef min
|
||||||
|
# define min( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef size_of
|
||||||
|
# define size_of( x ) ( sw )( sizeof( x ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef swap
|
||||||
|
# define swap( Type, a, b ) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
Type tmp = ( a ); \
|
||||||
|
( a ) = ( b ); \
|
||||||
|
( b ) = tmp; \
|
||||||
|
} while ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma region Basic Types
|
#pragma region Basic Types
|
||||||
#ifndef GEN_U8_MIN
|
#ifndef GEN_U8_MIN
|
||||||
@ -406,6 +410,9 @@ namespace gen
|
|||||||
#pragma endregion Basic Types
|
#pragma endregion Basic Types
|
||||||
|
|
||||||
#pragma region Debug
|
#pragma region Debug
|
||||||
|
constexpr
|
||||||
|
char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
|
||||||
|
|
||||||
#ifndef GEN_DEBUG_TRAP
|
#ifndef GEN_DEBUG_TRAP
|
||||||
# if defined( _MSC_VER )
|
# if defined( _MSC_VER )
|
||||||
# if _MSC_VER < 1300
|
# if _MSC_VER < 1300
|
||||||
@ -3012,6 +3019,9 @@ namespace gen
|
|||||||
, Code specifiers = NoCode, Code attributes = NoCode
|
, Code specifiers = NoCode, Code attributes = NoCode
|
||||||
, ModuleFlag mflags = ModuleFlag::None );
|
, ModuleFlag mflags = ModuleFlag::None );
|
||||||
|
|
||||||
|
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
|
||||||
|
Code def_body( CodeT type );
|
||||||
|
|
||||||
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
|
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
|
||||||
/// or provide as an array of Code objects.
|
/// or provide as an array of Code objects.
|
||||||
|
|
||||||
@ -3037,9 +3047,6 @@ namespace gen
|
|||||||
Code def_struct_body ( s32 num, Code* codes );
|
Code def_struct_body ( s32 num, Code* codes );
|
||||||
Code def_union_body ( s32 num, ... );
|
Code def_union_body ( s32 num, ... );
|
||||||
Code def_union_body ( s32 num, Code* codes );
|
Code def_union_body ( s32 num, Code* codes );
|
||||||
|
|
||||||
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
|
|
||||||
Code def_body( CodeT type );
|
|
||||||
# pragma endregion Upfront
|
# pragma endregion Upfront
|
||||||
|
|
||||||
# pragma region Parsing
|
# pragma region Parsing
|
||||||
|
Loading…
Reference in New Issue
Block a user