On Fri Apr 17 20:09:10 2009, cotto wrote:
> On Sun Jun 15 06:26:12 2008, [email protected] wrote:
> > On Sunday 15 June 2008 03:31:56 Patrick R. Michaud wrote:
> >
> > > On Sat, Jun 14, 2008 at 08:58:22PM -0400, Bob Rogers wrote:
> > > > [...] And
> > > > the easiest fix would be to decide not to support it at all.
> > > +1. Another +1 if we can somehow get IMCC to report an error
> > > when there's a label/symbol conflict.
> >
> > I think that may be possible. I'll look into it while I'm fixing
> > another bug
> > in register allocation today.
> >
> > -- c
> >
>
> The attached patch makes imcc fail more gracefully when a symreg and a
> label have the same name. I'm not exactly sure if this is the kind of
> fix that we're looking for, but it does report the correct line number
> for rgrjr's example.
The attached (updated) patch makes imcc catch two cases; when a named
variable is defined having the name of an existing label, and vice
versa. Both are fatal, as they can cause very misleading error
messages. The change causes a couple test failures and will probably
have to wait until after the next deprecation cycle, but it's only a
couple more months on a nearly 4-year-old ticket.
Ideally imcc would use a smart enough symbol table to differentiate
between labels and variable names, but it doesn't and that's why it's on
the way out.
I don't think there are any more cases that imcc needs to deal with, as
opcodes seem to work correctly.
Index: t/compilers/imcc/syn/labels.t
===================================================================
--- t/compilers/imcc/syn/labels.t (revision 38218)
+++ t/compilers/imcc/syn/labels.t (working copy)
@@ -7,7 +7,7 @@
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Config;
-use Parrot::Test tests => 3;
+use Parrot::Test tests => 5;
##############################
pir_output_is( <<'CODE', <<'OUT', "goto 1" );
@@ -56,7 +56,34 @@
/no label offset defined/
OUT
+##############################
+pir_error_output_like( <<'CODE', <<'OUT', "duplicate symbol (var defined first)" );
+.sub main
+ .local int foo
+ foo:
+.end
+CODE
+/Identifier 'foo' already defined/
+OUT
+##############################
+pir_error_output_like( <<'CODE', <<'OUT', "duplicate symbol (label defined first)" );
+.sub main :main
+ .local int i
+ i = 0
+foo:
+ .local int foo
+ if i == 1 goto done
+ i = 1
+ goto foo
+done:
+.end
+
+CODE
+/Label 'foo' already defined/
+OUT
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Index: compilers/imcc/symreg.c
===================================================================
--- compilers/imcc/symreg.c (revision 38218)
+++ compilers/imcc/symreg.c (working copy)
@@ -594,8 +594,14 @@
{
ASSERT_ARGS(mk_ident)
char * const fullname = _mk_fullname(pesky_global__namespace, name);
- SymReg *r = mk_symreg(interp, fullname, t);
+ SymReg *r = get_sym(interp, fullname);
+ if (r && r->type == VTADDRESS) {
+ IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
+ "Label '%s' already defined\n", name);
+ }
+
+ r = mk_symreg(interp, fullname, t);
r->type = VTIDENTIFIER;
if (pesky_global__namespace) {
@@ -930,15 +936,20 @@
/* we use this for labels/subs */
if (uniq && r && r->type == VTADDRESS && r->lhs_use_count) {
- if (uniq == U_add_uniq_label)
+ if (uniq == U_add_uniq_label) {
IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
- "Label '%s' already defined\n", sub_name);
+ "Label '%s' already defined\n", sub_name);
+ }
else if (uniq == U_add_uniq_sub) {
mem_sys_free(aux_name);
IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
"Subroutine '%s' already defined\n", name);
}
}
+ else if (r && r->type & VTIDENTIFIER) {
+ IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
+ "Identifier '%s' already defined\n", name);
+ }
r = _mk_symreg(hsh, sub_name, 0);
r->type = VTADDRESS;
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev