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)
61 token = module_base + row;
62 if (global_count < token)
67 public override string ToString ()
69 return Name + ": (" + Row + ")";
73 /// Whether the Location is Null
75 static public bool IsNull (Location l)
87 foreach (int b in list){
91 return (string) map [best];
102 foreach (int b in list){
110 // The ISymbolDocumentWriter interface is used by the symbol writer to
111 // describe a single source file - for each source file there's exactly
112 // one corresponding ISymbolDocumentWriter instance.
114 // This class has an internal hash table mapping source document names
115 // to such ISymbolDocumentWriter instances - so there's exactly one
116 // instance per document.
118 // This property returns the ISymbolDocumentWriter instance which belongs
119 // to the location's source file.
121 // If we don't have a symbol writer, this property is always null.
122 public ISymbolDocumentWriter SymbolDocument {
124 ISymbolWriter sw = CodeGen.SymbolWriter;
125 ISymbolDocumentWriter doc;
130 // If we don't have a symbol writer, return null.
134 string path = Path.GetFullPath (Name);
136 if (sym_docs.Contains (path))
137 // If we already created an ISymbolDocumentWriter
138 // instance for this document, return it.
139 doc = (ISymbolDocumentWriter) sym_docs [path];
141 // Create a new ISymbolDocumentWriter instance and
142 // store it in the hash table.
143 doc = sw.DefineDocument (path, SymLanguageType.CSharp,
144 SymLanguageVendor.Microsoft,
145 SymDocumentType.Text);
147 sym_docs.Add (path, doc);