mirror of
https://github.com/meekrosoft/fff
synced 2026-01-23 00:15:59 +01:00
Fix fakegen.rb C header generator for M macro compatibility.
This commit is contained in:
48
fakegen.rb
48
fakegen.rb
@@ -31,7 +31,7 @@ end
|
||||
# ------ Helper macros to use internally ------ #
|
||||
def output_internal_helper_macros
|
||||
putd "/* -- INTERNAL HELPER MACROS -- */"
|
||||
|
||||
|
||||
define_return_sequence_helper
|
||||
define_custom_fake_sequence_helper
|
||||
define_reset_fake_macro
|
||||
@@ -47,7 +47,7 @@ def output_internal_helper_macros
|
||||
define_return_fake_result_helper
|
||||
define_extern_c_helper
|
||||
define_reset_fake_helper
|
||||
|
||||
|
||||
putd "/* -- END INTERNAL HELPER MACROS -- */"
|
||||
putd ""
|
||||
end
|
||||
@@ -115,9 +115,9 @@ end
|
||||
def define_value_function_variables_helper
|
||||
putd ""
|
||||
putd "#define DECLARE_VALUE_FUNCTION_VARIABLES(RETURN_TYPE) \\"
|
||||
putd " RETURN_TYPE return_val; \\"
|
||||
putd " int return_val_seq_len; \\"
|
||||
putd " int return_val_seq_idx; \\"
|
||||
putd " RETURN_TYPE return_val; \\"
|
||||
putd " int return_val_seq_len; \\"
|
||||
putd " int return_val_seq_idx; \\"
|
||||
putd " RETURN_TYPE * return_val_seq; \\"
|
||||
end
|
||||
|
||||
@@ -149,8 +149,8 @@ end
|
||||
def define_extern_c_helper
|
||||
putd ""
|
||||
putd "#ifdef __cplusplus"
|
||||
putd " #define FFF_EXTERN_C extern \"C\"{"
|
||||
putd " #define FFF_END_EXTERN_C } "
|
||||
putd " #define FFF_EXTERN_C extern \"C\"{"
|
||||
putd " #define FFF_END_EXTERN_C } "
|
||||
putd "#else /* ansi c */"
|
||||
putd " #define FFF_EXTERN_C "
|
||||
putd " #define FFF_END_EXTERN_C "
|
||||
@@ -198,7 +198,7 @@ def output_macro(arg_count, has_varargs, is_value_function)
|
||||
output_variables(saved_arg_count, has_varargs, is_value_function)
|
||||
}
|
||||
popd
|
||||
|
||||
|
||||
putd ""
|
||||
output_macro_header(define_macro_name, saved_arg_count, has_varargs, return_type)
|
||||
pushd
|
||||
@@ -212,9 +212,9 @@ def output_macro(arg_count, has_varargs, is_value_function)
|
||||
putd "DEFINE_RESET_FUNCTION(FUNCNAME) \\"
|
||||
}
|
||||
popd
|
||||
|
||||
|
||||
putd ""
|
||||
|
||||
|
||||
output_macro_header(fake_macro_name, saved_arg_count, has_varargs, return_type)
|
||||
pushd
|
||||
putd macro_signature_for(declare_macro_name, saved_arg_count, has_varargs, return_type)
|
||||
@@ -246,7 +246,7 @@ def macro_signature_for(macro_name, arg_count, has_varargs, return_type)
|
||||
parameter_list += ", ..." if has_varargs
|
||||
|
||||
parameter_list += ") \\"
|
||||
|
||||
|
||||
parameter_list
|
||||
end
|
||||
|
||||
@@ -256,7 +256,7 @@ end
|
||||
|
||||
def output_variables(arg_count, has_varargs, is_value_function)
|
||||
in_struct{
|
||||
arg_count.times { |argN|
|
||||
arg_count.times { |argN|
|
||||
putd "DECLARE_ARG(ARG#{argN}_TYPE, #{argN}, FUNCNAME) \\"
|
||||
}
|
||||
putd "DECLARE_ALL_FUNC_COMMON \\"
|
||||
@@ -380,7 +380,7 @@ end
|
||||
|
||||
def extern_c
|
||||
putd "FFF_EXTERN_C \\"
|
||||
pushd
|
||||
pushd
|
||||
yield
|
||||
popd
|
||||
putd "FFF_END_EXTERN_C \\"
|
||||
@@ -405,7 +405,12 @@ def include_guard
|
||||
putd "#endif /* FAKE_FUNCTIONS */"
|
||||
end
|
||||
|
||||
def generate_arg_sequence(args, prefix, do_reverse, joinstr)
|
||||
def msvc_expand_macro_fix
|
||||
putd "/* MSVC expand macro fix */"
|
||||
putd "#define EXPAND(x) x"
|
||||
end
|
||||
|
||||
def generate_arg_sequence(args, prefix, do_reverse, joinstr)
|
||||
fmap = (0..args).flat_map {|i| [prefix + i.to_s]}
|
||||
if do_reverse then fmap.reverse.join(joinstr) else fmap.join(", ") end
|
||||
end
|
||||
@@ -416,25 +421,26 @@ def counting_macro_instance(type, vararg = :non_vararg, prefix = "")
|
||||
|
||||
<<-MACRO_COUNTING_INSTANCE
|
||||
#define #{prefix}FAKE_#{type.to_s}_FUNC#{appendix}(...) \
|
||||
#{prefix}FUNC_#{type.to_s}#{appendix}_(PP_NARG_MINUS#{minus_count}(__VA_ARGS__), __VA_ARGS__)
|
||||
EXPAND(#{prefix}FUNC_#{type.to_s}#{appendix}_(PP_NARG_MINUS#{minus_count}(__VA_ARGS__), __VA_ARGS__))
|
||||
|
||||
#define #{prefix}FUNC_#{type.to_s}#{appendix}_(N,...) \
|
||||
#{prefix}FUNC_#{type.to_s}#{appendix}_N(N,__VA_ARGS__)
|
||||
EXPAND(#{prefix}FUNC_#{type.to_s}#{appendix}_N(N,__VA_ARGS__))
|
||||
|
||||
#define #{prefix}FUNC_#{type.to_s}#{appendix}_N(N,...) \
|
||||
#{prefix}FAKE_#{type.to_s}_FUNC ## N#{" ## _VARARG" if vararg == :vararg}(__VA_ARGS__)
|
||||
EXPAND(#{prefix}FAKE_#{type.to_s}_FUNC ## N#{" ## _VARARG" if vararg == :vararg}(__VA_ARGS__))
|
||||
|
||||
MACRO_COUNTING_INSTANCE
|
||||
end
|
||||
|
||||
def output_macro_counting_shortcuts
|
||||
msvc_expand_macro_fix
|
||||
putd <<-MACRO_COUNTING
|
||||
|
||||
#define PP_NARG_MINUS2(...) \
|
||||
PP_NARG_MINUS2_(__VA_ARGS__, PP_RSEQ_N_MINUS2())
|
||||
EXPAND(PP_NARG_MINUS2_(__VA_ARGS__, PP_RSEQ_N_MINUS2()))
|
||||
|
||||
#define PP_NARG_MINUS2_(...) \
|
||||
PP_ARG_MINUS2_N(__VA_ARGS__)
|
||||
EXPAND(PP_ARG_MINUS2_N(__VA_ARGS__))
|
||||
|
||||
#define PP_ARG_MINUS2_N(returnVal, #{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N
|
||||
|
||||
@@ -443,10 +449,10 @@ def output_macro_counting_shortcuts
|
||||
|
||||
|
||||
#define PP_NARG_MINUS1(...) \
|
||||
PP_NARG_MINUS1_(__VA_ARGS__, PP_RSEQ_N_MINUS1())
|
||||
EXPAND(PP_NARG_MINUS1_(__VA_ARGS__, PP_RSEQ_N_MINUS1()))
|
||||
|
||||
#define PP_NARG_MINUS1_(...) \
|
||||
PP_ARG_MINUS1_N(__VA_ARGS__)
|
||||
EXPAND(PP_ARG_MINUS1_N(__VA_ARGS__))
|
||||
|
||||
#define PP_ARG_MINUS1_N(#{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N
|
||||
|
||||
|
||||
Reference in New Issue
Block a user