From a2a663dafd53cbebfa510f6dbd19aed6cc545e32 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 17 Apr 2015 23:45:20 +0200 Subject: parse: replace type-specific deleters by simple delete calls --- src/parse.cpp | 61 +++++++++++++++++++++++------------------------------------ src/parse.y | 33 ++++++++++---------------------- 2 files changed, 34 insertions(+), 60 deletions(-) diff --git a/src/parse.cpp b/src/parse.cpp index a0ce970..3afda25 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -5,19 +5,6 @@ typedef std::vector> vars_t; typedef std::pair, vars_t> rhs_t; -static inline void free_string(std::string *v) { - delete v; -} - -static inline void free_symbol(solar::symbol_t *v) { - delete v; -} - -static inline void free_rhs(rhs_t *v) { - delete v; -} - - typedef union parse_symbol_value { parse_token_value_t token; std::string *symbol_action; @@ -453,9 +440,9 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 5; parse_reduce_9(parser->stack[parser->top + 0].value.token.str, parser->stack[parser->top + 3].value.symbol_rhs, parser->stack[parser->top + 4].value.symbol_action, grammar); - free_string(parser->stack[parser->top + 0].value.token.str); - free_rhs(parser->stack[parser->top + 3].value.symbol_rhs); - free_string(parser->stack[parser->top + 4].value.symbol_action); + delete(parser->stack[parser->top + 0].value.token.str); + delete(parser->stack[parser->top + 3].value.symbol_rhs); + delete(parser->stack[parser->top + 4].value.symbol_action); parser->stack[++parser->top].state = 2; } break; @@ -469,7 +456,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 2; result.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, grammar); - free_symbol(parser->stack[parser->top + 1].value.symbol_symbol); + delete(parser->stack[parser->top + 1].value.symbol_symbol); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; parser->stack[++parser->top].state = 17; } @@ -529,7 +516,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 1; result.symbol_action = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); - free_string(parser->stack[parser->top + 0].value.token.str); + delete(parser->stack[parser->top + 0].value.token.str); parser->stack[parser->top].value.symbol_action = result.symbol_action; parser->stack[++parser->top].state = 24; } @@ -540,7 +527,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 2; result.symbol_rhs = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); - free_string(parser->stack[parser->top + 1].value.token.str); + delete(parser->stack[parser->top + 1].value.token.str); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; parser->stack[++parser->top].state = 17; } @@ -551,7 +538,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 1; result.symbol_symbol = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); - free_string(parser->stack[parser->top + 0].value.token.str); + delete(parser->stack[parser->top + 0].value.token.str); parser->stack[parser->top].value.symbol_symbol = result.symbol_symbol; switch (parser->stack[parser->top].state) { case 17: @@ -571,7 +558,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 1; result.symbol_term = parse_reduce_21(parser->stack[parser->top + 0].value.token.str, grammar); - free_string(parser->stack[parser->top + 0].value.token.str); + delete(parser->stack[parser->top + 0].value.token.str); parser->stack[parser->top].value.symbol_term = result.symbol_term; switch (parser->stack[parser->top].state) { case 17: @@ -930,8 +917,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 7; parse_reduce_3(parser->stack[parser->top + 5].value.token.str, parser->stack[parser->top + 6].value.token.str, grammar); - free_string(parser->stack[parser->top + 5].value.token.str); - free_string(parser->stack[parser->top + 6].value.token.str); + delete(parser->stack[parser->top + 5].value.token.str); + delete(parser->stack[parser->top + 6].value.token.str); parser->stack[++parser->top].state = 2; } break; @@ -941,8 +928,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 5; result.symbol_rhs = parse_reduce_13(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 3].value.symbol_varname, grammar); - free_symbol(parser->stack[parser->top + 1].value.symbol_symbol); - free_string(parser->stack[parser->top + 3].value.symbol_varname); + delete(parser->stack[parser->top + 1].value.symbol_symbol); + delete(parser->stack[parser->top + 3].value.symbol_varname); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; parser->stack[++parser->top].state = 17; } @@ -997,7 +984,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 8; parse_reduce_7(parser->stack[parser->top + 7].value.token.str, grammar); - free_string(parser->stack[parser->top + 7].value.token.str); + delete(parser->stack[parser->top + 7].value.token.str); parser->stack[++parser->top].state = 2; } break; @@ -1007,7 +994,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 8; parse_reduce_6(parser->stack[parser->top + 7].value.token.str, grammar); - free_string(parser->stack[parser->top + 7].value.token.str); + delete(parser->stack[parser->top + 7].value.token.str); parser->stack[++parser->top].state = 2; } break; @@ -1017,9 +1004,9 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 8; parse_reduce_4(parser->stack[parser->top + 5].value.symbol_term, parser->stack[parser->top + 6].value.token.str, parser->stack[parser->top + 7].value.symbol_varname, grammar); - free_symbol(parser->stack[parser->top + 5].value.symbol_term); - free_string(parser->stack[parser->top + 6].value.token.str); - free_string(parser->stack[parser->top + 7].value.symbol_varname); + delete(parser->stack[parser->top + 5].value.symbol_term); + delete(parser->stack[parser->top + 6].value.token.str); + delete(parser->stack[parser->top + 7].value.symbol_varname); parser->stack[++parser->top].state = 2; } break; @@ -1029,8 +1016,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 6; result.symbol_rhs = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 4].value.symbol_varname, grammar); - free_symbol(parser->stack[parser->top + 1].value.symbol_symbol); - free_string(parser->stack[parser->top + 4].value.symbol_varname); + delete(parser->stack[parser->top + 1].value.symbol_symbol); + delete(parser->stack[parser->top + 4].value.symbol_varname); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; parser->stack[++parser->top].state = 17; } @@ -1107,7 +1094,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 11; parse_reduce_10(parser->stack[parser->top + 0].value.token.str, parser->stack[parser->top + 4].value.token.c, parser->stack[parser->top + 8].value.token.c, grammar); - free_string(parser->stack[parser->top + 0].value.token.str); + delete(parser->stack[parser->top + 0].value.token.str); parser->stack[++parser->top].state = 2; } break; @@ -1166,8 +1153,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 12; parse_reduce_8(parser->stack[parser->top + 10].value.token.str, parser->stack[parser->top + 11].value.symbol_varname, grammar); - free_string(parser->stack[parser->top + 10].value.token.str); - free_string(parser->stack[parser->top + 11].value.symbol_varname); + delete(parser->stack[parser->top + 10].value.token.str); + delete(parser->stack[parser->top + 11].value.symbol_varname); parser->stack[++parser->top].state = 2; } break; @@ -1177,8 +1164,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus default: parser->top -= 13; parse_reduce_5(parser->stack[parser->top + 11].value.symbol_symbol, parser->stack[parser->top + 12].value.symbol_varname, grammar); - free_symbol(parser->stack[parser->top + 11].value.symbol_symbol); - free_string(parser->stack[parser->top + 12].value.symbol_varname); + delete(parser->stack[parser->top + 11].value.symbol_symbol); + delete(parser->stack[parser->top + 12].value.symbol_varname); parser->stack[++parser->top].state = 2; } break; diff --git a/src/parse.y b/src/parse.y index 4fcba12..7b46368 100644 --- a/src/parse.y +++ b/src/parse.y @@ -5,54 +5,41 @@ %source { typedef std::vector> vars_t; typedef std::pair, vars_t> rhs_t; - - -static inline void free_string(std::string *v) { - delete v; -} - -static inline void free_symbol(solar::symbol_t *v) { - delete v; -} - -static inline void free_rhs(rhs_t *v) { - delete v; -} } %type SYMBOL {std::string *} str -%destructor SYMBOL free_string +%destructor SYMBOL delete %type SYMBOL_UC {std::string *} str -%destructor SYMBOL_UC free_string +%destructor SYMBOL_UC delete %type BLOCK {std::string *} str -%destructor BLOCK free_string +%destructor BLOCK delete %type SQBLOCK {std::string *} str -%destructor SQBLOCK free_string +%destructor SQBLOCK delete %type STRING {std::string *} str -%destructor STRING free_string +%destructor STRING delete %type CHAR {unsigned char} c %type rhs {rhs_t *} -%destructor rhs free_rhs +%destructor rhs delete %type action {std::string *} -%destructor action free_string +%destructor action delete %type symbol {solar::symbol_t *} -%destructor symbol free_symbol +%destructor symbol delete %type term {solar::symbol_t *} -%destructor term free_symbol +%destructor term delete %type varname {std::string *} -%destructor varname free_string +%destructor varname delete %extra_arg {__attribute__((unused)) solar::grammar_t *} grammar -- cgit v1.2.3