From 9f5c32e2050295045c6982d23a80d4c492e0485b Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Wed, 8 May 2013 18:02:35 +0200 Subject: [PATCH] add h_cfgrammar_free() --- src/cfgrammar.c | 12 ++++++++++++ src/cfgrammar.h | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/cfgrammar.c b/src/cfgrammar.c index 80e60019..eb3239d2 100644 --- a/src/cfgrammar.c +++ b/src/cfgrammar.c @@ -1,6 +1,7 @@ /* Context-free grammar representation and analysis */ #include "cfgrammar.h" +#include "allocator.h" #include <assert.h> #include <ctype.h> @@ -10,6 +11,7 @@ HCFGrammar *h_cfgrammar_new(HAllocator *mm__) HCFGrammar *g = h_new(HCFGrammar, 1); assert(g != NULL); + g->mm__ = mm__; g->arena = h_new_arena(mm__, 0); // default blocksize g->nts = h_hashset_new(g->arena, h_eq_ptr, h_hash_ptr); g->geneps = NULL; @@ -19,6 +21,16 @@ HCFGrammar *h_cfgrammar_new(HAllocator *mm__) return g; } +/* Frees the given grammar and associated data. + * Does *not* free parsers' CFG forms as created by h_desugar. + */ +void h_cfgrammar_free(HCFGrammar *g) +{ + HAllocator *mm__ = g->mm__; + h_delete_arena(g->arena); + h_free(g); +} + // helpers static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol); diff --git a/src/cfgrammar.h b/src/cfgrammar.h index 5e12ba07..f336db5c 100644 --- a/src/cfgrammar.h +++ b/src/cfgrammar.h @@ -11,6 +11,7 @@ typedef struct HCFGrammar_ { HHashTable *first; // memoized first sets of the grammar's symbols HHashTable *follow; // memoized follow sets of the grammar's NTs HArena *arena; + HAllocator *mm__; } HCFGrammar; /* mapping input bytes or end to tokens @@ -29,6 +30,11 @@ static const HCFToken end_token = 0x200; */ HCFGrammar *h_cfgrammar(HAllocator* mm__, const HParser *parser); +/* Frees the given grammar and associated data. + * Does *not* free parsers' CFG forms as created by h_desugar. + */ +void h_cfgrammar_free(HCFGrammar *g); + /* Does the given symbol derive the empty string (under g)? */ bool h_symbol_derives_epsilon(HCFGrammar *g, const HCFChoice *symbol); -- GitLab