Author: marek
Date: 2007-05-15 15:28:30 -0400 (Tue, 15 May 2007)
New Revision: 77431

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/flowanalysis.cs
   trunk/mcs/mcs/statement.cs
Log:
2007-05-15  Marek Safar  <[EMAIL PROTECTED]>

        * flowanalysis.cs: Unified error message.

        * statement.cs (Block): Removed switch_block.
        (AddSwitchBlock): A label has to be unique in the scope of method.
        (DoLookupLabel): Simplified.



Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2007-05-15 19:13:11 UTC (rev 77430)
+++ trunk/mcs/mcs/ChangeLog     2007-05-15 19:28:30 UTC (rev 77431)
@@ -1,3 +1,11 @@
+2007-05-15  Marek Safar  <[EMAIL PROTECTED]>
+
+       * flowanalysis.cs: Unified error message.
+
+       * statement.cs (Block): Removed switch_block.
+       (AddSwitchBlock): A label has to be unique in the scope of method.
+       (DoLookupLabel): Simplified.
+
 2007-05-15  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * statement.cs (ToplevelBlock.child): Remove.

Modified: trunk/mcs/mcs/flowanalysis.cs
===================================================================
--- trunk/mcs/mcs/flowanalysis.cs       2007-05-15 19:13:11 UTC (rev 77430)
+++ trunk/mcs/mcs/flowanalysis.cs       2007-05-15 19:28:30 UTC (rev 77431)
@@ -556,6 +556,12 @@
                        stmt.AddUsageVector (vector);
                        return false;
                }
+               
+               public static void Error_UnknownLabel (Location loc, string 
label)
+               {
+                       Report.Error(159, loc, "The label `{0}:' could not be 
found within the scope of the goto statement",
+                               label);
+               }
 
                protected override UsageVector Merge ()
                {
@@ -723,7 +729,7 @@
                                throw new InternalErrorException ("Shouldn't 
get here");
 
                        if (Parent == null) {
-                               Report.Error (159, goto_stmt.loc, "No such 
label `{0}' in this scope", name);
+                               Error_UnknownLabel (goto_stmt.loc, name);
                                return false;
                        }
 

Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs  2007-05-15 19:13:11 UTC (rev 77430)
+++ trunk/mcs/mcs/statement.cs  2007-05-15 19:28:30 UTC (rev 77431)
@@ -917,7 +917,7 @@
                        }
 
                        if (!ec.Switch.GotDefault){
-                               Report.Error (159, loc, "No such label 
`default:' within the scope of the goto statement");
+                               FlowBranchingBlock.Error_UnknownLabel (loc, 
"default");
                                return;
                        }
                        ec.ig.Emit (OpCodes.Br, ec.Switch.DefaultTarget);
@@ -976,7 +976,8 @@
                        sl = (SwitchLabel) ec.Switch.Elements [val];
 
                        if (sl == null){
-                               Report.Error (159, loc, "No such label `case 
{0}:' within the scope of the goto statement", c.GetValue () == null ? "null" : 
val.ToString ());
+                               FlowBranchingBlock.Error_UnknownLabel (loc, 
"case " + 
+                                       (c.GetValue () == null ? "null" : 
val.ToString ()));
                                return false;
                        }
 
@@ -1507,11 +1508,6 @@
                //
                ArrayList temporary_variables;
                
-               //
-               // If this is a switch section, the enclosing switch block.
-               //
-               Block switch_block;
-
                ExpressionStatement scope_init;
 
                ArrayList anonymous_children;
@@ -1560,9 +1556,7 @@
 
                public Block CreateSwitchBlock (Location start)
                {
-                       Block new_block = new Block (this, start, start);
-                       new_block.switch_block = this;
-                       return new_block;
+                       return new Block (this, start, start);
                }
 
                public int ID {
@@ -1593,7 +1587,7 @@
                protected static void Error_158 (string name, Location loc)
                {
                        Report.Error (158, loc, "The label `{0}' shadows 
another label " +
-                                     "by the same name in a contained scope.", 
name);
+                                     "by the same name in a contained scope", 
name);
                }
 
                /// <summary>
@@ -1607,16 +1601,14 @@
                ///
                public bool AddLabel (LabeledStatement target)
                {
-                       if (switch_block != null)
-                               return switch_block.AddLabel (target);
-
                        string name = target.Name;
 
                        Block cur = this;
                        while (cur != null) {
-                               if (cur.DoLookupLabel (name) != null) {
-                                       Report.Error (140, target.loc,
-                                                     "The label `{0}' is a 
duplicate", name);
+                               LabeledStatement s = cur.DoLookupLabel (name);
+                               if (s != null) {
+                                       Report.SymbolRelatedToPreviousError 
(s.loc, s.Name);
+                                       Report.Error (140, target.loc, "The 
label `{0}' is a duplicate", name);
                                        return false;
                                }
 
@@ -1626,24 +1618,16 @@
                                cur = cur.Parent;
                        }
 
-                       while (cur != null) {
-                               if (cur.DoLookupLabel (name) != null) {
+                       if (Toplevel.children != null) {
+                               foreach (Block b in Toplevel.children) {
+                                       LabeledStatement s = b.LookupLabel 
(name);
+                                       if (s == null)
+                                               continue;
+
+                                       Report.SymbolRelatedToPreviousError 
(s.loc, s.Name);
                                        Error_158 (name, target.loc);
                                        return false;
                                }
-
-                               if (children != null) {
-                                       foreach (Block b in children) {
-                                               LabeledStatement s = 
b.DoLookupLabel (name);
-                                               if (s == null)
-                                                       continue;
-
-                                               Error_158 (name, target.loc);
-                                               return false;
-                                       }
-                               }
-
-                               cur = cur.Parent;
                        }
 
                        Toplevel.CheckError158 (name, target.loc);
@@ -1665,8 +1649,8 @@
                                return null;
 
                        foreach (Block child in children) {
-                               if (!child.Implicit)
-                                       continue;
+                               //if (!child.Implicit)
+                               //      continue;
 
                                s = child.LookupLabel (name);
                                if (s != null)
@@ -1678,14 +1662,10 @@
 
                LabeledStatement DoLookupLabel (string name)
                {
-                       if (switch_block != null)
-                               return switch_block.LookupLabel (name);
+                       if (labels == null)
+                               return null;
 
-                       if (labels != null)
-                               if (labels.Contains (name))
-                                       return ((LabeledStatement) labels 
[name]);
-
-                       return null;
+                       return ((LabeledStatement) labels [name]);
                }
 
                Hashtable known_variables;
@@ -2587,13 +2567,14 @@
                                        return false;
                        }
 
-                       return true;
+                       return DoCheckError158 (name, loc);
                }
 
                bool DoCheckError158 (string name, Location loc)
                {
                        LabeledStatement s = LookupLabel (name);
                        if (s != null) {
+                               Report.SymbolRelatedToPreviousError (s.loc, 
s.Name);
                                Error_158 (name, loc);
                                return false;
                        }

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

Reply via email to