mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Bugfixes during hiatus
Found while doing some metaprogramming for day 42 of handmade hero.
This commit is contained in:
parent
3dd5482a46
commit
912cc6b538
@ -330,6 +330,7 @@
|
|||||||
<ClCompile Include="project\dependencies\strings.cpp" />
|
<ClCompile Include="project\dependencies\strings.cpp" />
|
||||||
<ClCompile Include="project\dependencies\string_ops.cpp" />
|
<ClCompile Include="project\dependencies\string_ops.cpp" />
|
||||||
<ClCompile Include="project\dependencies\timing.cpp" />
|
<ClCompile Include="project\dependencies\timing.cpp" />
|
||||||
|
<ClCompile Include="project\Example.cpp" />
|
||||||
<ClCompile Include="project\gen.cpp" />
|
<ClCompile Include="project\gen.cpp" />
|
||||||
<ClCompile Include="project\gen.dep.cpp" />
|
<ClCompile Include="project\gen.dep.cpp" />
|
||||||
<ClCompile Include="singleheader\singleheader.cpp" />
|
<ClCompile Include="singleheader\singleheader.cpp" />
|
||||||
|
@ -1125,7 +1125,10 @@ String AST::to_string()
|
|||||||
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
||||||
result.append( "export " );
|
result.append( "export " );
|
||||||
|
|
||||||
result.append_fmt( "template< %S >\n%S", Params->to_string(), Declaration->to_string() );
|
if ( Params )
|
||||||
|
result.append_fmt( "template< %S >\n%S", Params->to_string(), Declaration->to_string() );
|
||||||
|
else
|
||||||
|
result.append_fmt( "template<>\n%S", Declaration->to_string() );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -175,21 +175,21 @@ void define_constants()
|
|||||||
#endif
|
#endif
|
||||||
# undef def_constant_code_type
|
# undef def_constant_code_type
|
||||||
|
|
||||||
# pragma push_macro( "forceinline" )
|
|
||||||
# pragma push_macro( "global" )
|
|
||||||
# pragma push_macro( "internal" )
|
|
||||||
# pragma push_macro( "local_persist" )
|
|
||||||
# pragma push_macro( "neverinline" )
|
|
||||||
# undef forceinline
|
|
||||||
# undef global
|
|
||||||
# undef internal
|
|
||||||
# undef local_persist
|
|
||||||
# undef neverinline
|
|
||||||
|
|
||||||
# define def_constant_spec( Type_, ... ) \
|
# define def_constant_spec( Type_, ... ) \
|
||||||
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
|
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
|
||||||
spec_##Type_.set_global();
|
spec_##Type_.set_global();
|
||||||
|
|
||||||
|
# pragma push_macro("forceinline")
|
||||||
|
# pragma push_macro("global")
|
||||||
|
# pragma push_macro("internal")
|
||||||
|
# pragma push_macro("local_persist")
|
||||||
|
# pragma push_macro("neverinline")
|
||||||
|
# undef forceinline
|
||||||
|
# undef global
|
||||||
|
# undef internal
|
||||||
|
# undef local_persist
|
||||||
|
# undef neverinline
|
||||||
def_constant_spec( const, ESpecifier::Const );
|
def_constant_spec( const, ESpecifier::Const );
|
||||||
def_constant_spec( consteval, ESpecifier::Consteval );
|
def_constant_spec( consteval, ESpecifier::Consteval );
|
||||||
def_constant_spec( constexpr, ESpecifier::Constexpr );
|
def_constant_spec( constexpr, ESpecifier::Constexpr );
|
||||||
@ -218,11 +218,11 @@ void define_constants()
|
|||||||
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
|
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
|
||||||
spec_local_persist.set_global();
|
spec_local_persist.set_global();
|
||||||
|
|
||||||
# pragma pop_macro( "forceinline" )
|
# pragma pop_macro("forceinline")
|
||||||
# pragma pop_macro( "global" )
|
# pragma pop_macro("global")
|
||||||
# pragma pop_macro( "internal" )
|
# pragma pop_macro("internal")
|
||||||
# pragma pop_macro( "local_persist" )
|
# pragma pop_macro("local_persist")
|
||||||
# pragma pop_macro( "neverinline" )
|
# pragma pop_macro("neverinline")
|
||||||
|
|
||||||
# undef def_constant_spec
|
# undef def_constant_spec
|
||||||
}
|
}
|
||||||
|
@ -775,6 +775,18 @@ namespace Parser
|
|||||||
|
|
||||||
if (left)
|
if (left)
|
||||||
move_forward();
|
move_forward();
|
||||||
|
|
||||||
|
if ( current == '=' )
|
||||||
|
{
|
||||||
|
token.Length++;
|
||||||
|
token.IsAssign = true;
|
||||||
|
// token.Flags |= TokFlags::Assignment;
|
||||||
|
// token.Type = TokType::Assign_Multiply;
|
||||||
|
|
||||||
|
if ( left )
|
||||||
|
move_forward();
|
||||||
|
}
|
||||||
|
|
||||||
goto FoundToken;
|
goto FoundToken;
|
||||||
}
|
}
|
||||||
case ';':
|
case ';':
|
||||||
@ -973,7 +985,14 @@ namespace Parser
|
|||||||
|
|
||||||
if ( left )
|
if ( left )
|
||||||
{
|
{
|
||||||
if ( current == '/' )
|
if ( current == '=' )
|
||||||
|
{
|
||||||
|
// token.Type = TokeType::Assign_Divide;
|
||||||
|
move_forward();
|
||||||
|
token.Length++;
|
||||||
|
token.IsAssign = true;
|
||||||
|
}
|
||||||
|
else if ( current == '/' )
|
||||||
{
|
{
|
||||||
token.Type = TokType::Comment;
|
token.Type = TokType::Comment;
|
||||||
token.Length = 2;
|
token.Length = 2;
|
||||||
@ -2820,7 +2839,7 @@ CodeOperator parse_operator_after_ret_type(
|
|||||||
if ( currtok.Text[1] == '=' )
|
if ( currtok.Text[1] == '=' )
|
||||||
op = Assign_Add;
|
op = Assign_Add;
|
||||||
|
|
||||||
if ( currtok.Text[1] == '+' )
|
else if ( currtok.Text[1] == '+' )
|
||||||
op = Increment;
|
op = Increment;
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -2840,7 +2859,7 @@ CodeOperator parse_operator_after_ret_type(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( currtok.Text[1] == '=' )
|
else if ( currtok.Text[1] == '=' )
|
||||||
op = Assign_Subtract;
|
op = Assign_Subtract;
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -3196,6 +3215,12 @@ CodeParam parse_params( bool use_template_capture )
|
|||||||
Context.pop();
|
Context.pop();
|
||||||
return { nullptr };
|
return { nullptr };
|
||||||
}
|
}
|
||||||
|
else if ( check ( TokType::Operator ) && currtok.Text[0] == '>' )
|
||||||
|
{
|
||||||
|
eat( TokType::Operator );
|
||||||
|
Context.pop();
|
||||||
|
return { nullptr };
|
||||||
|
}
|
||||||
|
|
||||||
CodeType type = { nullptr };
|
CodeType type = { nullptr };
|
||||||
Code value = { nullptr };
|
Code value = { nullptr };
|
||||||
|
@ -35,17 +35,17 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
|||||||
return OpValidateResult::Fail; \
|
return OpValidateResult::Fail; \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define check_param_eq_ret() \
|
# define check_param_eq_ret() \
|
||||||
if ( ! is_member_symbol && params_code->ValueType != ret_type ) \
|
if ( ! is_member_symbol && ! params_code->ValueType.is_equal( ret_type) ) \
|
||||||
{ \
|
{ \
|
||||||
log_failure("gen_def_operator: operator%s requires first parameter to equal return type\n" \
|
log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \
|
||||||
"param types: %s\n" \
|
"param types: %s\n" \
|
||||||
"return type: %s", \
|
"return type: %s", \
|
||||||
to_str(op), \
|
to_str(op).Ptr, \
|
||||||
params_code.debug_str(), \
|
params_code.debug_str(), \
|
||||||
ret_type.debug_str() \
|
ret_type.debug_str() \
|
||||||
); \
|
); \
|
||||||
return OpValidateResult::Fail; \
|
return OpValidateResult::Fail; \
|
||||||
}
|
}
|
||||||
#pragma endregion Helper Macros
|
#pragma endregion Helper Macros
|
||||||
|
|
||||||
@ -947,6 +947,7 @@ CodeOperator def_operator( OperatorT op, StrC nspace
|
|||||||
result = (CodeOperator) make_code();
|
result = (CodeOperator) make_code();
|
||||||
result->Name = get_cached_string( { str_len(name), name } );
|
result->Name = get_cached_string( { str_len(name), name } );
|
||||||
result->ModuleFlags = mflags;
|
result->ModuleFlags = mflags;
|
||||||
|
result->Op = op;
|
||||||
|
|
||||||
if ( body )
|
if ( body )
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ CodeBody gen_ecode( char const* path )
|
|||||||
|
|
||||||
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", (StrC)enum_entries, "enum Type : u32 { <entries> NumTypes };"));
|
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", (StrC)enum_entries, "enum Type : u32 { <entries> NumTypes };"));
|
||||||
|
|
||||||
#pragma push_macro( "local_persist" )
|
#pragma push_macro("local_persist")
|
||||||
#undef local_persist
|
#undef local_persist
|
||||||
CodeFn to_str = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
CodeFn to_str = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
||||||
StrC to_str( Type type )
|
StrC to_str( Type type )
|
||||||
@ -45,7 +45,7 @@ CodeBody gen_ecode( char const* path )
|
|||||||
return lookup[ type ];
|
return lookup[ type ];
|
||||||
}
|
}
|
||||||
)));
|
)));
|
||||||
#pragma pop_macro( "local_persist" )
|
#pragma pop_macro("local_persist")
|
||||||
|
|
||||||
CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) );
|
CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) );
|
||||||
CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) );
|
CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) );
|
||||||
@ -86,7 +86,7 @@ CodeBody gen_eoperator( char const* path )
|
|||||||
};
|
};
|
||||||
)));
|
)));
|
||||||
|
|
||||||
#pragma push_macro( "local_persist" )
|
#pragma push_macro("local_persist")
|
||||||
#undef local_persist
|
#undef local_persist
|
||||||
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
|
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
|
||||||
StrC to_str( Type op )
|
StrC to_str( Type op )
|
||||||
@ -99,7 +99,7 @@ CodeBody gen_eoperator( char const* path )
|
|||||||
return lookup[ op ];
|
return lookup[ op ];
|
||||||
}
|
}
|
||||||
)));
|
)));
|
||||||
#pragma pop_macro( "local_persist" )
|
#pragma pop_macro("local_persist")
|
||||||
|
|
||||||
CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
|
CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
|
||||||
|
|
||||||
@ -148,11 +148,11 @@ CodeBody gen_especifier( char const* path )
|
|||||||
}
|
}
|
||||||
)));
|
)));
|
||||||
|
|
||||||
#pragma push_macro( "local_persist" )
|
#pragma push_macro("local_persist")
|
||||||
#pragma push_macro( "do_once_start" )
|
#pragma push_macro("do_once_start")
|
||||||
#pragma push_macro( "do_once_end" )
|
#pragma push_macro("do_once_end")
|
||||||
#pragma push_macro( "forceinline" )
|
#pragma push_macro("forceinline")
|
||||||
#pragma push_macro( "neverinline" )
|
#pragma push_macro("neverinline")
|
||||||
#undef local_persist
|
#undef local_persist
|
||||||
#undef do_once_start
|
#undef do_once_start
|
||||||
#undef do_once_end
|
#undef do_once_end
|
||||||
@ -197,11 +197,11 @@ CodeBody gen_especifier( char const* path )
|
|||||||
return Invalid;
|
return Invalid;
|
||||||
}
|
}
|
||||||
)));
|
)));
|
||||||
#pragma pop_macro( "local_persist" )
|
#pragma pop_macro("local_persist")
|
||||||
#pragma pop_macro( "do_once_start" )
|
#pragma pop_macro("do_once_start")
|
||||||
#pragma pop_macro( "do_once_end" )
|
#pragma pop_macro("do_once_end")
|
||||||
#pragma pop_macro( "forceinline" )
|
#pragma pop_macro("forceinline")
|
||||||
#pragma pop_macro( "neverinline" )
|
#pragma pop_macro("neverinline")
|
||||||
|
|
||||||
CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );
|
CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );
|
||||||
|
|
||||||
@ -260,10 +260,10 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
|||||||
attribute_define_entries.append( "\n");
|
attribute_define_entries.append( "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma push_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" )
|
#pragma push_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
|
||||||
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
|
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
|
||||||
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), attribute_define_entries );
|
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), attribute_define_entries );
|
||||||
#pragma pop_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" )
|
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
|
||||||
|
|
||||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
|
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
|
||||||
enum Type : u32
|
enum Type : u32
|
||||||
@ -274,9 +274,9 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
|||||||
};
|
};
|
||||||
)));
|
)));
|
||||||
|
|
||||||
#pragma push_macro( "local_persist" )
|
#pragma push_macro("local_persist")
|
||||||
#pragma push_macro( "do_once_start" )
|
#pragma push_macro("do_once_start")
|
||||||
#pragma push_macro( "do_once_end" )
|
#pragma push_macro("do_once_end")
|
||||||
#undef local_persist
|
#undef local_persist
|
||||||
#undef do_once_start
|
#undef do_once_start
|
||||||
#undef do_once_end
|
#undef do_once_end
|
||||||
@ -320,9 +320,9 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
|||||||
return Invalid;
|
return Invalid;
|
||||||
}
|
}
|
||||||
)));
|
)));
|
||||||
#pragma pop_macro( "local_persist" )
|
#pragma pop_macro("local_persist")
|
||||||
#pragma pop_macro( "do_once_start" )
|
#pragma pop_macro("do_once_start")
|
||||||
#pragma pop_macro( "do_once_end" )
|
#pragma pop_macro("do_once_end")
|
||||||
|
|
||||||
CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
|
CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
|
||||||
CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
|
CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user