mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-08 16:48:15 +00:00
[examples] do the deduplication todos in types example
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:826
|
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:851
|
||||||
TypeInfoMember Circle_members[2] = {
|
TypeInfoMember Circle_members[2] = {
|
||||||
{"r", 1, -1, &F32_type_info},
|
{"r", 1, -1, &F32_type_info},
|
||||||
{"pos", 3, -1, &V2F32_type_info},
|
{"pos", 3, -1, &V2F32_type_info},
|
||||||
@@ -14,14 +14,14 @@ TypeInfoMember RoundedPolygon_members[3] = {
|
|||||||
{"p", 1, 1, &V2F32_type_info},
|
{"p", 1, 1, &V2F32_type_info},
|
||||||
};
|
};
|
||||||
|
|
||||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:865
|
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:890
|
||||||
TypeInfoEnumerant Shape_members[3] = {
|
TypeInfoEnumerant Shape_members[3] = {
|
||||||
{"Circle", 6, 1},
|
{"Circle", 6, 1},
|
||||||
{"Segment", 7, 2},
|
{"Segment", 7, 2},
|
||||||
{"Polygon", 7, 3},
|
{"Polygon", 7, 3},
|
||||||
};
|
};
|
||||||
|
|
||||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:901
|
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:926
|
||||||
TypeInfo U32_type_info = {TypeKind_Basic, "U32", 3, 4, 0, 0};
|
TypeInfo U32_type_info = {TypeKind_Basic, "U32", 3, 4, 0, 0};
|
||||||
TypeInfo F32_type_info = {TypeKind_Basic, "F32", 3, 4, 0, 0};
|
TypeInfo F32_type_info = {TypeKind_Basic, "F32", 3, 4, 0, 0};
|
||||||
TypeInfo V2F32_type_info = {TypeKind_Basic, "V2F32", 5, 8, 0, 0};
|
TypeInfo V2F32_type_info = {TypeKind_Basic, "V2F32", 5, 8, 0, 0};
|
||||||
@@ -30,7 +30,7 @@ TypeInfo RoundedSegment_type_info = {TypeKind_Struct, "RoundedSegment", 14, 3, R
|
|||||||
TypeInfo RoundedPolygon_type_info = {TypeKind_Struct, "RoundedPolygon", 14, 3, RoundedPolygon_members, 0};
|
TypeInfo RoundedPolygon_type_info = {TypeKind_Struct, "RoundedPolygon", 14, 3, RoundedPolygon_members, 0};
|
||||||
TypeInfo Shape_type_info = {TypeKind_Enum, "Shape", 5, 3, Shape_members, &U32_type_info};
|
TypeInfo Shape_type_info = {TypeKind_Enum, "Shape", 5, 3, Shape_members, &U32_type_info};
|
||||||
|
|
||||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:961
|
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:986
|
||||||
TypeInfo*
|
TypeInfo*
|
||||||
type_info_from_shape(Shape v)
|
type_info_from_shape(Shape v)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#if !defined(META_TYPES_H)
|
#if !defined(META_TYPES_H)
|
||||||
#define META_TYPES_H
|
#define META_TYPES_H
|
||||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:695
|
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:729
|
||||||
typedef struct Circle Circle;
|
typedef struct Circle Circle;
|
||||||
struct Circle
|
struct Circle
|
||||||
{
|
{
|
||||||
@@ -29,11 +29,11 @@ Shape_Segment = 2,
|
|||||||
Shape_Polygon = 3,
|
Shape_Polygon = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:779
|
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:813
|
||||||
TypeInfo* type_info_from_shape(Shape v);
|
TypeInfo* type_info_from_shape(Shape v);
|
||||||
U32 max_slot_from_shape(Shape v);
|
U32 max_slot_from_shape(Shape v);
|
||||||
|
|
||||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:810
|
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:835
|
||||||
extern TypeInfo U32_type_info;
|
extern TypeInfo U32_type_info;
|
||||||
extern TypeInfo F32_type_info;
|
extern TypeInfo F32_type_info;
|
||||||
extern TypeInfo V2F32_type_info;
|
extern TypeInfo V2F32_type_info;
|
||||||
|
|||||||
@@ -80,6 +80,52 @@ gen_enumerant_from_name(GEN_TypeInfo *enum_type, MD_String8 name)
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GEN_MapCase*
|
||||||
|
gen_map_case_from_enumerant(GEN_MapInfo *map, GEN_TypeEnumerant *enumerant)
|
||||||
|
{
|
||||||
|
GEN_MapCase *result = 0;
|
||||||
|
for (GEN_MapCase *map_case = map->first_case;
|
||||||
|
map_case != 0;
|
||||||
|
map_case = map_case->next)
|
||||||
|
{
|
||||||
|
if (map_case->in_enumerant == enumerant)
|
||||||
|
{
|
||||||
|
result = map_case;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MD_String8
|
||||||
|
gen_in_type_string_from_map(GEN_MapInfo *map)
|
||||||
|
{
|
||||||
|
MD_String8 result = {0};
|
||||||
|
if (map->types_are_good)
|
||||||
|
{
|
||||||
|
result = map->in->node->string;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
MD_String8
|
||||||
|
gen_out_type_string_from_map(GEN_MapInfo *map)
|
||||||
|
{
|
||||||
|
MD_String8 result = {0};
|
||||||
|
if (map->types_are_good)
|
||||||
|
{
|
||||||
|
if (map->out_is_type_info_ptr)
|
||||||
|
{
|
||||||
|
result = MD_S8Lit("TypeInfo*");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = map->out->node->string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
//~ analyzers /////////////////////////////////////////////////////////////////
|
//~ analyzers /////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -488,8 +534,7 @@ gen_equip_map_in_out_types(void)
|
|||||||
|
|
||||||
// types are good
|
// types are good
|
||||||
int types_are_good = 0;
|
int types_are_good = 0;
|
||||||
if (in_type_info != 0 &&
|
if (in_type_info != 0 && (out_type_info != 0 || out_is_type_info_ptr))
|
||||||
(out_type_info != 0 || out_is_type_info_ptr))
|
|
||||||
{
|
{
|
||||||
types_are_good = 1;
|
types_are_good = 1;
|
||||||
}
|
}
|
||||||
@@ -654,20 +699,9 @@ gen_check_complete_map_cases(void)
|
|||||||
enumerant != 0;
|
enumerant != 0;
|
||||||
enumerant = enumerant->next)
|
enumerant = enumerant->next)
|
||||||
{
|
{
|
||||||
// TODO deduplicate
|
GEN_MapCase *existing_case = gen_map_case_from_enumerant(map, enumerant);
|
||||||
int enumerant_has_case = 0;
|
|
||||||
for (GEN_MapCase *map_case = map->first_case;
|
|
||||||
map_case != 0;
|
|
||||||
map_case = map_case->next)
|
|
||||||
{
|
|
||||||
if (map_case->in_enumerant == enumerant)
|
|
||||||
{
|
|
||||||
enumerant_has_case = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!enumerant_has_case)
|
if (existing_case == 0)
|
||||||
{
|
{
|
||||||
if (!printed_message_for_this_map)
|
if (!printed_message_for_this_map)
|
||||||
{
|
{
|
||||||
@@ -784,17 +818,8 @@ gen_function_declarations_from_maps(FILE *out)
|
|||||||
{
|
{
|
||||||
if (map->types_are_good)
|
if (map->types_are_good)
|
||||||
{
|
{
|
||||||
// TODO deduplicate
|
MD_String8 in_type = gen_in_type_string_from_map(map);
|
||||||
MD_String8 in_type = map->in->node->string;
|
MD_String8 out_type = gen_out_type_string_from_map(map);
|
||||||
MD_String8 out_type = {0};
|
|
||||||
if (map->out_is_type_info_ptr)
|
|
||||||
{
|
|
||||||
out_type = MD_S8Lit("TypeInfo*");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out_type = map->out->node->string;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(out, "%.*s %.*s(%.*s v);\n",
|
fprintf(out, "%.*s %.*s(%.*s v);\n",
|
||||||
MD_S8VArg(out_type), MD_S8VArg(map->node->string), MD_S8VArg(in_type));
|
MD_S8VArg(out_type), MD_S8VArg(map->node->string), MD_S8VArg(in_type));
|
||||||
@@ -966,17 +991,8 @@ gen_function_definitions_from_maps(FILE *out)
|
|||||||
{
|
{
|
||||||
if (map->types_are_good)
|
if (map->types_are_good)
|
||||||
{
|
{
|
||||||
// TODO deduplicate
|
MD_String8 in_type = gen_in_type_string_from_map(map);
|
||||||
MD_String8 in_type = map->in->node->string;
|
MD_String8 out_type = gen_out_type_string_from_map(map);
|
||||||
MD_String8 out_type = {0};
|
|
||||||
if (map->out_is_type_info_ptr)
|
|
||||||
{
|
|
||||||
out_type = MD_S8Lit("TypeInfo*");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out_type = map->out->node->string;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(out, "%.*s\n", MD_S8VArg(out_type));
|
fprintf(out, "%.*s\n", MD_S8VArg(out_type));
|
||||||
fprintf(out, "%.*s(%.*s v)\n", MD_S8VArg(map->node->string), MD_S8VArg(in_type));
|
fprintf(out, "%.*s(%.*s v)\n", MD_S8VArg(map->node->string), MD_S8VArg(in_type));
|
||||||
@@ -1012,20 +1028,9 @@ gen_function_definitions_from_maps(FILE *out)
|
|||||||
enumerant != 0;
|
enumerant != 0;
|
||||||
enumerant = enumerant->next)
|
enumerant = enumerant->next)
|
||||||
{
|
{
|
||||||
// TODO deduplicate
|
GEN_MapCase *explicit_case = gen_map_case_from_enumerant(map, enumerant);
|
||||||
int enumerant_has_explicit_case = 0;
|
|
||||||
for (GEN_MapCase *map_case = map->first_case;
|
|
||||||
map_case != 0;
|
|
||||||
map_case = map_case->next)
|
|
||||||
{
|
|
||||||
if (map_case->in_enumerant == enumerant)
|
|
||||||
{
|
|
||||||
enumerant_has_explicit_case = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!enumerant_has_explicit_case)
|
if (explicit_case == 0)
|
||||||
{
|
{
|
||||||
map_has_an_implicit_case = 1;
|
map_has_an_implicit_case = 1;
|
||||||
MD_String8 in_expr = enumerant->node->string;
|
MD_String8 in_expr = enumerant->node->string;
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ struct GEN_MapInfo
|
|||||||
GEN_MapInfo *next;
|
GEN_MapInfo *next;
|
||||||
MD_Node *node;
|
MD_Node *node;
|
||||||
|
|
||||||
|
// TODO(allen): fix this shit idiot
|
||||||
GEN_TypeInfo *in;
|
GEN_TypeInfo *in;
|
||||||
GEN_TypeInfo *out;
|
GEN_TypeInfo *out;
|
||||||
int out_is_type_info_ptr;
|
int out_is_type_info_ptr;
|
||||||
@@ -95,6 +96,10 @@ void gen_type_resolve_error(MD_Node *reference);
|
|||||||
|
|
||||||
GEN_TypeEnumerant* gen_enumerant_from_name(GEN_TypeInfo *enum_type, MD_String8 name);
|
GEN_TypeEnumerant* gen_enumerant_from_name(GEN_TypeInfo *enum_type, MD_String8 name);
|
||||||
|
|
||||||
|
GEN_MapCase* gen_map_case_from_enumerant(GEN_MapInfo *map, GEN_TypeEnumerant *enumerant);
|
||||||
|
MD_String8 gen_in_type_string_from_map(GEN_MapInfo *map);
|
||||||
|
MD_String8 gen_out_type_string_from_map(GEN_MapInfo *map);
|
||||||
|
|
||||||
//~ analyzers /////////////////////////////////////////////////////////////////
|
//~ analyzers /////////////////////////////////////////////////////////////////
|
||||||
void gen_gather_types_and_maps(MD_Node *list);
|
void gen_gather_types_and_maps(MD_Node *list);
|
||||||
void gen_check_duplicate_member_names(void);
|
void gen_check_duplicate_member_names(void);
|
||||||
|
|||||||
+3
-15
@@ -10,6 +10,9 @@ Example Programs:
|
|||||||
[x] User error checking
|
[x] User error checking
|
||||||
[x] Datadesk-like setup
|
[x] Datadesk-like setup
|
||||||
[ ] Example type metadata
|
[ ] Example type metadata
|
||||||
|
[ ] Cleanup & Simplification Pass
|
||||||
|
[ ] Commentary
|
||||||
|
[ ] Example Type File With Errors
|
||||||
[ ] Example of simple expression parser
|
[ ] Example of simple expression parser
|
||||||
[ ] Example of C-like expression parser (with value and type expressions)
|
[ ] Example of C-like expression parser (with value and type expressions)
|
||||||
[ ] Example(s) of using overrides
|
[ ] Example(s) of using overrides
|
||||||
@@ -21,18 +24,3 @@ Example Metadesk Files:
|
|||||||
[x] identifiers, numbers, strings, and symbols
|
[x] identifiers, numbers, strings, and symbols
|
||||||
[x] sets, seperators, and tags
|
[x] sets, seperators, and tags
|
||||||
|
|
||||||
|
|
||||||
Allen's Final Tweak Notes (September 10th 2021):
|
|
||||||
|
|
||||||
*** MD_EachNodeRef seems bad to me. ***
|
|
||||||
|
|
||||||
Using it is equivalent to:
|
|
||||||
for (MD_EachNode(it, first_child)
|
|
||||||
{
|
|
||||||
MD_Node *node = MD_ResolveFromReference(it); // this line is saved by the macro
|
|
||||||
}
|
|
||||||
|
|
||||||
Explaning this concept seems more difficult with the extra macro. I think it'd be
|
|
||||||
clearer and basically just as maintenance efficient to live without this.
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user