using System;
using System.Reflection;
using System.Reflection.Emit;
- using System.Collections;
- using System.Collections.Specialized;
+ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Globalization;
//
// Assemblies references to be linked. Initialized with
// mscorlib.dll here.
- ArrayList references;
+ List<string> references;
//
// If any of these fail, we ignore the problem. This is so
// that we can list all the assemblies in Windows and not fail
// if they are missing on Linux.
//
- ArrayList soft_references;
+ List<string> soft_references;
//
// External aliases for assemblies.
//
- Hashtable external_aliases;
+ Dictionary<string, string> external_aliases;
//
// Modules to be linked
//
- ArrayList modules;
+ List<string> modules;
// Lookup paths
- static ArrayList link_paths;
+ List<string> link_paths;
// Whether we want to only run the tokenizer
bool tokenize;
bool want_debugging_support;
bool parse_only;
bool timestamps;
+ bool fatal_errors;
//
// Whether to load the initial config file (what CSC.RSP has by default)
reader.Position = 0;
Parse (reader, file);
+ reader.Dispose ();
input.Close ();
}
public static int Main (string[] args)
{
Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
-
- Driver d = Driver.Create (args, true, new ConsoleReportPrinter ());
+ var crp = new ConsoleReportPrinter ();
+ Driver d = Driver.Create (args, true, crp);
if (d == null)
return 1;
+ crp.Fatal = d.fatal_errors;
+
if (d.Compile () && d.Report.Errors == 0) {
if (d.Report.Warnings > 0) {
Console.WriteLine ("Compilation succeeded - {0} warning(s)", d.Report.Warnings);
foreach (string r in references)
LoadAssembly (r, false);
- foreach (DictionaryEntry entry in external_aliases)
- LoadAssembly ((string) entry.Value, (string) entry.Key, false);
+ foreach (var entry in external_aliases)
+ LoadAssembly (entry.Value, entry.Key, false);
GlobalRootNamespace.Instance.ComputeNamespaces (ctx);
}
static string [] LoadArgs (string file)
{
StreamReader f;
- ArrayList args = new ArrayList ();
+ var args = new List<string> ();
string line;
try {
f = new StreamReader (file);
}
}
- string [] ret_value = new string [args.Count];
- args.CopyTo (ret_value, 0);
-
- return ret_value;
+ return args.ToArray ();
}
//
bool ParseArguments (string[] args, bool require_files)
{
- references = new ArrayList ();
- external_aliases = new Hashtable ();
- soft_references = new ArrayList ();
- modules = new ArrayList (2);
- link_paths = new ArrayList ();
+ references = new List<string> ();
+ external_aliases = new Dictionary<string, string> ();
+ soft_references = new List<string> ();
+ modules = new List<string> (2);
+ link_paths = new List<string> ();
- ArrayList response_file_list = null;
+ List<string> response_file_list = null;
bool parsing_options = true;
for (int i = 0; i < args.Length; i++) {
string response_file = arg.Substring (1);
if (response_file_list == null)
- response_file_list = new ArrayList ();
+ response_file_list = new List<string> ();
if (response_file_list.Contains (response_file)) {
Report.Error (
{
Location.Initialize ();
- ArrayList cu = Location.SourceFiles;
+ var cu = Location.SourceFiles;
for (int i = 0; i < cu.Count; ++i) {
if (tokenize) {
- tokenize_file ((CompilationUnit) cu [i], ctx);
+ tokenize_file (cu [i], ctx);
} else {
- Parse ((CompilationUnit) cu [i]);
+ Parse (cu [i]);
}
}
}
return true;
case "--fatal":
- Report.Fatal = true;
+ fatal_errors = true;
return true;
case "--nowarn":
return true;
case "/platform":
-#if GMCS_SOURCE
switch (value.ToLower (CultureInfo.InvariantCulture)) {
case "anycpu":
RootContext.Platform = Platform.AnyCPU;
Report.Error (1672, "Invalid platform type for -platform. Valid options are `anycpu', `x86', `x64' or `itanium'");
break;
}
-#endif
+
return true;
// We just ignore this.
switch (value.ToLower (CultureInfo.InvariantCulture)) {
case "iso-1":
RootContext.Version = LanguageVersion.ISO_1;
- return true;
-
+ return true;
case "default":
RootContext.Version = LanguageVersion.Default;
-#if GMCS_SOURCE
RootContext.AddConditional ("__V2__");
-#endif
return true;
case "iso-2":
RootContext.Version = LanguageVersion.ISO_2;
public bool Compile ()
{
// TODO: Should be passed to parser as an argument
- RootContext.ToplevelTypes = new ModuleContainer (ctx, RootContext.Unsafe);
+ RootContext.ToplevelTypes = new ModuleCompiled (ctx, RootContext.Unsafe);
Parse ();
if (Report.Errors > 0)
{
interface IResource
{
- void Emit ();
+ void Emit (CompilerContext cc);
string FileName { get; }
}
class EmbededResource : IResource
{
static MethodInfo embed_res;
-
- static EmbededResource () {
- Type[] argst = new Type [] {
- typeof (string), typeof (string), typeof (ResourceAttributes)
- };
-
- embed_res = typeof (AssemblyBuilder).GetMethod (
- "EmbedResourceFile", BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic,
- null, CallingConventions.Any, argst, null);
-
- if (embed_res == null) {
- RootContext.ToplevelTypes.Compiler.Report.RuntimeMissingSupport (Location.Null, "Resource embedding");
- }
- }
-
readonly object[] args;
public EmbededResource (string name, string file, bool isPrivate)
args [2] = isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public;
}
- public void Emit()
+ public void Emit (CompilerContext cc)
{
+ if (embed_res == null) {
+ var argst = new [] {
+ typeof (string), typeof (string), typeof (ResourceAttributes)
+ };
+
+ embed_res = typeof (AssemblyBuilder).GetMethod (
+ "EmbedResourceFile", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
+ null, CallingConventions.Any, argst, null);
+
+ if (embed_res == null) {
+ cc.Report.RuntimeMissingSupport (Location.Null, "Resource embedding");
+ }
+ }
+
embed_res.Invoke (CodeGen.Assembly.Builder, args);
}
this.attribute = isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public;
}
- public void Emit ()
+ public void Emit (CompilerContext cc)
{
CodeGen.Assembly.Builder.AddResourceFile (name, Path.GetFileName(file), attribute);
}
}
- IDictionary embedded_resources = new HybridDictionary ();
+ Dictionary<string, IResource> embedded_resources = new Dictionary<string, IResource> ();
readonly CompilerContext ctx;
public Resources (CompilerContext ctx)
public void Add (bool embeded, string file, string name, bool isPrivate)
{
- if (embedded_resources.Contains (name)) {
+ if (embedded_resources.ContainsKey (name)) {
ctx.Report.Error (1508, "The resource identifier `{0}' has already been used in this assembly", name);
return;
}
continue;
}
- r.Emit ();
+ r.Emit (ctx);
}
}
}