aboutsummaryrefslogtreecommitdiff
path: root/src/preproc.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-06-26 15:18:29 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-06-26 21:23:42 +0300
commit440771ca0056eb20396e24f03d349a75ee1c9d22 (patch)
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')
-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
@@ -46,24 +46,25 @@ struct buffer_ctx {
size_t xlines; /* Number of #line directives output so far */
struct input_file_ident id;
FILE *infile;
};
extern int grecs_grecs__flex_debug;
static struct buffer_ctx *context_stack;
static char *linebufbase = NULL;
static size_t linebufsize = 0;
#define INFILE context_stack->infile
#define LOCUS context_stack->locus
+#define POINT context_stack->locus.beg
static char *linebuf;
static size_t bufsize;
static char *putback_buffer;
static size_t putback_size;
static size_t putback_max;
static int push_source (const char *name, int once);
static int pop_source (void);
static int parse_include (const char *text, int once);
ssize_t
@@ -114,26 +115,26 @@ putback(const char *str)
strcpy(putback_buffer, str);
putback_size = len - 1;
}
static void
pp_line_stmt()
{
size_t ls_size;
size_t pb_size;
if (grecs_asprintf(&linebufbase, &linebufsize,
"#line %lu \"%s\" %lu\n",
- (unsigned long) LOCUS.line,
- LOCUS.file, (unsigned long) context_stack->xlines))
+ (unsigned long) POINT.line,
+ POINT.file, (unsigned long) context_stack->xlines))
grecs_alloc_die();
ls_size = strlen(linebufbase);
pb_size = putback_size + ls_size + 1;
if (pb_size > putback_max) {
putback_max = pb_size;
putback_buffer = grecs_realloc(putback_buffer, putback_max);
}
context_stack->xlines++;
strcpy(putback_buffer + putback_size, linebufbase);
@@ -202,25 +203,25 @@ grecs_preproc_fill_buffer(char *buf, size_t size)
len = size;
memcpy(buf, linebuf, len);
buf += len;
size -= len;
if (size == 0) {
putback(linebuf + len);
break;
}
if (!is_line && len > 0 && linebuf[len - 1] == '\n')
- LOCUS.line++;
+ POINT.line++;
}
return bufsize - size;
}
#define STAT_ID_EQ(st,id) ((id).i_node == (st).st_ino \
&& (id).device == (st).st_dev)
static struct buffer_ctx *
ctx_lookup(struct stat *st)
{
struct buffer_ctx *ctx;
@@ -388,25 +389,25 @@ push_source(const char *name, int once)
FILE *fp;
struct buffer_ctx *ctx;
struct stat st;
int rc = stat(name, &st);
if (context_stack) {
if (rc) {
grecs_error(&LOCUS, errno,
_("Cannot stat `%s'"), name);
return 1;
}
- if (LOCUS.file && STAT_ID_EQ(st, context_stack->id)) {
+ if (POINT.file && STAT_ID_EQ(st, context_stack->id)) {
grecs_error(&LOCUS, 0, _("Recursive inclusion"));
return 1;
}
if ((ctx = ctx_lookup(&st))) {
grecs_error(&LOCUS, 0, _("Recursive inclusion"));
if (ctx->prev)
grecs_error(&ctx->prev->locus, 0,
_("`%s' already included here"),
name);
else
grecs_error(&LOCUS, 0,
@@ -422,28 +423,31 @@ push_source(const char *name, int once)
if (once && source_lookup(&st))
return -1;
fp = fopen(name, "r");
if (!fp) {
grecs_error(context_stack ? &LOCUS : NULL, errno,
_("Cannot open `%s'"), name);
return 1;
}
/* Push current context */
ctx = grecs_malloc(sizeof(*ctx));
- ctx->locus.file = grecs_install_text(name);
- ctx->locus.line = 1;
+ ctx->locus.beg.file = grecs_install_text(name);
+ ctx->locus.beg.line = 1;
+ ctx->locus.beg.col = 0;
+ ctx->locus.end.file = NULL;
+ ctx->locus.end.line = ctx->locus.end.col = 0;
ctx->xlines = 0;
- ctx->namelen = strlen(ctx->locus.file);
+ ctx->namelen = strlen(ctx->locus.beg.file);
ctx->id.i_node = st.st_ino;
ctx->id.device = st.st_dev;
ctx->infile = fp;
ctx->prev = context_stack;
context_stack = ctx;
if (grecs_grecs__flex_debug)
fprintf (stderr, "Processing file `%s'\n", name);
pp_line_stmt();
return 0;
@@ -461,29 +465,29 @@ pop_source()
/* Restore previous context */
ctx = context_stack->prev;
grecs_free(context_stack);
context_stack = ctx;
if (!context_stack) {
if (grecs_grecs__flex_debug)
fprintf(stderr, "End of input\n");
return 1;
}
- LOCUS.line++;
+ POINT.line++;
if (grecs_grecs__flex_debug)
fprintf(stderr, "Resuming file `%s' at line %lu\n",
- LOCUS.file, (unsigned long) LOCUS.line);
+ POINT.file, (unsigned long) POINT.line);
pp_line_stmt();
return 0;
}
char *
grecs_find_include_file(const char *name, int allow_cwd)
{
static char *cwd = ".";
struct file_data fd;

Return to:

Send suggestions and report system problems to the System administrator.