summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org>2017-06-18 11:00:02 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2017-06-18 11:17:41 (GMT)
commitffb02f79f0381f296e73add258f87ecb2456fba3 (patch) (side-by-side diff)
tree5d074c615fb42e58ae03145c4ad4a35da63dd9db /src
parent565ff017ae9e52bbe41ccfb90668a642a2704afe (diff)
downloadmailfromd-ffb02f79f0381f296e73add258f87ecb2456fba3.tar.gz
mailfromd-ffb02f79f0381f296e73add258f87ecb2456fba3.tar.bz2
Switch to detailed source locations from Mailutils 3.2.92
* configure.ac: Version 8.1.92 * NEWS: Update. * src/builtin/debug.bi (debug): Use mu_locus_range * src/builtin/from.bi: Likewise. * src/builtin/header.bi: Likewise. * src/builtin/progress.bi: Likewise. * src/builtin/qrnt.bi: Likewise. * src/builtin/rcpt.bi: Likewise. * src/exclist.c: Likewise. * src/builtin/sieve.bi: Use mu_locus_range (sieve): Accept new optional argument "col". * src/drivers.c: Use mu_locus_range (MARK_LOCUS): Rewrite as inline function. * src/gram.y: Use mu_locus_range and location macros from mailutils/yyloc.h Improve error diagnostics (parse_program): Prepare mu_strerr for locus-aware diagnostics. * src/lex.l: Use mu_linetrack_t to track locations. * src/mailfromd.h: Use mu_locus_range * src/main.c: Likewise. * src/pp.c: Likewise. * src/prog.c: Likewise. * src/prog.h: Likewise. * src/symbols.c: Likewise. * tests/ashadow.at: Expect detailed error locations. * tests/bctx00.at: Likewise. * tests/fctx00.at: Likewise. * tests/invcidr.at: Likewise. * tests/invcidr2.at: Likewise. * tests/module04.at: Likewise. * tests/module06.at: Likewise. * tests/poll04.at: Likewise. * tests/setvar.at: Likewise. * tests/shadow.at: Likewise. * tests/static02.at: Likewise.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/builtin/debug.bi10
-rw-r--r--src/builtin/from.bi6
-rw-r--r--src/builtin/header.bi40
-rw-r--r--src/builtin/progress.bi6
-rw-r--r--src/builtin/qrnt.bi6
-rw-r--r--src/builtin/rcpt.bi12
-rw-r--r--src/builtin/sieve.bi23
-rw-r--r--src/drivers.c178
-rw-r--r--src/exclist.c2
-rw-r--r--src/gram.y584
-rw-r--r--src/lex.l199
-rw-r--r--src/mailfromd.h61
-rw-r--r--src/main.c28
-rw-r--r--src/pp.c73
-rw-r--r--src/prog.c55
-rw-r--r--src/prog.h16
-rw-r--r--src/symbols.c33
17 files changed, 677 insertions, 655 deletions
diff --git a/src/builtin/debug.bi b/src/builtin/debug.bi
index 9645b7c..65c1748 100644
--- a/src/builtin/debug.bi
+++ b/src/builtin/debug.bi
@@ -66,18 +66,14 @@ END
MF_DEFUN(debug, VOID, STRING spec)
{
- struct locus loc;
- struct mu_locus mloc;
+ struct mu_locus_range loc = MU_LOCUS_RANGE_INITIALIZER;
env_get_locus(env, &loc);
- mloc.mu_file = (char*)loc.file;
- mloc.mu_line = loc.line;
- mloc.mu_col = loc.point;
mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_SET_LOCUS, &mloc);
+ MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &loc);
mu_debug_parse_spec(spec);
mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
+ MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL);
}
END
diff --git a/src/builtin/from.bi b/src/builtin/from.bi
index 7bcd242..ea2e16b 100644
--- a/src/builtin/from.bi
+++ b/src/builtin/from.bi
@@ -16,13 +16,13 @@
MF_DEFUN(set_from, VOID, STRING addr, OPTIONAL, STRING args)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s %s",
+ trace("%s%s:%u: %s %s",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(set_from),
addr);
env_msgmod(env, set_from, addr, MF_OPTVAL(args, NULL), 0);
diff --git a/src/builtin/header.bi b/src/builtin/header.bi
index 64ded90..162130b 100644
--- a/src/builtin/header.bi
+++ b/src/builtin/header.bi
@@ -16,22 +16,22 @@
MF_DEFUN(header_add, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
if (MF_DEFINED(idx)) {
- trace("%s%s:%lu: %s %ld \"%s: %s\"",
+ trace("%s%s:%u: %s %ld \"%s: %s\"",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_insert),
idx,
name, value);
env_msgmod(env, header_insert, name, value, idx);
} else {
- trace("%s%s:%lu: %s \"%s: %s\"",
+ trace("%s%s:%u: %s \"%s: %s\"",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_add),
name, value);
env_msgmod(env, header_add, name, value, 1);
@@ -41,13 +41,13 @@ END
MF_DEFUN(header_insert, VOID, STRING name, STRING value, NUMBER idx)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s %ld \"%s: %s\"",
+ trace("%s%s:%u: %s %ld \"%s: %s\"",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_insert),
idx,
name, value);
@@ -57,13 +57,13 @@ END
MF_DEFUN(header_delete, VOID, STRING name, OPTIONAL, NUMBER idx)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s \"%s\" (%lu)",
+ trace("%s%s:%u: %s \"%s\" (%lu)",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_delete),
name, MF_OPTVAL(idx, 1));
env_msgmod(env, header_delete, name, NULL, MF_OPTVAL(idx, 1));
@@ -73,13 +73,13 @@ END
MF_CAPTURE
MF_DEFUN(header_delete_nth, VOID, NUMBER idx)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s %lu",
+ trace("%s%s:%u: %s %lu",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_delete_nth),
idx);
env_msgmod(env, header_delete_nth, NULL, NULL, idx);
@@ -88,13 +88,13 @@ END
MF_DEFUN(header_replace, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s \"%s: %s\" (%lu)",
+ trace("%s%s:%u: %s \"%s: %s\" (%lu)",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_replace),
name, value, MF_OPTVAL(idx, 1));
env_msgmod(env, header_replace, name, value, MF_OPTVAL(idx, 1));
@@ -104,13 +104,13 @@ END
MF_CAPTURE
MF_DEFUN(header_replace_nth, VOID, NUMBER idx, STRING name, STRING value)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s \"%s: %s\" (%lu)",
+ trace("%s%s:%u: %s \"%s: %s\" (%lu)",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_replace_nth),
name, value, idx);
env_msgmod(env, header_replace_nth, name, value, idx);
diff --git a/src/builtin/progress.bi b/src/builtin/progress.bi
index 962c501..b9a439c 100644
--- a/src/builtin/progress.bi
+++ b/src/builtin/progress.bi
@@ -17,13 +17,13 @@
MF_STATE(eom)
MF_DEFUN(progress, VOID)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s",
+ trace("%s%s:%u: %s",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
"PROGRESS");
gacopyz_progress(env_get_context(env));
}
diff --git a/src/builtin/qrnt.bi b/src/builtin/qrnt.bi
index 5432deb..91ca7db 100644
--- a/src/builtin/qrnt.bi
+++ b/src/builtin/qrnt.bi
@@ -16,13 +16,13 @@
MF_DEFUN(quarantine, VOID, STRING reason)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s %s",
+ trace("%s%s:%u: %s %s",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(quarantine),
reason);
env_msgmod(env, quarantine, reason, NULL, 0);
diff --git a/src/builtin/rcpt.bi b/src/builtin/rcpt.bi
index cf03c07..5556357 100644
--- a/src/builtin/rcpt.bi
+++ b/src/builtin/rcpt.bi
@@ -16,13 +16,13 @@
MF_DEFUN(rcpt_add, VOID, STRING addr)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s %s",
+ trace("%s%s:%u: %s %s",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(rcpt_add),
addr);
env_msgmod(env, rcpt_add, addr, NULL, 0);
@@ -31,13 +31,13 @@ END
MF_DEFUN(rcpt_delete, VOID, STRING addr)
{
- struct locus locus;
+ struct mu_locus_range locus;
env_get_locus(env, &locus);
- trace("%s%s:%lu: %s %s",
+ trace("%s%s:%u: %s %s",
mailfromd_msgid(env_get_context(env)),
- locus.file, locus.line,
+ locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(rcpt_delete),
addr);
env_msgmod(env, rcpt_delete, addr, NULL, 0);
diff --git a/src/builtin/sieve.bi b/src/builtin/sieve.bi
index 7af7721..1a9cf9f 100644
--- a/src/builtin/sieve.bi
+++ b/src/builtin/sieve.bi
@@ -46,15 +46,16 @@ _sieve_file_action_log(mu_sieve_machine_t mach,
{
mu_stream_t stream;
eval_environ_t env = mu_sieve_get_data(mach);
- struct locus locus;
+ struct mu_locus_range locus;
_sieve_text_action_log(mach, action, fmt, ap);
mu_sieve_get_diag_stream(mach, &stream);
env_get_locus(env, &locus);
- mu_stream_printf(stream, "\033f<%lu>%s\033l<%lu>\033s<%d>\033O<%d>%s\n",
- (unsigned long) strlen(locus.file), locus.file,
- locus.line,
+ mu_stream_printf(stream, "\033f<%lu>%s\033l<%u>\033s<%d>\033O<%d>%s\n",
+ (unsigned long) strlen(locus.beg.mu_file),
+ locus.beg.mu_file,
+ locus.beg.mu_line,
MU_LOG_NOTICE,
MU_LOGMODE_LOCUS|MU_LOGMODE_SEVERITY,
_("sieve called from here"));
@@ -77,7 +78,7 @@ modify_debug_flags(mu_debug_level_t set, mu_debug_level_t clr)
}
MF_DEFUN(sieve, NUMBER, NUMBER nmsg, STRING script, OPTIONAL, NUMBER flags,
- STRING file, NUMBER line)
+ STRING file, NUMBER line, NUMBER col)
{
mu_sieve_machine_t mach;
int rc;
@@ -110,14 +111,16 @@ MF_DEFUN(sieve, NUMBER, NUMBER nmsg, STRING script, OPTIONAL, NUMBER flags,
mu_sieve_set_data(mach, env);
if (f & MF_SIEVE_TEXT) {
- struct locus locus;
-
+ struct mu_locus_range locus = MU_LOCUS_RANGE_INITIALIZER;
+ struct mu_locus_point pt;
+
env_get_locus(env, &locus);
if (f & MF_SIEVE_LOG)
mu_sieve_set_logger(mach, _sieve_text_action_log);
- rc = mu_sieve_compile_buffer(mach, script, strlen(script),
- MF_OPTVAL(file, locus.file),
- MF_OPTVAL(line, locus.line));
+ pt.mu_file = MF_OPTVAL(file, locus.beg.mu_file);
+ pt.mu_line = MF_OPTVAL(line, locus.beg.mu_line);
+ pt.mu_col = MF_OPTVAL(col, locus.beg.mu_col);
+ rc = mu_sieve_compile_text(mach, script, strlen(script), &pt);
} else {
if (f & MF_SIEVE_LOG)
mu_sieve_set_logger(mach, _sieve_file_action_log);
diff --git a/src/drivers.c b/src/drivers.c
index 3b98ccc..cbca6a5 100644
--- a/src/drivers.c
+++ b/src/drivers.c
@@ -14,14 +14,18 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#define MARK_LOCUS() \
- do if (!*old_locus || !LOCUS_EQ(*old_locus, &node->locus)) { \
- struct literal *lit = literal_lookup(node->locus.file); \
- *old_locus = &node->locus; \
- code_op(opcode_locus); \
- code_immediate(lit->off, ulong); \
- code_immediate(node->locus.line, str); \
- } while (0)
+static inline void
+mark_locus(NODE *node, struct mu_locus_range const **old_locus)
+{
+ if (!*old_locus
+ || !mu_locus_point_same_line (&(*old_locus)->beg, &node->locus.beg)) {
+ struct literal *lit = literal_lookup(node->locus.beg.mu_file);
+ *old_locus = &node->locus;
+ code_op(opcode_locus);
+ code_immediate(lit->off, ulong);
+ code_immediate(node->locus.beg.mu_line, ulong);
+ }
+}
static void code_trycatch_exit(unsigned id);
static unsigned trycatch_last_id(void);
@@ -74,9 +78,9 @@ mark_type_string(NODE *node)
}
void
-code_type_string(NODE *node, struct locus **old_locus)
+code_type_string(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_push);
code_immediate(node->v.literal->off, size);
}
@@ -92,9 +96,9 @@ print_type_symbol(NODE *node, int level)
}
void
-code_type_symbol(NODE *node, struct locus **old_locus)
+code_type_symbol(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_symbol);
code_immediate(node->v.literal->off, size);
}
@@ -115,9 +119,9 @@ print_type_number(NODE *node, int level)
}
void
-code_type_number(NODE *node, struct locus **old_locus)
+code_type_number(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_push);
code_immediate(node->v.number, long);
}
@@ -198,12 +202,12 @@ optimize_type_if(NODE *node)
}
void
-code_type_if(NODE *node, struct locus **old_locus)
+code_type_if(NODE *node, struct mu_locus_range const **old_locus)
{
prog_counter_t pos1, pos2, endpos;
code_node(node->v.cond.cond);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_bz);
pos1 = code_immediate(NULL, ptr);
traverse_tree(node->v.cond.if_true);
@@ -767,7 +771,7 @@ optimize_type_bin(NODE *node)
} while (0)
void
-code_type_bin(NODE *node, struct locus **old_locus)
+code_type_bin(NODE *node, struct mu_locus_range const **old_locus)
{
prog_counter_t pos1, pos2;
@@ -775,7 +779,7 @@ code_type_bin(NODE *node, struct locus **old_locus)
switch (node->v.bin.opcode) {
case bin_and:
- MARK_LOCUS();
+ mark_locus(node, old_locus);
/* cond1
if not true goto X
cond2
@@ -799,7 +803,7 @@ code_type_bin(NODE *node, struct locus **old_locus)
break;
case bin_or:
- MARK_LOCUS();
+ mark_locus(node, old_locus);
/* cond1
if true goto X
cond2
@@ -855,7 +859,7 @@ code_type_bin(NODE *node, struct locus **old_locus)
case bin_match:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
if (node->v.bin.qualifier & QUALIFIER_MX)
code_op(opcode_regmatch_mx);
else
@@ -864,7 +868,7 @@ code_type_bin(NODE *node, struct locus **old_locus)
case bin_fnmatch:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
if (node->v.bin.qualifier & QUALIFIER_MX)
code_op(opcode_fnmatch_mx);
else
@@ -873,61 +877,61 @@ code_type_bin(NODE *node, struct locus **old_locus)
case bin_add:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_add);
break;
case bin_sub:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_sub);
break;
case bin_mul:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_mul);
break;
case bin_div:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_div);
break;
case bin_mod:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_mod);
break;
case bin_logand:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_logand);
break;
case bin_logor:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_logor);
break;
case bin_logxor:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_logxor);
break;
case bin_shl:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_shl);
break;
case bin_shr:
code_node(node->v.bin.arg[1]);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_shr);
break;
@@ -987,10 +991,10 @@ optimize_type_un(NODE *node)
}
void
-code_type_un(NODE *node, struct locus **old_locus)
+code_type_un(NODE *node, struct mu_locus_range const **old_locus)
{
code_node(node->v.un.arg);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
switch (node->v.un.opcode) {
case unary_not:
code_op(opcode_not);
@@ -1076,7 +1080,7 @@ result_argptr(NODE *arg)
}
void
-code_type_result(NODE *node, struct locus **old_locus)
+code_type_result(NODE *node, struct mu_locus_range const **old_locus)
{
NODE *code, *xcode;
@@ -1113,7 +1117,7 @@ code_type_result(NODE *node, struct locus **old_locus)
code_result_arg(xcode);
code_result_arg(code);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_result);
code_immediate(node->v.ret.stat, int);
code_op(opcode_nil);
@@ -1145,9 +1149,9 @@ optimize_type_header(NODE *node)
}
void
-code_type_header(NODE *node, struct locus **old_locus)
+code_type_header(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
if (node->v.hdr.value)
code_node(node->v.hdr.value);
else {
@@ -1211,7 +1215,7 @@ optimize_type_builtin(NODE *node)
}
void
-code_type_builtin(NODE *node, struct locus **old_locus)
+code_type_builtin(NODE *node, struct mu_locus_range const **old_locus)
{
NODE *p;
int i;
@@ -1227,7 +1231,7 @@ code_type_builtin(NODE *node, struct locus **old_locus)
code_immediate(i, size);
}
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_builtin);
s = literal_lookup(node->v.builtin.builtin->name);
code_immediate(s->off, size);
@@ -1285,7 +1289,7 @@ optimize_type_concat(NODE *node)
}
void
-code_type_concat(NODE *node, struct locus **old_locus)
+code_type_concat(NODE *node, struct mu_locus_range const **old_locus)
{
code_node(node->v.concat.arg[0]);
code_node(node->v.concat.arg[1]);
@@ -1313,9 +1317,9 @@ mark_type_variable(NODE *node)
}
void
-code_type_variable(NODE *node, struct locus **old_locus)
+code_type_variable(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_memref(node);
code_op(opcode_deref);
}
@@ -1355,7 +1359,7 @@ optimize_type_asgn(NODE *node)
}
void
-code_type_asgn(NODE *node, struct locus **old_locus)
+code_type_asgn(NODE *node, struct mu_locus_range const **old_locus)
{
code_node(node->v.asgn.node);
node->v.asgn.var->type = node_type(node->v.asgn.node);
@@ -1382,9 +1386,9 @@ code_argref(NODE *node)
}
void
-code_type_arg(NODE *node, struct locus **old_locus)
+code_type_arg(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_argref(node);
code_op(opcode_deref);
}
@@ -1421,9 +1425,9 @@ code_argxref(NODE *node)
}
void
-code_type_argx(NODE *node, struct locus **old_locus)
+code_type_argx(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_argxref(node);
code_op(opcode_deref);
}
@@ -1456,10 +1460,10 @@ mark_type_vaptr(NODE *node)
}
void
-code_type_vaptr(NODE *node, struct locus **old_locus)
+code_type_vaptr(NODE *node, struct mu_locus_range const **old_locus)
{
NODE *arg = node->v.node;
- MARK_LOCUS();
+ mark_locus(node, old_locus);
switch (arg->type) {
case node_type_variable:
code_memref(arg);
@@ -1543,7 +1547,7 @@ mark_type_regex(NODE *node)
}
void
-code_type_regex(NODE *node, struct locus **old_locus)
+code_type_regex(NODE *node, struct mu_locus_range const **old_locus)
{
code_op(opcode_regex);
code_immediate(node->v.regex->index, size);
@@ -1595,7 +1599,7 @@ optimize_type_regcomp(NODE *node)
}
void
-code_type_regcomp(NODE *node, struct locus **old_locus)
+code_type_regcomp(NODE *node, struct mu_locus_range const **old_locus)
{
if (node->v.regcomp_data.regind == -1)
save_regexp(node);
@@ -1607,7 +1611,7 @@ code_type_regcomp(NODE *node, struct locus **old_locus)
struct trycatch_stack_entry {
int istry;
- struct locus *locus;
+ struct mu_locus_range locus;
unsigned id;
};
@@ -1623,14 +1627,15 @@ trycatch_last_id(void)
}
static void
-enter_trycatch(int istry, struct locus *locus)
+enter_trycatch(int istry, struct mu_locus_range const *locus)
{
struct trycatch_stack_entry ent;
if (!trycatch_stack)
trycatch_stack = mf_stack_create(sizeof(ent), 0);
ent.istry = istry;
- ent.locus = locus;
+ mu_locus_range_init(&ent.locus);
+ mu_locus_range_copy(&ent.locus, locus);
ent.id = trycatch_last_id() + 1;
mf_stack_push(trycatch_stack, &ent);
}
@@ -1638,7 +1643,10 @@ enter_trycatch(int istry, struct locus *locus)
static void
leave_trycatch()
{
- mf_stack_pop(trycatch_stack, NULL);
+ struct trycatch_stack_entry ent;
+ if (mf_stack_pop(trycatch_stack, &ent) == 0)
+ mu_locus_range_deinit(&ent.locus);
+
}
static int
@@ -1698,12 +1706,12 @@ optimize_type_catch(NODE *node)
}
void
-code_type_catch(NODE *node, struct locus **old_locus)
+code_type_catch(NODE *node, struct mu_locus_range const **old_locus)
{
prog_counter_t pos1, endpos;
prog_counter_t ctr;
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_catch);
pos1 = code_immediate(NULL, ptr);
code_exmask(node->v.catch.exmask);
@@ -1763,7 +1771,7 @@ optimize_type_try(NODE *node)
}
void
-code_type_try(NODE *node, struct locus **old_locus)
+code_type_try(NODE *node, struct mu_locus_range const **old_locus)
{
prog_counter_t pos, ctr, pos1;
prog_counter_t try_jmp_pc, catch_jmp_pc;
@@ -1801,7 +1809,7 @@ code_type_try(NODE *node, struct locus **old_locus)
code_put(pos1, (pos - pos1), long);
/* Compile `try' part */
- MARK_LOCUS();
+ mark_locus(node, old_locus);
jump_pc = 0;
enter_trycatch(1, &node->v.try.node->locus);
traverse_tree(node->v.try.node);
@@ -1860,10 +1868,10 @@ optimize_type_throw(NODE *node)
}
void
-code_type_throw(NODE *node, struct locus **old_locus)
+code_type_throw(NODE *node, struct mu_locus_range const **old_locus)
{
code_node(node->v.throw.expr);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_throw);
code_immediate(node->v.throw.code, ulong);
}
@@ -1891,10 +1899,10 @@ optimize_type_echo(NODE *node)
}
void
-code_type_echo(NODE *node, struct locus **old_locus)
+code_type_echo(NODE *node, struct mu_locus_range const **old_locus)
{
code_node(node->v.node);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_echo);
}
@@ -1923,15 +1931,15 @@ optimize_type_return(NODE *node)
}
void
-code_type_return(NODE *node, struct locus **old_locus)
+code_type_return(NODE *node, struct mu_locus_range const **old_locus)
{
if (func->rettype == dtype_unspecified) {
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_jmp);
jump_pc = code_immediate(jump_pc, long);
} else {
code_node(node->v.node);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_popreg);
code_op(opcode_jmp);
jump_pc = code_immediate(jump_pc, long);
@@ -1968,7 +1976,7 @@ optimize_type_call(NODE *node)
}
void
-code_type_call(NODE *node, struct locus **old_locus)
+code_type_call(NODE *node, struct mu_locus_range const **old_locus)
{
NODE *p;
struct literal *s;
@@ -2000,7 +2008,7 @@ code_type_call(NODE *node, struct locus **old_locus)
for (p = node->v.call.args, i = 0; p; p = p->next, i++)
code_node(p);
- MARK_LOCUS();
+ mark_locus(node, old_locus);
if (func->entry == 0) {
parse_error("INTERNAL ERROR at %s:%d: unresolved function %s",
__FILE__, __LINE__, func->sym.name);
@@ -2242,13 +2250,13 @@ L2:
static void
code_switch_branches(NODE *node, data_type_t type)
{
- prog_counter_t start, refpos, jmppos;
+ prog_counter_t refpos, jmppos;
struct case_stmt *pcase;
size_t data_off = node->v.switch_stmt.off;
code_op(opcode_popreg);
code_op(type == dtype_number ? opcode_xlat : opcode_xlats);
- start = code_immediate(node->v.switch_stmt.tabsize, ulong);
+ code_immediate(node->v.switch_stmt.tabsize, ulong);
code_immediate(data_off, size);
code_op(opcode_bnz);
code_immediate(1, long);
@@ -2291,7 +2299,7 @@ code_switch_branches(NODE *node, data_type_t type)
}
void
-code_type_switch(NODE *node, struct locus **old_locus)
+code_type_switch(NODE *node, struct mu_locus_range const **old_locus)
{
code_node(node->v.switch_stmt.node);
code_switch_branches(node, node_type(node->v.switch_stmt.node));
@@ -2374,11 +2382,11 @@ print_type_next(NODE *node, int level)
}
void
-code_type_next(NODE *node, struct locus **old_locus)
+code_type_next(NODE *node, struct mu_locus_range const **old_locus)
{
struct loop_stack ent;
- MARK_LOCUS();
+ mark_locus(node, old_locus);
if (find_loop(node->v.literal, &ent) == 0) {
parse_error_locus(&node->locus,
@@ -2406,11 +2414,11 @@ print_type_break(NODE *node, int level)
}
void
-code_type_break(NODE *node, struct locus **old_locus)
+code_type_break(NODE *node, struct mu_locus_range const **old_locus)
{
struct loop_stack ent;
- MARK_LOCUS();
+ mark_locus(node, old_locus);
if (find_loop(node->v.literal, &ent) == 0) {
parse_error_locus(&node->locus,
@@ -2497,7 +2505,7 @@ optimize_type_loop(NODE *node)
}
void
-code_type_loop(NODE *node, struct locus **old_locus)
+code_type_loop(NODE *node, struct mu_locus_range const **old_locus)
{
/* FIXME */
/*
@@ -2516,7 +2524,7 @@ code_type_loop(NODE *node, struct locus **old_locus)
*/
prog_counter_t begin, end, stmt, endjmp = 0, nxtjmp = 0;
- MARK_LOCUS();
+ mark_locus(node, old_locus);
enter_loop(node->v.loop.ident, &endjmp, &nxtjmp);
@@ -2559,9 +2567,9 @@ print_type_backref(NODE *node, int level)
}
void
-code_type_backref(NODE *node, struct locus **old_locus)
+code_type_backref(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
code_op(opcode_backref);
code_immediate(node->v.number, uint);
}
@@ -2608,7 +2616,7 @@ optimize_type_cast(NODE *node)
}
int
-code_cast(struct locus *locus, data_type_t fromtype, data_type_t totype)
+code_cast(struct mu_locus_range const *locus, data_type_t fromtype, data_type_t totype)
{
if (fromtype == totype)
return 0;
@@ -2633,7 +2641,7 @@ code_cast(struct locus *locus, data_type_t fromtype, data_type_t totype)
}
void
-code_type_cast(NODE *node, struct locus **old_locus)
+code_type_cast(NODE *node, struct mu_locus_range const **old_locus)
{
code_node(node->v.cast.node);
code_cast(&node->v.cast.node->locus,
@@ -2656,7 +2664,7 @@ optimize_type_funcdecl(NODE *node)
}
void
-code_type_funcdecl(NODE *node, struct locus **old_locus)
+code_type_funcdecl(NODE *node, struct mu_locus_range const **old_locus)
{
prog_counter_t pc;
@@ -2685,7 +2693,7 @@ optimize_type_progdecl(NODE *node)
}
void
-code_type_progdecl(NODE *node, struct locus **old_locus)
+code_type_progdecl(NODE *node, struct mu_locus_range const **old_locus)
{
enum smtp_state tag;
@@ -2745,9 +2753,9 @@ optimize_type_offset(NODE *node)
}
void
-code_type_offset(NODE *node, struct locus **old_locus)
+code_type_offset(NODE *node, struct mu_locus_range const **old_locus)
{
- MARK_LOCUS();
+ mark_locus(node, old_locus);
switch (node->v.var_ref.variable->storage_class) {
case storage_extern:
code_op(opcode_push);
diff --git a/src/exclist.c b/src/exclist.c
index 81db720..40a8074 100644
--- a/src/exclist.c
+++ b/src/exclist.c
@@ -31,7 +31,7 @@ static struct exclist *head, *tail;
size_t exception_count = 0;
void
-define_exception(struct literal *lit, struct locus *locus)
+define_exception(struct literal *lit, struct mu_locus_range const *locus)
{
const struct constant *cp;
struct value value;
diff --git a/src/gram.y b/src/gram.y
index b818710..60fd0f9 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -22,6 +22,7 @@
#include <fnmatch.h>
#include <netdb.h>
#include "mailfromd.h"
+#include <mailutils/yyloc.h>
#include "prog.h"
#include "optab.h"
@@ -38,23 +39,25 @@ static NODE *reverse(NODE *in);
static size_t nodelistlength(NODE *list);
static NODE *function_call(struct function *function, size_t count,
NODE *subtree);
-static NODE *declare_function(struct function *func, struct locus *loc,
+static NODE *declare_function(struct function *func,
+ struct mu_locus_range const *loc,
size_t nautos);
static data_type_t node_type(NODE *node);
static NODE *cast_arg_list(NODE *args, size_t parmc, data_type_t *parmtype,
int disable_prom);
-void add_xref(struct variable *var, const struct locus *locus);
+void add_xref(struct variable *var, struct mu_locus_range const *locus);
static struct variable *vardecl(const char *name, data_type_t type,
- storage_class_t sc, struct locus *loc);
+ storage_class_t sc,
+ struct mu_locus_range const *loc);
static struct variable *externdecl(const char *name, struct value *value,
- struct locus *loc);
+ struct mu_locus_range const *loc);
static int initialize_variable(struct variable *var, struct value *val,
- const struct locus *locus);
+ struct mu_locus_range const *locus);
static void apply_deferred_init(void);
static NODE *create_asgn_node(struct variable *var, NODE *expr,
- const struct locus *loc);
+ struct mu_locus_range const *loc);
-NODE *defined_parm(struct variable *var, struct locus *locus);
+NODE *defined_parm(struct variable *var, struct mu_locus_range const *locus);
static void register_auto(struct variable *var);
static void unregister_auto(struct variable *var);
@@ -211,14 +214,14 @@ type_to_string(data_type_t t)
}
static int
-check_func_usage(struct function *fp, const struct locus *locus)
+check_func_usage(struct function *fp, struct mu_locus_range const *locus)
{
switch (outer_context) {
case context_handler:
if (fp->statemask && !(STATMASK(state_tag) & fp->statemask)) {
parse_error_locus(locus,
_("function `%s' cannot be used in "
- "prog `%s'"),
+ "prog `%s'"),
fp->sym.name,
state_to_string(state_tag));
return 1;
@@ -236,15 +239,17 @@ check_func_usage(struct function *fp, const struct locus *locus)
}
static int
-check_builtin_usage(const struct builtin *bp)
+check_builtin_usage(const struct builtin *bp,
+ struct mu_locus_range const *locus)
{
switch (outer_context) {
case context_handler:
if (bp->statemask && !(STATMASK(state_tag) & bp->statemask)) {
- parse_error(_("built-in function `%s' cannot be used in "
- "prog `%s'"),
- bp->name,
- state_to_string(state_tag));
+ parse_error_locus(locus,
+ _("built-in function `%s' cannot be used in "
+ "prog `%s'"),
+ bp->name,
+ state_to_string(state_tag));
return 1;
}
break;
@@ -280,32 +285,6 @@ _create_alias(void *item, void *data)
install_alias(lit->text, fun, &fun->sym.locus);
return 0;
}
-
-#define YYLLOC_DEFAULT(Current, Rhs, N) \
- do { \
- if (N) { \
- (Current).beg = YYRHSLOC(Rhs, 1).beg; \
- (Current).end = YYRHSLOC(Rhs, N).end; \
- } else { \
- (Current).beg = YYRHSLOC(Rhs, 0).end; \
- (Current).end = (Current).beg; \
- } \
- } while (0)
-
-#define YY_LOCATION_PRINT(File, Loc) do { \
- if (LOCUS_EQ(&(Loc).beg, &(Loc).end)) \
- fprintf(File, "%s:%lu.%lu-%lu.%lu", \
- (Loc).beg.file, \
- (Loc).beg.line, (Loc).beg.point, \
- (Loc).end.line, (Loc).end.point); \
- else \
- fprintf(File, "%s:%lu.%lu-%s:%lu.%lu", \
- (Loc).beg.file, \
- (Loc).beg.line, (Loc).beg.point, \
- (Loc).end.file, \
- (Loc).end.line, (Loc).end.point); \
- } while (0)
-
%}
%error-verbose
@@ -576,20 +555,26 @@ opt_moddecl: /* empty */
moddecl : T_MODULE literal '.'
{
- if (top_module->dclname)
- parse_error_locus(&@2.beg,
+ if (top_module->dclname) {
+ struct mu_locus_range lr;
+ lr.beg = @1.beg;
+ lr.end = @3.end;
+ parse_error_locus(&lr,
_("duplicate module declaration"));
- else
+ } else
top_module->dclname = $2->text;
}
| T_MODULE literal qualifier '.'
{
- if (top_module->dclname)
- parse_error_locus(&@2.beg,
+ if (top_module->dclname) {
+ struct mu_locus_range lr;
+ lr.beg = @1.beg;
+ lr.end = @4.end;
+ parse_error_locus(&lr,
_("duplicate module declaration"));
- else {
+ } else {
if (($3 & (SYM_STATIC|SYM_PUBLIC)) == 0)
- parse_error_locus(&@3.beg,
+ parse_error_locus(&@3,
_("invalid module declaration"));
top_module->dclname = $2->text;
top_module->flags = $3;
@@ -633,7 +618,7 @@ literal : T_STRING
decl : T_PROG state_ident T_DO stmtlist T_DONE
{
- $$ = alloc_node(node_type_progdecl, &@1.beg);
+ $$ = alloc_node(node_type_progdecl, &@1);
$$->v.progdecl.tag = $2;
$$->v.progdecl.auto_count = forget_autos(PARMCOUNT(),
0, 0);
@@ -648,7 +633,7 @@ decl : T_PROG state_ident T_DO stmtlist T_DONE
NODE *np = progspecial[$1.code];
if (!np) {
- np = alloc_node(node_type_progdecl, &@1.beg);
+ np = alloc_node(node_type_progdecl, &@1);
$$ = progspecial[$1.code] = np;
np->v.progdecl.tag = state_tag;
np->v.progdecl.tree = $3.head;
@@ -671,16 +656,16 @@ decl : T_PROG state_ident T_DO stmtlist T_DONE
| qualifiers T_FUNC fundecl T_DO stmtlist T_DONE
{
if ($1 & SYM_PRECIOUS)
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("`precious' used with func"));
if (($1 & (SYM_STATIC|SYM_PUBLIC)) ==
(SYM_STATIC|SYM_PUBLIC))
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("`static' and `public' "
"used together"));
func->sym.flags = $1;
func->node = $5.head;
- $$ = declare_function(func, &@2.beg,
+ $$ = declare_function(func, &@2,
forget_autos(PARMCOUNT() + FUNC_HIDDEN_ARGS(func),
0, FUNC_HIDDEN_ARGS(func)));
outer_context = inner_context = context_none;
@@ -727,10 +712,10 @@ vardecl : qualifiers T_TYPE varname
if (($1 & (SYM_STATIC|SYM_PUBLIC))
== (SYM_STATIC|SYM_PUBLIC))
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`static' and `public' "
- "used together"));
- var = vardecl($3->text, $2, storage_extern, NULL);
+ "used together"));
+ var = vardecl($3->text, $2, storage_extern, &@3);
if (!var)
YYERROR;
var->sym.flags |= $1;
@@ -742,11 +727,11 @@ vardecl : qualifiers T_TYPE varname
if (($1 & (SYM_STATIC|SYM_PUBLIC))
== (SYM_STATIC|SYM_PUBLIC))
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`static' and `public' "
- "used together"));
+ "used together"));
- var = vardecl($3->text, $2, storage_extern, NULL);
+ var = vardecl($3->text, $2, storage_extern, &@2);
if (!var)
YYERROR;
var->sym.flags |= $1;
@@ -769,7 +754,7 @@ vardecl : qualifiers T_TYPE varname
YYERROR;
}
- if (initialize_variable(var, &value, &$4->locus))
+ if (initialize_variable(var, &value, &@3))
YYERROR;
}
| T_SET varname expr
@@ -794,7 +779,7 @@ vardecl : qualifiers T_TYPE varname
yyerror("initializer element is not constant");
YYERROR;
}
- if (!externdecl($2->text, &value, &@1.beg))
+ if (!externdecl($2->text, &value, &@2))
YYERROR;
}
;
@@ -834,11 +819,11 @@ constdecl : qualifiers T_CONST varname expr
struct variable *pvar;
if ($1 & SYM_PRECIOUS)
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`precious' used with const"));
if (($1 & (SYM_STATIC|SYM_PUBLIC)) ==
(SYM_STATIC|SYM_PUBLIC))
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`static' and `public' "
"used together"));
/* FIXME: This is necessary because constants can be
@@ -869,14 +854,14 @@ constdecl : qualifiers T_CONST varname expr
yyerror(_("initializer element is not constant"));
YYERROR;
}
- define_constant($3->text, &value, $1, &@2.beg);
+ define_constant($3->text, &value, $1, &@2);
$$ = NULL;
}
;
exdecl : T_DCLEX T_IDENTIFIER
{
- define_exception($2, &@1.beg);
+ define_exception($2, &@1);
}
;
@@ -901,7 +886,7 @@ fundecl : varname '(' parmdecl ')' aliasdecl retdecl
$3.count, $3.optcount,
$3.varargs,
ptypes, $6,
- &@1.beg);
+ &@1);
if ($5) {
mu_list_foreach($5, _create_alias, $$);
mu_list_destroy(&$5);
@@ -973,7 +958,7 @@ fparmlist : parmlist
parm : T_TYPE varname
{
- if (!vardecl($2->text, $1, storage_param, NULL))
+ if (!vardecl($2->text, $1, storage_param, &@2))
YYERROR;
$$ = mu_alloc(sizeof *$$);
$$->next = NULL;
@@ -982,7 +967,7 @@ parm : T_TYPE varname
/* FIXME: Is this still needed? */
| T_TYPE
{
- parse_warning_locus(&@1.beg,
+ parse_warning_locus(&@1,
_("unnamed formal parameters are deprecated"));
$$ = mu_alloc(sizeof *$$);
$$->next = NULL;
@@ -1029,9 +1014,9 @@ state_ident: T_IDENTIFIER
{
$$ = string_to_state($1->text);
if ($$ == smtp_state_none)
- parse_error_locus(&@1.beg,
- _("unknown smtp state tag: %s"),
- $1->text);
+ parse_error_locus(&@1,
+ _("unknown smtp state tag: %s"),
+ $1->text);
state_tag = $$;
outer_context = inner_context = context_handler;
}
@@ -1082,19 +1067,19 @@ asgn : T_SET varname expr
data_type_t t = node_type($3);
if (t == dtype_unspecified) {
- parse_error_locus(&@3.beg,
- _("unspecified value not ignored as "
- "it should be"));
+ parse_error_locus(&@3,
+ _("unspecified value not ignored as "
+ "it should be"));
YYERROR;
}
var = variable_lookup($2->text);
if (!var) {
- var = vardecl($2->text, t, storage_auto, &@1.beg);
+ var = vardecl($2->text, t, storage_auto, &@2);
if (!var)
YYERROR;
}
- $$ = create_asgn_node(var, $3, &@1.beg);
+ $$ = create_asgn_node(var, $3, &@1);
if (!$$)
YYERROR;
}
@@ -1102,17 +1087,17 @@ asgn : T_SET varname expr
autodcl : T_TYPE varname
{
- if (!vardecl($2->text, $1, storage_auto, NULL))
+ if (!vardecl($2->text, $1, storage_auto, &@2))
YYERROR;
$$ = NULL;
}
| T_TYPE varname expr
{
struct variable *var = vardecl($2->text, $1,
- storage_auto, NULL);
+ storage_auto, &@2);
if (!var)
YYERROR;
- $$ = create_asgn_node(var, $3, &@1.beg);
+ $$ = create_asgn_node(var, $3, &@1);
if (!$$)
YYERROR;
}
@@ -1122,11 +1107,11 @@ action : sendmail_action
{
if (inner_context == context_handler) {
if (state_tag == smtp_state_begin)
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("Sendmail action is not "
"allowed in begin block"));
else if (state_tag == smtp_state_end)
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("Sendmail action is not "
"allowed in end block"));
}
@@ -1135,17 +1120,17 @@ action : sendmail_action
{
if (inner_context == context_handler
&& state_tag == smtp_state_end)
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("header action is not allowed "
"in end block"));
}
| T_PASS
{
- $$ = alloc_node(node_type_noop, &@1.beg);
+ $$ = alloc_node(node_type_noop, &@1);
}
| T_ECHO expr
{
- $$ = alloc_node(node_type_echo, &@1.beg);
+ $$ = alloc_node(node_type_echo, &@1);
$$->v.node = cast_to(dtype_string, $2);
}
;
@@ -1155,19 +1140,19 @@ sendmail_action:
{
if ($2.code || $2.xcode || $2.message)
parse_warning(_("arguments are ignored for accept"));
- $$ = alloc_node(node_type_result, &@1.beg);
+ $$ = alloc_node(node_type_result, &@1);
$$->v.ret = $2;
$$->v.ret.stat = SMFIS_ACCEPT;
}
| T_REJECT maybe_triplet
{
- $$ = alloc_node(node_type_result, &@1.beg);
+ $$ = alloc_node(node_type_result, &@1);
$$->v.ret = $2;
$$->v.ret.stat = SMFIS_REJECT;
}
| T_REJECT '(' maybe_expr ',' maybe_xcode_expr ',' maybe_expr ')'
{
- $$ = alloc_node(node_type_result, &@1.beg);
+ $$ = alloc_node(node_type_result, &@1);
$$->v.ret.stat = SMFIS_REJECT;
$$->v.ret.code = $3 ? cast_to(dtype_string, $3) : NULL;
$$->v.ret.xcode = $5 ? cast_to(dtype_string, $5) : NULL;
@@ -1175,13 +1160,13 @@ sendmail_action:
}
| T_TEMPFAIL maybe_triplet
{
- $$ = alloc_node(node_type_result, &@1.beg);
+ $$ = alloc_node(node_type_result, &@1);
$$->v.ret = $2;
$$->v.ret.stat = SMFIS_TEMPFAIL;
}
| T_TEMPFAIL '(' maybe_expr ',' maybe_xcode_expr ',' maybe_expr ')'
{
- $$ = alloc_node(node_type_result, &@1.beg);
+ $$ = alloc_node(node_type_result, &@1);
$$->v.ret.stat = SMFIS_TEMPFAIL;
$$->v.ret.code = $3 ? cast_to(dtype_string, $3) : NULL;
$$->v.ret.xcode = $5 ? cast_to(dtype_string, $5) : NULL;
@@ -1189,13 +1174,13 @@ sendmail_action:
}
| T_CONTINUE
{
- $$ = alloc_node(node_type_result, &@1.beg);
+ $$ = alloc_node(node_type_result, &@1);
memset(&$$->v.ret, 0, sizeof $$->v.ret);
$$->v.ret.stat = SMFIS_CONTINUE;
}
| T_DISCARD
{
- $$ = alloc_node(node_type_result, &@1.beg);
+ $$ = alloc_node(node_type_result, &@1);
memset(&$$->v.ret, 0, sizeof $$->v.ret);
$$->v.ret.stat = SMFIS_DISCARD;
}
@@ -1204,7 +1189,7 @@ sendmail_action:
maybe_xcode_expr: maybe_expr
| xcode
{
- $$ = alloc_node(node_type_string, &@1.beg);
+ $$ = alloc_node(node_type_string, &@1);
$$->v.literal = $1;
}
;
@@ -1213,21 +1198,21 @@ maybe_xcode_expr: maybe_expr
header_action:
T_ADD string expr
{
- $$ = alloc_node(node_type_header, &@1.beg);
+ $$ = alloc_node(node_type_header, &@1);
$$->v.hdr.opcode = header_add;
$$->v.hdr.name = $2;
$$->v.hdr.value = cast_to(dtype_string, $3);
}
| T_REPLACE string expr
{
- $$ = alloc_node(node_type_header, &@1.beg);
+ $$ = alloc_node(node_type_header, &@1);
$$->v.hdr.opcode = header_replace;
$$->v.hdr.name = $2;
$$->v.hdr.value = cast_to(dtype_string, $3);
}
| T_DELETE string
{
- $$ = alloc_node(node_type_header, &@1.beg);
+ $$ = alloc_node(node_type_header, &@1);
$$->v.hdr.opcode = header_delete;
$$->v.hdr.name = $2;
$$->v.hdr.value = NULL;
@@ -1243,30 +1228,30 @@ maybe_triplet: /* empty */
triplet : code
{
- $$.code = alloc_node(node_type_string, &@1.beg);
+ $$.code = alloc_node(node_type_string, &@1);
$$.code->v.literal = $1;
$$.xcode = NULL;
$$.message = NULL;
}
| code xcode
{
- $$.code = alloc_node(node_type_string, &@1.beg);
+ $$.code = alloc_node(node_type_string, &@1);
$$.code->v.literal = $1;
- $$.xcode = alloc_node(node_type_string, &@2.beg);
+ $$.xcode = alloc_node(node_type_string, &@2);
$$.xcode->v.literal = $2;
$$.message = NULL;
}
| code xcode expr
{
- $$.code = alloc_node(node_type_string, &@1.beg);
+ $$.code = alloc_node(node_type_string, &@1);
$$.code->v.literal = $1;
- $$.xcode = alloc_node(node_type_string, &@2.beg);
+ $$.xcode = alloc_node(node_type_string, &@2);
$$.xcode->v.literal = $2;
$$.message = cast_to(dtype_string, $3);
}
| code expr
{
- $$.code = alloc_node(node_type_string, &@1.beg);
+ $$.code = alloc_node(node_type_string, &@1);
$$.code->v.literal = $1;
$$.xcode = NULL;
$$.message = cast_to(dtype_string, $2);
@@ -1316,7 +1301,7 @@ condition : if_cond
if_cond : T_IF expr stmtlist else_cond T_FI
{
- $$ = alloc_node(node_type_if, &@1.beg);
+ $$ = alloc_node(node_type_if, &@1);
$$->v.cond.cond = $2;
$$->v.cond.if_true = $3.head;
$$->v.cond.if_false = $4;
@@ -1329,7 +1314,7 @@ else_cond : /* empty */
}
| T_ELIF expr stmtlist else_cond
{
- $$ = alloc_node(node_type_if, &@1.beg);
+ $$ = alloc_node(node_type_if, &@1);
$$->v.cond.cond = $2;
$$->v.cond.if_true = $3.head;
$$->v.cond.if_false = $4;
@@ -1344,7 +1329,7 @@ case_cond : T_SWITCH expr T_DO cond_branches T_DONE
{
struct case_stmt *defcase = NULL, *pcase, *prev;
- $$ = alloc_node(node_type_switch, &@1.beg);
+ $$ = alloc_node(node_type_switch, &@1);
$$->v.switch_stmt.node = $2;
/* Make sure there is only one default case and
@@ -1374,7 +1359,8 @@ case_cond : T_SWITCH expr T_DO cond_branches T_DONE
if (!defcase) {
defcase = mu_alloc(sizeof *defcase);
- defcase->locus = @5.beg;
+ mu_locus_range_init(&defcase->locus);
+ mu_locus_range_copy(&defcase->locus, &@5);
defcase->valist = NULL;
defcase->node = alloc_node(node_type_noop,
&defcase->locus);
@@ -1399,7 +1385,8 @@ cond_branch: T_CASE valist ':' stmtlist
{
$$ = mu_alloc(sizeof *$$);
$$->next = NULL;
- $$->locus = @1.beg;
+ mu_locus_range_init (&$$->locus);
+ mu_locus_range_copy (&$$->locus, &@1);
$$->valist = $2.head;
$$->node = $4.head;
}
@@ -1407,7 +1394,8 @@ cond_branch: T_CASE valist ':' stmtlist
{
$$ = mu_alloc(sizeof *$$);
$$->next = NULL;
- $$->locus = @1.beg;
+ mu_locus_range_init (&$$->locus);
+ mu_locus_range_copy (&$$->locus, &@1);
$$->valist = NULL;
$$->node = $3.head;
}
@@ -1445,7 +1433,7 @@ value : T_STRING
string : value
{
if ($1.type != dtype_string) {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("expected string, but found %s"),
type_to_string($1.type));
/* Make sure we return something usable: */
@@ -1482,7 +1470,7 @@ loopstmt : T_LOOP loop_ident opt_loop_parms T_DO stmtlist T_DONE opt_while
{
leave_loop();
$3.end_while = $7;
- $$ = alloc_node(node_type_loop, &@1.beg);
+ $$ = alloc_node(node_type_loop, &@1);
$3.body = $5.head;
$3.ident = $2;
$$->v.loop = $3;
@@ -1534,21 +1522,21 @@ loop_parm_list: loop_parm
switch ($3.kw) {
case 0:
if ($$.stmt)
- parse_error_locus(&@3.beg,
+ parse_error_locus(&@3,
_("duplicate loop increment"));
$$.stmt = $3.expr;
break;
case T_FOR:
if ($$.for_stmt)
- parse_error_locus(&@3.beg,
+ parse_error_locus(&@3,
_("duplicate for statement"));
$$.for_stmt = $3.expr;
break;
case T_WHILE:
if ($$.beg_while)
- parse_error_locus(&@3.beg,
+ parse_error_locus(&@3,
_("duplicate while statement"));
$$.beg_while = $3.expr;
break;
@@ -1590,34 +1578,34 @@ jumpstmt : T_BREAK opt_ident
{
if (!within_loop($2)) {
if ($2)
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("no such loop: %s"),
$2->text);
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`break' used outside of `loop'"));
YYERROR;
}
- $$ = alloc_node(node_type_break, &@1.beg);
+ $$ = alloc_node(node_type_break, &@1);
$$->v.literal = $2;
}
| T_NEXT opt_ident
{
if (!within_loop($2)) {
if ($2) {
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("no such loop: %s"),
$2->text);
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`next' used outside `loop'"));
YYERROR;
} else {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`next' is used outside `loop'; "
"did you mean `pass'?"));
YYERROR;
}
} else {
- $$ = alloc_node(node_type_next, &@1.beg);
+ $$ = alloc_node(node_type_next, &@1);
$$->v.literal = $2;
}
}
@@ -1627,48 +1615,48 @@ jumpstmt : T_BREAK opt_ident
/* Expressions */
expr : T_NOT expr
{
- $$ = alloc_node(node_type_un, &@1.beg);
+ $$ = alloc_node(node_type_un, &@1);
$$->v.un.opcode = unary_not;
$$->v.un.arg = cast_to(dtype_number, $2);
}
| expr T_EQ expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_eq;
$$->v.bin.arg[0] = $1;
$$->v.bin.arg[1] = cast_to(node_type($1), $3);
}
| expr T_NE expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_ne;
$$->v.bin.arg[0] = $1;
$$->v.bin.arg[1] = cast_to(node_type($1), $3);
}
| expr T_LT expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_lt;
$$->v.bin.arg[0] = $1;
$$->v.bin.arg[1] = cast_to(node_type($1), $3);
}
| expr T_LE expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_le;
$$->v.bin.arg[0] = $1;
$$->v.bin.arg[1] = cast_to(node_type($1), $3);
}
| expr T_GT expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_gt;
$$->v.bin.arg[0] = $1;
$$->v.bin.arg[1] = cast_to(node_type($1), $3);
}
| expr T_GE expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_ge;
$$->v.bin.arg[0] = $1;
$$->v.bin.arg[1] = cast_to(node_type($1), $3);
@@ -1677,19 +1665,19 @@ expr : T_NOT expr
{
NODE *p;
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_match;
$$->v.bin.qualifier = $2.qualifier;
$$->v.bin.arg[0] = cast_to(dtype_string, $1);
$$->v.bin.arg[1] = p = alloc_node(node_type_regcomp,
- &@2.beg);
+ &@2);
p->v.regcomp_data.expr = cast_to(dtype_string, $3);
p->v.regcomp_data.flags = regex_flags;
p->v.regcomp_data.regind = -1;
}
| expr fnmatches expr %prec T_MATCHES
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_fnmatch;
$$->v.bin.qualifier = $2.qualifier;
$$->v.bin.arg[0] = cast_to(dtype_string, $1);
@@ -1697,14 +1685,14 @@ expr : T_NOT expr
}
| expr T_OR expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_or;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| expr T_AND expr
{
- $$ = alloc_node(node_type_bin, &@2.beg);
+ $$ = alloc_node(node_type_bin, &@2);
$$->v.bin.opcode = bin_and;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
@@ -1722,76 +1710,76 @@ maybe_expr : /* empty */
simp_expr : atom_expr
| simp_expr '+' simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_add;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr '.' simp_expr
{
- $$ = alloc_node(node_type_concat, &@2.beg);
+ $$ = alloc_node(node_type_concat, &@2);
$$->v.concat.arg[0] = cast_to(dtype_string, $1);
$$->v.concat.arg[1] = cast_to(dtype_string, $3);
}
| simp_expr '-' simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_sub;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr '*' simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_mul;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr '/' simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_div;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr '%' simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_mod;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr T_LOGAND simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_logand;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr T_LOGOR simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_logor;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr T_LOGXOR simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_logxor;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr T_SHL simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_shl;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
}
| simp_expr T_SHR simp_expr
{
- $$ = alloc_node(node_type_bin, &@1.beg);
+ $$ = alloc_node(node_type_bin, &@1);
$$->v.bin.opcode = bin_shr;
$$->v.bin.arg[0] = cast_to(dtype_number, $1);
$$->v.bin.arg[1] = cast_to(dtype_number, $3);
@@ -1814,7 +1802,7 @@ atom_expr : funcall
| atom
| '-' simp_expr %prec T_UMINUS
{
- $$ = alloc_node(node_type_un, &@1.beg);
+ $$ = alloc_node(node_type_un, &@1);
$$->v.un.opcode = unary_minus;
$$->v.un.arg = cast_to(dtype_number, $2);
}
@@ -1824,7 +1812,7 @@ atom_expr : funcall
}
| T_LOGNOT simp_expr %prec T_UMINUS
{
- $$ = alloc_node(node_type_un, &@1.beg);
+ $$ = alloc_node(node_type_un, &@1);
$$->v.un.opcode = unary_lognot;
$$->v.un.arg = cast_to(dtype_number, $2);
}
@@ -1832,31 +1820,31 @@ atom_expr : funcall
atom : T_SYMBOL
{
- $$ = create_node_symbol($1, &@1.beg);
+ $$ = create_node_symbol($1, &@1);
}
| T_NUMBER
{
- $$ = alloc_node(node_type_number, &@1.beg);
+ $$ = alloc_node(node_type_number, &@1);
$$->v.number = $1;
}
| T_BACKREF
{
- $$ = create_node_backref($1, &@1.beg);
+ $$ = create_node_backref($1, &@1);
}
| argref
| T_ARGCOUNT
{
- $$ = create_node_argcount(&@1.beg);
+ $$ = create_node_argcount(&@1);
}
| '@' T_VARIABLE
{
- $$ = alloc_node(node_type_offset, &@1.beg);
+ $$ = alloc_node(node_type_offset, &@1);
$$->v.var_ref.variable = $2;
$$->v.var_ref.nframes = catch_nesting;
}
| T_VAPTR paren_argref
{
- $$ = alloc_node(node_type_vaptr, &@1.beg);
+ $$ = alloc_node(node_type_vaptr, &@1);
$$->v.node = $2;
}
| strcat
@@ -1865,7 +1853,7 @@ atom : T_SYMBOL
strcat : strval
| strcat strval
{
- $$ = alloc_node(node_type_concat, &@2.beg);
+ $$ = alloc_node(node_type_concat, &@2);
$$->v.concat.arg[0] = $1;
$$->v.concat.arg[1] = $2;
}
@@ -1873,7 +1861,7 @@ strcat : strval
strval : T_STRING
{
- $$ = alloc_node(node_type_string, &@1.beg);
+ $$ = alloc_node(node_type_string, &@1);
$$->v.literal = $1;
}
| T_COMPOSE
@@ -1881,31 +1869,31 @@ strval : T_STRING
argref : variable
{
- $$ = create_node_variable($1, &@1.beg);
+ $$ = create_node_variable($1, &@1);
}
| T_ARG
{
- $$ = create_node_arg($1, &@1.beg);
+ $$ = create_node_arg($1, &@1);
}
| T_ARGX '(' expr ')'
{
if (outer_context == context_function) {
if (func->varargs) {
- $$ = alloc_node(node_type_argx, &@1.beg);
+ $$ = alloc_node(node_type_argx, &@1);
$$->v.argx.nargs = PARMCOUNT() +
FUNC_HIDDEN_ARGS(func);
$$->v.argx.node = $3;
} else {
- $$ = alloc_node(node_type_noop, &@1.beg);
- parse_error_locus(&@1.beg,
+ $$ = alloc_node(node_type_noop, &@1);
+ parse_error_locus(&@1,
_("$(expr) is allowed only "
"in a function with "
"variable number of "
"arguments"));
}
} else {
- $$ = alloc_node(node_type_noop, &@1.beg);
- parse_error_locus(&@1.beg,
+ $$ = alloc_node(node_type_noop, &@1);
+ parse_error_locus(&@1,
_("$(expr) is allowed only "
"in a function with "
"variable number of "
@@ -1923,21 +1911,21 @@ paren_argref: argref
funcall : T_BUILTIN '(' arglist ')'
{
- if (check_builtin_usage($1))
+ if (check_builtin_usage($1, &@1))
YYERROR;
if ($3.count < $1->parmcount - $1->optcount) {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("too few arguments in call to `%s'"),
$1->name);
YYERROR;
} else if ($3.count > $1->parmcount
&& !($1->flags & MFD_BUILTIN_VARIADIC)) {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("too many arguments in call to `%s'"),
$1->name);
YYERROR;
} else {
- $$ = alloc_node(node_type_builtin, &@1.beg);
+ $$ = alloc_node(node_type_builtin, &@1);
$$->v.builtin.builtin = $1;
$$->v.builtin.args =
reverse(cast_arg_list($3.head,
@@ -1948,22 +1936,22 @@ funcall : T_BUILTIN '(' arglist ')'
}
| T_BUILTIN '(' ')'
{
- if (check_builtin_usage($1))
+ if (check_builtin_usage($1, &@1))
YYERROR;
if ($1->parmcount - $1->optcount) {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("too few arguments in call to `%s'"),
$1->name);
YYERROR;
} else {
- $$ = alloc_node(node_type_builtin, &@1.beg);
+ $$ = alloc_node(node_type_builtin, &@1);
$$->v.builtin.builtin = $1;
$$->v.builtin.args = NULL;
}
}
| T_FUNCTION '(' arglist ')'
{
- if (check_func_usage($1, &@1.beg))
+ if (check_func_usage($1, &@1))
YYERROR;
$$ = function_call($1, $3.count, $3.head);
if (!$$)
@@ -1971,7 +1959,7 @@ funcall : T_BUILTIN '(' arglist ')'
}
| T_FUNCTION '(' ')'
{
- if (check_func_usage($1, &@1.beg))
+ if (check_func_usage($1, &@1))
YYERROR;
$$ = function_call($1, 0, NULL);
if (!$$)
@@ -1996,7 +1984,7 @@ arglist : expr
variable : T_VARIABLE
{
- add_xref($1, &@1.beg);
+ add_xref($1, &@1);
}
| T_BOGUS
{
@@ -2014,7 +2002,7 @@ catch : simple_catch
}
| try_block simple_catch
{
- $$ = alloc_node(node_type_try, &@1.beg);
+ $$ = alloc_node(node_type_try, &@1);
$$->v.try.node = $1;
$$->v.try.catch = $2;
}
@@ -2038,14 +2026,14 @@ simple_catch
inner_context = $<tie_in>4;
catch_nesting--;
- $$ = alloc_node(node_type_catch, &@1.beg);
+ $$ = alloc_node(node_type_catch, &@1);
$$->v.catch.exmask = exmask_create();
$$->v.catch.context = outer_context;/*??*/
$$->v.catch.exmask->all = $2.all;
if (!$2.all) {
for (i = 0, p = $2.valist; p; p = p->next, i++) {
if (p->value.type != dtype_number) {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("expected numeric value, but found `%s'"),
p->value.v.literal->text);
continue;
@@ -2071,12 +2059,12 @@ catchlist : '*'
throw : T_THROW value expr
{
- $$ = alloc_node(node_type_throw, &@1.beg);
+ $$ = alloc_node(node_type_throw, &@1);
if ($2.type != dtype_number)
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("exception code not a number"));
else if ($2.v.number > exception_count)
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("invalid exception number: %lu"),
$2.v.number);
@@ -2088,24 +2076,24 @@ throw : T_THROW value expr
return : T_RETURN
{
if (!func)
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`return' outside of a function"));
else if (func->rettype != dtype_unspecified)
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`return' with no value, in function "
"returning non-void"));
- $$ = alloc_node(node_type_return, &@1.beg);
+ $$ = alloc_node(node_type_return, &@1);
$$->v.node = NULL;
}
| T_RETURN expr
{
if (!func)
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`return' outside of a function"));
else {
- $$ = alloc_node(node_type_return, &@1.beg);
+ $$ = alloc_node(node_type_return, &@1);
if (func->rettype == dtype_unspecified) {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`return' with a value, in function "
"returning void"));
$$->v.node = NULL;
@@ -2129,7 +2117,7 @@ on_cond : on pollstmt do branches T_DONE
fp = function_lookup($2.client_addr ?
"strictpoll" : "stdpoll");
if (!fp) {
- parse_error_locus(&@1.beg,
+ parse_error_locus(&@1,
_("`on poll' used without prior `require poll'"));
YYERROR;
}
@@ -2139,7 +2127,7 @@ on_cond : on pollstmt do branches T_DONE
head = tail = $2.client_addr;
tail = $2.email;
if (!tail) {
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("recipient address not specified "
"in `on poll' construct"));
YYERROR;
@@ -2153,7 +2141,7 @@ on_cond : on pollstmt do branches T_DONE
np = $2.ehlo;
else {
/* FIXME: Pass NULL? */
- np = alloc_node(node_type_variable, &@2.beg);
+ np = alloc_node(node_type_variable, &@2);
np->v.var_ref.variable =
variable_lookup("ehlo_domain");
np->v.var_ref.nframes = 0;
@@ -2165,7 +2153,7 @@ on_cond : on pollstmt do branches T_DONE
np = $2.mailfrom;
else {
/* FIXME: Pass NULL? */
- np = alloc_node(node_type_variable, &@2.beg);
+ np = alloc_node(node_type_variable, &@2);
np->v.var_ref.variable =
variable_lookup("mailfrom_address");
np->v.var_ref.nframes = 0;
@@ -2175,13 +2163,13 @@ on_cond : on pollstmt do branches T_DONE
sel = function_call(fp, nodelistlength(head), head);
- $$ = alloc_node(node_type_switch, &@1.beg);
+ $$ = alloc_node(node_type_switch, &@1);
$$->v.switch_stmt.node = sel;
$$->v.switch_stmt.cases = $4.head;
}
| on funcall do branches T_DONE
{
- $$ = alloc_node(node_type_switch, &@1.beg);
+ $$ = alloc_node(node_type_switch, &@1);
$$->v.switch_stmt.node = $2;
$$->v.switch_stmt.cases = $4.head;
}
@@ -2276,7 +2264,7 @@ branch : T_WHEN valist ':' stmtlist
for (p = $2.head; p; p = p->next) {
if (p->value.type == dtype_string) {
- parse_error_locus(&@2.beg,
+ parse_error_locus(&@2,
_("invalid data type, "
"expected number"));
/* Try to continue */
@@ -2287,7 +2275,8 @@ branch : T_WHEN valist ':' stmtlist
$$ = mu_alloc(sizeof *$$);
$$->next = NULL;
- $$->locus = @1.beg;
+ mu_locus_range_init (&$$->locus);
+ mu_locus_range_copy (&$$->locus, &@1);
$$->valist = $2.head;
$$->node = $4.head;
}
@@ -2302,10 +2291,56 @@ yyerror(char const *s)
return 0;
}
+struct stream_state
+{
+ int mode;
+ struct mu_locus_range loc;
+ int sevmask;
+};
+
+void
+stream_state_save(mu_stream_t str, struct stream_state *st)
+{
+ mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_GET_MODE, &st->mode);
+ mu_locus_range_init(&st->loc);
+ mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE, &st->loc);
+ mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_GET_SEVERITY_MASK,
+ &st->sevmask);
+}
+
+void
+stream_state_restore(mu_stream_t str, struct stream_state *st)
+{
+ mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_MODE, &st->mode);
+ mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &st->loc);
+ mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_SEVERITY_MASK,
+ &st->sevmask);
+ mu_locus_range_deinit(&st->loc);
+}
+
int
parse_program(char *name, int ydebug)
{
int rc;
+ struct stream_state st;
+ int mode;
+
+ stream_state_save(mu_strerr, &st);
+
+ mode = st.mode | MU_LOGMODE_LOCUS | MU_LOGMODE_SEVERITY;
+ mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
+ mode = MU_DEBUG_LEVEL_MASK (MU_DIAG_ERROR);
+ mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_SEVERITY_MASK,
+ &mode);
+
yydebug = ydebug;
if (lex_new_source(name, 0))
return -1;
@@ -2313,11 +2348,30 @@ parse_program(char *name, int ydebug)
catch_nesting = 0;
code_immediate(NULL, ptr); /* Reserve 0 slot */
rc = yyparse() + error_count;
+
+ stream_state_restore(mu_strerr, &st);
+
return rc;
}
+static void
+alloc_locus(struct mu_locus_range const *locus)
+{
+ struct literal *lit;
+ if (locus->beg.mu_file) {
+ lit = string_alloc(locus->beg.mu_file,
+ strlen(locus->beg.mu_file));
+ lit->flags |= SYM_REFERENCED;
+ }
+ if (!mu_locus_point_same_file(&locus->beg, &locus->end)) {
+ lit = string_alloc(locus->end.mu_file,
+ strlen(locus->end.mu_file));
+ lit->flags |= SYM_REFERENCED;
+ }
+}
+
NODE *
-alloc_node(enum node_type type, const struct locus *locus)
+alloc_node(enum node_type type, struct mu_locus_range const *locus)
{
NODE *node = malloc(sizeof(*node));
if (!node) {
@@ -2325,7 +2379,9 @@ alloc_node(enum node_type type, const struct locus *locus)
abort();
}
node->type = type;
- node->locus = *locus;
+ mu_locus_range_init (&node->locus);
+ mu_locus_range_copy (&node->locus, locus);
+ alloc_locus(locus);
node->next = NULL;
return node;
}
@@ -2340,7 +2396,7 @@ void
copy_node(NODE *dest, NODE *src)
{
dest->type = src->type;
- dest->locus = src->locus;
+ mu_locus_range_copy (&dest->locus, &src->locus);
dest->v = src->v;
}
@@ -2501,7 +2557,7 @@ print_quoted_string(const char *str)
struct node_drv {
void (*print) (NODE *, int);
void (*mark) (NODE *);
- void (*code) (NODE *, struct locus **);
+ void (*code) (NODE *, struct mu_locus_range const **);
void (*optimize) (NODE *);
};
@@ -2637,28 +2693,28 @@ variable_enumerator(void *item, void *data)
int
print_locus(void *item, void *data)
{
- struct locus *loc = item;
- struct locus **prev = data;
+ struct mu_locus_range *loc = item;
+ struct mu_locus_range **prev = data;
int c;
if (!*prev) {
*prev = loc;
- printf("%s", loc->file);
+ printf("%s", loc->beg.mu_file);
c = ':';
- } else if (strcmp((*prev)->file, loc->file)) {
+ } else if (mu_locus_point_same_file (&(*prev)->beg, &loc->beg)) {
*prev = loc;
- printf(", %s", loc->file);
+ printf(", %s", loc->beg.mu_file);
c = ':';
} else
c = ',';
- printf("%c%lu", c, (unsigned long) loc->line);
+ printf("%c%u", c, loc->beg.mu_line);
return 0;
}
void
print_xref_var(struct variable *var)
{
- struct locus *prev = NULL;
+ struct mu_locus_range *prev = NULL;
var = (struct variable *)symbol_resolve_alias(&var->sym);
printf("%-32.32s %6s %lu ",
var->sym.name, type_to_string(var->type),
@@ -2866,7 +2922,7 @@ code_node(NODE *node)
if (!node)
error_count++;
else {
- static struct locus *old_locus;
+ static struct mu_locus_range const *old_locus;
struct node_drv *nd = find_node_drv(node->type);
if (nd->code)
nd->code(node, &old_locus);
@@ -2992,7 +3048,7 @@ static void
compile_tree(NODE *node)
{
struct node_drv *nd;
- struct locus *plocus;
+ struct mu_locus_range const *plocus;
for (; node; node = node->next) {
switch (node->type) {
@@ -3291,7 +3347,7 @@ dbg_dict_getsym (void *data, const char *str)
void
mailfromd_test(int argc, char **argv)
{
- int i, rc;
+ int i;
mu_assoc_t dict = NULL;
eval_environ_t env;
char *p, *end;
@@ -3343,7 +3399,7 @@ mailfromd_test(int argc, char **argv)
env_make_frame(env);
- rc = xeval(env, test_state);
+ xeval(env, test_state);
env_leave_frame(env, state_parms[test_state].cnt);
env_final_gc(env);
@@ -3461,7 +3517,8 @@ nodelistlength(NODE *p)
}
static NODE *
-create_asgn_node(struct variable *var, NODE *expr, const struct locus *loc)
+create_asgn_node(struct variable *var, NODE *expr,
+ struct mu_locus_range const *loc)
{
NODE *node;
data_type_t t = node_type(expr);
@@ -3489,7 +3546,7 @@ function_call(struct function *function, size_t count, NODE *subtree)
parse_error(_("too many arguments in call to `%s'"),
function->sym.name);
} else {
- np = alloc_node(node_type_call, get_locus());
+ np = alloc_node(node_type_call, &yylloc);
np->v.call.func = function;
np->v.call.args = reverse(cast_arg_list(subtree,
function->parmcount,
@@ -3602,7 +3659,7 @@ cast_to(data_type_t type, NODE *node)
default:
abort();
}
- np = alloc_node(node_type_cast, get_locus());
+ np = alloc_node(node_type_cast, &yylloc);
np->v.cast.data_type = type;
np->v.cast.node = node;
node->next = NULL;
@@ -3640,24 +3697,28 @@ cast_arg_list(NODE *args, size_t parmc, data_type_t *parmtype, int disable_prom)
}
void
-add_xref(struct variable *var, const struct locus *locus)
+add_xref(struct variable *var, struct mu_locus_range const *locus)
{
if (script_dump_xref) {
- struct locus *elt = mu_alloc(sizeof *elt);
+ /* FIXME: either change type to mu_locus_point, or
+ change print_locus above */
+ struct mu_locus_range *elt = mu_zalloc(sizeof *elt);
if (!var->xref)
mu_list_create(&var->xref);
- *elt = *locus;
+ mu_locus_range_copy(elt, locus);
mu_list_append(var->xref, elt);
}
}
struct variable *
vardecl(const char *name, data_type_t type, storage_class_t sc,
- struct locus *loc)
+ struct mu_locus_range const *loc)
{
struct variable *var;
const struct constant *cptr;
-
+
+ if (!loc)
+ loc = &yylloc;
if (type == dtype_unspecified) {
parse_error(_("cannot define variable of unspecified type"));
return NULL;
@@ -3678,20 +3739,23 @@ vardecl(const char *name, data_type_t type, storage_class_t sc,
case storage_auto:
if (var->storage_class == storage_param) {
- parse_warning(_("automatic variable `%s' "
- "is shadowing a parameter"),
- var->sym.name);
+ parse_warning_locus(loc,
+ _("automatic variable `%s' "
+ "is shadowing a parameter"),
+ var->sym.name);
} else
- parse_warning(_("automatic variable `%s' "
- "is shadowing a global"),
+ parse_warning_locus(loc,
+ _("automatic variable `%s' "
+ "is shadowing a global"),
var->sym.name);
unregister_auto(var);
break;
case storage_param:
- parse_warning(_("parameter `%s' is shadowing a "
- "global"),
- name);
+ parse_warning_locus(loc,
+ _("parameter `%s' is shadowing a "
+ "global"),
+ name);
}
/* Do the shadowing */
@@ -3702,9 +3766,10 @@ vardecl(const char *name, data_type_t type, storage_class_t sc,
switch (sc) {
case storage_extern:
if (var->type != type) {
- parse_error(_("redeclaring `%s' as different "
- "data type"),
- name);
+ parse_error_locus(loc,
+ _("redeclaring `%s' as different "
+ "data type"),
+ name);
parse_error_locus(&var->sym.locus,
_("this is the location of the "
"previous definition"));
@@ -3714,21 +3779,25 @@ vardecl(const char *name, data_type_t type, storage_class_t sc,
case storage_auto:
if (var->type != type) {
- parse_error(_("redeclaring `%s' as different "
- "data type"),
- name);
+ parse_error_locus(loc,
+ _("redeclaring `%s' as different "
+ "data type"),
+ name);
parse_error_locus(&var->sym.locus,
- _("this is the location of the "
- "previous definition"));
+ _("this is the location of the "
+ "previous definition"));
return NULL;
} else {
- parse_error(_("duplicate variable: %s"), name);
+ parse_error_locus(loc,
+ _("duplicate variable: %s"),
+ name);
return NULL;
}
break;
case storage_param:
- parse_error(_("duplicate parameter: %s"), name);
+ parse_error_locus(loc, _("duplicate parameter: %s"),
+ name);
return NULL;
}
}
@@ -3736,7 +3805,8 @@ vardecl(const char *name, data_type_t type, storage_class_t sc,
/* FIXME: This is necessary because constants can be
referred to the same way as variables. */
if (cptr = constant_lookup(name)) {
- parse_warning(_("variable name `%s' clashes with a constant name"),
+ parse_warning_locus(loc,
+ _("variable name `%s' clashes with a constant name"),
name);
parse_warning_locus(&cptr->sym.locus,
_("this is the location of the "
@@ -3747,13 +3817,13 @@ vardecl(const char *name, data_type_t type, storage_class_t sc,
var->storage_class = sc;
switch (sc) {
case storage_extern:
- add_xref(var, loc ? loc : get_locus());
+ add_xref(var, loc);
break;
case storage_auto:
case storage_param:
register_auto(var);
}
- var->sym.locus = *get_locus();
+ mu_locus_range_copy(&var->sym.locus, loc);
return var;
}
@@ -3789,7 +3859,8 @@ cast_value(data_type_t type, struct value *value)
}
static struct variable *
-externdecl(const char *name, struct value *value, struct locus *loc)
+externdecl(const char *name, struct value *value,
+ struct mu_locus_range const *loc)
{
struct variable *var = vardecl(name, value->type, storage_extern, loc);
if (!var)
@@ -3804,14 +3875,14 @@ struct deferred_decl {
struct deferred_decl *next;
struct literal *name;
struct value value;
- struct locus locus;
+ struct mu_locus_range locus;
};
struct deferred_decl *deferred_decl;
void
defer_initialize_variable(const char *arg, const char *val,
- struct locus *ploc)
+ struct mu_locus_range const *ploc)
{
struct deferred_decl *p;
struct literal *name = string_alloc(arg, strlen(arg));
@@ -3821,14 +3892,15 @@ defer_initialize_variable(const char *arg, const char *val,
name->text);
p->value.type = dtype_string;
p->value.v.literal = string_alloc(val, strlen(val));
- p->locus = *ploc;
+ mu_locus_range_copy (&p->locus, ploc);
return;
}
p = mu_alloc(sizeof *p);
p->name = name;
p->value.type = dtype_string;
p->value.v.literal = string_alloc(val, strlen(val));
- p->locus = *ploc;
+ mu_locus_range_init (&p->locus);
+ mu_locus_range_copy (&p->locus, ploc);
p->next = deferred_decl;
deferred_decl = p;
}
@@ -3855,7 +3927,7 @@ apply_deferred_init()
struct declvar {
struct declvar *next;
- struct locus locus;
+ struct mu_locus_range locus;
struct variable *var;
struct value val;
};
@@ -3889,7 +3961,7 @@ set_poll_arg(struct poll_data *poll, int kw, NODE *expr)
int
initialize_variable(struct variable *var, struct value *val,
- const struct locus *locus)
+ struct mu_locus_range const *locus)
{
struct declvar *dv;
@@ -3897,7 +3969,7 @@ initialize_variable(struct variable *var, struct value *val,
return 1;
for (dv = declvar; dv; dv = dv->next)
if (dv->var == var) {
- if (dv->locus.file) {
+ if (dv->locus.beg.mu_file) {
parse_warning_locus(locus,
_("variable `%s' already initialized"),
var->sym.name);
@@ -3905,12 +3977,11 @@ initialize_variable(struct variable *var, struct value *val,
_("this is the location of the "
"previous initialization"));
}
+
if (locus)
- dv->locus = *locus;
- else {
- dv->locus.file = NULL;
- dv->locus.line = 0;
- }
+ mu_locus_range_copy (&dv->locus, locus);
+ else
+ mu_locus_range_deinit (&dv->locus);
dv->val = *val;
return 0;
}
@@ -3918,12 +3989,9 @@ initialize_variable(struct variable *var, struct value *val,
dv = mu_alloc(sizeof *dv);
dv->next = declvar;
dv->var = var;
+ mu_locus_range_init (&dv->locus);
if (locus)
- dv->locus = *locus;
- else {
- dv->locus.file = "<unknown>";
- dv->locus.line = 1;
- }
+ mu_locus_range_copy (&dv->locus, locus);
dv->val = *val;
declvar = dv;
var->sym.flags |= SYM_INITIALIZED;
@@ -3951,8 +4019,7 @@ ensure_initialized_variable(const char *name, struct value *val)
if (dv->var == var)
return;
dv = mu_alloc(sizeof *dv);
- dv->locus.file = NULL;
- dv->locus.line = 0;
+ mu_locus_range_init (&dv->locus);
dv->var = var;
dv->val = *val;
dv->next = declvar;
@@ -4275,7 +4342,8 @@ function_name()
}
NODE *
-declare_function(struct function *func, struct locus *loc, size_t nautos)
+declare_function(struct function *func, struct mu_locus_range const *loc,
+ size_t nautos)
{
NODE *node = alloc_node(node_type_funcdecl, loc);
node->v.funcdecl.func = func;
@@ -4286,7 +4354,7 @@ declare_function(struct function *func, struct locus *loc, size_t nautos)
NODE *
-create_node_variable(struct variable *var, const struct locus *locus)
+create_node_variable(struct variable *var, struct mu_locus_range const *locus)
{
NODE *node = alloc_node(node_type_variable, locus);
node->v.var_ref.variable = var;
@@ -4295,7 +4363,7 @@ create_node_variable(struct variable *var, const struct locus *locus)
}
NODE *
-create_node_argcount(const struct locus *locus)
+create_node_argcount(struct mu_locus_range const *locus)
{
NODE *node;
@@ -4316,7 +4384,7 @@ create_node_argcount(const struct locus *locus)
}
NODE *
-create_node_arg(long num, const struct locus *locus)
+create_node_arg(long num, struct mu_locus_range const *locus)
{
NODE *node;
@@ -4333,7 +4401,7 @@ create_node_arg(long num, const struct locus *locus)
}
NODE *
-create_node_symbol(struct literal *lit, const struct locus *locus)
+create_node_symbol(struct literal *lit, struct mu_locus_range const *locus)
{
NODE *node;
register_macro(state_tag, lit->text);
@@ -4343,7 +4411,7 @@ create_node_symbol(struct literal *lit, const struct locus *locus)
}
NODE *
-create_node_backref(long num, const struct locus *locus)
+create_node_backref(long num, struct mu_locus_range const *locus)
{
NODE *node = alloc_node(node_type_backref, locus);
node->v.number = num;
diff --git a/src/lex.l b/src/lex.l
index 787bd88..978f8ad 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -26,19 +26,26 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "mailfromd.h"
+#include <mailutils/yyloc.h>
#include "gram.h"
#include "prog.h"
#include "srvcfg.h"
-static struct locus locus; /* Current input location */
-static struct locus start_locus; /* Location when the last state switch
- occurred */
+static mu_linetrack_t trk;
+
+static struct mu_locus_point start_locus; /* Location when the last state switch
+ occurred */
static mu_opool_t string_pool; /* Opool for constructing string values */
static char *multiline_delimiter; /* End of here-document delimiter */
static size_t multiline_delimiter_len; /* Length of multiline_delimiter_len */
static int multiline_unescape; /* Unescape here-document contents */
static int (*char_to_strip)(char); /* Strip matching characters of each
here-document line */
+struct mu_locus_range const *
+get_locus(void)
+{
+ return &yylloc;
+}
static int
is_tab(char c)
@@ -59,6 +66,13 @@ c_unescape(unsigned char inc)
return outc ? outc : inc;
}
+static void
+switch_origin(struct mu_locus_point *pt)
+{
+ mu_linetrack_origin(trk, pt);
+ mu_locus_point_deinit(pt);
+}
+
#define line_begin string_begin
#define line_add string_add
#define line_add_char string_add_char
@@ -67,13 +81,6 @@ static void string(const char *str, size_t len);
static int isemptystr(char *text);
static int builtin_const(const char *s, size_t len);
-/* External interface to locus */
-const struct locus *
-get_locus()
-{
- return &locus;
-}
-
/* Input context flags */
#define INCTX_MODULE 0x1 /* current input is a MFL module */
@@ -84,7 +91,8 @@ get_locus()
/* Input context stack */
struct inctx { /* input context structure */
struct inctx *parent; /* parent context */
- struct locus locus; /* locus where the context was pushed */
+ struct mu_locus_range locus;/* locus where the context was pushed */
+ mu_linetrack_t trk;
struct input_file_ident id;/* file id structure to prevent recursion */
FILE *file; /* saved yyin */
pid_t pp_pid; /* preprocessor pid, if used */
@@ -123,7 +131,9 @@ inctx_push()
{
struct inctx *ctx = mu_alloc(sizeof(*ctx));
- ctx->locus = locus;
+ mu_locus_range_init(&ctx->locus);
+ mu_locus_range_copy(&ctx->locus, &yylloc);
+ ctx->trk = trk;
ctx->id = input_file_id;
ctx->file = yyin;
ctx->pp_pid = pp_pid;
@@ -145,7 +155,8 @@ inctx_pop()
inctx_tos = ctx->parent;
- locus = ctx->locus;
+ mu_locus_range_deinit(&ctx->locus);
+ trk = ctx->trk;
yyin = ctx->file;
input_file_id = ctx->id;
inctx_flags = ctx->inctx_flags;
@@ -179,7 +190,7 @@ lex_new_source_0(const char *name)
}
}
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
- assign_locus(&locus, name, "1");
+ MU_ASSERT (mu_linetrack_create (&trk, name, 2));
return EX_OK;
}
@@ -270,25 +281,20 @@ variable_or_const()
yylval.literal->text);
return T_BOGUS;
}
- add_xref(vptr, &locus);
+ add_xref(vptr, &yylloc);
yylval.var = vptr;
return T_VARIABLE;
}
-/* Advance locus to the next line */
-void
-advance_line()
-{
- ++locus.line;
- locus.point = 0;
- locus.leng = 0;
-}
-
/* Saved lexer state before entering COMMENT */
static int save_state;
/* Same as BEGIN, but also saves the current locus. It is then used
to report unclosed constructs at the end of file. */
-#define BEGIN_X(s) do { BEGIN(s); start_locus = locus; } while(0)
+#define BEGIN_X(s) \
+ do { \
+ BEGIN(s); \
+ mu_locus_point_copy (&start_locus, &yylloc.beg); \
+ } while(0)
/* If emit_token is not 0, push back current input and return the value
of emit_token. Clear emit_token before returning. */
@@ -299,18 +305,15 @@ static int save_state;
if (yy_flex_debug) \
fprintf(stderr, "--emitting %d (module %s)\n", \
tok,top_module->name); \
+ mu_linetrack_retreat(trk, yyleng); \
yyless(0); \
- yylloc.beg = yylloc.end = locus; \
- yylloc.beg.point -= yyleng; \
return tok; \
} else { \
- locus.point += yyleng; \
- locus.leng = yyleng; \
- yylloc.beg = yylloc.end = locus; \
- yylloc.beg.point -= yyleng; \
+ mu_linetrack_advance(trk, &yylloc, yytext, yyleng); \
+ mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM, \
+ MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &yylloc);\
}
-
/* Read next input chunk. */
#define YY_INPUT(buf,result,max_size) \
if (yyin == NULL) \
@@ -325,7 +328,7 @@ static int save_state;
/* String composer */
-static struct locus string_beg;
+static struct mu_locus_point string_beg;
static NODE *string_head, *string_tail;
static void
@@ -346,8 +349,7 @@ compose_start(int state)
"finished when a new one started");
abort();
}
- string_beg = locus;
- string_beg.point -= string_beg.leng;
+ mu_locus_point_copy(&string_beg, &yylloc.beg);
BEGIN_X(state);
}
@@ -368,7 +370,8 @@ compose_finish()
}
}
yylval.node = string_head;
- yylloc.beg = string_beg;
+ mu_locus_point_copy(&yylloc.beg, &string_beg);
+ mu_locus_point_deinit(&string_beg);
string_head = string_tail = NULL;
return T_COMPOSE;
}
@@ -376,7 +379,7 @@ compose_finish()
static void
compose_add_literal(struct literal *lit)
{
- NODE *node = alloc_node(node_type_string, &locus);
+ NODE *node = alloc_node(node_type_string, &yylloc);
node->v.literal = lit;
compose_add_node(node);
if (yy_flex_debug)
@@ -392,7 +395,7 @@ compose_add_string(const char *text, size_t length)
static void
compose_add_number(long num)
{
- NODE *node = alloc_node(node_type_number, &locus);
+ NODE *node = alloc_node(node_type_number, &yylloc);
node->v.number = num;
compose_add_node(node);
}
@@ -430,7 +433,7 @@ compose_add_variable_or_const(int what)
break;
case T_VARIABLE:
- compose_add_node(create_node_variable(yylval.var, &locus));
+ compose_add_node(create_node_variable(yylval.var, &yylloc));
}
}
@@ -476,19 +479,22 @@ ICONST {LOCUS}|{VCONST}|{STATEDIR}|{PREPROC}
<INITIAL,XIDENT>"/*" { save_state = YYSTATE; BEGIN_X(COMMENT); }
<COMMENT>[^*\n]* /* eat anything that's not a '*' */
<COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
-<COMMENT>\n advance_line();
+<COMMENT>\n ;
<COMMENT>"*"+"/" BEGIN(save_state);
/* Shell magic sequence */
^#!" "?"/".*\n {
- if (locus.line == 1) {
+ if (yylloc.beg.mu_line == 1) {
BEGIN_X(SHELLMAGIC);
}
- advance_line();
}
-<SHELLMAGIC>^"!#"[ \t]*\n { advance_line(); BEGIN(INITIAL); }
-<SHELLMAGIC>.*\n { advance_line(); }
+<SHELLMAGIC>^"!#"[ \t]*\n { BEGIN(INITIAL); }
+<SHELLMAGIC>.*\n ;
/* Configuration directives */
-^[ \t]*#[ \t]*{P}[ \t]+\".*\".*\n parse_line_cpp(yytext, &locus);
+^[ \t]*#[ \t]*{P}[ \t]+\".*\".*\n {
+ struct mu_locus_point pt;
+ if (parse_line_cpp(yytext, &pt) == 0)
+ switch_origin(&pt);
+}
/* Normally, everything within a comment should be ignored, so
the exclusive condition for the rule below is an error.
Unfortunately, GNU m4 in versions up to 1.4.9 outputs line
@@ -501,16 +507,18 @@ ICONST {LOCUS}|{VCONST}|{STATEDIR}|{PREPROC}
this kludge until I am pretty sure there are no 1.4.9 around.
*/
<INITIAL,COMMENT>^[ \t]*#[ \t]*line[ \t].*\n {
- parse_line(yytext, &locus);
+ struct mu_locus_point pt;
+ if (parse_line(yytext, &pt) == 0)
+ switch_origin(&pt);
}
^[ \t]*#[ \t]*pragma[ \t].*\n {
+ mu_linetrack_retreat(trk, 1);
yyless(yyleng-1);
parse_pragma(yytext);
}
^[ \t]*#[ \t]*error[ \t].*\n {
yytext[yyleng-1] = 0; /* Kill trailing newline */
parse_error("%s", yytext);
- advance_line();
}
^[ \t]*#[ \t]*include_once[ \t].*\n {
parse_include(yytext, 1);
@@ -519,15 +527,16 @@ ICONST {LOCUS}|{VCONST}|{STATEDIR}|{PREPROC}
parse_include(yytext, 0);
}
/* End-of-line comments */
-#.*\n { advance_line(); }
+#.*\n ;
#.* /* end-of-file comment */;
/* expected identified (after 'require' or initial 'from') */
<XIDENT>{IDENT} { BEGIN(INITIAL);
string(yytext, yyleng);
return T_IDENTIFIER; }
<XIDENT>{WS} ;
-<XIDENT>\n { advance_line(); }
+<XIDENT>\n ;
<XIDENT>. { BEGIN(INITIAL);
+ mu_linetrack_retreat(trk, yyleng);
yyless(0); }
/* Reserved words */
accept return T_ACCEPT;
@@ -589,12 +598,12 @@ public return T_PUBLIC;
module { if (inctx_tos && inctx_flags == 0) {
int c;
int flen;
- const char *fname = strrchr(locus.file, '/');
+ const char *fname = strrchr(yylloc.beg.mu_file, '/');
if (fname)
fname++;
else
- fname = locus.file;
+ fname = yylloc.beg.mu_file;
flen = strlen(fname);
if (flen > 3 && strcmp(fname + flen - 3, ".mf") == 0)
@@ -606,14 +615,17 @@ module { if (inctx_tos && inctx_flags == 0) {
_("use `require %*.*s' instead"),
flen, flen, fname);
inctx_flags |= INCTX_IGNORE_BYE;
- start_locus = locus;
+ mu_locus_point_copy(&start_locus, &yylloc.beg);
while ((c = input()) != '.') {
if (c == 0) {
- parse_error_locus(&start_locus,
- _("unexpected end of file"));
+ mu_diag_at_locus_point(MU_DIAG_ERROR, &start_locus,
+ "%s",
+ _("unexpected end of file"));
return 0;
- } else if (c == '\n')
- advance_line();
+ } else {
+ char ch = c;
+ mu_linetrack_advance(trk, &yylloc, &ch, 1);
+ }
}
} else if (inctx_flags & INCTX_HADINPUT)
parse_error(_("misplaced `module'"));
@@ -652,13 +664,13 @@ dclex return T_DCLEX;
return T_ARGCOUNT;
}
<ML,CML,STR>\$# {
- compose_add_node(create_node_argcount(&locus));
+ compose_add_node(create_node_argcount(&yylloc));
}
<INITIAL,ONBLOCK>\${P} {
yylval.number = strtol(yytext + 1, NULL, 0);
return T_ARG; }
<ML,CML,STR>\${P} {
- compose_add_node(create_node_arg(strtol(yytext + 1, NULL, 0), &locus));
+ compose_add_node(create_node_arg(strtol(yytext + 1, NULL, 0), &yylloc));
}
<INITIAL,ONBLOCK>\$/"(" { return T_ARGX; }
/* Sendmail variables */
@@ -684,20 +696,20 @@ dclex return T_DCLEX;
line_add("}", 1);
line_finish();
}
- compose_add_node(create_node_symbol(yylval.literal, &locus));
+ compose_add_node(create_node_symbol(yylval.literal, &yylloc));
}
<INITIAL,ONBLOCK>\$\{{IDENT}\} {
string(yytext+1, yyleng - 1); return T_SYMBOL; }
<ML,CML,STR>\$\{{IDENT}\} {
string(yytext+1, yyleng - 1);
- compose_add_node(create_node_symbol(yylval.literal, &locus)); }
+ compose_add_node(create_node_symbol(yylval.literal, &yylloc)); }
/* Back-references */
<INITIAL,ONBLOCK>\\{P} {
yylval.number = strtoul(yytext+1, NULL, 0);
return T_BACKREF; }
<ML,CML,STR>\\{P} {
compose_add_node(create_node_backref(strtoul(yytext+1, NULL, 10),
- &locus)); }
+ &yylloc)); }
/* Numeric strings */
0[xX]{X}{X}* { yylval.number = strtoul(yytext, NULL, 16); return T_NUMBER; };
0{O}{O}* { yylval.number = strtoul(yytext, NULL, 8); return T_NUMBER; };
@@ -734,7 +746,7 @@ dclex return T_DCLEX;
if (!vptr) {
return T_IDENTIFIER;
}
- add_xref(vptr, &locus);
+ add_xref(vptr, &yylloc);
yylval.var = vptr;
return T_VARIABLE;
}
@@ -742,8 +754,7 @@ dclex return T_DCLEX;
/* Strings */
'[^\n']*' { string(yytext+1, yyleng-2); return T_STRING; }
\"[^\\\"$%\n]*\" { string(yytext+1, yyleng-2); return T_STRING; }
-\"[^\\\"$%\n]*\\\n { advance_line();
- compose_start(STR);
+\"[^\\\"$%\n]*\\\n { compose_start(STR);
compose_add_string(yytext + 1, yyleng - 3); }
\"[^\\\"$%\n]*/[\\$%] { compose_start(STR);
compose_add_string(yytext+1, yyleng-1); }
@@ -776,7 +787,7 @@ dclex return T_DCLEX;
compose_start(STR);
line_add_char(c_unescape(yytext[2]));
}
-<STR>[^\\\"$%\n]*\\\n { advance_line(); line_add(yytext, yyleng - 2); }
+<STR>[^\\\"$%\n]*\\\n { line_add(yytext, yyleng - 2); }
<STR>[^\\\"$%\n]*\" { BEGIN(INITIAL);
if (yyleng > 1)
line_add(yytext, yyleng - 1);
@@ -817,7 +828,6 @@ dclex return T_DCLEX;
"<<"(-" "?)?'{IDENT}'[ \t]*.*\n {
char *p;
- advance_line();
char_to_strip = NULL;
multiline_unescape = 1;
@@ -858,7 +868,6 @@ dclex return T_DCLEX;
<QML>[^\n]*\n {
char *p;
- advance_line();
p = yytext;
if (char_to_strip)
for (; char_to_strip (*p); p++)
@@ -903,7 +912,6 @@ dclex return T_DCLEX;
<ML>[^\\$%\n]*\n/% {
char *p;
- advance_line();
p = yytext;
if (char_to_strip)
for (; char_to_strip (*p); p++)
@@ -925,7 +933,6 @@ dclex return T_DCLEX;
<ML>[^\\$%\n]*\n {
char *p;
- advance_line();
p = yytext;
if (char_to_strip)
for (; char_to_strip (*p); p++)
@@ -944,7 +951,6 @@ dclex return T_DCLEX;
line_add(p, strlen(p));
}
<CML>[^\\$%\n]*\n {
- advance_line();
if (yyleng >= multiline_delimiter_len
&& memcmp(yytext, multiline_delimiter,
multiline_delimiter_len) == 0
@@ -961,7 +967,7 @@ dclex return T_DCLEX;
}
/* Other tokens */
{WS} ;
-\n { advance_line(); }
+\n ;
"="|"==" return T_EQ;
"!=" return T_NE;
"<" return T_LT;
@@ -1063,45 +1069,21 @@ string_add_char(unsigned char c)
}
void
-print_parse_message(const struct locus *locus,
- const char *prefix, const char *fmt, va_list ap)
-{
- int n;
- char buf[512]; /* FIXME */
-
- if (locus && locus->file) {
- if (location_column_option)
- n = snprintf(buf, sizeof buf, "%s:%lu:%lu: ",
- locus->file, (unsigned long) locus->line,
- (unsigned long)locus->point);
- else
- n = snprintf(buf, sizeof buf, "%s:%lu: ",
- locus->file, (unsigned long) locus->line);
- } else
- n = 0;
- if (prefix)
- n += snprintf(buf + n, sizeof buf - n, "%s: ", prefix);
- vsnprintf(buf + n, sizeof buf - n, gettext(fmt), ap);
- mu_error("%s", buf);
-}
-
-void
parse_warning(const char *fmt, ...)
{
va_list ap;
-
va_start(ap, fmt);
- print_parse_message(&locus, _("warning"), fmt, ap);
+ mu_diag_voutput (MU_DIAG_WARNING, fmt, ap);
va_end(ap);
}
void
-parse_warning_locus(const struct locus *loc, const char *fmt, ...)
+parse_warning_locus(struct mu_locus_range const *loc, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- print_parse_message(loc, _("warning"), fmt, ap);
+ mu_vdiag_at_locus_range(MU_DIAG_WARNING, loc, fmt, ap);
va_end(ap);
}
@@ -1111,18 +1093,18 @@ parse_error(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- print_parse_message(&locus, NULL, fmt, ap);
+ mu_diag_voutput(MU_DIAG_ERROR, fmt, ap);
va_end(ap);
error_count++;
}
void
-parse_error_locus(const struct locus *loc, const char *fmt, ...)
+parse_error_locus(struct mu_locus_range const *loc, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- print_parse_message(loc, NULL, fmt, ap);
+ mu_vdiag_at_locus_range(MU_DIAG_ERROR, loc, fmt, ap);
va_end(ap);
error_count++;
}
@@ -1139,6 +1121,7 @@ lex_close_source()
else
fclose(yyin);
yyin = NULL;
+ mu_linetrack_destroy(&trk);
switch (YYSTATE) {
case INITIAL:
@@ -1146,19 +1129,21 @@ lex_close_source()
break;
case COMMENT:
- parse_error_locus(&start_locus, _("end of file in comment"));
+ mu_diag_at_locus_point (MU_DIAG_ERROR, &start_locus,
+ "%s", _("end of file in comment"));
break;
case STR:
case ML:
case CML:
case QML:
- parse_error_locus(&start_locus, _("end of file in string"));
+ mu_diag_at_locus_point (MU_DIAG_ERROR, &start_locus,
+ "%s", _("end of file in string"));
break;
case SHELLMAGIC:
- parse_error_locus(&start_locus,
- _("end of file in shell block"));
+ mu_diag_at_locus_point (MU_DIAG_ERROR, &start_locus,
+ "%s", _("end of file in shell block"));
break;
}
return inctx_pop();
@@ -1209,11 +1194,11 @@ data_type_t
builtin_const_value(const char *s, size_t len, const char **sval, long *nval)
{
if (strncmp(s, "__file__", len) == 0) {
- struct literal *lit = literal_lookup(locus.file);
+ struct literal *lit = literal_lookup(yylloc.beg.mu_file);
*sval = lit->text;
return dtype_string;
} else if (strncmp(s, "__line__", len) == 0) {
- *nval = locus.line;
+ *nval = yylloc.beg.mu_line;
return dtype_number;
} else if (strncmp(s, "__function__", len) == 0) {
*sval = function_name();
diff --git a/src/mailfromd.h b/src/mailfromd.h
index e27a78d..527d4f9 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -143,26 +143,7 @@ typedef enum {
/* Parse tree node */
typedef struct node NODE;
-/* Input location */
-struct locus {
- const char *file; /* File name */
- unsigned long line; /* Line number */
- unsigned long point; /* Offset in the input line */
- unsigned long leng; /* Length of the input token */
-};
-
-#define LOCUS_EQ(a,b) \
- ((((a)->file == (b)->file) \
- || ((a)->file && (b)->file && strcmp((a)->file, (b)->file) == 0)) \
- && (a)->line == (b)->line)
-
-/* Input location for the parser */
-typedef struct mf_yyltype {
- struct locus beg;
- struct locus end;
-} mf_yyltype_t;
-
-#define YYLTYPE mf_yyltype_t
+typedef struct mu_locus_range mf_yyltype_t;
struct if_node { /* if statement */
NODE *cond; /* Condition */
@@ -313,7 +294,7 @@ struct valist {
struct case_stmt {
struct case_stmt *next;
- struct locus locus;
+ struct mu_locus_range locus;
struct valist *valist;
NODE *node;
};
@@ -384,7 +365,7 @@ struct argx_node {
struct node {
NODE *next; /* Link to the next node */
enum node_type type; /* Node type */
- struct locus locus; /* Corresponding input location */
+ struct mu_locus_range locus; /* Corresponding input location */
union {
struct literal *literal;
long number;
@@ -457,7 +438,7 @@ struct mf_symbol {
struct mf_symbol *alias;
struct module *module; /* Backlink to the module where it is
defined */
- struct locus locus; /* Location of the definition */
+ struct mu_locus_range locus; /* Location of the definition */
unsigned flags; /* SYM_ flags */
};
@@ -510,7 +491,7 @@ struct variable {
size_t *addrptr; /* Address pointer (for built-in vars) */
struct variable *shadowed; /* Points to the variable shadowed by
this one */
- mu_list_t xref; /* List of struct locus */
+ mu_list_t xref; /* List of struct mu_locus_range */
struct variable *next; /* Next variable in this class */
};
@@ -576,7 +557,7 @@ struct variable *builtin_variable_install(const char *name,
unsigned flags,
size_t *addrptr);
void defer_initialize_variable(const char *arg, const char *val,
- struct locus *locus);
+ struct mu_locus_range const *locus);
int variable_or_constant_lookup(const char *name, void **dptr);
@@ -584,11 +565,12 @@ struct function *function_install(const char *name,
size_t parmcnt, size_t optcnt, int varargs,
data_type_t *parmtypes,
data_type_t rettype,
- const struct locus *locus);
+ const struct mu_locus_range *locus);
struct function *function_lookup(const char *name);
struct literal *literal_lookup(const char *text);
const struct constant *define_constant(const char *name, struct value *value,
- unsigned flags, struct locus *loc);
+ unsigned flags,
+ struct mu_locus_range const *loc);
const struct constant *constant_lookup(const char *name);
const struct value *constant_lookup_value(const char *name);
@@ -604,7 +586,7 @@ struct sym_regex {
struct sym_regex *install_regex(struct literal *lit, unsigned regflags);
void install_alias(const char *name, struct function *fun,
- const struct locus *locus);
+ const struct mu_locus_range *locus);
struct rt_regex {
@@ -681,7 +663,7 @@ extern struct module *top_module;
#define TOP_MODULE_SYMTAB(ns) MODULE_SYMTAB(top_module,ns)
int set_top_module(const char *name, const char *file,
struct import_rule *import_rules,
- const struct locus *locus);
+ struct mu_locus_range const *locus);
void pop_top_module(void);
void collect_modules(struct module ***pmodv, size_t *pmodc);
int module_symtab_enumerate(enum module_namespace ns, symtab_enumerator_t fun,
@@ -704,10 +686,9 @@ void require_module(const char *modname, struct import_rule *import_rules);
int parse_include(const char *text, int once);
int parse_require(const char *text, mf_yyltype_t *loc);
-int parse_line(char *text, struct locus *ploc);
-void parse_line_cpp(char *text, struct locus *ploc);
+int parse_line(char *text, struct mu_locus_point *pt);
+int parse_line_cpp(char *text, struct mu_locus_point *pt);
void alloc_ext_pp(void);
-int assign_locus(struct locus *ploc, const char *name, const char *line);
int source_lookup(struct input_file_ident *idptr);
#define LEX_NONE 0
@@ -727,7 +708,7 @@ void free_parser_data(void);
void add_include_dir(const char *dir);
int parse_program(char *name, int ydebug);
void parse_pragma(const char *text);
-const struct locus *get_locus(void);
+struct mu_locus_range const *get_locus(void);
const char *msgmod_opcode_str(enum msgmod_opcode opcode);
const char *sfsistat_str(sfsistat s);
const char *mf_exception_str(unsigned ex);
@@ -738,13 +719,11 @@ const char *storage_class_str(storage_class_t sc);
enum smtp_state string_to_state(const char *name);
const char *state_to_string(enum smtp_state state);
void parse_error(const char *fmt, ...) MU_PRINTFLIKE(1,2);
-void parse_error_locus(const struct locus *loc, const char *fmt, ...)
+void parse_error_locus(struct mu_locus_range const *loc, const char *fmt, ...)
MU_PRINTFLIKE(2,3);
void parse_warning(const char *fmt, ...) MU_PRINTFLIKE(1,2);
-void parse_warning_locus(const struct locus *loc, const char *fmt, ...)
+void parse_warning_locus(struct mu_locus_range const *loc, const char *fmt, ...)
MU_PRINTFLIKE(2,3);
-void print_parse_message(const struct locus *locus,
- const char *prefix, const char *fmt, va_list ap);
void print_syntax_tree(void);
void print_macros(void);
@@ -835,7 +814,7 @@ int env_set_variable(eval_environ_t env, char *ident, char *value);
int eval_environment(eval_environ_t env, prog_counter_t pc);
sfsistat environment_get_status(eval_environ_t env);
const char *environment_get_null_symbol(eval_environ_t env,
- struct locus *locus);
+ struct mu_locus_range *locus);
SMFICTX *env_get_context(eval_environ_t env);
size_t env_get_line_count(eval_environ_t env);
int env_get_stream(eval_environ_t env, mu_stream_t *pstr);
@@ -909,7 +888,7 @@ void mf_add_runtime_params(struct mu_cfg_param *p);
/* deprecation.c */
void deprecation_warning(const char *fmt, ...) MU_PRINTFLIKE(1,2);
-void deprecation_warning_locus(const struct locus *locus, const char *fmt, ...)
+void deprecation_warning_locus(const struct mu_locus_range *locus, const char *fmt, ...)
MU_PRINTFLIKE(2,3);
void final_deprecation_warning(void);
@@ -934,7 +913,7 @@ void add_fixup_command(enum fixup_op opcode, mf_yyltype_t *locus, char *arg);
void add_fixup_command_fmt(enum fixup_op opcode, mf_yyltype_t *locus,
const char *fmt, ...)
MU_PRINTFLIKE(3,4);
-void add_fixup_command_locus(enum fixup_op opcode, const struct locus *locus,
+void add_fixup_command_locus(enum fixup_op opcode, const struct mu_locus_range *locus,
char *arg);
void fixup_create_script(void);
@@ -952,7 +931,7 @@ extern struct sockaddr *callout_server_sa;
extern socklen_t callout_server_sa_len;
/* exclist.c */
-void define_exception(struct literal *lit, struct locus *locus);
+void define_exception(struct literal *lit, struct mu_locus_range const *locus);
void enumerate_exceptions(int (*efn)(const struct constant *cp,
const struct literal *lit,
void *data),
diff --git a/src/main.c b/src/main.c
index 49d0217..66a9780 100644
--- a/src/main.c
+++ b/src/main.c
@@ -375,7 +375,7 @@ opt_variable(struct mu_parseopt *po, struct mu_option *op,
char const *arg)
{
char *p;
- struct locus locus = { "<command line>", 1, 0 };
+ struct mu_locus_range locus = {{ "<command line>", 1, 0 }};
p = strchr(arg, '=');
if (!p) {
@@ -421,7 +421,6 @@ static void
opt_set_milter_timeout(struct mu_parseopt *po, struct mu_option *op,
char const *arg)
{
- int rc;
time_t v;
if (mu_str_to_c(arg, mu_c_time, &v, NULL)) {
@@ -676,8 +675,7 @@ cb_set_variable(void *data, mu_config_value_t *arg)
{
const char *value;
char *alloc_str = NULL;
- struct mu_locus mloc;
- struct locus locus;
+ struct mu_locus_range locus = MU_LOCUS_RANGE_INITIALIZER;
if (mu_cfg_assert_value_type(arg, MU_CFG_ARRAY))
return 1;
@@ -712,24 +710,10 @@ cb_set_variable(void *data, mu_config_value_t *arg)
abort();
}
- locus.leng = 0;
- if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_GET_LOCUS, &mloc)) {
- locus.file = "<unknown>";
- locus.line = 0;
- locus.point = 0;
- } else {
- if (mloc.mu_file) {
- struct literal *lit = string_alloc(mloc.mu_file,
- strlen(mloc.mu_file));
- free(mloc.mu_file);
- locus.file = lit->text;
- } else
- locus.file = "<unknown>";
- locus.line = mloc.mu_line;
- locus.point = mloc.mu_col;
- }
+ mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE, &locus);
defer_initialize_variable(arg->v.arg.v[0].v.string, value, &locus);
+ mu_locus_range_deinit(&locus);
free(alloc_str);
return 0;
}
@@ -1119,7 +1103,6 @@ static int
args_in_order(int argc, char **argv)
{
int i;
- int flag = 0;
for (i = 0; i < argc; i++) {
size_t len = strcspn(argv[i], "=");
if (len > 3
@@ -1244,7 +1227,6 @@ struct mu_cli_setup cli = {
int
main(int argc, char **argv)
{
- int rc;
prog_counter_t entry_point;
int stderr_is_closed = stderr_closed_p();
diff --git a/src/pp.c b/src/pp.c
index 070afc3..e062786 100644
--- a/src/pp.c
+++ b/src/pp.c
@@ -155,7 +155,6 @@ int
begin_module(const char *modname, const char *filename,
struct import_rule *import_rules)
{
- struct locus locus;
int rc;
if (access(filename, R_OK)) {
@@ -164,8 +163,7 @@ begin_module(const char *modname, const char *filename,
mu_strerror(errno));
return 1;
}
- locus = *get_locus();
- if (set_top_module(modname, filename, import_rules, &locus) == 0)
+ if (set_top_module(modname, filename, import_rules, get_locus()) == 0)
rc = lex_new_source(filename, LEX_MODULE);
else
rc = 0;
@@ -204,8 +202,6 @@ parse_include(const char *text, int once)
p = tmp;
}
- advance_line();
-
if (p)
rc = lex_new_source(p, once ? LEX_ONCE : LEX_NONE);
free(tmp);
@@ -232,10 +228,30 @@ require_module(const char *modname, struct import_rule *import_rules)
free(fname);
}
+static int
+assign_locus(struct mu_locus_point *ploc, const char *name,
+ const char *linestr)
+{
+ char *p;
+ unsigned long linenum;
+ errno = 0;
+ linenum = strtoul(linestr, &p, 10);
+ if (errno)
+ return errno;
+ if (*p)
+ return MU_ERR_PARSE;
+ if (linenum > UINT_MAX)
+ return ERANGE;
+ mu_locus_point_init(ploc);
+ mu_locus_point_set_file(ploc, name);
+ ploc->mu_line = (unsigned) linenum;
+ return 0;
+}
+
int
-parse_line(char *text, struct locus *ploc)
+parse_line(char *text, struct mu_locus_point *ploc)
{
- int rc = 1;
+ int rc;
struct mu_wordsplit ws;
while (*text && mu_isspace (*text))
@@ -245,7 +261,7 @@ parse_line(char *text, struct locus *ploc)
if (mu_wordsplit(text, &ws, MU_WRDSF_DEFFLAGS)) {
parse_error(_("cannot parse #line line: %s"),
mu_wordsplit_strerror (&ws));
- return errno;
+ return 1;
} else {
if (ws.ws_wordc == 2)
rc = assign_locus(ploc, NULL, ws.ws_wordv[1]);
@@ -253,7 +269,7 @@ parse_line(char *text, struct locus *ploc)
rc = assign_locus(ploc, ws.ws_wordv[2],
ws.ws_wordv[1]);
else
- parse_error(_("invalid #line statement"));
+ rc = 1;
if (rc)
parse_error(_("malformed #line statement"));
@@ -262,38 +278,26 @@ parse_line(char *text, struct locus *ploc)
return rc;
}
-void
-parse_line_cpp(char *text, struct locus *ploc)
+int
+parse_line_cpp(char *text, struct mu_locus_point *ploc)
{
struct mu_wordsplit ws;
-
+ int rc;
+
if (mu_wordsplit(text, &ws, MU_WRDSF_DEFFLAGS)) {
parse_error(_("cannot parse #line line: %s"),
mu_wordsplit_strerror (&ws));
- return;
- } else if (ws.ws_wordc < 3)
+ rc = 1;
+ } else if (ws.ws_wordc < 3) {
parse_error(_("invalid #line statement"));
- else {
- if (assign_locus(ploc, ws.ws_wordv[2], ws.ws_wordv[1]))
- parse_error(_("malformed #line statement"));
- }
+ rc = 1;
+ } else if (assign_locus(ploc, ws.ws_wordv[2], ws.ws_wordv[1])) {
+ parse_error(_("malformed #line statement"));
+ rc = 1;
+ } else
+ rc = 0;
mu_wordsplit_free(&ws);
-}
-
-int
-assign_locus(struct locus *ploc, const char *name, const char *line)
-{
- char *p;
-
- if (name) {
- struct literal *lit = string_alloc(name, strlen(name));
- lit->flags |= SYM_REFERENCED;
- ploc->file = lit->text;
- }
- ploc->line = strtoul(line, &p, 10);
- ploc->point = 0;
- ploc->leng = 0;
- return *p != 0;
+ return rc;
}
static void
@@ -302,7 +306,6 @@ stderr_redirector(char *ppcmd, char **argv)
if (!logger_flags(LOGF_STDERR)) {
int p[2];
char buf[1024];
- size_t size = 0;
FILE *fp;
pid_t pid;
diff --git a/src/prog.c b/src/prog.c
index 3af9402..12dc69e 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -237,11 +237,7 @@ struct exception_context {
struct environ_locus {
unsigned long file; /* File name */
- unsigned long line; /* Line number */
-#if 0
- unsigned long point; /* Offset in the input line */
- unsigned long leng; /* Length of the input token */
-#endif
+ unsigned int line; /* Line number */
};
struct environ_cleanup_closure {
@@ -384,14 +380,15 @@ env_var_inc(eval_environ_t env, size_t off)
static void env_register_auto(eval_environ_t env, void *ptr);
void
-env_get_locus(eval_environ_t env, struct locus *locus)
+env_get_locus(eval_environ_t env, struct mu_locus_range *locus)
{
- locus->file = (char*)(env->dataseg + env->locus.file);
- env_register_auto(env, (void*) locus->file);
- locus->line = env->locus.line;
+ mu_locus_range_init(locus);
+ locus->beg.mu_file = (char*)(env->dataseg + env->locus.file);
+ env_register_auto(env, (void*) locus->beg.mu_file);
+ locus->beg.mu_line = env->locus.line;
#if 0
- locus->point = env->locus.point;
- locus->leng = env->locus.leng;
+ locus->beg.mu_col = env->locus.point;
+ ...
#endif
}
@@ -593,7 +590,7 @@ prog_trace(eval_environ_t env, const char *fmt, ...)
va_start(ap, fmt);
vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- logmsg(MU_LOG_DEBUG, "%4lu: %s:%lu: %s",
+ logmsg(MU_LOG_DEBUG, "%4lu: %s:%u: %s",
(unsigned long) env->pc,
ENV_LOC_FILE(env), ENV_LOC_LINE(env),
buf);
@@ -613,7 +610,7 @@ runtime_stack_trace(eval_environ_t env)
int i;
prog_counter_t pc = mf_c_val(env->dataseg[base + 2], ulong) - 1;
char *name;
- struct locus *ploc = NULL, loc;
+ struct mu_locus_point *ploc = NULL, loc;
if (pc < 2)
break; /*FIXME*/
@@ -628,23 +625,21 @@ runtime_stack_trace(eval_environ_t env)
for (i = 0; i < 10; i++) {
if (pc > i + 3
&& prog[pc - i - 3].c_instr == instr_locus) {
- loc.file = (char*)(env->dataseg
+ loc.mu_file = (char*)(env->dataseg
+ mf_cell_c_value(prog[pc - i - 2], size));
- loc.line = mf_cell_c_value(prog[pc - i - 1], size);
+ loc.mu_line = mf_cell_c_value(prog[pc - i - 1], size);
ploc = &loc;
break;
}
}
if (ploc)
- mu_error("%04lu: %s:%lu: %s",
+ mu_error("%04lu: %s:%u: %s",
(unsigned long) pc,
- ploc->file, (unsigned long) ploc->line,
- name);
+ ploc->mu_file, ploc->mu_line, name);
else
mu_error("%04lu: %s",
- (unsigned long) pc,
- name);
+ (unsigned long) pc, name);
}
mu_error(_("stack trace finishes"));
}
@@ -655,7 +650,7 @@ runtime_warning(eval_environ_t env, const char *fmt, ...)
va_list ap;
mu_diag_printf(MU_DIAG_WARNING,
- _("RUNTIME WARNING near %s:%lu: "),
+ _("RUNTIME WARNING near %s:%u: "),
ENV_LOC_FILE(env), ENV_LOC_LINE(env));
va_start(ap, fmt);
mu_diag_output(MU_DIAG_WARNING, fmt, ap);
@@ -669,7 +664,7 @@ runtime_error(eval_environ_t env, const char *fmt, ...)
va_list ap;
char buf[512];
- n = snprintf(buf, sizeof buf, _("RUNTIME ERROR near %s:%lu: "),
+ n = snprintf(buf, sizeof buf, _("RUNTIME ERROR near %s:%u: "),
ENV_LOC_FILE(env), ENV_LOC_LINE(env));
va_start(ap, fmt);
vsnprintf(buf + n, sizeof buf - n, fmt, ap);
@@ -1683,7 +1678,7 @@ instr_next(eval_environ_t env)
{
if (PROG_TRACE_ENGINE)
prog_trace(env, "NEXT");
- trace("%s%s:%lu: next",
+ trace("%s%s:%u: next",
mailfromd_msgid(env->ctx),
ENV_LOC_FILE(env), ENV_LOC_LINE(env));
}
@@ -1706,7 +1701,7 @@ instr_result(eval_environ_t env)
SP(xcode),
SP(message));
- trace("%s%s:%lu: %s %s %s %s",
+ trace("%s%s:%u: %s %s %s %s",
mailfromd_msgid(env->ctx),
ENV_LOC_FILE(env), ENV_LOC_LINE(env),
sfsistat_str(status),
@@ -1751,7 +1746,7 @@ instr_header(eval_environ_t env)
advance_pc(env, 2);
adjust_stack(env, 1);
- trace("%s%s:%lu: %s %s %s",
+ trace("%s%s:%u: %s %s %s",
mailfromd_msgid(env->ctx),
ENV_LOC_FILE(env), ENV_LOC_LINE(env),
msgmod_opcode_str(opcode),
@@ -2157,7 +2152,7 @@ dump_code(prog_counter_t start, prog_counter_t end)
static void
_fixup(prog_counter_t pc, struct optab *op, void *data)
{
- struct locus *locus = data;
+ struct mu_locus_range *locus = data;
enum instr_opcode opcode = (enum instr_opcode) mf_cell_c_value(prog[pc], int);
prog[pc].c_instr = op->instr;
if (opcode == opcode_regex) {
@@ -2181,16 +2176,18 @@ _fixup(prog_counter_t pc, struct optab *op, void *data)
} else
regtab[index].compiled = 1;
} else if (opcode == opcode_locus) {
- locus->file = (char*) (dataseg + mf_cell_c_value(prog[pc+1], size));
- locus->line = mf_cell_c_value(prog[pc+2], size);
+ mu_locus_point_set_file(&locus->beg,
+ (char*) (dataseg + mf_cell_c_value(prog[pc+1], size)));
+ locus->beg.mu_line = mf_cell_c_value(prog[pc+2], size);
}
}
void
fixup_code()
{
- struct locus locus = { "<unknown>", 0 };
+ struct mu_locus_range locus = MU_LOCUS_RANGE_INITIALIZER;
scan_code(0, pc, _fixup, &locus);
+ mu_locus_range_deinit(&locus);
if (error_count)
exit(EX_CONFIG);
}
diff --git a/src/prog.h b/src/prog.h
index 4208e60..f0d97bb 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -107,7 +107,7 @@ void prog_trace(eval_environ_t env, const char *fmt, ...)
MU_PRINTFLIKE(2, 3);
void runtime_stack_trace(eval_environ_t env);
void env_var_inc(eval_environ_t env, size_t off);
-void env_get_locus(eval_environ_t env, struct locus *loc);
+void env_get_locus(eval_environ_t env, struct mu_locus_range *loc);
STKVAL env_get_reg(eval_environ_t env);
prog_counter_t env_register_read(eval_environ_t env, int what);
char *env_vaptr(eval_environ_t env, size_t off);
@@ -134,14 +134,14 @@ void enter_loop(struct literal *lit,
prog_counter_t *begptr, prog_counter_t *endptr);
void leave_loop(void);
-NODE *alloc_node(enum node_type type, const struct locus *locus);
-NODE *create_node_variable(struct variable *var, const struct locus *locus);
-NODE *create_node_argcount(const struct locus *locus);
-NODE *create_node_arg(long num, const struct locus *locus);
-NODE *create_node_symbol(struct literal *lit, const struct locus *loc);
-NODE *create_node_backref(long num, const struct locus *locus);
+NODE *alloc_node(enum node_type type, const struct mu_locus_range *locus);
+NODE *create_node_variable(struct variable *var, const struct mu_locus_range *locus);
+NODE *create_node_argcount(const struct mu_locus_range *locus);
+NODE *create_node_arg(long num, const struct mu_locus_range *locus);
+NODE *create_node_symbol(struct literal *lit, const struct mu_locus_range *loc);
+NODE *create_node_backref(long num, const struct mu_locus_range *locus);
NODE *cast_to(data_type_t type, NODE *node);
-void add_xref(struct variable *var, const struct locus *locus);
+void add_xref(struct variable *var, const struct mu_locus_range *locus);
extern mf_code_cell_t *prog;
extern unsigned error_count;
diff --git a/src/symbols.c b/src/symbols.c
index 2fb3b8d..57959d1 100644
--- a/src/symbols.c
+++ b/src/symbols.c
@@ -336,7 +336,7 @@ import_builtin_variables(struct symtab *st)
struct symimport_closure {
struct module *module;
- struct locus locus;
+ struct mu_locus_range locus;
struct import_rule *rules;
char *newname;
};
@@ -384,7 +384,7 @@ import_confun(struct symtab *tab,
struct mf_symbol *src = (struct mf_symbol*)srcent;
struct mf_symbol *dst = (struct mf_symbol*)dstent;
- if (LOCUS_EQ(&src->locus, &dst->locus))
+ if (mu_locus_point_same_file (&src->locus.beg, &dst->locus.beg))
return 0;
parse_error_locus(&sip->locus,
_("symbol import conflict: %s"), srcent->name);
@@ -406,7 +406,7 @@ import_cpyfun(struct syment **pdst, struct syment *src, size_t symsize,
mdst->name = mf_strdup(sip->newname);
mdst->refcnt = 1;
mdst->alias = (struct mf_symbol*)src;
- mdst->locus = s->locus;
+ mu_locus_range_copy(&mdst->locus, &s->locus);
dst = (struct syment*)mdst;
free(sip->newname);
sip->newname = NULL;
@@ -420,7 +420,7 @@ import_cpyfun(struct syment **pdst, struct syment *src, size_t symsize,
int
module_import_symbols(struct module *dst, struct module *src,
- const struct locus *loc)
+ struct mu_locus_range const *loc)
{
int i;
struct symimport_closure clos;
@@ -566,7 +566,7 @@ module_pop()
int
set_top_module(const char *name, const char *file,
struct import_rule *import_rules,
- const struct locus *locus)
+ struct mu_locus_range const *locus)
{
struct module *mod;
struct syment *ent;
@@ -602,9 +602,10 @@ pop_top_module()
struct module *mod = top_module;
top_module = module_pop();
/* Import symbols from mod to top_module */
- if (mod != top_module)
- module_import_symbols(top_module, mod,
- get_locus()); /*FIXME: locus?*/
+ if (mod != top_module) {
+ struct mu_locus_range lr = MU_LOCUS_RANGE_INITIALIZER;
+ module_import_symbols(top_module, mod, &lr); /*FIXME: locus?*/
+ }
}
}
@@ -752,7 +753,7 @@ builtin_lookup(const char *name)
static void
init_variable(struct variable *var)
{
- var->sym.locus = *get_locus(); /* FIXME */
+ mu_locus_range_init (&var->sym.locus);
var->sym.module = top_module;
var->sym.flags = 0;
var->type = dtype_unspecified;
@@ -828,7 +829,7 @@ builtin_variable_install(const char *name, data_type_t type, unsigned flags,
static struct function *
-function_lookup_or_install(const char *name, const struct locus *locus)
+function_lookup_or_install(const char *name, struct mu_locus_range const *locus)
{
struct function *fp;
struct syment *ent;
@@ -866,12 +867,12 @@ function_lookup_or_install(const char *name, const struct locus *locus)
struct function *
function_install(const char *name, size_t parmcnt, size_t optcnt, int varargs,
data_type_t *parmtypes, data_type_t rettype,
- const struct locus *locus)
+ struct mu_locus_range const *locus)
{
struct function *fp = function_lookup_or_install(name, locus);
fp->sym.name = mf_strdup(name);
fp->sym.module = top_module;
- fp->sym.locus = *locus;
+ mu_locus_range_copy(&fp->sym.locus, locus);
fp->node = NULL;
fp->entry = 0;
fp->parmcount = parmcnt;
@@ -895,12 +896,12 @@ function_lookup(const char *name)
void
install_alias(const char *name, struct function *fun,
- const struct locus *locus)
+ struct mu_locus_range const *locus)
{
struct function *fp = function_lookup_or_install(name, locus);
fp->sym.name = mf_strdup(name);
fp->sym.module = top_module;
- fp->sym.locus = *locus;
+ mu_locus_range_copy(&fp->sym.locus, locus);
fp->sym.alias = (struct mf_symbol*) fun;
}
@@ -929,7 +930,7 @@ literal_lookup(const char *text)
const struct constant *
define_constant(const char *name, struct value *value, unsigned flags,
- struct locus *locus)
+ struct mu_locus_range const *locus)
{
struct constant *cp;
struct syment *ent;
@@ -955,7 +956,7 @@ define_constant(const char *name, struct value *value, unsigned flags,
"previous definition");
}
cp->sym.module = top_module;
- cp->sym.locus = *locus;
+ mu_locus_range_copy(&cp->sym.locus, locus);
cp->sym.flags = flags;
cp->value = *value;
return cp;

Return to:

Send suggestions and report system problems to the System administrator.