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;
+ internal int fatal_errors;
//
// Whether to load the initial config file (what CSC.RSP has by default)
//
Encoding encoding;
- readonly CompilerContext ctx;
+ internal readonly CompilerContext ctx;
static readonly char[] argument_value_separator = new char [] { ';', ',' };
public static Driver Create (string[] args, bool require_files, ReportPrinter printer)
{
- Driver d = new Driver (new CompilerContext (new Report (printer)));
+ Driver d = new Driver (new CompilerContext (new ReflectionMetaImporter (), new Report (printer)));
if (!d.ParseArguments (args, require_files))
return null;
{
Console.WriteLine (
"Other flags in the compiler\n" +
- " --fatal Makes errors fatal\n" +
+ " --fatal[=COUNT] Makes errors after COUNT fatal\n" +
+ " --lint Enhanced warnings\n" +
" --parse Only parses the source file\n" +
- " --typetest Tests the tokenizer's built-in type parser\n" +
" --stacktrace Shows stack trace at error location\n" +
" --timestamp Displays time stamps of various compiler events\n" +
- " --expect-error X Expect that error X will be encountered\n" +
" -v Verbose parsing (for debugging the parser)\n" +
" --mcs-debug X Sets MCS debugging level to X\n");
}
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);
// Extern aliased refs require special handling
if (alias == null)
- GlobalRootNamespace.Instance.AddAssemblyReference (a);
+ ctx.GlobalRootNamespace.AddAssemblyReference (a);
else
- GlobalRootNamespace.Instance.DefineRootNamespace (alias, a, ctx);
+ ctx.GlobalRootNamespace.DefineRootNamespace (alias, a, ctx);
} catch (BadImageFormatException f) {
// .NET 2.0 throws this if we try to load a module without an assembly manifest ...
}
}
- GlobalRootNamespace.Instance.AddModuleReference (m);
+ ctx.GlobalRootNamespace.AddModuleReference (m);
} catch (BadImageFormatException f) {
Error9 ("module", f.FileName, f.FusionLog);
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);
+ ctx.GlobalRootNamespace.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]);
}
}
}
}
link_paths.Add (args [++i]);
return true;
+
+ case "--lint":
+ RootContext.EnhancedWarnings = true;
+ return true;
case "--nostdlib":
Report.Warning (-29, 1, "Compatibility: Use -nostdlib instead of --nostdlib");
RootContext.StdLib = false;
return true;
- case "--fatal":
- Report.Fatal = true;
- return true;
-
case "--nowarn":
Report.Warning (-29, 1, "Compatibility: Use -nowarn instead of --nowarn");
if ((i + 1) >= args.Length){
Report.Warning (-29, 1, "Compatibility: Use -noconfig option instead of --noconfig");
load_default_config = false;
return true;
+
+ default:
+ if (arg.StartsWith ("--fatal")){
+ if (arg.StartsWith ("--fatal=")){
+ if (!Int32.TryParse (arg.Substring (8), out fatal_errors))
+ fatal_errors = 1;
+ } else
+ fatal_errors = 1;
+ return true;
+ }
+ break;
}
return false;
RootContext.Optimize = false;
return true;
+ // TODO: Not supported by csc 3.5+
case "/incremental":
case "/incremental+":
case "/incremental-":
{
// TODO: Should be passed to parser as an argument
RootContext.ToplevelTypes = new ModuleCompiled (ctx, RootContext.Unsafe);
+ var ctypes = TypeManager.InitCoreTypes ();
Parse ();
if (Report.Errors > 0)
set_method.Invoke (CodeGen.Assembly.Builder, BindingFlags.Default, null, new object[]{true}, null);
}
- GlobalRootNamespace.Instance.AddModuleReference (RootContext.ToplevelTypes.Builder);
+ ctx.GlobalRootNamespace.AddModuleReference (RootContext.ToplevelTypes.Builder);
//
// Load assemblies required
if (timestamps)
ShowTime ("Loading references");
+ ctx.MetaImporter.Initialize ();
LoadReferences ();
if (modules.Count > 0) {
if (timestamps)
ShowTime ("References loaded");
- if (!TypeManager.InitCoreTypes (ctx) || Report.Errors > 0)
+ if (!TypeManager.InitCoreTypes (ctx, ctypes))
return false;
TypeManager.InitOptionalCoreTypes (ctx);
return false;
if (timestamps)
ShowTime ("Populate tree");
- if (!RootContext.StdLib)
- RootContext.BootCorlib_PopulateCoreTypes ();
+
RootContext.PopulateTypes ();
if (Report.Errors == 0 &&
if (RootContext.VerifyClsCompliance) {
if (CodeGen.Assembly.IsClsCompliant) {
AttributeTester.VerifyModulesClsCompliance (ctx);
- TypeManager.LoadAllImportedTypes ();
}
}
if (Report.Errors > 0)
if (timestamps)
ShowTime ("Closing types");
- RootContext.CloseTypes ();
+ RootContext.CloseTypes (ctx);
PEFileKinds k = PEFileKinds.ConsoleApplication;
}
- 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;
}
{
Driver.Reset ();
CSharpParser.yacc_verbose_flag = 0;
- RootContext.Reset (full_flag);
Location.Reset ();
- TypeManager.Reset ();
- PredefinedAttributes.Reset ();
- TypeHandle.Reset ();
- if (full_flag)
- GlobalRootNamespace.Reset ();
+ if (!full_flag)
+ return;
+
+ RootContext.Reset (full_flag);
+ TypeManager.Reset ();
+ ArrayContainer.Reset ();
+ ReferenceContainer.Reset ();
+ PointerContainer.Reset ();
+ Parameter.Reset ();
+
+ Unary.Reset ();
+ Binary.Reset ();
+ ConstantFold.Reset ();
+ CastFromDecimal.Reset ();
+ StringConcat.Reset ();
NamespaceEntry.Reset ();
CodeGen.Reset ();
Attribute.Reset ();
- AttributeTester.Reset ();
AnonymousTypeClass.Reset ();
AnonymousMethodBody.Reset ();
AnonymousMethodStorey.Reset ();
Linq.QueryBlock.TransparentParameter.Reset ();
Convert.Reset ();
TypeInfo.Reset ();
- DynamicExpressionStatement.Reset ();
}
}
}