[map] Expose PtrMap on md.h. Remove NodeTable defines.

This commit is contained in:
Miguel Lechon
2021-03-22 15:45:36 +01:00
parent 14549f8483
commit 20f85761c7
4 changed files with 20 additions and 20 deletions
@@ -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_MapCollisionRule_Chain, index_string->string, root);
MD_StringMap_Insert(&index_table, MD_MapCollisionRule_Chain, index_string->string, root);
}
goto end_index_build;
}
+5 -1
View File
@@ -696,10 +696,14 @@ MD_FUNCTION MD_String16 MD_S16FromS8(MD_String8 str);
MD_FUNCTION MD_String8 MD_S8FromS32(MD_String32 str);
MD_FUNCTION MD_String32 MD_S32FromS8(MD_String8 str);
//~ String-To-Node-List Table
//~ String-To-Pointer Table
MD_FUNCTION MD_MapSlot *MD_StringMap_Lookup(MD_Map *table, MD_String8 string);
MD_FUNCTION MD_b32 MD_StringMap_Insert(MD_Map *table, MD_MapCollisionRule collision_rule, MD_String8 string, void *value);
//~ Pointer-To-Pointer Table
MD_FUNCTION MD_MapSlot *MD_PtrMap_Lookup(MD_Map *map, void *key);
MD_FUNCTION MD_b32 MD_PtrMap_Insert(MD_Map *map, MD_MapCollisionRule collision_rule, void *key, void *value);
//~ Parsing
MD_FUNCTION MD_b32 MD_TokenKindIsWhitespace(MD_TokenKind kind);
MD_FUNCTION MD_b32 MD_TokenKindIsComment(MD_TokenKind kind);
+4 -8
View File
@@ -1033,10 +1033,6 @@ MD_StringMap_Insert(MD_Map *map, MD_MapCollisionRule collision_rule, MD_String8
return !!slot;
}
// NOTE(mal): Original MD_NodeTable interface
#define MD_NodeTable_Lookup(map, string) MD_StringMap_Lookup(map, string)
#define MD_NodeTable_Insert(map, collision_rule, string, node) MD_StringMap_Insert(map, collision_rule, string, (void *) node)
/////////////////////////////////////////////
//~ NOTE(mal): MD_PtrMap
@@ -1053,7 +1049,7 @@ MD_HashPointer(void *p)
}
MD_FUNCTION_IMPL MD_MapSlot *
MD_PtrMap_Lookup(MD_Map *map, void *key) // NOTE(mal): Or MD_PtrFromPtr
MD_PtrMap_Lookup(MD_Map *map, void *key)
{
_MD_Map_Initialize(map);
@@ -2095,13 +2091,13 @@ MD_ParseWholeString(MD_String8 filename, MD_String8 contents)
MD_Token token = MD_ZERO_STRUCT;
if(MD_Parse_RequireKind(&ctx, MD_TokenKind_Identifier, &token))
{
MD_MapSlot *existing_namespace_slot = MD_NodeTable_Lookup(&ctx.namespace_table, token.string);
MD_MapSlot *existing_namespace_slot = MD_StringMap_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_MapCollisionRule_Overwrite, token.string, ns);
existing_namespace_slot = MD_NodeTable_Lookup(&ctx.namespace_table, token.string);
MD_StringMap_Insert(&ctx.namespace_table, MD_MapCollisionRule_Overwrite, token.string, ns);
existing_namespace_slot = MD_StringMap_Lookup(&ctx.namespace_table, token.string);
}
ctx.selected_namespace = (MD_Node *)existing_namespace_slot->value;
}
+10 -10
View File
@@ -252,7 +252,7 @@ static void ExpandRule(MD_Node *rule, MD_String8List *out_strings, MD_Node *cur_
}
else // NOTE(mal): Non-terminal production
{
MD_Node * production = MD_NodeTable_Lookup(globals.production_table, rule_element->string)->value;
MD_Node * production = MD_StringMap_Lookup(globals.production_table, rule_element->string)->value;
MD_Assert(production);
ExpandProduction(production, out_strings, cur_node, op_flags, depth_map, max_depth, depth+1);
}
@@ -293,13 +293,13 @@ static MD_Node * FindNonTerminalProduction(MD_Node *node, MD_Map *visited)
MD_b32 should_visit = 1;
if(!MD_NodeIsNil(node->first_child) && node->string.size)
{
if(MD_NodeTable_Lookup(visited, node->string))
if(MD_StringMap_Lookup(visited, node->string))
{
should_visit = 0;
}
else
{
MD_b32 inserted = MD_NodeTable_Insert(visited, MD_MapCollisionRule_Overwrite, node->string, node);
MD_b32 inserted = MD_StringMap_Insert(visited, MD_MapCollisionRule_Overwrite, node->string, node);
MD_Assert(inserted);
}
}
@@ -313,7 +313,7 @@ static MD_Node * FindNonTerminalProduction(MD_Node *node, MD_Map *visited)
}
else
{
MD_MapSlot *slot = MD_NodeTable_Lookup(globals.production_table, node->string);
MD_MapSlot *slot = MD_StringMap_Lookup(globals.production_table, node->string);
if(slot)
{
MD_Node *production = slot->value;
@@ -431,7 +431,7 @@ static void ComputeElementDepth(MD_Map *depth_map, MD_Node *re)
}
else
{
MD_Node * production = MD_NodeTable_Lookup(globals.production_table, re->string)->value;
MD_Node * production = MD_StringMap_Lookup(globals.production_table, re->string)->value;
result = GET_DEPTH(depth_map, production)+1;
}
}
@@ -580,7 +580,7 @@ int main(int argument_count, char **arguments)
globals.production_table = &production_table_;
for(MD_EachNode(production, productions->first_child))
{
MD_b32 inserted = MD_NodeTable_Insert(globals.production_table, MD_MapCollisionRule_Overwrite,
MD_b32 inserted = MD_StringMap_Insert(globals.production_table, MD_MapCollisionRule_Overwrite,
production->string, production);
MD_Assert(inserted);
}
@@ -588,7 +588,7 @@ int main(int argument_count, char **arguments)
// NOTE(mal): Check for root production
MD_Node* file_production = 0;
{
MD_MapSlot *file_production_slot = MD_NodeTable_Lookup(globals.production_table, MD_S8Lit("file"));
MD_MapSlot *file_production_slot = MD_StringMap_Lookup(globals.production_table, MD_S8Lit("file"));
if(!file_production_slot)
{
fprintf(stderr, "Error: Grammar file does not specify \"file\" production\n");
@@ -613,7 +613,7 @@ int main(int argument_count, char **arguments)
// NOTE(mal): Check that all productions are reachable
for(MD_EachNode(production, productions->first_child))
{
MD_MapSlot *slot = MD_NodeTable_Lookup(&visited_productions, production->string);
MD_MapSlot *slot = MD_StringMap_Lookup(&visited_productions, production->string);
if(!slot)
{
fprintf(stderr, "Warning: Unreachable production \"%.*s\"\n", MD_StringExpand(production->string));
@@ -660,7 +660,7 @@ int main(int argument_count, char **arguments)
MD_Assert(MD_NodeIsNil(rule_element->first_child));
if(!(rule_element->flags & MD_NodeFlag_CharLiteral))
{
MD_Node * production = MD_NodeTable_Lookup(globals.production_table, rule_element->string)->value;
MD_Node * production = MD_StringMap_Lookup(globals.production_table, rule_element->string)->value;
depth = GET_DEPTH(depth_map, production);
}
depth += 1;
@@ -713,7 +713,7 @@ int main(int argument_count, char **arguments)
RandomSeries random_series = rand_seed(0, 0); // NOTE(mal): Reproduceable
globals.random_series = &random_series;
MD_Node* file_production_node = MD_NodeTable_Lookup(globals.production_table, MD_S8Lit("file"))->value;
MD_Node* file_production_node = MD_StringMap_Lookup(globals.production_table, MD_S8Lit("file"))->value;
// NOTE(mal): Generate test_count unique tests, sorted by complexity
MD_u32 test_count = 1000;