mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
Added is_body to AST and Code types
This commit is contained in:
parent
31691b1466
commit
8ef982003a
@ -90,6 +90,7 @@ CodeBody parse_file( const char* path )
|
||||
{
|
||||
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
||||
CodeBody code = parse_global_body( { file.size, (char const*)file.data } );
|
||||
log_fmt("\nParsed: %s\n", path);
|
||||
return code;
|
||||
}
|
||||
|
||||
@ -126,7 +127,7 @@ int gen_main()
|
||||
header.print( debug );
|
||||
|
||||
CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" );
|
||||
CodeBody memory = def_body(ECode::Struct_Body);
|
||||
CodeBody memory = def_body(ECode::Global_Body);
|
||||
for ( Code entry = parsed_memory.begin(); entry != parsed_memory.end(); ++ entry )
|
||||
{
|
||||
switch (entry->Type)
|
||||
@ -145,12 +146,32 @@ int gen_main()
|
||||
CodeFn fn = entry.cast<CodeFn>();
|
||||
s32 constexpr_found = fn->Specs.remove( ESpecifier::Constexpr );
|
||||
if (constexpr_found > -1) {
|
||||
log_fmt("Found constexpr proc\n");
|
||||
log_fmt("Found constexpr: %S\n", entry->to_string());
|
||||
fn->Specs.append(ESpecifier::Inline);
|
||||
}
|
||||
memory.append(entry);
|
||||
}
|
||||
break;
|
||||
case ECode::Template:
|
||||
{
|
||||
CodeTemplate tmpl = entry.cast<CodeTemplate>();
|
||||
if ( tmpl->Declaration->Name.contains(txt("swap")))
|
||||
{
|
||||
CodeBody macro_swap = parse_global_body( txt(R"(
|
||||
#define swap( a, b ) \
|
||||
do \
|
||||
{ \
|
||||
typeof( a ) temp = ( a ); \
|
||||
( a ) = ( b ); \
|
||||
( b ) = temp; \
|
||||
} while ( 0 )
|
||||
)"
|
||||
));
|
||||
memory.append(macro_swap);
|
||||
log_fmt( "\nmacro swap: %S\n", macro_swap.to_string() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ECode::Class:
|
||||
case ECode::Struct:
|
||||
{
|
||||
@ -175,17 +196,26 @@ int gen_main()
|
||||
break;
|
||||
case ECode::Preprocess_If:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_memory );
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_memory );
|
||||
if (found) break;
|
||||
|
||||
memory.append(entry);
|
||||
}
|
||||
break;
|
||||
case ECode::Preprocess_IfDef:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_memory );
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_memory );
|
||||
if (found) break;
|
||||
|
||||
memory.append(entry);
|
||||
}
|
||||
break;
|
||||
case ECode::Preprocess_Pragma:
|
||||
{
|
||||
swap_pragma_region_implementation( txt("FixedArena"), gen_fixed_arenas, entry, memory);
|
||||
b32 found = swap_pragma_region_implementation( txt("FixedArena"), gen_fixed_arenas, entry, memory);
|
||||
if (found) break;
|
||||
|
||||
memory.append(entry);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
@ -194,26 +224,28 @@ int gen_main()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
header.print( memory );
|
||||
header.print( dump_to_scratch_and_retireve(memory) );
|
||||
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
||||
header.print( string_ops );
|
||||
|
||||
CodeBody printing_parsed = parse_file( project_dir "dependencies/printing.hpp" );
|
||||
CodeBody printing = def_body(ECode::Struct_Body);
|
||||
CodeBody printing = def_body(ECode::Global_Body);
|
||||
for ( Code entry = printing_parsed.begin(); entry != printing_parsed.end(); ++ entry )
|
||||
{
|
||||
switch (entry->Type)
|
||||
{
|
||||
case ECode::Preprocess_IfDef:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, printing_parsed );
|
||||
}
|
||||
}
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, printing_parsed );
|
||||
if (found) break;
|
||||
|
||||
if (entry->Type == ECode::Variable &&
|
||||
contains(entry->Name, txt("Msg_Invalid_Value")))
|
||||
printing.append(entry);
|
||||
}
|
||||
break;
|
||||
case ECode::Variable:
|
||||
{
|
||||
if (contains(entry->Name, txt("Msg_Invalid_Value")))
|
||||
{
|
||||
CodeDefine define = def_define(entry->Name, entry->Value->Content);
|
||||
printing.append(define);
|
||||
@ -221,42 +253,55 @@ int gen_main()
|
||||
}
|
||||
printing.append(entry);
|
||||
}
|
||||
|
||||
header.print(printing);
|
||||
|
||||
CodeBody parsed_containers = parse_file( project_dir "dependencies/containers.hpp" );
|
||||
CodeBody containers = def_body(ECode::Struct_Body);
|
||||
for ( Code entry = parsed_containers.begin(); entry != parsed_containers.end(); ++ entry )
|
||||
{
|
||||
switch ( entry->Type )
|
||||
{
|
||||
case ECode::Preprocess_Pragma:
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
found = swap_pragma_region_implementation( txt("Array"), gen_array_base, entry, containers);
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
|
||||
found = swap_pragma_region_implementation( txt("HashTable"), gen_hashtable_base, entry, containers);
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
|
||||
containers.append(entry);
|
||||
}
|
||||
default:
|
||||
printing.append(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
header.print(dump_to_scratch_and_retireve(printing));
|
||||
|
||||
header.print(containers);
|
||||
CodeBody containers = def_body(ECode::Global_Body);
|
||||
{
|
||||
containers.append( def_pragma(code(region Containers)));
|
||||
|
||||
containers.append( gen_array_base() );
|
||||
containers.append( gen_hashtable_base() );
|
||||
|
||||
containers.append( def_pragma(code(endregion Containers)));
|
||||
}
|
||||
header.print(fmt_newline);
|
||||
header.print(dump_to_scratch_and_retireve(containers));
|
||||
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
header.print( hashing );
|
||||
|
||||
CodeBody parsed_strings = parse_file( project_dir "dependencies/strings.hpp" );
|
||||
CodeBody strings = def_body(ECode::Global_Body);
|
||||
for ( Code entry = parsed_strings.begin(); entry != parsed_strings.end(); ++ entry )
|
||||
{
|
||||
switch (entry->Type)
|
||||
{
|
||||
case ECode::Preprocess_IfDef:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_strings );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
strings.append(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
header.print(dump_to_scratch_and_retireve(strings));
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_end );
|
||||
}
|
||||
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
|
||||
format_file( "gen/gen.h" );
|
||||
// format_file( "gen/gen.h" );
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
|
@ -19,7 +19,7 @@ CodeBody gen_array_base()
|
||||
// Code grow_formula = untyped_str( txt( "#define gen_array_grow_formula( value ) ( 2 * value + 8 )\n" ));
|
||||
Code get_header = untyped_str( txt( "#define array_get_header( Type, self ) ( (ArrayHeader*)( self ) - 1)\n" ));
|
||||
|
||||
return def_global_body( args( td_header, header, get_header ) );
|
||||
return def_global_body( args( fmt_newline, td_header, header, get_header, fmt_newline ) );
|
||||
};
|
||||
|
||||
CodeBody gen_array( StrC type, StrC array_name )
|
||||
|
@ -7,9 +7,13 @@ using SwapContentProc = CodeBody(void);
|
||||
|
||||
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& body )
|
||||
{
|
||||
b32 found = false;
|
||||
CodePreprocessCond cond = entry_iter.cast<CodePreprocessCond>();
|
||||
if ( cond->Content.contains(cond_sig) )
|
||||
{
|
||||
log_fmt("Preprocess cond found: %S\n", cond->Content);
|
||||
found = true;
|
||||
|
||||
s32 depth = 1;
|
||||
++ entry_iter; for(b32 continue_for = true; continue_for && entry_iter != body.end(); ) switch
|
||||
(entry_iter->Type) {
|
||||
@ -34,7 +38,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
|
||||
}
|
||||
}
|
||||
|
||||
return entry_iter != body.end();
|
||||
return found;
|
||||
}
|
||||
|
||||
bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_content, Code& entry_iter, CodeBody& body )
|
||||
|
@ -4406,6 +4406,7 @@ CodeTemplate parse_template()
|
||||
result->Params = params;
|
||||
result->Declaration = definition;
|
||||
result->ModuleFlags = mflags;
|
||||
// result->Name = definition->Name;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
|
@ -14,20 +14,17 @@ template<class TType>
|
||||
using TRemoveConst = typename RemoveConst<TType>::Type;
|
||||
|
||||
#pragma region Array
|
||||
#if ! GEN_COMPILER_C
|
||||
#define Array(Type) Array<Type>
|
||||
|
||||
// #define array_init(Type, ...) array_init <Type>(__VA_ARGS__)
|
||||
// #define array_init_reserve(Type, ...) array_init_reserve<Type>(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
struct ArrayHeader;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
template<class Type> struct Array;
|
||||
template<class Type> struct Array;
|
||||
#else
|
||||
template<class Type>
|
||||
using Array = Type*;
|
||||
template<class Type> using Array = Type*;
|
||||
#endif
|
||||
|
||||
usize array_grow_formula(ssize value);
|
||||
|
@ -205,7 +205,7 @@
|
||||
# define foreach(Type, entry_id, iterable) for ( Type entry_id : iterable )
|
||||
#endif
|
||||
|
||||
#if GENC_COMPILERC
|
||||
#if GEN_COMPILER_C
|
||||
# if __STDC_VERSION__ >= 202311L
|
||||
# define enum_underlying(type) : type
|
||||
# else
|
||||
|
@ -14,23 +14,13 @@
|
||||
#define GEN__HIGHS ( GEN__ONES * ( GEN_U8_MAX / 2 + 1 ) )
|
||||
#define GEN__HAS_ZERO( x ) ( ( ( x ) - GEN__ONES ) & ~( x ) & GEN__HIGHS )
|
||||
|
||||
#if ! GEN_COMPILER_C
|
||||
template< class Type >
|
||||
void swap( Type& a, Type& b )
|
||||
{
|
||||
template< class Type >
|
||||
void swap( Type& a, Type& b )
|
||||
{
|
||||
Type tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
#else
|
||||
#define swap( a, b ) \
|
||||
do { \
|
||||
typeof(a) \
|
||||
temp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = temp; \
|
||||
} while(0)
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Checks if value is power of 2.
|
||||
b32 is_power_of_two( ssize x );
|
||||
|
@ -106,7 +106,7 @@
|
||||
# define GEN_GCC_VERSION_CHECK(major,minor,patch) (0)
|
||||
#endif
|
||||
|
||||
#ifndef GEN_COMPIELR_C
|
||||
#ifndef GEN_COMPILER_C
|
||||
# if defined(__STDC_VERSION__)
|
||||
# define GEN_COMPILER_C 1
|
||||
# else
|
||||
|
@ -11,8 +11,10 @@ struct StrC
|
||||
ssize Len;
|
||||
char const* Ptr;
|
||||
|
||||
#if ! GEN_COMPILER_C
|
||||
operator char const* () const { return Ptr; }
|
||||
char const& operator[]( ssize index ) const { return Ptr[index]; }
|
||||
#endif
|
||||
};
|
||||
|
||||
#define cast_to_strc( str ) * rcast( StrC*, (str) - sizeof(ssize) )
|
||||
@ -29,12 +31,7 @@ StrC to_str( char const* str ) {
|
||||
// I kept it for simplicty of porting but its not necessary to keep it that way.
|
||||
#pragma region String
|
||||
struct StringHeader;
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef char* String;
|
||||
#else
|
||||
struct String;
|
||||
#endif
|
||||
|
||||
String string_make(AllocatorInfo allocator, char const* str);
|
||||
String string_make(AllocatorInfo allocator, StrC str);
|
||||
|
Loading…
Reference in New Issue
Block a user