Merge pull request #819 from brendanzagaeski/patch-1
[mono.git] / mcs / mcs / location.cs
index d513a296c2019678c491cebb25976592775c75f7..e7daa53ce0bd98a5f86aeba6f18d632b7f65690f 100644 (file)
@@ -192,7 +192,6 @@ namespace Mono.CSharp
                const int max_column = column_mask;
 
                static List<SourceFile> source_list;
-               static int current_source;
                static Checkpoint [] checkpoints;
                static int checkpoint_index;
                
@@ -207,7 +206,6 @@ namespace Mono.CSharp
                public static void Reset ()
                {
                        source_list = new List<SourceFile> ();
-                       current_source = 0;
                        checkpoint_index = 0;
                }
 
@@ -224,7 +222,7 @@ namespace Mono.CSharp
                // </summary>
                static public void Initialize (List<SourceFile> files)
                {
-#if NET_4_0 || MONODROID
+#if NET_4_0 || MOBILE_DYNAMIC
                        source_list.AddRange (files);
 #else
                        source_list.AddRange (files.ToArray ());
@@ -235,13 +233,7 @@ namespace Mono.CSharp
                                checkpoints [0] = new Checkpoint (0, 0);
                }
 
-               static public void Push (SourceFile file)
-               {
-                       current_source = file != null ? file.Index : -1;
-                       // File is always pushed before being changed.
-               }
-               
-               public Location (int row, int column)
+               public Location (SourceFile file, int row, int column)
                {
                        if (row <= 0)
                                token = 0;
@@ -252,6 +244,9 @@ namespace Mono.CSharp
                                long target = -1;
                                long delta = 0;
 
+                               // TODO: For eval only, need better handling of empty
+                               int file_index = file == null ? 0 : file.Index;
+
                                // FIXME: This value is certainly wrong but what was the intension
                                int max = checkpoint_index < 10 ?
                                        checkpoint_index : 10;
@@ -260,13 +255,13 @@ namespace Mono.CSharp
                                        delta = row - offset;
                                        if (delta >= 0 &&
                                                delta < (1 << line_delta_bits) &&
-                                               checkpoints [checkpoint_index - i].File == current_source) {
+                                               checkpoints[checkpoint_index - i].File == file_index) {
                                                target = checkpoint_index - i;
                                                break;
                                        }
                                }
                                if (target == -1) {
-                                       AddCheckpoint (current_source, row);
+                                       AddCheckpoint (file_index, row);
                                        target = checkpoint_index;
                                        delta = row % (1 << line_delta_bits);
                                }
@@ -284,7 +279,7 @@ namespace Mono.CSharp
 
                public static Location operator - (Location loc, int columns)
                {
-                       return new Location (loc.Row, loc.Column - columns);
+                       return new Location (loc.SourceFile, loc.Row, loc.Column - columns);
                }
 
                static void AddCheckpoint (int file, int row)
@@ -417,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;
                        }
 
@@ -435,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")]
@@ -468,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")]
@@ -478,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")]
@@ -497,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;
                }