glcpp: Add plumbing to support line locations.

This commit is contained in:
Kenneth Graunke
2010-06-16 16:35:57 -07:00
parent f70f60739a
commit 465e03ee07
3 changed files with 21 additions and 9 deletions

View File

@@ -29,7 +29,7 @@
#include "glcpp-parse.h" #include "glcpp-parse.h"
%} %}
%option bison-bridge reentrant noyywrap %option bison-bridge bison-locations reentrant noyywrap
%option extra-type="glcpp_parser_t *" %option extra-type="glcpp_parser_t *"
%option prefix="glcpp_" %option prefix="glcpp_"

View File

@@ -34,7 +34,7 @@
stream = talloc_asprintf_append(stream, fmt, args) stream = talloc_asprintf_append(stream, fmt, args)
static void static void
yyerror (glcpp_parser_t *parser, const char *error); yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
static void static void
_define_object_macro (glcpp_parser_t *parser, _define_object_macro (glcpp_parser_t *parser,
@@ -133,7 +133,7 @@ _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser);
#define yylex glcpp_parser_lex #define yylex glcpp_parser_lex
static int static int
glcpp_parser_lex (YYSTYPE *yylval, glcpp_parser_t *parser); glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
static void static void
glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list); glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
@@ -142,6 +142,7 @@ glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
%pure-parser %pure-parser
%error-verbose %error-verbose
%locations
%parse-param {glcpp_parser_t *parser} %parse-param {glcpp_parser_t *parser}
%lex-param {glcpp_parser_t *parser} %lex-param {glcpp_parser_t *parser}
@@ -364,7 +365,7 @@ text_line:
non_directive: non_directive:
pp_tokens NEWLINE { pp_tokens NEWLINE {
yyerror (parser, "Invalid tokens after #"); yyerror (& @1, parser, "Invalid tokens after #");
} }
; ;
@@ -861,9 +862,10 @@ _token_list_print (glcpp_parser_t *parser, token_list_t *list)
} }
void void
yyerror (glcpp_parser_t *parser, const char *error) yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
{ {
glcpp_printf(parser->errors, "Parse error: %s\n", error); glcpp_printf(parser->errors, "%u:%u(%u): preprocessor error: %s\n",
locp->source, locp->first_line, locp->first_column, error);
} }
glcpp_parser_t * glcpp_parser_t *
@@ -1452,13 +1454,13 @@ _define_function_macro (glcpp_parser_t *parser,
} }
static int static int
glcpp_parser_lex (YYSTYPE *yylval, glcpp_parser_t *parser) glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
{ {
token_node_t *node; token_node_t *node;
int ret; int ret;
if (parser->lex_from_list == NULL) { if (parser->lex_from_list == NULL) {
ret = glcpp_lex (yylval, parser->scanner); ret = glcpp_lex (yylval, yylloc, parser->scanner);
/* XXX: This ugly block of code exists for the sole /* XXX: This ugly block of code exists for the sole
* purpose of converting a NEWLINE token into a SPACE * purpose of converting a NEWLINE token into a SPACE

View File

@@ -59,6 +59,16 @@ typedef union YYSTYPE
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
typedef struct YYLTYPE {
int first_line;
int first_column;
int last_line;
int last_column;
unsigned source;
} YYLTYPE;
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
struct token { struct token {
int type; int type;
YYSTYPE value; YYSTYPE value;
@@ -163,7 +173,7 @@ void
glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader); glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader);
int int
glcpp_lex (YYSTYPE *lvalp, yyscan_t scanner); glcpp_lex (YYSTYPE *lvalp, YYLTYPE *llocp, yyscan_t scanner);
int int
glcpp_lex_destroy (yyscan_t scanner); glcpp_lex_destroy (yyscan_t scanner);