2 // location.cs: Keeps track of the location of source code entity
\r
7 // (C) 2001 Ximian, Inc.
\r
11 using System.Collections;
\r
13 namespace Mono.CSharp {
\r
15 /// Keeps track of the location in the program
\r
19 /// This uses a compact representation and a couple of auxiliary
\r
20 /// structures to keep track of tokens to (file,line) mappings.
\r
22 /// We could probably also keep track of columns by storing those
\r
23 /// in 8 bits (and say, map anything after char 255 to be `255+').
\r
25 public struct Location {
\r
28 static Hashtable map;
\r
29 static ArrayList list;
\r
30 static int global_count;
\r
31 static int module_base;
\r
35 map = new Hashtable ();
\r
36 list = new ArrayList ();
\r
41 static public void Push (string name)
\r
43 map.Remove (global_count);
\r
44 map.Add (global_count, name);
\r
45 list.Add (global_count);
\r
46 module_base = global_count;
\r
49 public Location (int row)
\r
54 token = module_base + row;
\r
55 if (global_count < token)
\r
56 global_count = token;
\r
60 public override string ToString ()
\r
62 return Name + ": (" + Row + ")";
\r
66 /// Whether the Location is Null
\r
68 static public bool IsNull (Location l)
\r
70 return l.token == -1;
\r
73 static public Location Null {
\r
75 return new Location (-1);
\r
79 public string Name {
\r
86 foreach (int b in list){
\r
90 return (string) map [best];
\r
101 foreach (int b in list){
\r
105 return token - best;
\r