From 8807a16fe3115e19ce4d65f1c8beb476494ccaec Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 14 Oct 2014 21:24:31 -0700 Subject: More type safety, with help from C++ compiler. * parser.h (scanner_t): New typedef. Cleverly, we use yyguts_t as the basis for this, which pays off in a few places, getting rid of conversions. (parser_t): scanner member redeclared to scanner_t *. (yyerror, yyerr, yyerrof, end_of_regex, end_of_char): Declarations updated. * parser.l (yyerror, yyerrorf, num_esc): scanner argument becomes scanner_t * instead of void *. (yyscanner): Occurrences replaced by yyg: why should we refer to the type-unsafe void *yyscanner, when we know that in the middle of the yylex function we have the properly typed yyguts_t *yyg. (end_of_regex, end_of_char): Argument changes to scanner_t * and name strategically changes to yyg, eliminating the local variable and cast. * parser.y (sym_helper): scanner argument becomes scanner_t * instead of void *. (%parse-param}: void *scnr becomes scanner_t *scnr. (define-transform, yybadtoken): Use scanner_t * instead of void *. (parse): Since yylex_init takes a void **, we use it to initialize a local void *, and then assign it to the structure member. --- parser.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'parser.h') diff --git a/parser.h b/parser.h index bb85d01c..532fbfb1 100644 --- a/parser.h +++ b/parser.h @@ -24,6 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +typedef struct yyguts_t scanner_t; + typedef struct { cnum lineno; int errors; @@ -31,17 +33,17 @@ typedef struct { val name; val prepared_msg; val syntax_tree; - void *scanner; + scanner_t *scanner; } parser_t; extern const wchar_t *spec_file; extern val form_to_ln_hash; -void yyerror(void *scanner, parser_t *, const char *s); -void yyerr(void *scanner, const char *s); -void yyerrorf(void *scanner, val s, ...); +void yyerror(scanner_t *scanner, parser_t *, const char *s); +void yyerr(scanner_t *scanner, const char *s); +void yyerrorf(scanner_t *scanner, val s, ...); void yybadtoken(parser_t *, int tok, val context); -void end_of_regex(void *scanner); -void end_of_char(void *scanner); +void end_of_regex(scanner_t *scanner); +void end_of_char(scanner_t *scanner); int yylex_init(void **pscanner); int yylex_destroy(void *scanner); parser_t *yyget_extra(void *scanner); -- cgit v1.2.3