[svn:parrot] r39652 - trunk/compilers/imcc

NotFound at svn.parrot.org NotFound at svn.parrot.org
Thu Jun 18 16:23:32 UTC 2009


Author: NotFound
Date: Thu Jun 18 16:23:30 2009
New Revision: 39652
URL: https://trac.parrot.org/parrot/changeset/39652

Log:
[imcc] emit a warning on duplicate .local or .param identifiers with different type, TT #767

Modified:
   trunk/compilers/imcc/symreg.c

Modified: trunk/compilers/imcc/symreg.c
==============================================================================
--- trunk/compilers/imcc/symreg.c	Thu Jun 18 12:56:49 2009	(r39651)
+++ trunk/compilers/imcc/symreg.c	Thu Jun 18 16:23:30 2009	(r39652)
@@ -74,6 +74,14 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+static SymReg * get_sym_by_name(
+    ARGIN(const SymHash *hsh),
+    ARGIN(const char *name))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 static int int_overflows(ARGIN(const SymReg *r))
         __attribute__nonnull__(1);
 
@@ -105,6 +113,9 @@
 #define ASSERT_ARGS_add_ns __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(name)
+#define ASSERT_ARGS_get_sym_by_name __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(hsh) \
+    || PARROT_ASSERT_ARG(name)
 #define ASSERT_ARGS_int_overflows __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(r)
 #define ASSERT_ARGS_mk_pmc_const_2 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -203,6 +214,35 @@
 }
 
 
+/*
+
+=item C<static SymReg * get_sym_by_name(const SymHash *hsh, const char *name)>
+
+Gets a symbol from the hash, with the given C<name>.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+static SymReg *
+get_sym_by_name(ARGIN(const SymHash *hsh), ARGIN(const char *name))
+{
+    ASSERT_ARGS(get_sym_by_name)
+
+    SymReg            *p;
+    const unsigned int i = hash_str(name) % hsh->size;
+
+    for (p = hsh->data[i]; p; p = p->next) {
+        if (STREQ(name, p->name))
+            return p;
+    }
+
+    return NULL;
+}
+
+
 /* symbolic registers */
 
 /*
@@ -600,10 +640,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_by_name(&(IMCC_INFO(interp)->last_unit->hash), name);
+    if (r && r->set != t)
+        IMCC_warning(interp, "Duplicated IDENTIFIER '%s'\n", fullname);
 
+    r = mk_symreg(interp, fullname, t);
     r->type = VTIDENTIFIER;
 
+
     if (pesky_global__namespace) {
         Identifier * const ident = mem_allocate_zeroed_typed(Identifier);
 


More information about the parrot-commits mailing list