From 0774523d1882a087b648e4017e634eb12c12f377 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 17 Jun 2010 12:41:46 -0700 Subject: [PATCH] glcpp: Add line locations to "Unterminated #if" error message. --- glcpp/glcpp-parse.y | 15 +++++++++------ glcpp/glcpp.h | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/glcpp/glcpp-parse.y b/glcpp/glcpp-parse.y index 02608644c38..74159c19d81 100644 --- a/glcpp/glcpp-parse.y +++ b/glcpp/glcpp-parse.y @@ -123,7 +123,8 @@ _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, token_list_t *list); static void -_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, int condition); +_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, + int condition); static void _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, @@ -190,7 +191,7 @@ line: expanded_line: IF_EXPANDED expression NEWLINE { - _glcpp_parser_skip_stack_push_if (parser, $2); + _glcpp_parser_skip_stack_push_if (parser, & @1, $2); } | ELIF_EXPANDED expression NEWLINE { _glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2); @@ -234,12 +235,12 @@ control_line: | HASH_IFDEF IDENTIFIER NEWLINE { macro_t *macro = hash_table_find (parser->defines, $2); talloc_free ($2); - _glcpp_parser_skip_stack_push_if (parser, macro != NULL); + _glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL); } | HASH_IFNDEF IDENTIFIER NEWLINE { macro_t *macro = hash_table_find (parser->defines, $2); talloc_free ($2); - _glcpp_parser_skip_stack_push_if (parser, macro == NULL); + _glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL); } | HASH_ELIF pp_tokens NEWLINE { token_list_t *expanded; @@ -923,7 +924,7 @@ void glcpp_parser_destroy (glcpp_parser_t *parser) { if (parser->skip_stack) - glcpp_print (parser->errors, "Error: Unterminated #if\n"); + glcpp_error (&parser->skip_stack->loc, parser, "Unterminated #if\n"); glcpp_lex_destroy (parser->scanner); hash_table_dtor (parser->defines); talloc_free (parser); @@ -1579,7 +1580,8 @@ glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list) } static void -_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, int condition) +_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, + int condition) { skip_type_t current = SKIP_NO_SKIP; skip_node_t *node; @@ -1588,6 +1590,7 @@ _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, int condition) current = parser->skip_stack->type; node = xtalloc (parser, skip_node_t); + node->loc = *loc; if (current == SKIP_NO_SKIP) { if (condition) diff --git a/glcpp/glcpp.h b/glcpp/glcpp.h index 45bbff3ad4a..4a2489a96d9 100644 --- a/glcpp/glcpp.h +++ b/glcpp/glcpp.h @@ -131,6 +131,7 @@ typedef enum skip_type { typedef struct skip_node { skip_type_t type; + YYLTYPE loc; /* location of the initial #if/#elif/... */ struct skip_node *next; } skip_node_t; -- 2.30.2