2023-07-18 21:13:12 -07:00
|
|
|
#ifdef GEN_TIME
|
2023-06-28 11:43:21 -07:00
|
|
|
#include "gen.hpp"
|
|
|
|
|
|
|
|
using namespace gen;
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
u32 gen_sanity_upfront()
|
2023-06-28 11:43:21 -07:00
|
|
|
{
|
|
|
|
Builder
|
|
|
|
gen_sanity_file;
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_sanity_file.open("./sanity.Upfront.gen.hpp");
|
2023-06-28 11:43:21 -07:00
|
|
|
|
|
|
|
// Comment
|
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeComment comment_test = def_comment( txt_StrC("Sanity check: def_comment test") );
|
2023-06-28 11:43:21 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(comment_test);
|
|
|
|
}
|
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
gen_sanity_file.print_fmt("\n");
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_sanity_file.print( def_comment( txt_StrC(
|
2023-06-28 21:20:23 -07:00
|
|
|
"The following will show a series of base cases for the gen api.\n"
|
|
|
|
)));
|
|
|
|
|
2023-06-28 11:43:21 -07:00
|
|
|
// Class
|
|
|
|
{
|
2023-07-13 22:37:22 -07:00
|
|
|
CodeClass fwd = def_class( name(TestEmptyClass) );
|
|
|
|
CodeClass empty_body;
|
2023-06-28 11:43:21 -07:00
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeComment cmt = def_comment( txt_StrC("Empty class body") );
|
|
|
|
CodeBody body = def_class_body( args( cmt ) );
|
2023-06-28 11:43:21 -07:00
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
empty_body = def_class( name(TestEmptyClass), body );
|
2023-06-28 11:43:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(empty_body);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-06-28 18:20:29 -07:00
|
|
|
// Typedef
|
2023-06-28 11:43:21 -07:00
|
|
|
{
|
2023-07-13 22:37:22 -07:00
|
|
|
CodeType t_unsigned_char = def_type( name(unsigned char) );
|
|
|
|
CodeTypedef u8_typedef = def_typedef( name(u8), t_unsigned_char );
|
2023-06-28 18:20:29 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(u8_typedef);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Enum
|
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeEnum fwd = def_enum( name(ETestEnum), NoCode, t_u8 );
|
2023-07-13 22:37:22 -07:00
|
|
|
CodeEnum def;
|
2023-06-28 18:20:29 -07:00
|
|
|
{
|
2023-07-13 22:37:22 -07:00
|
|
|
Code body = untyped_str( code(
|
2023-06-30 21:23:40 -07:00
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C
|
2023-06-28 18:20:29 -07:00
|
|
|
));
|
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
def = def_enum( name(ETestEnum), body, t_u8 );
|
|
|
|
}
|
|
|
|
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeEnum fwd_enum_class = def_enum( name(ETestEnumClass), NoCode, t_u8, EnumClass );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(def);
|
|
|
|
gen_sanity_file.print(fwd_enum_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// External Linkage
|
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeBody body = def_extern_link_body( 1
|
2023-07-11 22:33:11 -07:00
|
|
|
, def_comment( txt_StrC("Empty extern body") )
|
2023-06-28 21:20:23 -07:00
|
|
|
);
|
|
|
|
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeExtern c_extern = def_extern_link( name(C), body );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(c_extern);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Friend
|
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeClass fwd = def_class( name(TestFriendFwd));
|
|
|
|
CodeBody body = def_class_body( args( def_friend( fwd ) ) );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print( def_class( name(TestFriend), body ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Function
|
|
|
|
{
|
2023-07-13 22:37:22 -07:00
|
|
|
CodeFn fwd = def_function( name(test_function) );
|
|
|
|
CodeFn def;
|
2023-06-28 21:20:23 -07:00
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeBody body = def_function_body( 1
|
2023-07-11 22:33:11 -07:00
|
|
|
, def_comment( txt_StrC("Empty function body") )
|
2023-06-28 21:20:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
def = def_function( name(test_function), __, __, body );
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Include
|
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeInclude include = def_include( txt_StrC("../DummyInclude.hpp") );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(include);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Module
|
|
|
|
if (0)
|
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeModule module_export = def_module( name(TestModule), ModuleFlag::Export );
|
|
|
|
CodeModule module_import = def_module( name(TestModule), ModuleFlag::Import );
|
|
|
|
CodeModule module_both = def_module( name(TestModule), ModuleFlag::Export | ModuleFlag::Import );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(module_global_fragment);
|
|
|
|
gen_sanity_file.print(module_private_fragment);
|
|
|
|
gen_sanity_file.print(module_export);
|
|
|
|
gen_sanity_file.print(module_import);
|
|
|
|
gen_sanity_file.print(module_both);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Namespace
|
|
|
|
{
|
2023-07-15 17:56:27 -07:00
|
|
|
CodeNamespace namespace_def;
|
2023-06-28 21:20:23 -07:00
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeBody body = def_namespace_body( 1
|
2023-07-11 22:33:11 -07:00
|
|
|
, def_comment( txt_StrC("Empty namespace body") )
|
2023-06-28 21:20:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
namespace_def = def_namespace( name(TestNamespace), body );
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print(namespace_def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Operator
|
|
|
|
{
|
2023-06-29 19:48:47 -07:00
|
|
|
// Going to make a bit flag set of overloads for this.
|
|
|
|
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeEnum bitflagtest;
|
2023-06-29 19:48:47 -07:00
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeBody body = def_enum_body( 1, untyped_str( code(
|
2023-06-30 21:23:40 -07:00
|
|
|
A = 1 << 0,
|
|
|
|
B = 1 << 1,
|
|
|
|
C = 1 << 2
|
2023-06-29 19:48:47 -07:00
|
|
|
)));
|
|
|
|
bitflagtest = def_enum( name(EBitFlagtest), body, t_u8, EnumClass );
|
|
|
|
}
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeType t_bitflag = def_type( name(EBitFlagtest) );
|
2023-06-29 19:48:47 -07:00
|
|
|
|
2023-07-13 22:37:22 -07:00
|
|
|
CodeOperator op_fwd, op_or;
|
2023-06-29 19:48:47 -07:00
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeParam params = def_params( args(
|
2023-06-29 19:48:47 -07:00
|
|
|
def_param( t_bitflag, name(a) ),
|
|
|
|
def_param( t_bitflag, name(b) )
|
2023-07-15 12:20:55 -07:00
|
|
|
));
|
2023-06-29 19:48:47 -07:00
|
|
|
|
|
|
|
op_fwd = def_operator( EOperator::BOr, params, t_bitflag );
|
2023-07-13 22:37:22 -07:00
|
|
|
op_or = def_operator( EOperator::BOr, params, t_bitflag, untyped_str( code(
|
2023-06-29 19:48:47 -07:00
|
|
|
return EBitFlagtest( (u8)a | (u8)b );
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print(bitflagtest);
|
|
|
|
gen_sanity_file.print(op_fwd);
|
|
|
|
gen_sanity_file.print(op_or);
|
2023-06-28 21:20:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-07-10 19:14:41 -07:00
|
|
|
// Operator cast
|
|
|
|
{
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_u8_ptr = def_type( name(u8), __, spec_ptr );
|
2023-07-10 19:14:41 -07:00
|
|
|
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeOpCast op_ptr = def_operator_cast( t_u8_ptr, __ );
|
2023-07-10 19:14:41 -07:00
|
|
|
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeClass op_class = def_class( name(TestOperatorCast), def_class_body( args( op_ptr) ) );
|
2023-07-10 19:14:41 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(op_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
// Parameters
|
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeFn fwd;
|
2023-06-28 21:20:23 -07:00
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeParam params = def_param( t_u8, name(a) );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
fwd = def_function( name(test_function_wparam), params );
|
|
|
|
}
|
|
|
|
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeFn def, def2;
|
2023-06-28 21:20:23 -07:00
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeBody body = def_function_body( 1
|
2023-07-11 22:33:11 -07:00
|
|
|
, def_comment( txt_StrC("Empty function body") )
|
2023-06-28 21:20:23 -07:00
|
|
|
);
|
|
|
|
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeParam params = def_params( args(
|
2023-07-12 00:41:16 -07:00
|
|
|
def_param( t_u8, name(a) )
|
2023-07-08 20:29:18 -07:00
|
|
|
, def_param( t_u8, name(b) )
|
2023-07-12 00:41:16 -07:00
|
|
|
));
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
def = def_function( name(test_function_wparams), params, __, body );
|
|
|
|
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeParam param_a = def_param( t_u8, name(a));
|
|
|
|
CodeParam param_b = def_param( t_u8, name(b));
|
|
|
|
CodeParam params_arr[2] = { param_a, param_b };
|
2023-06-28 21:20:23 -07:00
|
|
|
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeParam params2 = def_params( 2, params_arr );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
def2 = def_function( name(test_function_wparams2), params2, __, body );
|
2023-06-28 18:20:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(def);
|
2023-06-28 21:20:23 -07:00
|
|
|
gen_sanity_file.print(def2);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Specifiers
|
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeFn fwd_fn = def_function( name(test_function_specifiers), __, __, __, spec_inline );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
// TODO : Need an op overload here
|
2023-06-28 21:20:23 -07:00
|
|
|
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeType u8_ptr = def_type( name(u8), __, spec_ptr );
|
|
|
|
CodeTypedef typedef_u8_ptr = def_typedef( name(ConstExprTest), u8_ptr );
|
2023-07-08 20:29:18 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(fwd_fn);
|
|
|
|
gen_sanity_file.print(typedef_u8_ptr);
|
2023-06-28 11:43:21 -07:00
|
|
|
}
|
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Struct
|
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeClass fwd = def_class( name(TestEmptyStruct) );
|
|
|
|
CodeClass empty_body;
|
2023-06-28 21:20:23 -07:00
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeComment cmt = def_comment( txt_StrC("Empty struct body") );
|
|
|
|
CodeBody body = def_class_body( args( cmt ) );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
empty_body = def_class( name(TestEmptyStruct), body );
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(empty_body);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Union
|
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeBody body = def_union_body( 1
|
2023-07-11 22:33:11 -07:00
|
|
|
, def_comment( txt_StrC("Empty union body") )
|
2023-06-28 21:20:23 -07:00
|
|
|
);
|
|
|
|
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeUnion def = def_union( name(TestEmptyUnion), body );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Using
|
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeUsing reg = def_using( name(TestUsing), t_u8 );
|
|
|
|
CodeUsingNamespace nspace = def_using_namespace( name(TestNamespace) );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(reg);
|
|
|
|
gen_sanity_file.print(nspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Variable
|
|
|
|
{
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeVar bss = def_variable( t_u8, name(test_variable) );
|
|
|
|
CodeVar data = def_variable( t_u8, name(test_variable2), untyped_str( code( 0x12 )) );
|
2023-06-28 21:20:23 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(bss);
|
|
|
|
gen_sanity_file.print(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-07-10 19:14:41 -07:00
|
|
|
// Template
|
|
|
|
{
|
2023-07-15 12:20:55 -07:00
|
|
|
CodeType t_Type = def_type( name(Type) );
|
2023-07-10 19:14:41 -07:00
|
|
|
|
2023-07-15 19:27:38 -07:00
|
|
|
CodeTemplate tmpl = def_template( def_param( t_class, name(Type) )
|
2023-07-10 19:14:41 -07:00
|
|
|
, def_function( name(test_template), def_param( t_Type, name(a) ), __
|
2023-07-11 22:33:11 -07:00
|
|
|
, def_function_body(1, def_comment( txt_StrC("Empty template function body")))
|
2023-07-10 19:14:41 -07:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
gen_sanity_file.print(tmpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_sanity_file.print( def_comment( txt_StrC(
|
2023-06-28 21:20:23 -07:00
|
|
|
"End of base case tests.\n"
|
|
|
|
)));
|
|
|
|
|
2023-06-28 11:43:21 -07:00
|
|
|
gen_sanity_file.write();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|