Maintain more tokens locations.
authorMarek Safar <marek.safar@gmail.com>
Fri, 22 Mar 2013 15:30:33 +0000 (16:30 +0100)
committerMarek Safar <marek.safar@gmail.com>
Fri, 22 Mar 2013 15:30:33 +0000 (16:30 +0100)
mcs/mcs/cs-parser.jay
mcs/mcs/location.cs

index d32d28cd689511d765fd624d41a3b0179405e5fa..9330a3eb02da5bbc0cbab366565604f40be949c1 100644 (file)
@@ -702,10 +702,11 @@ attribute_section_cont
                else
                        $$ = $4;
 
+               lbag.InsertLocation ($$, 0, PopLocation ());
                if ($5 != null) {
-                       lbag.AddLocation ($$, PopLocation (), GetLocation ($2), GetLocation ($5), GetLocation ($6));
+                       lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
                } else {
-                       lbag.AddLocation ($$, PopLocation (), GetLocation ($2), GetLocation ($6));
+                       lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
                }
 
                current_attr_target = null;
@@ -715,10 +716,11 @@ attribute_section_cont
          {
                $$ = $1;
 
+               lbag.InsertLocation ($$, 0, PopLocation ());
                if ($2 != null) {
-                       lbag.AddLocation ($$, PopLocation (), GetLocation($2), GetLocation ($3));
+                       lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
                } else {
-                       lbag.AddLocation ($$, PopLocation (), GetLocation($3));
+                       lbag.AddLocation ($$, GetLocation($3));
                }
          }
        | IDENTIFIER error
@@ -757,7 +759,10 @@ attribute_list
        | attribute_list COMMA attribute
          {
                var attrs = (List<Attribute>) $1;
-               attrs.Add ((Attribute) $3);
+               if (attrs != null) {
+                       attrs.Add ((Attribute) $3);
+                       lbag.AppendTo (attrs, GetLocation ($2));
+               }
 
                $$ = attrs;
          }
@@ -5626,6 +5631,9 @@ for_initializer
          opt_local_variable_initializer opt_variable_declarators
          {
                $$ = current_variable;
+               if ($4 != null)
+                       lbag.AddLocation (current_variable, PopLocation ());
+                       
                current_variable = null;
          }
        | statement_expression_list
index 85eb26c5a1941b47bff6b5272a38d061284e6aed..10afaa1cc263a97ef0ff931eaaa422d01a822619 100644 (file)
@@ -412,11 +412,28 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
                public class MemberLocations
                {
                        public readonly IList<Tuple<Modifiers, Location>> Modifiers;
-                       Location[] locations;
+                       List<Location> locations;
 
-                       public MemberLocations (IList<Tuple<Modifiers, Location>> mods, Location[] locs)
+                       public MemberLocations (IList<Tuple<Modifiers, Location>> mods)
                        {
                                Modifiers = mods;
+                       }
+
+                       public MemberLocations (IList<Tuple<Modifiers, Location>> mods, Location loc)
+                               : this (mods)
+                       {
+                               AddLocations (loc);
+                       }
+
+                       public MemberLocations (IList<Tuple<Modifiers, Location>> mods, Location[] locs)
+                               : this (mods)
+                       {
+                               AddLocations (locs);
+                       }
+
+                       public MemberLocations (IList<Tuple<Modifiers, Location>> mods, List<Location> locs)
+                               : this (mods)
+                       {
                                locations = locs;
                        }
 
@@ -430,31 +447,50 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
                        
                        public int Count {
                                get {
-                                       return locations.Length;
+                                       return locations.Count;
                                }
                        }
 
                        #endregion
 
+                       public void AddLocations (Location loc)
+                       {
+                               if (locations == null) {
+                                       locations = new List<Location> ();
+                               }
+
+                               locations.Add (loc);
+                       }
+
                        public void AddLocations (params Location[] additional)
                        {
                                if (locations == null) {
-                                       locations = additional;
+                                       locations = new List<Location> (additional);
                                } else {
-                                       int pos = locations.Length;
-                                       Array.Resize (ref locations, pos + additional.Length);
-                                       additional.CopyTo (locations, pos);
+                                       locations.AddRange (additional);
                                }
                        }
                }
 
-               Dictionary<object, Location[]> simple_locs = new Dictionary<object, Location[]> (ReferenceEquality<object>.Default);
+               Dictionary<object, List<Location>> simple_locs = new Dictionary<object, List<Location>> (ReferenceEquality<object>.Default);
                Dictionary<MemberCore, MemberLocations> member_locs = new Dictionary<MemberCore, MemberLocations> (ReferenceEquality<MemberCore>.Default);
 
                [Conditional ("FULL_AST")]
                public void AddLocation (object element, params Location[] locations)
                {
-                       simple_locs.Add (element, locations);
+                       simple_locs.Add (element, new List<Location> (locations));
+               }
+
+               [Conditional ("FULL_AST")]
+               public void InsertLocation (object element, int index, Location location)
+               {
+                       List<Location> found;
+                       if (!simple_locs.TryGetValue (element, out found)) {
+                               found = new List<Location> ();
+                               simple_locs.Add (element, found);
+                       }
+
+                       found.Insert (index, location);
                }
 
                [Conditional ("FULL_AST")]
@@ -463,7 +499,19 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
                        if (locations.Length == 0)
                                throw new ArgumentException ("Statement is missing semicolon location");
 
-                       simple_locs.Add (element, locations);
+                       AddLocation (element, locations);
+               }
+
+               [Conditional ("FULL_AST")]
+               public void AddMember (MemberCore member, IList<Tuple<Modifiers, Location>> modLocations)
+               {
+                       member_locs.Add (member, new MemberLocations (modLocations));
+               }
+
+               [Conditional ("FULL_AST")]
+               public void AddMember (MemberCore member, IList<Tuple<Modifiers, Location>> modLocations, Location location)
+               {
+                       member_locs.Add (member, new MemberLocations (modLocations, location));
                }
 
                [Conditional ("FULL_AST")]
@@ -473,13 +521,21 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
                }
 
                [Conditional ("FULL_AST")]
-               public void AppendTo (object existing, params Location[] locations)
+               public void AddMember (MemberCore member, IList<Tuple<Modifiers, Location>> modLocations, List<Location> locations)
                {
-                       Location[] locs;
-                       if (simple_locs.TryGetValue (existing, out locs)) {
-                               simple_locs [existing] = locs.Concat (locations).ToArray ();
-                               return;
+                       member_locs.Add (member, new MemberLocations (modLocations, locations));
+               }
+
+               [Conditional ("FULL_AST")]
+               public void AppendTo (object element, Location location)
+               {
+                       List<Location> found;
+                       if (!simple_locs.TryGetValue (element, out found)) {
+                               found = new List<Location> ();
+                               simple_locs.Add (element, found);
                        }
+
+                       found.Add (location);
                }
 
                [Conditional ("FULL_AST")]
@@ -492,9 +548,9 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
                        }
                }
 
-               public Location[] GetLocations (object element)
+               public List<Location> GetLocations (object element)
                {
-                       Location[] found;
+                       List<Location> found;
                        simple_locs.TryGetValue (element, out found);
                        return found;
                }