summaryrefslogtreecommitdiffabout
path: root/src/preproc.c
authorSergey Poznyakoff <gray@gnu.org.ua>2011-06-26 12:18:29 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-06-26 18:23:42 (GMT)
commit440771ca0056eb20396e24f03d349a75ee1c9d22 (patch) (unidiff)
tree3ec58a85e96d21a855ad3dcefaa8adc51039fc38 /src/preproc.c
parent4c1959a4848c30206de3be4b16bdf04b650daae8 (diff)
downloadgrecs-440771ca0056eb20396e24f03d349a75ee1c9d22.tar.gz
grecs-440771ca0056eb20396e24f03d349a75ee1c9d22.tar.bz2
Keep track of columns in the node and value locations. Improve error diagnostics.
* src/grecs.h (grecs_locus_point): New struct. (grecs_locus_point_advance_line): New macro. (grecs_locus_t): Redesign. (grecs_value) <locus>: New member. (grecs_node) <idloc>: New member. (grecs_print_diag_fun): Change signature. (grecs_warning,grecs_error): Change signature. (grecs_parse_line_directive) (grecs_parse_line_directive_cpp) (grecs_string_convert): Change signature. (grecs_current_locus): Remove. (grecs_current_locus_point): New extern. * src/grecs-locus.h: New file. * src/Make.am (noinst_HEADERS): Add grecs-locus.h. * src/join.c (reset_locus): Rewrite. * src/lookup.c: Initialize new members of grecs_value and grecs_node. (split_cfg_path): Return wrdse error code. (grecs_node_from_path_locus): Take two grecs_locus_t arguments. Make sure all created nodes have their locus members properly initialized. * src/parser.c (grecs_parse): Initialize grecs_current_locus_point. * src/tree.c (grecs_node_create_points): New function. (string_to_bool,string_to_host,string_to_sockaddr) (grecs_string_convert): Change signatures. Be more precise in what locus to report. * src/diag.c (default_print_diag): Use YY_LOCATION_PRINT to output locus. (grecs_print_diag_fun): Change signature. (grecs_warning,grecs_error): Change signature. * src/format.c (grecs_format_locus): Rewrite. (grecs_format_node): Be more precise in what locus is being output. * src/bind-gram.y: Keep track of locations. Turn on error-verbose mode. * src/grecs-gram.y: Likewise. * src/meta1-gram.y: Likewise. * src/bind-lex.l: Keep track of locations. * src/git-parser.c: Likewise. * src/grecs-lex.l: Likewise. * src/meta1-lex.l: Likewise. * src/path-parser.c: Likewise. * src/preproc.c: Likewise. * tests/gcf1.conf: Untabify. * tests/format01.at: Reflect changes in the output. * tests/join.at: Likewise. * tests/set.at: Likewise. * tests/locus-bind.at: New testcase. * tests/locus-git.at: New testcase. * tests/locus-meta1.at: New testcase. * tests/locus00.at: New testcase. * tests/locus01.at: New testcase. * tests/locus02.at: New testcase. * tests/path-locus.at: New testcase.
Diffstat (limited to 'src/preproc.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/preproc.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/preproc.c b/src/preproc.c
index 1eeddd0..a5dda52 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -55,6 +55,7 @@ static size_t linebufsize = 0;
55 55
56#define INFILE context_stack->infile 56#define INFILE context_stack->infile
57#define LOCUS context_stack->locus 57#define LOCUS context_stack->locus
58#define POINT context_stack->locus.beg
58 59
59static char *linebuf; 60static char *linebuf;
60static size_t bufsize; 61static size_t bufsize;
@@ -123,8 +124,8 @@ pp_line_stmt()
123 124
124 if (grecs_asprintf(&linebufbase, &linebufsize, 125 if (grecs_asprintf(&linebufbase, &linebufsize,
125 "#line %lu \"%s\" %lu\n", 126 "#line %lu \"%s\" %lu\n",
126 (unsigned long) LOCUS.line, 127 (unsigned long) POINT.line,
127 LOCUS.file, (unsigned long) context_stack->xlines)) 128 POINT.file, (unsigned long) context_stack->xlines))
128 grecs_alloc_die(); 129 grecs_alloc_die();
129 130
130 ls_size = strlen(linebufbase); 131 ls_size = strlen(linebufbase);
@@ -211,7 +212,7 @@ grecs_preproc_fill_buffer(char *buf, size_t size)
211 } 212 }
212 213
213 if (!is_line && len > 0 && linebuf[len - 1] == '\n') 214 if (!is_line && len > 0 && linebuf[len - 1] == '\n')
214 LOCUS.line++; 215 POINT.line++;
215 } 216 }
216 return bufsize - size; 217 return bufsize - size;
217} 218}
@@ -397,7 +398,7 @@ push_source(const char *name, int once)
397 return 1; 398 return 1;
398 } 399 }
399 400
400 if (LOCUS.file && STAT_ID_EQ(st, context_stack->id)) { 401 if (POINT.file && STAT_ID_EQ(st, context_stack->id)) {
401 grecs_error(&LOCUS, 0, _("Recursive inclusion")); 402 grecs_error(&LOCUS, 0, _("Recursive inclusion"));
402 return 1; 403 return 1;
403 } 404 }
@@ -431,10 +432,13 @@ push_source(const char *name, int once)
431 432
432 /* Push current context */ 433 /* Push current context */
433 ctx = grecs_malloc(sizeof(*ctx)); 434 ctx = grecs_malloc(sizeof(*ctx));
434 ctx->locus.file = grecs_install_text(name); 435 ctx->locus.beg.file = grecs_install_text(name);
435 ctx->locus.line = 1; 436 ctx->locus.beg.line = 1;
437 ctx->locus.beg.col = 0;
438 ctx->locus.end.file = NULL;
439 ctx->locus.end.line = ctx->locus.end.col = 0;
436 ctx->xlines = 0; 440 ctx->xlines = 0;
437 ctx->namelen = strlen(ctx->locus.file); 441 ctx->namelen = strlen(ctx->locus.beg.file);
438 ctx->id.i_node = st.st_ino; 442 ctx->id.i_node = st.st_ino;
439 ctx->id.device = st.st_dev; 443 ctx->id.device = st.st_dev;
440 ctx->infile = fp; 444 ctx->infile = fp;
@@ -470,11 +474,11 @@ pop_source()
470 return 1; 474 return 1;
471 } 475 }
472 476
473 LOCUS.line++; 477 POINT.line++;
474 478
475 if (grecs_grecs__flex_debug) 479 if (grecs_grecs__flex_debug)
476 fprintf(stderr, "Resuming file `%s' at line %lu\n", 480 fprintf(stderr, "Resuming file `%s' at line %lu\n",
477 LOCUS.file, (unsigned long) LOCUS.line); 481 POINT.file, (unsigned long) POINT.line);
478 482
479 pp_line_stmt(); 483 pp_line_stmt();
480 484

Return to:

Send suggestions and report system problems to the System administrator.