Store the pod_struct_offset of members

This commit is contained in:
doyle 2019-04-22 02:18:28 +10:00
parent 455d9bcbfc
commit b9c4b080f2
2 changed files with 87 additions and 79 deletions

View File

@ -1,6 +1,9 @@
#ifndef DQN_INSPECT_H #ifndef DQN_INSPECT_H
#define DQN_INSPECT_H #define DQN_INSPECT_H
#define _CRT_SECURE_NO_WARNINGS // NOTE: Undefined at end of file
#include <stddef.h>
// //
// DqnInspect.h - Minimal Inspection System, Single Header, CRT Dependencies Only // DqnInspect.h - Minimal Inspection System, Single Header, CRT Dependencies Only
// Public Domain or MIT License (see bottom of file) // Public Domain or MIT License (see bottom of file)
@ -61,12 +64,14 @@ struct DqnInspectMetadata
struct DqnInspectMember struct DqnInspectMember
{ {
enum struct DqnInspectMemberType type_enum; enum struct DqnInspectMemberType name_type;
char const * name;
int name_len;
int pod_struct_offset;
enum struct DqnInspectDeclType decl_type; enum struct DqnInspectDeclType decl_type;
char const * decl_type_str; char const * decl_type_str;
int decl_type_len; int decl_type_len;
char const * name;
int name_len;
char const * template_expr; char const * template_expr;
int template_expr_len; int template_expr_len;
int array_dimensions; // > 0 means array int array_dimensions; // > 0 means array
@ -88,7 +93,6 @@ struct DqnInspectStruct
// #include "../Data/DqnInspect_TestDataGenerated.cpp" // #include "../Data/DqnInspect_TestDataGenerated.cpp"
#ifdef DQN_INSPECT_EXECUTABLE_IMPLEMENTATION #ifdef DQN_INSPECT_EXECUTABLE_IMPLEMENTATION
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
@ -2050,10 +2054,12 @@ int main(int argc, char *argv[])
FprintfIndented(output_file, indent_level, "{\n"); FprintfIndented(output_file, indent_level, "{\n");
indent_level++; indent_level++;
FprintfIndented(output_file, indent_level, "DqnInspectMemberType::%.*s_%.*s,\n", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str); FprintfIndented(output_file, indent_level, "DqnInspectMemberType::%.*s_%.*s, ", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
FprintfIndented(output_file, indent_level, "DqnInspectDeclType::%.*s_,\n", decl->type.len, decl->type.str);
FprintfIndented(output_file, indent_level, "STR_AND_LEN(\"%.*s\"), ", decl->type.len, decl->type.str);
fprintf(output_file, "STR_AND_LEN(\"%.*s\"),\n", decl->name.len, decl->name.str); fprintf(output_file, "STR_AND_LEN(\"%.*s\"),\n", decl->name.len, decl->name.str);
FprintfIndented(output_file, indent_level, "offsetof(%.*s, %.*s),\n", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
FprintfIndented(output_file, indent_level, "DqnInspectDeclType::");
FprintDeclType(output_file, decl->type);
fprintf(output_file, ", STR_AND_LEN(\"%.*s\"),\n", decl->type.len, decl->type.str);
if (decl->template_expr.len <= 0) if (decl->template_expr.len <= 0)
FprintfIndented(output_file, indent_level, "nullptr, 0, // template_expr and template_expr_len\n"); FprintfIndented(output_file, indent_level, "nullptr, 0, // template_expr and template_expr_len\n");
@ -2212,3 +2218,5 @@ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*/ */
#undef _CRT_SECURE_NO_WARNINGS

View File

@ -95,193 +95,193 @@ DqnInspectMetadata const DqnInspectMetadata_SampleStruct_draw_color[] =
DqnInspectMember const DqnInspect_SampleStruct_Members[] = DqnInspectMember const DqnInspect_SampleStruct_Members[] =
{ {
{ {
DqnInspectMemberType::SampleStruct_ebo, DqnInspectMemberType::SampleStruct_ebo, STR_AND_LEN("ebo"),
DqnInspectDeclType::int_, offsetof(SampleStruct, ebo),
STR_AND_LEN("int"), STR_AND_LEN("ebo"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
DqnInspectMetadata_SampleStruct_ebo, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_ebo), // metadata array DqnInspectMetadata_SampleStruct_ebo, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_ebo), // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_vbo, DqnInspectMemberType::SampleStruct_vbo, STR_AND_LEN("vbo"),
DqnInspectDeclType::int_, offsetof(SampleStruct, vbo),
STR_AND_LEN("int"), STR_AND_LEN("vbo"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_vao, DqnInspectMemberType::SampleStruct_vao, STR_AND_LEN("vao"),
DqnInspectDeclType::int_, offsetof(SampleStruct, vao),
STR_AND_LEN("int"), STR_AND_LEN("vao"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
DqnInspectMetadata_SampleStruct_vao, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_vao), // metadata array DqnInspectMetadata_SampleStruct_vao, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_vao), // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_a, DqnInspectMemberType::SampleStruct_a, STR_AND_LEN("a"),
DqnInspectDeclType::int *const_, offsetof(SampleStruct, a),
STR_AND_LEN("int *const"), STR_AND_LEN("a"), DqnInspectDeclType::int_Ptr_const_, STR_AND_LEN("int *const"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_b, DqnInspectMemberType::SampleStruct_b, STR_AND_LEN("b"),
DqnInspectDeclType::int const *const_, offsetof(SampleStruct, b),
STR_AND_LEN("int const *const"), STR_AND_LEN("b"), DqnInspectDeclType::int_const_Ptr_const_, STR_AND_LEN("int const *const"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_c, DqnInspectMemberType::SampleStruct_c, STR_AND_LEN("c"),
DqnInspectDeclType::int_, offsetof(SampleStruct, c),
STR_AND_LEN("int"), STR_AND_LEN("c"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_d, DqnInspectMemberType::SampleStruct_d, STR_AND_LEN("d"),
DqnInspectDeclType::int *_, offsetof(SampleStruct, d),
STR_AND_LEN("int *"), STR_AND_LEN("d"), DqnInspectDeclType::int_Ptr_, STR_AND_LEN("int *"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_e, DqnInspectMemberType::SampleStruct_e, STR_AND_LEN("e"),
DqnInspectDeclType::int *_, offsetof(SampleStruct, e),
STR_AND_LEN("int *"), STR_AND_LEN("e"), DqnInspectDeclType::int_Ptr_, STR_AND_LEN("int *"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_draw_color, DqnInspectMemberType::SampleStruct_draw_color, STR_AND_LEN("draw_color"),
DqnInspectDeclType::V4_, offsetof(SampleStruct, draw_color),
STR_AND_LEN("V4"), STR_AND_LEN("draw_color"), DqnInspectDeclType::V4_, STR_AND_LEN("V4"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
DqnInspectMetadata_SampleStruct_draw_color, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_draw_color), // metadata array DqnInspectMetadata_SampleStruct_draw_color, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_draw_color), // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_lights, DqnInspectMemberType::SampleStruct_lights, STR_AND_LEN("lights"),
DqnInspectDeclType::Array_, offsetof(SampleStruct, lights),
STR_AND_LEN("Array"), STR_AND_LEN("lights"), DqnInspectDeclType::Array_, STR_AND_LEN("Array"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_camera_matrixes, DqnInspectMemberType::SampleStruct_camera_matrixes, STR_AND_LEN("camera_matrixes"),
DqnInspectDeclType::Array_, offsetof(SampleStruct, camera_matrixes),
STR_AND_LEN("Array"), STR_AND_LEN("camera_matrixes"), DqnInspectDeclType::Array_, STR_AND_LEN("Array"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_bitmaps, DqnInspectMemberType::SampleStruct_bitmaps, STR_AND_LEN("bitmaps"),
DqnInspectDeclType::char **_, offsetof(SampleStruct, bitmaps),
STR_AND_LEN("char **"), STR_AND_LEN("bitmaps"), DqnInspectDeclType::char_Ptr_Ptr_, STR_AND_LEN("char **"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
2, // array_dimensions 2, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_shaders, DqnInspectMemberType::SampleStruct_shaders, STR_AND_LEN("shaders"),
DqnInspectDeclType::int_, offsetof(SampleStruct, shaders),
STR_AND_LEN("int"), STR_AND_LEN("shaders"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_win32_handle, DqnInspectMemberType::SampleStruct_win32_handle, STR_AND_LEN("win32_handle"),
DqnInspectDeclType::void *_, offsetof(SampleStruct, win32_handle),
STR_AND_LEN("void *"), STR_AND_LEN("win32_handle"), DqnInspectDeclType::void_Ptr_, STR_AND_LEN("void *"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_lighting_ambient_coeff, DqnInspectMemberType::SampleStruct_lighting_ambient_coeff, STR_AND_LEN("lighting_ambient_coeff"),
DqnInspectDeclType::V3_, offsetof(SampleStruct, lighting_ambient_coeff),
STR_AND_LEN("V3"), STR_AND_LEN("lighting_ambient_coeff"), DqnInspectDeclType::V3_, STR_AND_LEN("V3"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_draw_call_count, DqnInspectMemberType::SampleStruct_draw_call_count, STR_AND_LEN("draw_call_count"),
DqnInspectDeclType::int_, offsetof(SampleStruct, draw_call_count),
STR_AND_LEN("int"), STR_AND_LEN("draw_call_count"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_f, DqnInspectMemberType::SampleStruct_f, STR_AND_LEN("f"),
DqnInspectDeclType::int_, offsetof(SampleStruct, f),
STR_AND_LEN("int"), STR_AND_LEN("f"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_g, DqnInspectMemberType::SampleStruct_g, STR_AND_LEN("g"),
DqnInspectDeclType::int const_, offsetof(SampleStruct, g),
STR_AND_LEN("int const"), STR_AND_LEN("g"), DqnInspectDeclType::int_const_, STR_AND_LEN("int const"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_h, DqnInspectMemberType::SampleStruct_h, STR_AND_LEN("h"),
DqnInspectDeclType::int *const_, offsetof(SampleStruct, h),
STR_AND_LEN("int *const"), STR_AND_LEN("h"), DqnInspectDeclType::int_Ptr_const_, STR_AND_LEN("int *const"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_i, DqnInspectMemberType::SampleStruct_i, STR_AND_LEN("i"),
DqnInspectDeclType::int const*_, offsetof(SampleStruct, i),
STR_AND_LEN("int const*"), STR_AND_LEN("i"), DqnInspectDeclType::int_const_Ptr_, STR_AND_LEN("int const*"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_j, DqnInspectMemberType::SampleStruct_j, STR_AND_LEN("j"),
DqnInspectDeclType::int *********const_, offsetof(SampleStruct, j),
STR_AND_LEN("int *********const"), STR_AND_LEN("j"), DqnInspectDeclType::int_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_const_, STR_AND_LEN("int *********const"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
9, // array_dimensions 9, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_k, DqnInspectMemberType::SampleStruct_k, STR_AND_LEN("k"),
DqnInspectDeclType::int_, offsetof(SampleStruct, k),
STR_AND_LEN("int"), STR_AND_LEN("k"), DqnInspectDeclType::int_, STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions 0, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_l, DqnInspectMemberType::SampleStruct_l, STR_AND_LEN("l"),
DqnInspectDeclType::int ******_, offsetof(SampleStruct, l),
STR_AND_LEN("int ******"), STR_AND_LEN("l"), DqnInspectDeclType::int_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_, STR_AND_LEN("int ******"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
6, // array_dimensions 6, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array
}, },
{ {
DqnInspectMemberType::SampleStruct_m, DqnInspectMemberType::SampleStruct_m, STR_AND_LEN("m"),
DqnInspectDeclType::int *_, offsetof(SampleStruct, m),
STR_AND_LEN("int *"), STR_AND_LEN("m"), DqnInspectDeclType::int_Ptr_, STR_AND_LEN("int *"),
nullptr, 0, // template_expr and template_expr_len nullptr, 0, // template_expr and template_expr_len
1, // array_dimensions 1, // array_dimensions
nullptr, 0, // metadata array nullptr, 0, // metadata array