[qfcc] Implement location printing for the parsers

It's pretty bare-bones, but it's at least consistent across all the
parsers, and it's currently used only by the parser debug support.
This commit is contained in:
Bill Currie 2024-08-30 13:13:13 +09:00
parent daaaeb9aed
commit bca4d0e794
6 changed files with 32 additions and 8 deletions

View file

@ -49,6 +49,21 @@ typedef struct rua_loc_s {
int file;
} rua_loc_t;
#define RUA_LOC_DEFAULT(Current, Rhs, N) \
do if (N) { \
(Current).line = YYRHSLOC (Rhs, 1).line; \
(Current).column = YYRHSLOC (Rhs, 1).column; \
(Current).last_line = YYRHSLOC (Rhs, N).last_line; \
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
(Current).file = YYRHSLOC (Rhs, N).file; \
} else { \
(Current).line = (Current).last_line = \
YYRHSLOC (Rhs, 0).last_line; \
(Current).column = (Current).last_column = \
YYRHSLOC (Rhs, 0).last_column; \
(Current).file = YYRHSLOC (Rhs, 0).file; \
} while (0)
typedef struct expr_s expr_t;
typedef struct symtab_s symtab_t;
typedef struct function_s function_t;
@ -156,6 +171,8 @@ void rua_macro_line (rua_macro_t *macro, void *scanner);
void rua_macro_va_opt (rua_macro_t *macro, void *scanner);
void rua_macro_va_args (rua_macro_t *macro, void *scanner);
void rua_print_location (FILE *out, const rua_loc_t *loc);
#include "tools/qfcc/source/pre-parse.h"
typedef struct rua_parser_s {

View file

@ -103,8 +103,8 @@ parse_error (void *scanner)
#define PARSE_ERROR do { parse_error (scanner); YYERROR; } while (0)
#define first_line line
#define first_column column
#define YYLLOC_DEFAULT(Current, Rhs, N) RUA_LOC_DEFAULT(Current, Rhs, N)
#define YYLOCATION_PRINT rua_print_location
int yylex (YYSTYPE *yylval, YYLTYPE *yylloc);

View file

@ -80,8 +80,8 @@ parse_error (void *scanner)
#define PARSE_ERROR do { parse_error (scanner); YYERROR; } while (0)
#endif
#define first_line line
#define first_column column
#define YYLLOC_DEFAULT(Current, Rhs, N) RUA_LOC_DEFAULT(Current, Rhs, N)
#define YYLOCATION_PRINT rua_print_location
%}
%code requires {

View file

@ -2408,3 +2408,10 @@ rua_macro_va_args (rua_macro_t *macro, void *scanner)
macro->tail = arg->tail;
}
}
void
rua_print_location (FILE *out, const rua_loc_t *loc)
{
fprintf (out, "%s:[%d.%d-%d.%d]", GETSTR (loc->file),
loc->line, loc->column, loc->last_line, loc->last_column);
}

View file

@ -103,8 +103,8 @@ parse_error (void *scanner)
#define PARSE_ERROR do { parse_error (scanner); YYERROR; } while (0)
#define first_line line
#define first_column column
#define YYLLOC_DEFAULT(Current, Rhs, N) RUA_LOC_DEFAULT(Current, Rhs, N)
#define YYLOCATION_PRINT rua_print_location
int yylex (YYSTYPE *yylval, YYLTYPE *yylloc);

View file

@ -84,8 +84,8 @@ parse_error (void *scanner)
#define PARSE_ERROR do { parse_error (scanner); YYERROR; } while (0)
#define first_line line
#define first_column column
#define YYLLOC_DEFAULT(Current, Rhs, N) RUA_LOC_DEFAULT(Current, Rhs, N)
#define YYLOCATION_PRINT rua_print_location
int yylex (void);