2023-08-28 20:46:50 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-08-21 17:30:13 -07:00
|
|
|
#pragma once
|
2023-08-21 20:02:20 -07:00
|
|
|
#include "interface.cpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2023-08-03 20:18:33 -07:00
|
|
|
#pragma region Upfront
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
enum OpValidateResult : u32
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
OpValResult_Fail,
|
|
|
|
OpValResult_Global,
|
|
|
|
OpValResult_Member
|
2023-07-24 14:45:27 -07:00
|
|
|
};
|
|
|
|
|
2024-12-10 10:56:56 -08:00
|
|
|
internal neverinline
|
2024-12-11 10:33:35 -08:00
|
|
|
OpValidateResult operator__validate( Operator op, CodeParams params_code, CodeTypename ret_type, CodeSpecifiers specifier )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 10:51:29 -08:00
|
|
|
if ( op == Op_Invalid )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
log_failure("gen::def_operator: op cannot be invalid");
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma region Helper Macros
|
2024-12-07 14:17:02 -08:00
|
|
|
# define check_params() \
|
|
|
|
if ( ! params_code ) \
|
|
|
|
{ \
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: params is null and operator %S requires it", operator_to_str(op)); \
|
2024-12-07 14:17:02 -08:00
|
|
|
return OpValResult_Fail; \
|
|
|
|
} \
|
|
|
|
if ( params_code->Type != CT_Parameters ) \
|
|
|
|
{ \
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: params is not of Parameters type - %S", code_debug_str( cast(Code, params_code))); \
|
2024-12-07 14:17:02 -08:00
|
|
|
return OpValResult_Fail; \
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
# define check_param_eq_ret() \
|
|
|
|
if ( ! is_member_symbol && ! code_is_equal(cast(Code, params_code->ValueType), cast(Code, ret_type)) ) \
|
|
|
|
{ \
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S requires first parameter to equal return type\n" \
|
|
|
|
"param types: %S\n" \
|
|
|
|
"return type: %S", \
|
|
|
|
operator_to_str(op), \
|
2024-12-07 14:17:02 -08:00
|
|
|
code_debug_str(cast(Code, params_code)), \
|
|
|
|
code_debug_str(cast(Code, ret_type)) \
|
|
|
|
); \
|
|
|
|
return OpValResult_Fail; \
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
#pragma endregion Helper Macros
|
|
|
|
|
|
|
|
if ( ! ret_type )
|
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: ret_type is null but is required by operator %S", operator_to_str(op));
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( ret_type->Type != CT_Typename )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S - ret_type is not of typename type - %S",
|
|
|
|
operator_to_str(op),
|
|
|
|
code_debug_str(cast(Code, ret_type))
|
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_member_symbol = false;
|
|
|
|
|
|
|
|
switch ( op )
|
|
|
|
{
|
|
|
|
# define specs( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_Assign:
|
2023-07-24 14:45:27 -07:00
|
|
|
check_params();
|
|
|
|
|
|
|
|
if ( params_code->NumEntries > 1 )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_operator: "
|
2024-12-14 05:04:54 -08:00
|
|
|
"operator %S does not support non-member definition (more than one parameter provided) - %S",
|
2024-12-06 02:29:17 -08:00
|
|
|
operator_to_str(op),
|
2024-12-06 21:21:09 -08:00
|
|
|
code_debug_str(cast(Code, params_code))
|
2023-07-24 17:59:20 -07:00
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
is_member_symbol = true;
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_Assign_Add:
|
|
|
|
case Op_Assign_Subtract:
|
|
|
|
case Op_Assign_Multiply:
|
|
|
|
case Op_Assign_Divide:
|
|
|
|
case Op_Assign_Modulo:
|
|
|
|
case Op_Assign_BAnd:
|
|
|
|
case Op_Assign_BOr:
|
|
|
|
case Op_Assign_BXOr:
|
|
|
|
case Op_Assign_LShift:
|
|
|
|
case Op_Assign_RShift:
|
2023-07-24 14:45:27 -07:00
|
|
|
check_params();
|
|
|
|
|
|
|
|
if ( params_code->NumEntries == 1 )
|
|
|
|
is_member_symbol = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
check_param_eq_ret();
|
|
|
|
|
|
|
|
if (params_code->NumEntries > 2 )
|
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S may not be defined with more than two parametes - param count; %d\n%S"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
, params_code->NumEntries
|
2024-12-06 21:21:09 -08:00
|
|
|
, code_debug_str(cast(Code, params_code))
|
2023-07-24 17:59:20 -07:00
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_Increment:
|
|
|
|
case Op_Decrement:
|
2023-07-24 14:45:27 -07:00
|
|
|
// If its not set, it just means its a prefix member op.
|
|
|
|
if ( params_code )
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( params_code->Type != CT_Parameters )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S params code provided is not of Parameters type - %S"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2024-12-06 21:21:09 -08:00
|
|
|
, code_debug_str(cast(Code, params_code))
|
2023-07-24 17:59:20 -07:00
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ( params_code->NumEntries )
|
|
|
|
{
|
|
|
|
case 1:
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( code_is_equal((Code)params_code->ValueType, (Code)t_int ) )
|
2023-07-24 14:45:27 -07:00
|
|
|
is_member_symbol = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
check_param_eq_ret();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
check_param_eq_ret();
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! code_is_equal((Code)params_get(params_code, 1), (Code)t_int ) )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
log_failure("gen::def_operator: "
|
2024-12-14 05:04:54 -08:00
|
|
|
"operator %S requires second parameter of non-member definition to be int for post-decrement",
|
2024-12-06 02:29:17 -08:00
|
|
|
operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S recieved unexpected number of parameters recived %d instead of 0-2"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
, params_code->NumEntries
|
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_Unary_Plus:
|
|
|
|
case Op_Unary_Minus:
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( ! params_code )
|
|
|
|
is_member_symbol = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( params_code->Type != CT_Parameters )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: params is not of Parameters type - %S", code_debug_str((Code)params_code));
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( code_is_equal((Code)params_code->ValueType, (Code)ret_type ) )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
log_failure("gen::def_operator: "
|
2024-12-14 05:04:54 -08:00
|
|
|
"operator %S is non-member symbol yet first paramter does not equal return type\n"
|
|
|
|
"param type: %S\n"
|
|
|
|
"return type: %S\n"
|
2024-12-06 21:21:09 -08:00
|
|
|
, code_debug_str((Code)params_code)
|
|
|
|
, code_debug_str((Code)ret_type)
|
2023-07-24 17:59:20 -07:00
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( params_code->NumEntries > 1 )
|
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S may not have more than one parameter - param count: %d"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
, params_code->NumEntries
|
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_BNot:
|
2024-04-17 14:40:32 -07:00
|
|
|
{
|
|
|
|
// Some compilers let you do this...
|
|
|
|
#if 0
|
|
|
|
if ( ! ret_type.is_equal( t_bool) )
|
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure( "gen::def_operator: operator %S return type is not a boolean - %S", operator_to_str(op) code_debug_str(params_code) );
|
2024-04-17 14:40:32 -07:00
|
|
|
return OpValidateResult::Fail;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( ! params_code )
|
|
|
|
is_member_symbol = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( params_code->Type != CT_Parameters )
|
2024-04-17 14:40:32 -07:00
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure( "gen::def_operator: operator %S - params is not of Parameters type - %S", operator_to_str(op), code_debug_str((Code)params_code) );
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( params_code->NumEntries > 1 )
|
|
|
|
{
|
|
|
|
log_failure(
|
2024-12-14 05:04:54 -08:00
|
|
|
"gen::def_operator: operator %S may not have more than one parameter - param count: %d",
|
2024-12-07 14:17:02 -08:00
|
|
|
operator_to_str( op ),
|
|
|
|
params_code->NumEntries
|
2024-04-17 14:40:32 -07:00
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_Add:
|
|
|
|
case Op_Subtract:
|
|
|
|
case Op_Multiply:
|
|
|
|
case Op_Divide:
|
|
|
|
case Op_Modulo:
|
|
|
|
case Op_BAnd:
|
|
|
|
case Op_BOr:
|
|
|
|
case Op_BXOr:
|
|
|
|
case Op_LShift:
|
|
|
|
case Op_RShift:
|
2023-07-24 14:45:27 -07:00
|
|
|
check_params();
|
|
|
|
|
|
|
|
switch ( params_code->NumEntries )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
is_member_symbol = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2024-12-14 05:04:54 -08:00
|
|
|
// This is allowed for arithemtic operators
|
|
|
|
// if ( ! code_is_equal((Code)params_code->ValueType, (Code)ret_type ) )
|
|
|
|
// {
|
|
|
|
// log_failure("gen::def_operator: "
|
|
|
|
// "operator %S is non-member symbol yet first paramter does not equal return type\n"
|
|
|
|
// "param type: %S\n"
|
|
|
|
// "return type: %S\n"
|
|
|
|
// , code_debug_str((Code)params_code)
|
|
|
|
// , code_debug_str((Code)ret_type)
|
|
|
|
// );
|
|
|
|
// return OpValResult_Fail;
|
|
|
|
// }
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S recieved unexpected number of paramters recived %d instead of 0-2"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
, params_code->NumEntries
|
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_UnaryNot:
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( ! params_code )
|
|
|
|
is_member_symbol = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( params_code->Type != CT_Parameters )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S - params is not of Parameters type - %S", operator_to_str(op), code_debug_str((Code)params_code));
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( params_code->NumEntries != 1 )
|
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S recieved unexpected number of paramters recived %d instead of 0-1"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
, params_code->NumEntries
|
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! code_is_equal((Code)ret_type, (Code)t_bool ))
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S return type must be of type bool - %S"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2024-12-06 21:21:09 -08:00
|
|
|
, code_debug_str((Code)ret_type)
|
2023-07-24 17:59:20 -07:00
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_LAnd:
|
|
|
|
case Op_LOr:
|
|
|
|
case Op_LEqual:
|
|
|
|
case Op_LNot:
|
|
|
|
case Op_Lesser:
|
|
|
|
case Op_Greater:
|
|
|
|
case Op_LesserEqual:
|
|
|
|
case Op_GreaterEqual:
|
2023-07-24 14:45:27 -07:00
|
|
|
check_params();
|
|
|
|
|
|
|
|
switch ( params_code->NumEntries )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
is_member_symbol = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S recieved unexpected number of paramters recived %d instead of 1-2"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
, params_code->NumEntries
|
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_Indirection:
|
|
|
|
case Op_AddressOf:
|
|
|
|
case Op_MemberOfPointer:
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( params_code && params_code->NumEntries > 1)
|
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S recieved unexpected number of paramters recived %d instead of 0-1"
|
2024-12-06 02:29:17 -08:00
|
|
|
, operator_to_str(op)
|
2023-07-24 17:59:20 -07:00
|
|
|
, params_code->NumEntries
|
|
|
|
);
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is_member_symbol = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_PtrToMemOfPtr:
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( params_code )
|
|
|
|
{
|
2024-12-14 05:04:54 -08:00
|
|
|
log_failure("gen::def_operator: operator %S expects no paramters - %S", operator_to_str(op), code_debug_str((Code)params_code));
|
2024-12-03 12:19:39 -08:00
|
|
|
return OpValResult_Fail;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_Subscript:
|
|
|
|
case Op_FunctionCall:
|
|
|
|
case Op_Comma:
|
2023-07-24 14:45:27 -07:00
|
|
|
check_params();
|
|
|
|
break;
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-03 10:51:29 -08:00
|
|
|
case Op_New:
|
|
|
|
case Op_Delete:
|
2024-04-17 14:40:32 -07:00
|
|
|
// This library doesn't support validating new and delete yet.
|
|
|
|
break;
|
2023-07-24 14:45:27 -07:00
|
|
|
# undef specs
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
return is_member_symbol ? OpValResult_Member : OpValResult_Global;
|
2023-07-24 14:45:27 -07:00
|
|
|
# undef check_params
|
|
|
|
# undef check_ret_type
|
|
|
|
# undef check_param_eq_ret
|
|
|
|
}
|
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
forceinline
|
2024-12-12 09:55:15 -08:00
|
|
|
bool name__check( char const* context, Str name )
|
2024-12-12 08:35:50 -08:00
|
|
|
{
|
|
|
|
if ( name.Len <= 0 ) {
|
|
|
|
log_failure( "gen::%s: Invalid name length provided - %d", name.Len );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( name.Ptr == nullptr ) {
|
|
|
|
log_failure( "gen::%s: name is null" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
#define name_check( context, name ) name__check( #context, name )
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
forceinline
|
|
|
|
bool null__check( char const* context, char const* code_id, Code code ) {
|
|
|
|
if ( code == nullptr ) {
|
|
|
|
log_failure( "gen::%s: %s provided is null", context, code_id );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
#define null_check( context, code ) null__check( #context, #code, cast(Code, code) )
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
/*
|
2024-12-16 18:48:01 -08:00
|
|
|
The implementation of the upfront constructors involves doing three things:
|
2023-07-24 14:45:27 -07:00
|
|
|
* Validate the arguments given to construct the intended type of AST is valid.
|
|
|
|
* Construct said AST type.
|
|
|
|
* Lock the AST (set to readonly) and return the valid object.
|
|
|
|
|
|
|
|
If any of the validation fails, it triggers a call to log_failure with as much info the give the user so that they can hopefully
|
|
|
|
identify the issue without having to debug too much (at least they can debug though...)
|
|
|
|
|
|
|
|
The largest of the functions is related to operator overload definitions.
|
|
|
|
The library validates a good protion of their form and thus the argument processing for is quite a bit.
|
|
|
|
*/
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeAttributes def_attributes( Str content )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( content.Len <= 0 || content.Ptr == nullptr ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure( "gen::def_attributes: Invalid attributes provided" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
Code
|
|
|
|
result = make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_PlatformAttributes;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( content );
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Content = result->Name;
|
|
|
|
return (CodeAttributes) result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeComment def_comment( Str content )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( content.Len <= 0 || content.Ptr == nullptr )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_comment: Invalid comment provided:" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-13 16:16:52 -08:00
|
|
|
StrBuilder cmt_formatted = strbuilder_make_reserve( _ctx->Allocator_Temp, kilobytes(1) );
|
2023-08-22 21:05:58 -07:00
|
|
|
char const* end = content.Ptr + content.Len;
|
|
|
|
char const* scanner = content.Ptr;
|
|
|
|
s32 curr = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char const* next = scanner;
|
|
|
|
s32 length = 0;
|
|
|
|
while ( next != end && scanner[ length ] != '\n' )
|
|
|
|
{
|
|
|
|
next = scanner + length;
|
|
|
|
length++;
|
|
|
|
}
|
|
|
|
length++;
|
|
|
|
|
2024-12-13 16:16:52 -08:00
|
|
|
strbuilder_append_fmt(& cmt_formatted, "//%.*s", length, scanner );
|
2023-08-22 21:05:58 -07:00
|
|
|
scanner += length;
|
|
|
|
}
|
|
|
|
while ( scanner <= end );
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
if ( * strbuilder_back(cmt_formatted) != '\n' )
|
|
|
|
strbuilder_append_str( & cmt_formatted, txt("\n") );
|
2023-08-23 10:17:22 -07:00
|
|
|
|
2024-12-13 10:20:16 -08:00
|
|
|
Str name = strbuilder_to_str(cmt_formatted);
|
2024-12-09 11:55:02 -08:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
Code
|
|
|
|
result = make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Comment;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Content = result->Name;
|
2023-08-23 10:17:22 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_free(& cmt_formatted);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return (CodeComment) result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
CodeConstructor def_constructor( Opts_def_constructor p )
|
2023-08-07 00:10:45 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.params && p.params->Type != CT_Parameters ) {
|
|
|
|
log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str((Code)p.params));
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
CodeConstructor result = (CodeConstructor) make_code();
|
|
|
|
if ( p.params ) {
|
|
|
|
result->Params = p.params;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.initializer_list ) {
|
|
|
|
result->InitializerList = p.initializer_list;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.body )
|
2023-08-07 00:10:45 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
switch ( p.body->Type ) {
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Body:
|
|
|
|
case CT_Untyped:
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-12 08:35:50 -08:00
|
|
|
log_failure("gen::def_constructor: body must be either of Function_Body or Untyped type - %s", code_debug_str(p.body));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Constructor;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = p.body;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Constructor_Fwd;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeClass def_class( Str name, Opts_def_struct p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_class, name ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
|
|
|
log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(p.attributes) );
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( p.parent && ( p.parent->Type != CT_Class && p.parent->Type != CT_Struct && p.parent->Type != CT_Typename && p.parent->Type != CT_Untyped ) ) {
|
|
|
|
log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", code_debug_str(p.parent) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeClass
|
2024-12-14 15:49:41 -08:00
|
|
|
result = (CodeClass) make_code();
|
|
|
|
result->Name = cache_str( name );
|
|
|
|
result->ModuleFlags = p.mflags;
|
|
|
|
result->Attributes = p.attributes;
|
|
|
|
result->ParentAccess = p.parent_access;
|
|
|
|
result->ParentType = p.parent;
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.body )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
switch ( p.body->Type )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Body:
|
|
|
|
case CT_Untyped:
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-12 08:35:50 -08:00
|
|
|
log_failure("gen::def_class: body must be either of Class_Body or Untyped type - %s", code_debug_str(p.body));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Type = CT_Class;
|
|
|
|
result->Body = p.body;
|
|
|
|
result->Body->Parent = cast(Code, result);
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
else {
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Class_Fwd;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
for (s32 idx = 0; idx < p.num_interfaces; idx++ ) {
|
|
|
|
class_add_interface(result, p.interfaces[idx] );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-14 15:49:41 -08:00
|
|
|
CodeDefine def_define( Str name, MacroType type, Opts_def_define p )
|
2023-07-29 22:21:04 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_define, name ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-29 22:21:04 -07:00
|
|
|
}
|
|
|
|
CodeDefine
|
|
|
|
result = (CodeDefine) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Preprocess_Define;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-14 15:49:41 -08:00
|
|
|
result->Params = p.params;
|
|
|
|
if ( p.content.Len <= 0 || p.content.Ptr == nullptr )
|
2024-12-14 18:21:13 -08:00
|
|
|
result->Body = untyped_str( txt("\n") );
|
2024-04-17 14:40:32 -07:00
|
|
|
else
|
2024-12-14 18:21:13 -08:00
|
|
|
result->Body = untyped_str( strbuilder_to_str(strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S\n", p.content)) );
|
2023-07-29 22:21:04 -07:00
|
|
|
|
2024-12-14 15:49:41 -08:00
|
|
|
b32 register_define = ! p.dont_register_to_preprocess_macros;
|
|
|
|
if ( register_define ) {
|
2024-12-15 07:08:28 -08:00
|
|
|
Macro macro_entry = { result->Name, type, p.flags };
|
|
|
|
register_macro(macro_entry);
|
2024-12-10 16:31:50 -08:00
|
|
|
}
|
2023-07-29 22:21:04 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
CodeDestructor def_destructor( Opts_def_destructor p )
|
2023-08-07 00:10:45 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) {
|
|
|
|
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", code_debug_str(p.specifiers) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
2024-12-04 21:40:51 -08:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
CodeDestructor
|
|
|
|
result = (CodeDestructor) make_code();
|
|
|
|
result->Specs = p.specifiers;
|
|
|
|
if ( p.body )
|
2023-08-07 00:10:45 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
switch ( p.body->Type )
|
2023-08-07 00:10:45 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Body:
|
|
|
|
case CT_Untyped:
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-12 08:35:50 -08:00
|
|
|
log_failure("gen::def_destructor: body must be either of Function_Body or Untyped type - %s", code_debug_str(p.body));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Destructor;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = p.body;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Destructor_Fwd;
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeEnum def_enum( Str name, Opts_def_enum p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_enum, name ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.type && p.type->Type != CT_Typename ) {
|
|
|
|
log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", code_debug_str(p.type) );
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
|
|
|
log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(p.attributes) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeEnum
|
|
|
|
result = (CodeEnum) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-12 08:35:50 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
|
|
|
if ( p.body )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
switch ( p.body->Type )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Body:
|
|
|
|
case CT_Untyped:
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-12 08:35:50 -08:00
|
|
|
log_failure( "gen::def_enum: body must be of Enum_Body or Untyped type %s", code_debug_str(p.body));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Type = p.specifier == EnumDecl_Class ?
|
2024-12-03 12:19:39 -08:00
|
|
|
CT_Enum_Class : CT_Enum;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = p.body;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Type = p.specifier == EnumDecl_Class ?
|
2024-12-03 12:19:39 -08:00
|
|
|
CT_Enum_Class_Fwd : CT_Enum_Fwd;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Attributes = p.attributes;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.type ) {
|
|
|
|
result->UnderlyingType = p.type;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
else if ( p.type_macro ) {
|
|
|
|
result->UnderlyingTypeMacro = p.type_macro;
|
2024-12-11 10:33:35 -08:00
|
|
|
}
|
2024-12-03 12:19:39 -08:00
|
|
|
else if ( result->Type != CT_Enum_Class_Fwd && result->Type != CT_Enum_Fwd )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
log_failure( "gen::def_enum: enum forward declaration must have an underlying type" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeExec def_execution( Str content )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( content.Len <= 0 || content.Ptr == nullptr ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure( "gen::def_execution: Invalid execution provided" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
CodeExec
|
|
|
|
result = (CodeExec) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Execution;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Content = cache_str( content );
|
2024-12-12 08:35:50 -08:00
|
|
|
return result;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeExtern def_extern_link( Str name, CodeBody body )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check(def_extern_link, name) || ! null_check(def_extern_link, body) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( body->Type != CT_Extern_Linkage_Body && body->Type != CT_Untyped ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::def_extern_linkage: body is not of extern_linkage or untyped type %s", code_debug_str(body));
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeExtern
|
|
|
|
result = (CodeExtern)make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Extern_Linkage;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Body = body;
|
2024-12-12 08:35:50 -08:00
|
|
|
return result;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeFriend def_friend( Code declaration )
|
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! null_check( def_friend, declaration ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
switch ( declaration->Type )
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Fwd:
|
|
|
|
case CT_Function_Fwd:
|
|
|
|
case CT_Operator_Fwd:
|
|
|
|
case CT_Struct_Fwd:
|
|
|
|
case CT_Class:
|
|
|
|
case CT_Function:
|
|
|
|
case CT_Operator:
|
|
|
|
case CT_Struct:
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::def_friend: requires declartion to have class, function, operator, or struct - %s", code_debug_str(declaration));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeFriend
|
2024-12-12 08:35:50 -08:00
|
|
|
result = (CodeFriend) make_code();
|
|
|
|
result->Type = CT_Friend;
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Declaration = declaration;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeFn def_function( Str name, Opts_def_function p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_function, name )) {
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.params && p.params->Type != CT_Parameters ) {
|
|
|
|
log_failure( "gen::def_function: params was not a `Parameters` type: %s", code_debug_str(p.params) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.ret_type && p.ret_type->Type != CT_Typename ) {
|
|
|
|
log_failure( "gen::def_function: ret_type was not a Typename: %s", code_debug_str(p.ret_type) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.specs && p.specs-> Type != CT_Specifiers ) {
|
|
|
|
log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", code_debug_str(p.specs) );
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( p.attrs && p.attrs->Type != CT_PlatformAttributes ) {
|
|
|
|
log_failure( "gen::def_function: attributes was not a `PlatformAttributes` type: %s", code_debug_str(p.attrs) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeFn
|
|
|
|
result = (CodeFn) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-12 08:35:50 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
|
|
|
if ( p.body )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
switch ( p.body->Type )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Body:
|
|
|
|
case CT_Execution:
|
|
|
|
case CT_Untyped:
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
log_failure("gen::def_function: body must be either of Function_Body, Execution, or Untyped type. %s", code_debug_str(p.body));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Function;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = p.body;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Function_Fwd;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Attributes = p.attrs;
|
|
|
|
result->Specs = p.specs;
|
|
|
|
result->Params = p.params;
|
|
|
|
result->ReturnType = p.ret_type ? p.ret_type : t_void;
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeInclude def_include( Str path, Opts_def_include p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( path.Len <= 0 || path.Ptr == nullptr ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure( "gen::def_include: Invalid path provided - %d" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder content = p.foreign ?
|
2024-12-13 16:16:52 -08:00
|
|
|
strbuilder_fmt_buf( _ctx->Allocator_Temp, "<%.*s>", path.Len, path.Ptr )
|
|
|
|
: strbuilder_fmt_buf( _ctx->Allocator_Temp, "\"%.*s\"", path.Len, path.Ptr );
|
2023-08-23 10:17:22 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
CodeInclude
|
|
|
|
result = (CodeInclude) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Preprocess_Include;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( strbuilder_to_str(content) );
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Content = result->Name;
|
2024-12-12 08:35:50 -08:00
|
|
|
return result;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeModule def_module( Str name, Opts_def_module p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_module, name )) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
CodeModule
|
|
|
|
result = (CodeModule) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Module;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-02 21:45:30 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
2024-12-12 08:35:50 -08:00
|
|
|
return result;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_namespace, name )) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( ! null_check( def_namespace, body)) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( body && body->Type != CT_Namespace_Body && body->Type != CT_Untyped ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::def_namespace: body is not of namespace or untyped type %s", code_debug_str(body));
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-08-06 11:58:43 -07:00
|
|
|
CodeNS
|
|
|
|
result = (CodeNS) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Namespace;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-02 21:45:30 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Body = body;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
|
|
|
log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", code_debug_str(p.attributes) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) {
|
|
|
|
log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", code_debug_str(p.specifiers) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
OpValidateResult check_result = operator__validate( op, p.params, p.ret_type, p.specifiers );
|
|
|
|
if ( check_result == OpValResult_Fail ) {
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2023-08-04 13:12:13 -07:00
|
|
|
char const* name = nullptr;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
Str op_str = operator_to_str( op );
|
2023-08-04 13:12:13 -07:00
|
|
|
if ( nspace.Len > 0 )
|
2024-12-12 09:55:15 -08:00
|
|
|
name = c_str_fmt_buf( "%.*soperator %.*s", nspace.Len, nspace.Ptr, op_str.Len, op_str.Ptr );
|
2023-08-04 13:12:13 -07:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
name = c_str_fmt_buf( "operator %.*s", op_str.Len, op_str.Ptr );
|
2024-12-09 11:55:02 -08:00
|
|
|
|
2024-12-13 10:20:16 -08:00
|
|
|
Str name_resolved = { name, c_str_len(name) };
|
2024-12-09 11:55:02 -08:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
CodeOperator
|
|
|
|
result = (CodeOperator) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name_resolved );
|
2024-12-12 08:35:50 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
2023-10-22 18:41:36 -07:00
|
|
|
result->Op = op;
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.body )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
switch ( p.body->Type )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Body:
|
|
|
|
case CT_Execution:
|
|
|
|
case CT_Untyped:
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
log_failure("gen::def_operator: body must be either of Function_Body, Execution, or Untyped type. %s", code_debug_str(p.body));
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = check_result == OpValResult_Global ?
|
|
|
|
CT_Operator : CT_Operator_Member;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = p.body;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = check_result == OpValResult_Global ?
|
|
|
|
CT_Operator_Fwd : CT_Operator_Member_Fwd;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Attributes = p.attributes;
|
|
|
|
result->Specs = p.specifiers;
|
|
|
|
result->ReturnType = p.ret_type;
|
|
|
|
result->Params = p.params;
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! null_check( def_operator_cast, type )) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( type->Type != CT_Typename ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_operator_cast: type is not a typename - %s", code_debug_str(type) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeOpCast result = (CodeOpCast) make_code();
|
2024-12-12 08:35:50 -08:00
|
|
|
if (p.body)
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Operator_Cast;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.body->Type != CT_Function_Body && p.body->Type != CT_Execution ) {
|
|
|
|
log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", code_debug_str(p.body) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = p.body;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Operator_Cast_Fwd;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Specs = p.specs;
|
2023-07-24 14:45:27 -07:00
|
|
|
result->ValueType = type;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeParams def_param( CodeTypename type, Str name, Opts_def_param p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_param, name ) || ! null_check( def_param, type ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( type->Type != CT_Typename ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_param: type is not a typename - %s", code_debug_str(type) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.value && p.value->Type != CT_Untyped ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_param: value is not untyped - %s", code_debug_str(p.value) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams
|
2024-12-12 08:35:50 -08:00
|
|
|
result = (CodeParams) make_code();
|
|
|
|
result->Type = CT_Parameters;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2023-07-24 14:45:27 -07:00
|
|
|
result->ValueType = type;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Value = p.value;
|
2023-07-24 14:45:27 -07:00
|
|
|
result->NumEntries++;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodePragma def_pragma( Str directive )
|
2023-07-29 22:21:04 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( directive.Len <= 0 || directive.Ptr == nullptr ) {
|
2023-07-29 22:21:04 -07:00
|
|
|
log_failure( "gen::def_comment: Invalid comment provided:" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-29 22:21:04 -07:00
|
|
|
}
|
|
|
|
CodePragma
|
|
|
|
result = (CodePragma) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Preprocess_Pragma;
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Content = cache_str( directive );
|
2023-07-29 22:21:04 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str expr )
|
2023-07-29 22:21:04 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( expr.Len <= 0 || expr.Ptr == nullptr ) {
|
2023-07-29 22:21:04 -07:00
|
|
|
log_failure( "gen::def_comment: Invalid comment provided:" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-29 22:21:04 -07:00
|
|
|
}
|
|
|
|
CodePreprocessCond
|
|
|
|
result = (CodePreprocessCond) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Content = cache_str( expr );
|
2023-07-29 22:21:04 -07:00
|
|
|
switch (type)
|
|
|
|
{
|
2024-12-01 02:30:37 -08:00
|
|
|
case PreprocessCond_If:
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Preprocess_If;
|
2023-08-08 19:14:58 -07:00
|
|
|
break;
|
2024-12-01 02:30:37 -08:00
|
|
|
case PreprocessCond_IfDef:
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Preprocess_IfDef;
|
2023-08-08 19:14:58 -07:00
|
|
|
break;
|
2024-12-01 02:30:37 -08:00
|
|
|
case PreprocessCond_IfNotDef:
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Preprocess_IfNotDef;
|
2023-08-08 19:14:58 -07:00
|
|
|
break;
|
2024-12-01 02:30:37 -08:00
|
|
|
case PreprocessCond_ElIf:
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Preprocess_ElIf;
|
2023-08-08 19:14:58 -07:00
|
|
|
break;
|
2023-07-29 22:21:04 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
CodeSpecifiers def_specifier( Specifier spec )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
CodeSpecifiers
|
|
|
|
result = (CodeSpecifiers) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Specifiers;
|
2024-12-06 21:21:09 -08:00
|
|
|
specifiers_append(result, spec );
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeStruct def_struct( Str name, Opts_def_struct p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
|
|
|
log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(cast(Code, p.attributes)) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.parent && p.parent->Type != CT_Typename ) {
|
|
|
|
log_failure( "gen::def_struct: parent was not a `Struct` type - %s", code_debug_str(p.parent) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.body && p.body->Type != CT_Struct_Body ) {
|
|
|
|
log_failure( "gen::def_struct: body was not a Struct_Body type - %s", code_debug_str(p.body) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeStruct
|
|
|
|
result = (CodeStruct) make_code();
|
2024-12-12 08:35:50 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
2024-12-09 11:55:02 -08:00
|
|
|
if ( name.Len )
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.body ) {
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Struct;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = p.body;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
else {
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Struct_Fwd;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Attributes = p.attributes;
|
|
|
|
result->ParentAccess = p.parent_access;
|
|
|
|
result->ParentType = p.parent;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
for (s32 idx = 0; idx < p.num_interfaces; idx++ ) {
|
|
|
|
struct_add_interface(result, p.interfaces[idx] );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! null_check( def_template, declaration ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( params && params->Type != CT_Parameters ){
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_template: params is not of parameters type - %s", code_debug_str(params) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
switch (declaration->Type )
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class:
|
|
|
|
case CT_Function:
|
|
|
|
case CT_Struct:
|
|
|
|
case CT_Variable:
|
|
|
|
case CT_Using:
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_template: declaration is not of class, function, struct, variable, or using type - %s", code_debug_str(declaration) );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeTemplate
|
|
|
|
result = (CodeTemplate) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Template;
|
2024-12-02 21:45:30 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Params = params;
|
|
|
|
result->Declaration = declaration;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeTypename def_type( Str name, Opts_def_type p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_type, name )) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
2024-12-02 21:45:30 -08:00
|
|
|
Code arrayexpr = p.arrayexpr;
|
|
|
|
CodeSpecifiers specifiers = p.specifiers;
|
|
|
|
CodeAttributes attributes = p.attributes;
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
|
|
|
log_failure( "gen::def_type: attributes is not of attributes type - %s", code_debug_str((Code)p.attributes) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) {
|
|
|
|
log_failure( "gen::def_type: specifiers is not of specifiers type - %s", code_debug_str((Code)p.specifiers) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.arrayexpr && p.arrayexpr->Type != CT_Untyped ) {
|
|
|
|
log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str((Code)p.arrayexpr) );
|
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename
|
2024-12-12 08:35:50 -08:00
|
|
|
result = (CodeTypename) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Type = CT_Typename;
|
|
|
|
result->Attributes = p.attributes;
|
|
|
|
result->Specs = p.specifiers;
|
|
|
|
result->ArrExpr = p.arrayexpr;
|
|
|
|
result->TypeTag = p.type_tag;
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! null_check( def_typedef, type ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
switch ( type->Type )
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class:
|
|
|
|
case CT_Class_Fwd:
|
|
|
|
case CT_Enum:
|
|
|
|
case CT_Enum_Fwd:
|
|
|
|
case CT_Enum_Class:
|
|
|
|
case CT_Enum_Class_Fwd:
|
|
|
|
case CT_Function_Fwd:
|
|
|
|
case CT_Struct:
|
|
|
|
case CT_Struct_Fwd:
|
|
|
|
case CT_Union:
|
|
|
|
case CT_Typename:
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
default:
|
2024-12-06 21:21:09 -08:00
|
|
|
log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", code_debug_str((Code)type) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
2024-12-06 21:21:09 -08:00
|
|
|
log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", code_debug_str((Code)p.attributes) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Registering the type.
|
2024-12-09 11:55:02 -08:00
|
|
|
CodeTypename registered_type = def_type( name );
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! registered_type ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure( "gen::def_typedef: failed to register type" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeTypedef
|
2024-12-12 08:35:50 -08:00
|
|
|
result = (CodeTypedef) make_code();
|
|
|
|
result->Type = CT_Typedef;
|
|
|
|
result->ModuleFlags = p.mflags;
|
2023-07-24 14:45:27 -07:00
|
|
|
result->UnderlyingType = type;
|
|
|
|
|
2023-08-07 17:16:04 -07:00
|
|
|
if ( name.Len <= 0 )
|
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if (type->Type != CT_Untyped) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_typedef: name was empty and type was not untyped (indicating its a function typedef) - %s", code_debug_str(type) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-07 17:16:04 -07:00
|
|
|
}
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( type->Name );
|
2023-08-07 17:16:04 -07:00
|
|
|
result->IsFunction = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2023-08-07 17:16:04 -07:00
|
|
|
result->IsFunction = false;
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeUnion def_union( Str name, CodeBody body, Opts_def_union p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! null_check( def_union, body ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
if ( body->Type != CT_Union_Body ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_union: body was not a Union_Body type - %s", code_debug_str(body) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_union: attributes was not a PlatformAttributes type - %s", code_debug_str(p.attributes) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeUnion
|
|
|
|
result = (CodeUnion) make_code();
|
2024-12-02 21:45:30 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Union;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Body = body;
|
|
|
|
result->Attributes = p.attributes;
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( name.Ptr )
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeUsing def_using( Str name, CodeTypename type, Opts_def_using p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_using, name ) || null_check( def_using, type ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-09 11:55:02 -08:00
|
|
|
CodeTypename register_type = def_type( name );
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! register_type ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure( "gen::def_using: failed to register type" );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_using: attributes was not a PlatformAttributes type - %s", code_debug_str(p.attributes) );
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeUsing
|
2024-12-12 08:35:50 -08:00
|
|
|
result = (CodeUsing) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-12 08:35:50 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
|
|
|
result->Type = CT_Using;
|
2023-07-24 14:45:27 -07:00
|
|
|
result->UnderlyingType = type;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->Attributes = p.attributes;
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeUsing def_using_namespace( Str name )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-12 08:35:50 -08:00
|
|
|
if ( ! name_check( def_using_namespace, name ) ) {
|
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
CodeUsing
|
|
|
|
result = (CodeUsing) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Using_Namespace;
|
2024-12-12 08:35:50 -08:00
|
|
|
return result;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable p )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-15 15:21:03 -08:00
|
|
|
if ( ! name_check( def_variable, name ) || ! null_check( def_variable, type ) ) {
|
2024-12-12 08:35:50 -08:00
|
|
|
GEN_DEBUG_TRAP();
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_variable: attributes was not a `PlatformAttributes` type - %s", code_debug_str(p.attributes) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( p.specifiers && p.specifiers->Type != CT_Specifiers )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", code_debug_str(p.specifiers) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( type->Type != CT_Typename )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "gen::def_variable: type was not a Typename - %s", code_debug_str(type) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-09 11:55:02 -08:00
|
|
|
if ( p.value && p.value->Type != CT_Untyped )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-09 11:55:02 -08:00
|
|
|
log_failure( "gen::def_variable: value was not a `Untyped` type - %s", code_debug_str(p.value) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeVar
|
|
|
|
result = (CodeVar) make_code();
|
2024-12-13 16:16:52 -08:00
|
|
|
result->Name = cache_str( name );
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Variable;
|
2024-12-02 21:45:30 -08:00
|
|
|
result->ModuleFlags = p.mflags;
|
2024-12-12 08:35:50 -08:00
|
|
|
result->ValueType = type;
|
|
|
|
result->Attributes = p.attributes;
|
|
|
|
result->Specs = p.specifiers;
|
|
|
|
result->Value = p.value;
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma region Helper Macros for def_**_body functions
|
|
|
|
#define def_body_start( Name_ ) \
|
|
|
|
if ( num <= 0 ) \
|
|
|
|
{ \
|
|
|
|
log_failure("gen::" stringize(Name_) ": num cannot be zero or negative"); \
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode; \
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define def_body_code_array_start( Name_ ) \
|
|
|
|
if ( num <= 0 ) \
|
|
|
|
{ \
|
|
|
|
log_failure("gen::" stringize(Name_) ": num cannot be zero or negative"); \
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode; \
|
2023-07-24 14:45:27 -07:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
if ( codes == nullptr ) \
|
|
|
|
{ \
|
|
|
|
log_failure("gen::" stringize(Name_)" : Provided a null array of codes"); \
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode; \
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion Helper Macros for def_**_body functions
|
|
|
|
|
|
|
|
CodeBody def_class_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_class_body );
|
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
CodeBody result = ( CodeBody )make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Class_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
2023-08-03 08:01:43 -07:00
|
|
|
va_start( va, num );
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::"
|
|
|
|
"def_class_body"
|
|
|
|
": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_CLASS_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_class_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_class_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Function_Body;
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
codes++;
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_class_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_CLASS_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-14 15:49:41 -08:00
|
|
|
CodeDefineParams def_define_params( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_define_params );
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
CodeDefineParams param = pcast( CodeDefineParams, pod );
|
|
|
|
|
|
|
|
null_check( def_define_params, param );
|
|
|
|
if ( param->Type != CT_Parameters_Define ) {
|
|
|
|
log_failure( "gen::def_define_params: param %d is not a parameter for a preprocessor define", num - num + 1 );
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeDefineParams result = (CodeDefineParams) code_duplicate(param);
|
|
|
|
while ( -- num )
|
|
|
|
{
|
|
|
|
pod = va_arg(va, Code_POD);
|
|
|
|
param = pcast( CodeDefineParams, pod );
|
|
|
|
if ( param->Type != CT_Parameters_Define ) {
|
|
|
|
log_failure( "gen::def_define_params: param %d is not a parameter for a preprocessor define", num - num + 1 );
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
define_params_append(result, param );
|
|
|
|
}
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeDefineParams def_define_params_arr( s32 num, CodeDefineParams* codes )
|
2024-12-14 15:49:41 -08:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_define_params );
|
|
|
|
|
|
|
|
# define check_current(current) \
|
|
|
|
if ( current == nullptr ) { \
|
|
|
|
log_failure("gen::def_define_params: Provide a null code in codes array"); \
|
|
|
|
return InvalidCode; \
|
|
|
|
} \
|
|
|
|
if (current->Type != CT_Parameters_Define ) { \
|
|
|
|
log_failure("gen::def_define_params: Code in coes array is not of paramter for preprocessor define type - %s", code_debug_str(current) ); \
|
|
|
|
return InvalidCode; \
|
|
|
|
}
|
|
|
|
CodeDefineParams current = (CodeDefineParams)code_duplicate(* codes);
|
|
|
|
check_current(current);
|
|
|
|
|
|
|
|
CodeDefineParams
|
|
|
|
result = (CodeDefineParams) make_code();
|
|
|
|
result->Name = current->Name;
|
|
|
|
result->Type = current->Type;
|
|
|
|
while( codes++, current = * codes, num--, num > 0 ) {
|
|
|
|
check_current(current);
|
|
|
|
define_params_append(result, current );
|
|
|
|
}
|
|
|
|
# undef check_current
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
CodeBody def_enum_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_enum_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Enum_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_enum_body: Provided a null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( entry->Type != CT_Untyped && entry->Type != CT_Comment ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::def_enum_body: Entry type is not allowed - %s. Must be of untyped or comment type.", code_debug_str(entry) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
while ( num--, num > 0 );
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return (CodeBody) result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_enum_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_enum_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Enum_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_enum_body: Provided a null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( entry->Type != CT_Untyped && entry->Type != CT_Comment ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::def_enum_body: Entry type is not allowed: %s", code_debug_str(entry) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
while ( codes++, num--, num > 0 );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeBody def_export_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_export_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Export_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry)
|
2023-08-03 08:01:43 -07:00
|
|
|
{
|
|
|
|
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_export_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_export_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Export_Body;
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
codes++;
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeBody def_extern_link_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_extern_linkage_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Extern_Linkage_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_extern_link_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_extern_linkage_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Extern_Linkage_Body;
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
codes++;
|
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeBody def_function_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_function_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Function_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" stringize(def_function_body) ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_function_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_function_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Function_Body;
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
codes++;
|
2024-12-13 17:40:18 -08:00
|
|
|
if (!entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_function_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeBody def_global_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_global_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Global_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Global_Body:
|
2024-12-06 21:21:09 -08:00
|
|
|
// result.body_append( entry.code_cast<CodeBody>() ) ;
|
2024-12-09 11:55:02 -08:00
|
|
|
body_append_body( result, cast(CodeBody, entry) );
|
2023-08-06 11:58:43 -07:00
|
|
|
continue;
|
|
|
|
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_global_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_global_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Global_Body;
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
codes++;
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Global_Body:
|
2024-12-09 11:55:02 -08:00
|
|
|
body_append_body(result, cast(CodeBody, entry) );
|
2023-08-06 11:58:43 -07:00
|
|
|
continue;
|
|
|
|
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeBody def_namespace_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_namespace_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Namespace_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_namespace_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_namespace_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Global_Body;
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
codes++;
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", code_debug_str(entry) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams def_params( s32 num, ... )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_start( def_params );
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams param = pcast( CodeParams, pod );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
null_check( def_params, param );
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( param->Type != CT_Parameters ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure( "gen::def_params: param %d is not a Parameters", num - num + 1 );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams result = (CodeParams) code_duplicate(param);
|
2023-07-24 14:45:27 -07:00
|
|
|
while ( -- num )
|
|
|
|
{
|
|
|
|
pod = va_arg(va, Code_POD);
|
2024-12-11 10:33:35 -08:00
|
|
|
param = pcast( CodeParams, pod );
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( param->Type != CT_Parameters ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure( "gen::def_params: param %d is not a Parameters", num - num + 1 );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
params_append(result, param );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeParams def_params_arr( s32 num, CodeParams* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_params );
|
|
|
|
|
2024-12-09 11:55:02 -08:00
|
|
|
# define check_current(current) \
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( current == nullptr ) { \
|
2024-12-09 11:55:02 -08:00
|
|
|
log_failure("gen::def_params: Provide a null code in codes array"); \
|
|
|
|
return InvalidCode; \
|
|
|
|
} \
|
2024-12-13 17:40:18 -08:00
|
|
|
if (current->Type != CT_Parameters ) { \
|
2024-12-09 11:55:02 -08:00
|
|
|
log_failure("gen::def_params: Code in coes array is not of paramter type - %s", code_debug_str(current) ); \
|
|
|
|
return InvalidCode; \
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams current = (CodeParams)code_duplicate(* codes);
|
2024-12-09 11:55:02 -08:00
|
|
|
check_current(current);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams
|
|
|
|
result = (CodeParams) make_code();
|
2023-07-24 14:45:27 -07:00
|
|
|
result->Name = current->Name;
|
|
|
|
result->Type = current->Type;
|
|
|
|
result->ValueType = current->ValueType;
|
2024-12-13 17:40:18 -08:00
|
|
|
while( codes++, current = * codes, num--, num > 0 ) {
|
2024-12-09 11:55:02 -08:00
|
|
|
check_current(current);
|
2024-12-06 21:21:09 -08:00
|
|
|
params_append(result, current );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
# undef check_current
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeSpecifiers def_specifiers( s32 num, ... )
|
|
|
|
{
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( num <= 0 ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_specifiers: num cannot be zero or less");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( num > AST_ArrSpecs_Cap ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_specifiers: num of speciifers to define AST larger than AST specicifier capacity - %d", num);
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeSpecifiers
|
|
|
|
result = (CodeSpecifiers) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Specifiers;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2024-12-13 17:40:18 -08:00
|
|
|
do {
|
2024-12-03 10:14:14 -08:00
|
|
|
Specifier type = (Specifier)va_arg(va, int);
|
2024-12-06 21:21:09 -08:00
|
|
|
specifiers_append(result, type );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
while ( --num, num );
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeSpecifiers def_specifiers_arr( s32 num, Specifier* specs )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( num <= 0 ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_specifiers: num cannot be zero or less");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( num > AST_ArrSpecs_Cap ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_specifiers: num of speciifers to define AST larger than AST specicifier capacity - %d", num);
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
CodeSpecifiers
|
|
|
|
result = (CodeSpecifiers) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Specifiers;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
s32 idx = 0;
|
2024-12-13 17:40:18 -08:00
|
|
|
do {
|
2024-12-06 21:21:09 -08:00
|
|
|
specifiers_append(result, specs[idx] );
|
2023-07-24 14:45:27 -07:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
while ( --num, num );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeBody def_struct_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_struct_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Struct_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast(Code, pod);
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", code_debug_str(entry));
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_struct_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_struct_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Struct_Body;
|
2023-08-03 08:01:43 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
codes++;
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry) {
|
2023-08-03 08:01:43 -07:00
|
|
|
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-14 08:24:21 -08:00
|
|
|
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES_CASES:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", code_debug_str(entry) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry);
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while (num--, num > 0);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeBody def_union_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
def_body_start( def_union_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Union_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Code_POD pod = va_arg(va, Code_POD);
|
|
|
|
Code entry = pcast( Code, pod );
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_union_body: Provided a null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( entry->Type != CT_Untyped && entry->Type != CT_Comment ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::def_union_body: Entry type is not allowed - %s. Must be of untyped or comment type.", code_debug_str(entry) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
while ( num--, num > 0 );
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 19:53:32 -08:00
|
|
|
CodeBody def_union_body_arr( s32 num, Code* codes )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
def_body_code_array_start( def_union_body );
|
|
|
|
|
|
|
|
CodeBody
|
|
|
|
result = (CodeBody) make_code();
|
2024-12-03 12:19:39 -08:00
|
|
|
result->Type = CT_Union_Body;
|
2023-07-24 14:45:27 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( ! entry ) {
|
2023-07-24 14:45:27 -07:00
|
|
|
log_failure("gen::def_union_body: Provided a null entry");
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-13 17:40:18 -08:00
|
|
|
if ( entry->Type != CT_Untyped && entry->Type != CT_Comment ) {
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("gen::def_union_body: Entry type is not allowed: %s", code_debug_str(entry) );
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(result, entry );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
while ( codes++, num--, num > 0 );
|
|
|
|
|
|
|
|
return (CodeBody) result;
|
|
|
|
}
|
|
|
|
|
|
|
|
# undef name_check
|
|
|
|
# undef null_check
|
2023-08-03 20:18:33 -07:00
|
|
|
# undef def_body_start
|
|
|
|
# undef def_body_code_array_start
|
|
|
|
|
|
|
|
#pragma endregion Upfront
|