2 // location.cs: Keeps track of the location of source code entity
7 // (C) 2001 Ximian, Inc.
11 using System.Collections;
12 using System.Diagnostics.SymbolStore;
14 namespace Mono.CSharp {
16 /// Keeps track of the location in the program
20 /// This uses a compact representation and a couple of auxiliary
21 /// structures to keep track of tokens to (file,line) mappings.
23 /// We could probably also keep track of columns by storing those
24 /// in 8 bits (and say, map anything after char 255 to be `255+').
26 public struct Location {
30 static Hashtable sym_docs;
31 static ArrayList list;
32 static int global_count;
33 static int module_base;
35 public readonly static Location Null;
39 map = new Hashtable ();
40 list = new ArrayList ();
41 sym_docs = new Hashtable ();
47 static public void Push (string name)
49 map.Remove (global_count);
50 map.Add (global_count, name);
51 list.Add (global_count);
52 module_base = global_count;
55 public Location (int row)
60 token = module_base + row;
61 if (global_count < token)
66 public override string ToString ()
68 return Name + ": (" + Row + ")";
72 /// Whether the Location is Null
74 static public bool IsNull (Location l)
86 foreach (int b in list){
90 return (string) map [best];
101 foreach (int b in list){
109 // The ISymbolDocumentWriter interface is used by the symbol writer to
110 // describe a single source file - for each source file there's exactly
111 // one corresponding ISymbolDocumentWriter instance.
113 // This class has an internal hash table mapping source document names
114 // to such ISymbolDocumentWriter instances - so there's exactly one
115 // instance per document.
117 // This property returns the ISymbolDocumentWriter instance which belongs
118 // to the location's source file.
120 // If we don't have a symbol writer, this property is always null.
121 public ISymbolDocumentWriter SymbolDocument {
123 ISymbolWriter sw = CodeGen.SymbolWriter;
124 ISymbolDocumentWriter doc;
129 // If we don't have a symbol writer, return null.
133 if (sym_docs.Contains (Name))
134 // If we already created an ISymbolDocumentWriter
135 // instance for this document, return it.
136 doc = (ISymbolDocumentWriter) sym_docs [Name];
138 // Create a new ISymbolDocumentWriter instance and
139 // store it in the hash table.
140 doc = sw.DefineDocument (Name, SymLanguageType.CSharp,
141 SymLanguageVendor.Microsoft,
142 SymDocumentType.Text);
144 sym_docs.Add (Name, doc);