/// This is intentionally a class and not a struct since we need
/// to pass this by reference.
/// </remarks>
- public class SourceFile : ISourceFile {
+ public class SourceFile : ISourceFile, IEquatable<SourceFile>
+ {
public readonly string Name;
- public readonly string Path;
+ public readonly string FullPathName;
public readonly int Index;
public bool AutoGenerated;
- public bool IsIncludeFile;
SourceFileEntry file;
byte[] guid, checksum;
- public SourceFile (string name, string path, int index, bool is_include)
+ public SourceFile (string name, string path, int index)
{
this.Index = index;
this.Name = name;
- this.Path = path;
- this.IsIncludeFile = is_include;
+ this.FullPathName = path;
}
public SourceFileEntry SourceFileEntry {
public virtual void DefineSymbolInfo (MonoSymbolWriter symwriter)
{
if (guid != null)
- file = symwriter.DefineDocument (Path, guid, checksum);
+ file = symwriter.DefineDocument (FullPathName, guid, checksum);
else {
- file = symwriter.DefineDocument (Path);
+ file = symwriter.DefineDocument (FullPathName);
if (AutoGenerated)
file.SetAutoGenerated ();
}
}
+ public bool Equals (SourceFile other)
+ {
+ return FullPathName == other.FullPathName;
+ }
+
public override string ToString ()
{
return String.Format ("SourceFile ({0}:{1}:{2}:{3})",
- Name, Path, Index, SourceFileEntry);
+ Name, FullPathName, Index, SourceFileEntry);
}
}
- public class CompilationUnit : SourceFile, ICompileUnit
+ public class CompilationSourceFile : SourceFile, ICompileUnit
{
CompileUnitEntry comp_unit;
Dictionary<string, SourceFile> include_files;
Dictionary<string, bool> conditionals;
+ NamespaceContainer ns_container;
+
+ public CompilationSourceFile (string name, string fullPathName, int index)
+ : base (name, fullPathName, index)
+ {
+ }
- public CompilationUnit (string name, string path, int index)
- : base (name, path, index, false)
- { }
+ CompileUnitEntry ICompileUnit.Entry {
+ get { return comp_unit; }
+ }
+
+ public CompileUnitEntry CompileUnitEntry {
+ get { return comp_unit; }
+ }
- public void AddFile (SourceFile file)
+ public NamespaceContainer NamespaceContainer {
+ get {
+ return ns_container;
+ }
+ set {
+ ns_container = value;
+ }
+ }
+
+ public void AddIncludeFile (SourceFile file)
{
if (file == this)
return;
if (include_files == null)
include_files = new Dictionary<string, SourceFile> ();
- if (!include_files.ContainsKey (file.Path))
- include_files.Add (file.Path, file);
+ if (!include_files.ContainsKey (file.FullPathName))
+ include_files.Add (file.FullPathName, file);
}
public void AddDefine (string value)
conditionals [value] = false;
}
- CompileUnitEntry ICompileUnit.Entry {
- get { return comp_unit; }
- }
-
- public CompileUnitEntry CompileUnitEntry {
- get { return comp_unit; }
- }
-
public override void DefineSymbolInfo (MonoSymbolWriter symwriter)
{
base.DefineSymbolInfo (symwriter);
const int column_mask = (1 << column_bits) - 1;
static List<SourceFile> source_list;
- static List<CompilationUnit> compile_units;
- static Dictionary<string, int> source_files;
- static int source_count;
static int current_source;
static int current_compile_unit;
static Checkpoint [] checkpoints;
public static void Reset ()
{
- 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;
checkpoint_index = 0;
}
- // <summary>
- // This must be called before parsing/tokenizing any files.
- // </summary>
- static public void AddFile (Report r, string name)
- {
- string path = Path.GetFullPath (name);
- int id;
- if (source_files.TryGetValue (path, out id)){
- string other_name = source_list [id - 1].Name;
- if (name.Equals (other_name))
- r.Warning (2002, 1, "Source file `{0}' specified multiple times", other_name);
- else
- r.Warning (2002, 1, "Source filenames `{0}' and `{1}' both refer to the same file: {2}", name, other_name, path);
- return;
- }
-
- source_files.Add (path, ++source_count);
- CompilationUnit unit = new CompilationUnit (name, path, source_count);
- source_list.Add (unit);
- compile_units.Add (unit);
- }
-
- public static string FirstFile {
- get {
- return compile_units.Count == 0 ? null : compile_units[0].Name;
- }
- }
-
- public static IList<CompilationUnit> SourceFiles {
- get {
- return compile_units;
- }
+ public static SourceFile AddFile (string name, string fullName)
+ {
+ var source = new SourceFile (name, fullName, source_list.Count + 1);
+ source_list.Add (source);
+ return source;
}
// <summary>
// source file. We reserve some extra space for files we encounter via #line
// directives while parsing.
// </summary>
- static public void Initialize ()
+ static public void Initialize (List<CompilationSourceFile> files)
{
+#if NET_4_0
+ source_list.AddRange (files);
+#else
+ source_list.AddRange (files.ToArray ());
+#endif
+
checkpoints = new Checkpoint [source_list.Count * 2];
if (checkpoints.Length > 0)
checkpoints [0] = new Checkpoint (0, 0, 0);
}
- // <remarks>
- // This is used when we encounter a #line preprocessing directive.
- // </remarks>
- static public SourceFile LookupFile (CompilationUnit comp_unit, string name)
- {
- 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);
-
- source_files.Add (path, ++source_count);
- SourceFile retval = new SourceFile (name, path, source_count, true);
- source_list.Add (retval);
- return retval;
- }
-
- int index = source_files [path];
- return source_list [index - 1];
- }
-
- static public void Push (CompilationUnit compile_unit, SourceFile file)
+ static public void Push (CompilationSourceFile compile_unit, SourceFile file)
{
current_source = file != null ? file.Index : -1;
current_compile_unit = compile_unit != null ? compile_unit.Index : -1;
// File is always pushed before being changed.
}
-
- // <remarks>
- // If we're compiling with debugging support, this is called between parsing
- // and code generation to register all the source files with the
- // symbol writer.
- // </remarks>
- static public void DefineSymbolDocuments (MonoSymbolWriter symwriter)
- {
- foreach (CompilationUnit unit in compile_units)
- unit.DefineSymbolInfo (symwriter);
- }
public Location (int row)
: this (row, 0)
static void AddCheckpoint (int compile_unit, int file, int row)
{
if (checkpoints.Length == ++checkpoint_index) {
- Array.Resize (ref checkpoints, checkpoint_index + 2);
+ Array.Resize (ref checkpoints, checkpoint_index * 2);
}
checkpoints [checkpoint_index] = new Checkpoint (compile_unit, file, row);
}
if (token == 0 || index == 0)
return "Internal";
- return source_list [index - 1].Path;
+ return source_list[index - 1].FullPathName;
}
}
}
}
- public CompilationUnit CompilationUnit {
+ public CompilationSourceFile CompilationUnit {
get {
int index = CompilationUnitIndex;
if (index == 0)
return null;
- return (CompilationUnit) source_list [index - 1];
+ return (CompilationSourceFile) source_list [index - 1];
}
}