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.MonoBASIC {
18 /// Keeps track of the location in the program
22 /// This uses a compact representation and a couple of auxiliary
23 /// structures to keep track of tokens to (file,line) mappings.
25 /// We could probably also keep track of columns by storing those
26 /// in 8 bits (and say, map anything after char 255 to be `255+').
28 public struct Location {
32 static Hashtable sym_docs;
33 static ArrayList list;
34 static int global_count;
35 static int module_base;
37 public readonly static Location Null;
41 map = new Hashtable ();
42 list = new ArrayList ();
43 sym_docs = new Hashtable ();
49 static public void Push (string name)
51 map.Remove (global_count);
52 map.Add (global_count, name);
53 list.Add (global_count);
54 module_base = global_count;
57 public Location (int row, int col)
59 if (row < 0 || col < 0)
64 token = module_base + (row << 8) + col;
65 if (global_count < token)
70 public override string ToString ()
72 return Name + ": (" + Row + ")";
76 /// Whether the Location is Null
78 static public bool IsNull (Location l)
90 foreach (int b in list){
94 return (string) map [best];
105 foreach (int b in list){
109 return (token - best) >> 8;
120 foreach (int b in list){
124 return (token - best) & 0xFF;
128 // The ISymbolDocumentWriter interface is used by the symbol writer to
129 // describe a single source file - for each source file there's exactly
130 // one corresponding ISymbolDocumentWriter instance.
132 // This class has an internal hash table mapping source document names
133 // to such ISymbolDocumentWriter instances - so there's exactly one
134 // instance per document.
136 // This property returns the ISymbolDocumentWriter instance which belongs
137 // to the location's source file.
139 // If we don't have a symbol writer, this property is always null.
140 public ISymbolDocumentWriter SymbolDocument {
142 ISymbolWriter sw = CodeGen.SymbolWriter;
143 ISymbolDocumentWriter doc;
148 // If we don't have a symbol writer, return null.
152 string path = Path.GetFullPath (Name);
154 if (sym_docs.Contains (path))
155 // If we already created an ISymbolDocumentWriter
156 // instance for this document, return it.
157 doc = (ISymbolDocumentWriter) sym_docs [path];
159 // Create a new ISymbolDocumentWriter instance and
160 // store it in the hash table.
161 doc = sw.DefineDocument (path, SymLanguageType.Basic,
162 SymLanguageVendor.Microsoft,
163 SymDocumentType.Text);
165 sym_docs.Add (path, doc);