Remove MD_Map aliases.

This commit is contained in:
Miguel Lechon
2021-03-16 19:15:48 +01:00
parent 541a5443b6
commit 6026c3639d
5 changed files with 33 additions and 45 deletions
@@ -28,7 +28,7 @@ struct PageInfo
static PageInfo ParsePageInfo(MD_Node *page);
static SiteInfo ParseSiteInfo(MD_Node *site);
static MD_String8 MakeDateString(MD_Node *date);
static void GeneratePageContent(MD_NodeTable *index_table, SiteInfo *site_info, PageInfo *page_info, FILE *file, MD_Node *node);
static void GeneratePageContent(MD_Map *index_table, SiteInfo *site_info, PageInfo *page_info, FILE *file, MD_Node *node);
int main(int argument_count, char **arguments)
{
@@ -80,7 +80,7 @@ int main(int argument_count, char **arguments)
}
//~ NOTE(rjf): Generate index table.
MD_NodeTable index_table = {0};
MD_Map index_table = {0};
{
for(MD_EachNode(root, first_root))
{
@@ -90,7 +90,7 @@ int main(int argument_count, char **arguments)
{
for(MD_EachNode(index_string, node->first_child))
{
MD_NodeTable_Insert(&index_table, MD_NodeTableCollisionRule_Chain, index_string->string, root);
MD_NodeTable_Insert(&index_table, MD_MapCollisionRule_Chain, index_string->string, root);
}
goto end_index_build;
}
@@ -372,7 +372,7 @@ MakeDateString(MD_Node *date)
}
static void
GeneratePageContent(MD_NodeTable *index_table, SiteInfo *site_info, PageInfo *page_info, FILE *file, MD_Node *node)
GeneratePageContent(MD_Map *index_table, SiteInfo *site_info, PageInfo *page_info, FILE *file, MD_Node *node)
{
//~ NOTE(rjf): Text blobs
@@ -513,7 +513,7 @@ GeneratePageContent(MD_NodeTable *index_table, SiteInfo *site_info, PageInfo *pa
MD_Node *index_string = 0;
for(MD_u64 idx = 0; !MD_NodeIsNil(index_string = MD_ChildFromIndex(node, idx)); idx += 1)
{
for(MD_NodeTableSlot *slot = MD_NodeTable_Lookup(index_table, index_string->string);
for(MD_MapSlot *slot = MD_NodeTable_Lookup(index_table, index_string->string);
slot; slot = slot->next)
{
if(slot->value)
+3 -15
View File
@@ -409,18 +409,6 @@ struct MD_Map
MD_MapSlot **table;
};
/////////////////////////////////////////////
//~ NOTE(mal): Helpers
typedef MD_Map MD_StringMap;
typedef MD_Map MD_PtrMap;
// NOTE(mal): MD_NodeTable interface
typedef MD_Map MD_NodeTable;
typedef MD_MapSlot MD_NodeTableSlot;
typedef MD_MapCollisionRule MD_NodeTableCollisionRule;
#define MD_NodeTableCollisionRule_Chain MD_MapCollisionRule_Chain
#define MD_NodeTableCollisionRule_Overwrite MD_MapCollisionRule_Overwrite
//~ Token kinds.
typedef enum MD_TokenKind
@@ -512,7 +500,7 @@ struct MD_ParseCtx
MD_u8 *at;
MD_String8 filename;
MD_String8 file_contents;
MD_NodeTable namespace_table;
MD_Map namespace_table;
MD_Node *selected_namespace;
MD_b32 catastrophic_error;
};
@@ -708,8 +696,8 @@ MD_FUNCTION MD_String8 MD_S8FromS32(MD_String32 str);
MD_FUNCTION MD_String32 MD_S32FromS8(MD_String8 str);
//~ String-To-Node-List Table
MD_FUNCTION MD_NodeTableSlot *MD_NodeTable_Lookup(MD_NodeTable *table, MD_String8 string);
MD_FUNCTION MD_b32 MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rule, MD_String8 string, MD_Node *node);
MD_FUNCTION MD_MapSlot *MD_NodeTable_Lookup(MD_Map *table, MD_String8 string);
MD_FUNCTION MD_b32 MD_NodeTable_Insert(MD_Map *table, MD_MapCollisionRule collision_rule, MD_String8 string, MD_Node *node);
//~ Parsing
MD_FUNCTION MD_b32 MD_TokenKindIsWhitespace(MD_TokenKind kind);
+6 -6
View File
@@ -962,7 +962,7 @@ _MD_Map_Initialize(MD_Map *map)
/////////////////////////////////////////////
//~ NOTE(mal): MD_StringMap
MD_FUNCTION_IMPL MD_MapSlot *
MD_StringMap_Lookup(MD_StringMap *map, MD_String8 string) // NOTE(mal): Or MD_PtrFromString
MD_StringMap_Lookup(MD_Map *map, MD_String8 string) // NOTE(mal): Or MD_PtrFromString
{
_MD_Map_Initialize(map);
@@ -982,7 +982,7 @@ MD_StringMap_Lookup(MD_StringMap *map, MD_String8 string) // NOTE(mal): Or
}
MD_FUNCTION_IMPL MD_b32
MD_StringMap_Insert(MD_StringMap *map, MD_MapCollisionRule collision_rule, MD_String8 string, void *value)
MD_StringMap_Insert(MD_Map *map, MD_MapCollisionRule collision_rule, MD_String8 string, void *value)
{
_MD_Map_Initialize(map);
@@ -1055,7 +1055,7 @@ MD_HashPointer(void *p)
}
MD_FUNCTION_IMPL MD_MapSlot *
MD_PtrMap_Lookup(MD_PtrMap *map, void *key) // NOTE(mal): Or MD_PtrFromPtr
MD_PtrMap_Lookup(MD_Map *map, void *key) // NOTE(mal): Or MD_PtrFromPtr
{
_MD_Map_Initialize(map);
@@ -1076,7 +1076,7 @@ MD_PtrMap_Lookup(MD_PtrMap *map, void *key) // NOTE(mal): Or
}
MD_FUNCTION_IMPL MD_b32
MD_PtrMap_Insert(MD_PtrMap *map, MD_MapCollisionRule collision_rule, void *key, void *value)
MD_PtrMap_Insert(MD_Map *map, MD_MapCollisionRule collision_rule, void *key, void *value)
{
_MD_Map_Initialize(map);
@@ -2080,12 +2080,12 @@ MD_ParseWholeString(MD_String8 filename, MD_String8 contents)
MD_Token token = MD_ZERO_STRUCT;
if(MD_Parse_RequireKind(&ctx, MD_TokenKind_Identifier, &token))
{
MD_NodeTableSlot *existing_namespace_slot = MD_NodeTable_Lookup(&ctx.namespace_table, token.string);
MD_MapSlot *existing_namespace_slot = MD_NodeTable_Lookup(&ctx.namespace_table, token.string);
if(existing_namespace_slot == 0)
{
MD_Node *ns = _MD_MakeNodeFromString_Ctx(&ctx, MD_NodeKind_Namespace, token.string,
token.outer_string.str);
MD_NodeTable_Insert(&ctx.namespace_table, MD_NodeTableCollisionRule_Overwrite, token.string, ns);
MD_NodeTable_Insert(&ctx.namespace_table, MD_MapCollisionRule_Overwrite, token.string, ns);
existing_namespace_slot = MD_NodeTable_Lookup(&ctx.namespace_table, token.string);
}
ctx.selected_namespace = (MD_Node *)existing_namespace_slot->value;
+17 -17
View File
@@ -36,7 +36,7 @@ static RandomSeries rand_seed(MD_u64 initstate, MD_u64 initseq)
MD_GLOBAL struct
{
RandomSeries *random_series;
MD_NodeTable *production_table;
MD_Map *production_table;
} globals = {0};
static void TagSquareBracketSetsAsOptional(MD_Node *node, MD_Node *optional_tag)
@@ -82,8 +82,8 @@ static MD_Node * NewChild(MD_Node *parent)
#define OPTIONAL_TAG "optional"
#define GET_DEPTH(depth_map, node) ((MD_u64)MD_PtrMap_Lookup(depth_map, node)->value)
#define SET_DEPTH(depth_map, node, depth) MD_PtrMap_Insert(depth_map, MD_NodeTableCollisionRule_Overwrite, node, (void *)(depth))
static void PrintRule(MD_PtrMap *depth_map, MD_Node *rule)
#define SET_DEPTH(depth_map, node, depth) MD_PtrMap_Insert(depth_map, MD_MapCollisionRule_Overwrite, node, (void *)(depth))
static void PrintRule(MD_Map *depth_map, MD_Node *rule)
{
MD_b32 is_literal_char = rule->flags & MD_NodeFlag_CharLiteral;
@@ -153,11 +153,11 @@ static void Extend(MD_String8 *s, char c)
}
static void ExpandProduction(MD_Node *production, MD_String8List *out, MD_Node *cur_node,
OperationFlags op_flags, MD_PtrMap *depth_map,
OperationFlags op_flags, MD_Map *depth_map,
MD_u32 max_depth, MD_u32 depth);
static void ExpandRule(MD_Node *rule, MD_String8List *out_strings, MD_Node *cur_node, OperationFlags op_flags,
MD_PtrMap *depth_map, MD_u32 max_depth, MD_u32 depth)
MD_Map *depth_map, MD_u32 max_depth, MD_u32 depth)
{
for(MD_EachNode(rule_element, rule->first_child))
{
@@ -269,7 +269,7 @@ static void ExpandRule(MD_Node *rule, MD_String8List *out_strings, MD_Node *cur_
}
static void ExpandProduction(MD_Node *production, MD_String8List *out, MD_Node *cur_node,
OperationFlags op_flags, MD_PtrMap *depth_map,
OperationFlags op_flags, MD_Map *depth_map,
MD_u32 max_depth, MD_u32 depth)
{
MD_i64 rule_count = MD_ChildCountFromNode(production);
@@ -285,7 +285,7 @@ static void ExpandProduction(MD_Node *production, MD_String8List *out, MD_Node *
ExpandRule(rule, out, cur_node, op_flags, depth_map, max_depth, depth);
}
static MD_Node * FindNonTerminalProduction(MD_Node *node, MD_NodeTable *visited)
static MD_Node * FindNonTerminalProduction(MD_Node *node, MD_Map *visited)
{
MD_Node *result = 0;
@@ -298,7 +298,7 @@ static MD_Node * FindNonTerminalProduction(MD_Node *node, MD_NodeTable *visited)
}
else
{
MD_b32 inserted = MD_NodeTable_Insert(visited, MD_NodeTableCollisionRule_Overwrite, node->string, node);
MD_b32 inserted = MD_NodeTable_Insert(visited, MD_MapCollisionRule_Overwrite, node->string, node);
MD_Assert(inserted);
}
}
@@ -312,7 +312,7 @@ static MD_Node * FindNonTerminalProduction(MD_Node *node, MD_NodeTable *visited)
}
else
{
MD_NodeTableSlot *slot = MD_NodeTable_Lookup(globals.production_table, node->string);
MD_MapSlot *slot = MD_NodeTable_Lookup(globals.production_table, node->string);
if(slot)
{
MD_Node *production = slot->value;
@@ -406,7 +406,7 @@ struct Test
Test *next;
};
static void ComputeElementDepth(MD_PtrMap *depth_map, MD_Node *re)
static void ComputeElementDepth(MD_Map *depth_map, MD_Node *re)
{
MD_u64 result = 0;
MD_b32 has_children = !MD_NodeIsNil(re->first_child);
@@ -575,11 +575,11 @@ int main(int argument_count, char **arguments)
}
// NOTE(mal): Build production hash table
MD_NodeTable production_table_ = {0};
MD_Map production_table_ = {0};
globals.production_table = &production_table_;
for(MD_EachNode(production, productions->first_child))
{
MD_b32 inserted = MD_NodeTable_Insert(globals.production_table, MD_NodeTableCollisionRule_Overwrite,
MD_b32 inserted = MD_NodeTable_Insert(globals.production_table, MD_MapCollisionRule_Overwrite,
production->string, production);
MD_Assert(inserted);
}
@@ -587,7 +587,7 @@ int main(int argument_count, char **arguments)
// NOTE(mal): Check for root production
MD_Node* file_production = 0;
{
MD_NodeTableSlot *file_production_slot = MD_NodeTable_Lookup(globals.production_table, MD_S8Lit("file"));
MD_MapSlot *file_production_slot = MD_NodeTable_Lookup(globals.production_table, MD_S8Lit("file"));
if(!file_production_slot)
{
fprintf(stderr, "Error: Grammar file does not specify \"file\" production\n");
@@ -597,7 +597,7 @@ int main(int argument_count, char **arguments)
}
// NOTE(mal): Check that all branches lead to terminal nodes
MD_NodeTable visited_productions = {0};
MD_Map visited_productions = {0};
for(MD_EachNode(production, productions->first_child))
{
@@ -612,7 +612,7 @@ int main(int argument_count, char **arguments)
// NOTE(mal): Check that all productions are reachable
for(MD_EachNode(production, productions->first_child))
{
MD_NodeTableSlot *slot = MD_NodeTable_Lookup(&visited_productions, production->string);
MD_MapSlot *slot = MD_NodeTable_Lookup(&visited_productions, production->string);
if(!slot)
{
fprintf(stderr, "Warning: Unreachable production \"%.*s\"\n", MD_StringExpand(production->string));
@@ -622,8 +622,8 @@ int main(int argument_count, char **arguments)
// NOTE(mal): Compute depth of productions, rules, rule elements
// NOTE(mal): Init all MD_Node depths to 0
MD_PtrMap depth_map_ = {0};
MD_PtrMap *depth_map = &depth_map_;
MD_Map depth_map_ = {0};
MD_Map *depth_map = &depth_map_;
for(MD_EachNode(production, productions->first_child))
{
SET_DEPTH(depth_map, production, 0);
+2 -2
View File
@@ -506,7 +506,7 @@ int main(void)
MD_MapCollisionRule rules[] = { MD_MapCollisionRule_Chain, MD_MapCollisionRule_Overwrite };
for(int i_rule = 0; i_rule < MD_ArrayCount(rules); ++i_rule)
{
MD_StringMap map = {0};
MD_Map map = {0};
MD_StringMap_Insert(&map, rules[i_rule], keys[0], (void *)0);
MD_StringMap_Insert(&map, rules[i_rule], keys[1], (void *)1);
MD_StringMap_Insert(&map, rules[i_rule], keys[2], (void *)2);
@@ -525,7 +525,7 @@ int main(void)
MD_MapCollisionRule rules[] = { MD_MapCollisionRule_Chain, MD_MapCollisionRule_Overwrite };
for(int i_rule = 0; i_rule < MD_ArrayCount(rules); ++i_rule)
{
MD_PtrMap map = {0};
MD_Map map = {0};
MD_PtrMap_Insert(&map, rules[i_rule], (void *)0, (void *)0);
MD_PtrMap_Insert(&map, rules[i_rule], (void *)1, (void *)1);
MD_PtrMap_Insert(&map, rules[i_rule], (void *)2, (void *)2);