2 // location.cs: Keeps track of the location of source code entity
7 // (C) 2001 Ximian, Inc.
12 using System.Collections;
13 using System.Diagnostics.SymbolStore;
15 namespace Mono.CSharp {
17 /// Keeps track of the location in the program
21 /// This uses a compact representation and a couple of auxiliary
22 /// structures to keep track of tokens to (file,line) mappings.
24 /// We could probably also keep track of columns by storing those
25 /// in 8 bits (and say, map anything after char 255 to be `255+').
27 public struct Location {
31 static Hashtable sym_docs;
32 static ArrayList list;
33 static int global_count;
34 static int module_base;
36 public readonly static Location Null;
40 map = new Hashtable ();
41 list = new ArrayList ();
42 sym_docs = new Hashtable ();
48 static public void Push (string name)
50 map.Remove (global_count);
51 map.Add (global_count, name);
52 list.Add (global_count);
53 module_base = global_count;
56 public Location (int row, int col)
58 if (row < 0 || col < 0)
63 token = module_base + (row << 8) + col;
64 if (global_count < token)
69 public override string ToString ()
71 return Name + ": (" + Row + ")";
75 /// Whether the Location is Null
77 static public bool IsNull (Location l)
89 foreach (int b in list){
93 return (string) map [best];
104 foreach (int b in list){
108 return (token - best) >> 8;
119 foreach (int b in list){
123 return (token - best) & 0xFF;
127 // The ISymbolDocumentWriter interface is used by the symbol writer to
128 // describe a single source file - for each source file there's exactly
129 // one corresponding ISymbolDocumentWriter instance.
131 // This class has an internal hash table mapping source document names
132 // to such ISymbolDocumentWriter instances - so there's exactly one
133 // instance per document.
135 // This property returns the ISymbolDocumentWriter instance which belongs
136 // to the location's source file.
138 // If we don't have a symbol writer, this property is always null.
139 public ISymbolDocumentWriter SymbolDocument {
141 ISymbolWriter sw = CodeGen.SymbolWriter;
142 ISymbolDocumentWriter doc;
147 // If we don't have a symbol writer, return null.
151 string path = Path.GetFullPath (Name);
153 if (sym_docs.Contains (path))
154 // If we already created an ISymbolDocumentWriter
155 // instance for this document, return it.
156 doc = (ISymbolDocumentWriter) sym_docs [path];
158 // Create a new ISymbolDocumentWriter instance and
159 // store it in the hash table.
160 doc = sw.DefineDocument (path, SymLanguageType.CSharp,
161 SymLanguageVendor.Microsoft,
162 SymDocumentType.Text);
164 sym_docs.Add (path, doc);