Author: manjula
Date: 2005-06-27 06:25:45 -0400 (Mon, 27 Jun 2005)
New Revision: 46546

Modified:
   trunk/mcs/mbas/ChangeLog
   trunk/mcs/mbas/mb-parser.jay
   trunk/mcs/mbas/statement.cs
Log:
Support and successfully find label definition inside child block


Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog    2005-06-27 10:14:07 UTC (rev 46545)
+++ trunk/mcs/mbas/ChangeLog    2005-06-27 10:25:45 UTC (rev 46546)
@@ -1,3 +1,7 @@
+2005-06-27 Manjula GHM <[EMAIL PROTECTED]>
+       * mb-parser.jay:
+       *statement.cs: Support and successfully find label definition inside 
child block
+
 2005-06-23 Manjula GHM <[EMAIL PROTECTED]>
        *mb-parser.jay: Clear the hashtable in end of block
 

Modified: trunk/mcs/mbas/mb-parser.jay
===================================================================
--- trunk/mcs/mbas/mb-parser.jay        2005-06-27 10:14:07 UTC (rev 46545)
+++ trunk/mcs/mbas/mb-parser.jay        2005-06-27 10:25:45 UTC (rev 46546)
@@ -2739,7 +2739,7 @@
          {
                LabeledStatement labeled = new LabeledStatement ((string) $1, 
lexer.Location);
 
-               if (!current_block.AddLabel ((string) $1, labeled)){
+               if (!current_block.AddLabel ((string) $1, 
labeled,lexer.Location)){
                        Location l = lexer.Location;
                        Report.Error (140, l, "The label '" + ((string) $1) + 
"' is a duplicate");
                }       
@@ -2749,7 +2749,7 @@
          {
                LabeledStatement labeled = new LabeledStatement ((string) $1, 
lexer.Location);
 
-               if (!current_block.AddLabel ((string) $1, labeled)){
+               if (!current_block.AddLabel ((string) $1, 
labeled,lexer.Location)){
                        Location l = lexer.Location;
                        Report.Error (140, l, "The label '" + ((string) $1) + 
"' is a duplicate");
                }       
@@ -3788,7 +3788,6 @@
          {
                if ($2 != null){
                        DictionaryEntry de = (DictionaryEntry) $2;
-
                        $$ = declare_local_variables ((Expression) de.Key, 
(ArrayList) de.Value, (Location)$1);
                }
          }

Modified: trunk/mcs/mbas/statement.cs
===================================================================
--- trunk/mcs/mbas/statement.cs 2005-06-27 10:14:07 UTC (rev 46545)
+++ trunk/mcs/mbas/statement.cs 2005-06-27 10:25:45 UTC (rev 46546)
@@ -888,6 +888,7 @@
                public override bool Resolve (EmitContext ec)
                {
                        label = block.LookupLabel (target);
+
                        if (label == null){
                                Report.Error (
                                        30132, loc,
@@ -899,8 +900,8 @@
                        if (!label.IsDefined)
                                label.AddUsageVector 
(ec.CurrentBranching.CurrentUsageVector);
 
-                       ec.CurrentBranching.CurrentUsageVector.Breaks = 
FlowReturns.ALWAYS;
-
+                        ec.CurrentBranching.CurrentUsageVector.Breaks = 
FlowReturns.ALWAYS;
+                       label.AddReference ();
                        return true;
                }
                
@@ -946,9 +947,10 @@
 
                public Label LabelTarget (EmitContext ec)
                {
-                       if (defined)
+                       if (defined) 
                                return label;
                        label = ec.ig.DefineLabel ();
+
                        defined = true;
 
                        return label;
@@ -972,12 +974,14 @@
                                vectors = new ArrayList ();
 
                        vectors.Add (vector.Clone ());
+
                }
 
                public override bool Resolve (EmitContext ec)
                {
-                       if (vectors != null)
+                       if (vectors != null) {
                                
ec.CurrentBranching.CurrentUsageVector.MergeJumpOrigins (vectors);
+                       }
                        else {
                                ec.CurrentBranching.CurrentUsageVector.Breaks = 
FlowReturns.NEVER;
                                ec.CurrentBranching.CurrentUsageVector.Returns 
= FlowReturns.NEVER;
@@ -985,6 +989,7 @@
 
                        referenced = true;
 
+
                        return true;
                }
 
@@ -995,6 +1000,10 @@
 
                        return false;
                }
+               public void AddReference ()
+                {
+                        referenced = true;
+                }
        }
        
 
@@ -2925,6 +2934,7 @@
                ///   otherwise.
                /// </returns>
                ///
+/**
                public bool AddLabel (string name, LabeledStatement target)
                {
                        if (labels == null)
@@ -2935,17 +2945,98 @@
                        labels.Add (name, target);
                        return true;
                }
+**/
 
+
+                public bool AddLabel (string name, LabeledStatement target, 
Location loc)
+                {
+/**
+                        if (switch_block != null)
+                                return switch_block.AddLabel (name, target, 
loc);
+**/
+                        Block cur = this;
+                        while (cur != null) {
+
+                                if (cur.DoLookupLabel (name) != null) {
+                                        Report.Error (
+                                                140, loc, "The label '" + name 
+"' is a duplicate");
+                                        return false;
+                                }
+
+                                if (!Implicit)
+                                        break;
+
+                                cur = cur.Parent;
+                        }
+
+                        while (cur != null) {
+                                if (cur.DoLookupLabel (name) != null) {
+                                        Report.Error (
+                                                158, loc,
+                                                "The label '"+ name +"' 
shadows another label " +
+                                                "by the same name in a 
containing scope.");
+                                        return false;
+                                }
+
+                                if (children != null) {
+                                        foreach (Block b in children) {
+                                                LabeledStatement s = 
b.DoLookupLabel (name);
+                                                if (s == null)
+                                                        continue;
+                                                Report.Error (
+                                                        158, s.Location,
+                                                        "The label '"+ name 
+"' shadows another " +
+                                                        "label by the same 
name in a " +
+                                                        "containing scope.");
+                                                return false;
+                                        }
+                                }
+                               cur = cur.Parent;
+                        }
+                        if (labels == null)
+                                labels = new CaseInsensitiveHashtable ();
+                        if (labels.Contains (name))
+                                return false;
+
+                        labels.Add (name, target);
+                        return true;
+
+                }
+               
                public LabeledStatement LookupLabel (string name)
+                {
+                       Block cur = this;
+                        LabeledStatement s = DoLookupLabel (name);
+                        if (s != null) {
+                                return s;
+}
+                        if (children == null)
+                                return null;
+
+                        foreach (Block child in children) {
+                                if (!child.Implicit)
+                                        continue;
+
+                                s = child.LookupLabel (name);
+                                if (s != null) {
+                               cur = child;
+                                        return s;
+}
+                        }
+
+                        return null;
+                }
+
+               public LabeledStatement DoLookupLabel (string name)
                {
                        if (labels != null){
                                if (labels.Contains (name))
                                        return ((LabeledStatement) labels 
[name]);
                        }
-
+/**
                        if (Parent != null)
                                return Parent.LookupLabel (name);
-
+**/
                        return null;
                }
 
@@ -3455,6 +3546,12 @@
                        ec.CurrentBlock = prev_block;
                        return has_ret;
                }
+               
+               public override string ToString ()
+                {
+                        return String.Format ("{0} ({1}:{2})", GetType (),ID, 
StartLocation);
+                }
+
        }
 
        public class StatementSequence : Expression {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to