From b18a53b912ae66ad2bb23985640c9fac56ced358 Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Tue, 2 May 2023 23:45:52 -0300 Subject: parser: Split block into small functions Since it is possible to look a future token without consuming it, it was possible to split the block parser into small chunks of code. There is the performance drawback, because now the parser makes multiple lookups to the same token. However IMO that it is not a big concern given the small computation required to get a token. Also it can be easily addressed by computing all token in advance. Memory Leak: During the refactor I found some extra memory leaks related to not released scopes. So then, more than just printing a message I introduced an assert on scope.c to make sure developers will get this feedback asap because our testing framework suppress messages from stderr when the test passes. Signed-off-by: Carlos Maniero --- src/scope.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/scope.c') diff --git a/src/scope.c b/src/scope.c index 662e59c..6338e60 100644 --- a/src/scope.c +++ b/src/scope.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ #include "scope.h" +#include #include #include #include @@ -58,6 +59,7 @@ scope_destroy(scope_t *scope) fprintf(stderr, "Stack not cleaned before destroying. This may lead to memory leaks.\n" "Please make sure to call the leave function before destroying it."); + assert(scope->stack->size == 1); } for (size_t i = 0; i < scope->stack->size; i++) { -- cgit v1.2.3