using System;
using System.IO;
-using System.Collections;
+using System.Collections.Generic;
using Mono.CompilerServices.SymbolWriter;
namespace Mono.CSharp {
public class CompilationUnit : SourceFile, ICompileUnit
{
CompileUnitEntry comp_unit;
- Hashtable include_files;
+ Dictionary<string, SourceFile> include_files;
+ Dictionary<string, bool> conditionals;
public CompilationUnit (string name, string path, int index)
: base (name, path, index, false)
public void AddFile (SourceFile file)
{
+ if (file == this)
+ return;
+
if (include_files == null)
- include_files = new Hashtable ();
+ include_files = new Dictionary<string, SourceFile> ();
- if (!include_files.Contains (file.Path))
+ if (!include_files.ContainsKey (file.Path))
include_files.Add (file.Path, file);
}
+ public void AddDefine (string value)
+ {
+ if (conditionals == null)
+ conditionals = new Dictionary<string, bool> (2);
+
+ conditionals [value] = true;
+ }
+
+ public void AddUndefine (string value)
+ {
+ if (conditionals == null)
+ conditionals = new Dictionary<string, bool> (2);
+
+ conditionals [value] = false;
+ }
+
CompileUnitEntry ICompileUnit.Entry {
get { return comp_unit; }
}
}
}
}
+
+ public bool IsConditionalDefined (string value)
+ {
+ if (conditionals != null) {
+ bool res;
+ if (conditionals.TryGetValue (value, out res))
+ return res;
+
+ // When conditional was undefined
+ if (conditionals.ContainsKey (value))
+ return false;
+ }
+
+ return RootContext.IsConditionalDefined (value);
+ }
}
/// <summary>
}
}
- static ArrayList source_list;
- static ArrayList compile_units;
- static Hashtable source_files;
+ static List<SourceFile> source_list;
+ static List<CompilationUnit> compile_units;
+ static Dictionary<string, int> source_files;
static int checkpoint_bits;
static int source_count;
static int current_source;
static Location ()
{
- source_files = new Hashtable ();
- source_list = new ArrayList ();
- compile_units = new ArrayList ();
- current_source = 0;
- current_compile_unit = 0;
+ Reset ();
checkpoints = new Checkpoint [10];
}
public static void Reset ()
{
- source_files = new Hashtable ();
- source_list = new ArrayList ();
- compile_units = new ArrayList ();
+ source_files = new Dictionary<string, int> ();
+ source_list = new List<SourceFile> ();
+ compile_units = new List<CompilationUnit> ();
current_source = 0;
current_compile_unit = 0;
source_count = 0;
// <summary>
// This must be called before parsing/tokenizing any files.
// </summary>
- static public void AddFile (string name)
+ static public void AddFile (Report r, string name)
{
string path = Path.GetFullPath (name);
-
- if (source_files.Contains (path)){
- int id = (int) source_files [path];
- string other_name = ((SourceFile) source_list [id - 1]).Name;
+ int id;
+ if (source_files.TryGetValue (path, out id)){
+ string other_name = source_list [id - 1].Name;
if (name.Equals (other_name))
- Report.Warning (2002, 1, "Source file `{0}' specified multiple times", other_name);
+ r.Warning (2002, 1, "Source file `{0}' specified multiple times", other_name);
else
- Report.Warning (2002, 1, "Source filenames `{0}' and `{1}' both refer to the same file: {2}", name, other_name, path);
+ r.Warning (2002, 1, "Source filenames `{0}' and `{1}' both refer to the same file: {2}", name, other_name, path);
return;
}
compile_units.Add (unit);
}
- static public CompilationUnit[] SourceFiles {
+ public static IList<CompilationUnit> SourceFiles {
get {
- CompilationUnit[] retval = new CompilationUnit [compile_units.Count];
- compile_units.CopyTo (retval, 0);
- return retval;
+ return compile_units;
}
}
// <remarks>
// This is used when we encounter a #line preprocessing directive.
// </remarks>
- static public SourceFile LookupFile (string name)
+ static public SourceFile LookupFile (CompilationUnit comp_unit, string name)
{
- string path = name.Length == 0 ? string.Empty : Path.GetFullPath (name);
-
- if (!source_files.Contains (path)) {
+ string path;
+ if (!Path.IsPathRooted (name)) {
+ string root = Path.GetDirectoryName (comp_unit.Path);
+ path = Path.Combine (root, name);
+ } else
+ path = name;
+
+ if (!source_files.ContainsKey (path)) {
if (source_count >= (1 << checkpoint_bits))
return new SourceFile (name, path, 0, true);
}
}
}
-
- public class LocatedToken
- {
- public readonly Location Location;
- public readonly string Value;
-
- public LocatedToken (Location loc, string value)
- {
- Location = loc;
- Value = value;
- }
-
- public override string ToString ()
- {
- return Location.ToString () + Value;
- }
- }
}