2023-07-08 11:11:41 -07:00
|
|
|
#pragma once
|
|
|
|
#ifdef gen_time
|
|
|
|
#include "gen.hpp"
|
|
|
|
|
|
|
|
using namespace gen;
|
|
|
|
|
2023-07-08 20:29:18 -07:00
|
|
|
u32 gen_sanity()
|
2023-07-08 11:11:41 -07:00
|
|
|
{
|
|
|
|
Builder
|
|
|
|
gen_sanity_file;
|
2023-07-08 20:29:18 -07:00
|
|
|
gen_sanity_file.open("./sanity.Parsed.gen.hpp");
|
2023-07-08 11:11:41 -07:00
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_sanity_file.print( def_comment( txt_StrC(
|
2023-07-08 11:11:41 -07:00
|
|
|
"The following will show a series of base cases for the gen parsed api.\n"
|
|
|
|
)));
|
|
|
|
|
|
|
|
// Typedef
|
|
|
|
{
|
|
|
|
Code u8_typedef = parse_typedef( code(
|
|
|
|
typedef unsigned char u8;
|
|
|
|
));
|
|
|
|
|
|
|
|
gen_sanity_file.print(u8_typedef);
|
|
|
|
}
|
|
|
|
|
2023-07-08 14:14:05 -07:00
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Class
|
|
|
|
{
|
|
|
|
Code fwd = parse_class( code(
|
|
|
|
class TestEmptyClass;
|
|
|
|
));
|
|
|
|
|
|
|
|
Code empty_body = parse_class( code(
|
|
|
|
class TestEmptyClass
|
|
|
|
{};
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
empty_body->body()->add_entry( def_comment( txt_StrC("Empty class body") ) );
|
2023-07-08 14:14:05 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(empty_body);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Enum
|
2023-07-08 15:49:49 -07:00
|
|
|
{
|
|
|
|
Code fwd = parse_enum( code(
|
|
|
|
enum ETestEnum : u8;
|
|
|
|
));
|
|
|
|
|
|
|
|
Code def = parse_enum( code(
|
|
|
|
enum ETestEnum : u8
|
|
|
|
{
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
|
|
|
Code fwd_enum_class = parse_enum( code(
|
2023-07-08 16:13:52 -07:00
|
|
|
enum class ETestEnumClass : u8;
|
2023-07-08 15:49:49 -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-08 14:14:05 -07:00
|
|
|
{
|
2023-07-11 22:33:11 -07:00
|
|
|
Code empty_comment = def_comment( txt_StrC("Empty external linkage") );
|
2023-07-08 14:14:05 -07:00
|
|
|
|
2023-07-08 20:29:18 -07:00
|
|
|
Code c_extern = parse_extern_link( code(
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
c_extern->body()->add_entry( empty_comment );
|
2023-07-08 20:29:18 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(c_extern);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Friend
|
|
|
|
{
|
|
|
|
Code fwd = parse_class( code(
|
|
|
|
class TestFriendClass;
|
|
|
|
));
|
|
|
|
|
|
|
|
Code def = parse_class( code(
|
|
|
|
class TestFriend
|
|
|
|
{
|
|
|
|
friend class TestFriendClass;
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Function
|
|
|
|
{
|
|
|
|
Code fwd = parse_function( code(
|
|
|
|
void test_function();
|
|
|
|
));
|
|
|
|
|
|
|
|
Code def = parse_function( code(
|
|
|
|
void test_function()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
def->body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
2023-07-08 20:29:18 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Namespace
|
|
|
|
{
|
|
|
|
Code def = parse_namespace( code(
|
|
|
|
namespace TestNamespace
|
|
|
|
{
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
def->body()->add_entry( def_comment( txt_StrC("Empty namespace body") ) );
|
2023-07-08 20:29:18 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Operator
|
|
|
|
{
|
2023-07-09 09:35:48 -07:00
|
|
|
Code bitflagtest = parse_enum( code(
|
2023-07-08 20:29:18 -07:00
|
|
|
enum class EBitFlagTest : u8
|
|
|
|
{
|
|
|
|
A = 1 << 0,
|
|
|
|
B = 1 << 1,
|
|
|
|
C = 1 << 2
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
|
|
|
Code op_fwd = parse_operator( code(
|
|
|
|
EBitFlagTest operator | ( EBitFlagTest a, EBitFlagTest b );
|
|
|
|
));
|
|
|
|
|
|
|
|
Code op_or = parse_operator( code(
|
|
|
|
EBitFlagTest operator | ( EBitFlagTest a, EBitFlagTest b )
|
|
|
|
{
|
|
|
|
return EBitFlagTest( (u8)a | (u8)b );
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
gen_sanity_file.print(bitflagtest);
|
|
|
|
gen_sanity_file.print(op_fwd);
|
|
|
|
gen_sanity_file.print(op_or);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-07-10 19:14:41 -07:00
|
|
|
// Operator cast
|
|
|
|
{
|
|
|
|
Code op_ptr = parse_operator_cast( code(
|
|
|
|
operator u8* ();
|
|
|
|
));
|
|
|
|
|
|
|
|
Code class_def = parse_class( code(
|
|
|
|
class TestClass
|
|
|
|
{
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
class_def->body()->add_entry( op_ptr );
|
2023-07-10 19:14:41 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(class_def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-07-08 20:29:18 -07:00
|
|
|
// Parameters
|
|
|
|
{
|
|
|
|
Code fwd = parse_function( code(
|
2023-07-09 10:07:30 -07:00
|
|
|
void test_function_param( int a );
|
2023-07-08 20:29:18 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
Code def = parse_function( code(
|
2023-07-09 10:07:30 -07:00
|
|
|
void test_function_param2( int a, int b )
|
2023-07-08 20:29:18 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
def->body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
2023-07-08 20:29:18 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(def);
|
2023-07-08 14:14:05 -07:00
|
|
|
}
|
|
|
|
|
2023-07-08 15:49:49 -07:00
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
2023-07-08 20:29:18 -07:00
|
|
|
// Specifiers
|
|
|
|
{
|
|
|
|
Code fwd_fn = parse_function( code(
|
|
|
|
inline
|
|
|
|
void test_function_specifiers();
|
|
|
|
));
|
|
|
|
|
|
|
|
Code typedef_u8_ptr = parse_typedef( code(
|
|
|
|
typedef u8* u8_ptr;
|
|
|
|
));
|
|
|
|
|
|
|
|
gen_sanity_file.print(fwd_fn);
|
|
|
|
gen_sanity_file.print(typedef_u8_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Struct
|
|
|
|
{
|
|
|
|
Code fwd = parse_struct( code(
|
|
|
|
struct TestEmptyStruct;
|
|
|
|
));
|
|
|
|
|
|
|
|
Code empty_body = parse_struct( code(
|
|
|
|
struct TestEmptyStruct
|
|
|
|
{};
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
empty_body->body()->add_entry( def_comment( txt_StrC("Empty struct body") ) );
|
2023-07-08 20:29:18 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(fwd);
|
|
|
|
gen_sanity_file.print(empty_body);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Union
|
|
|
|
{
|
|
|
|
Code empty = parse_union( code(
|
|
|
|
union TestEmptyUnion
|
|
|
|
{
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
2023-07-12 12:59:47 -07:00
|
|
|
empty->body()->add_entry( def_comment( txt_StrC("Empty union body") ) );
|
2023-07-08 20:29:18 -07:00
|
|
|
|
2023-07-10 19:14:41 -07:00
|
|
|
gen_sanity_file.print( parse_typedef( code( typedef unsigned short u16; )) );
|
|
|
|
gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) );
|
|
|
|
|
2023-07-08 20:29:18 -07:00
|
|
|
Code def = parse_union( code(
|
|
|
|
union TestUnion
|
|
|
|
{
|
2023-07-10 19:14:41 -07:00
|
|
|
u8 a;
|
2023-07-08 20:29:18 -07:00
|
|
|
u16 b;
|
|
|
|
u32 c;
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
|
|
|
gen_sanity_file.print(empty);
|
|
|
|
gen_sanity_file.print(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Using
|
|
|
|
{
|
|
|
|
Code reg = parse_using( code(
|
|
|
|
using TestUsing = u8;
|
|
|
|
));
|
|
|
|
|
2023-07-10 19:14:41 -07:00
|
|
|
Code nspace = parse_namespace( code(
|
2023-07-08 20:29:18 -07:00
|
|
|
namespace TestNamespace
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2023-07-10 19:14:41 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
Code npspace_using = parse_using( code(
|
|
|
|
using namespace TestNamespace;
|
2023-07-08 20:29:18 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
gen_sanity_file.print(reg);
|
|
|
|
gen_sanity_file.print(nspace);
|
2023-07-10 19:14:41 -07:00
|
|
|
gen_sanity_file.print(npspace_using);
|
2023-07-08 20:29:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// Variable
|
|
|
|
{
|
|
|
|
Code bss = parse_variable( code(
|
|
|
|
u8 test_variable;
|
|
|
|
));
|
|
|
|
|
|
|
|
Code data = parse_variable( code(
|
|
|
|
u8 test_variable = 0x12;
|
|
|
|
));
|
2023-07-10 19:14:41 -07:00
|
|
|
|
|
|
|
gen_sanity_file.print(bss);
|
|
|
|
gen_sanity_file.print(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_sanity_file.print_fmt("\n");
|
|
|
|
|
|
|
|
// template
|
|
|
|
{
|
|
|
|
#pragma push_macro("template")
|
|
|
|
#undef template
|
|
|
|
Code tmpl = parse_template( code(
|
|
|
|
template< typename Type >
|
|
|
|
void test_template( Type a )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
));
|
|
|
|
#pragma pop_macro("template")
|
|
|
|
|
|
|
|
gen_sanity_file.print(tmpl);
|
2023-07-08 20:29:18 -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-07-08 20:29:18 -07:00
|
|
|
"End of base case tests\n"
|
|
|
|
)));
|
|
|
|
|
2023-07-08 11:11:41 -07:00
|
|
|
gen_sanity_file.write();
|
2023-07-08 20:29:18 -07:00
|
|
|
return 0;
|
2023-07-08 11:11:41 -07:00
|
|
|
}
|
|
|
|
#endif
|