// Marek Safar (marek.safar@gmail.com)
//
//
-// Licensed under the terms of the GNU GPL
+// Dual licensed under the terms of the MIT X11 or GNU GPL
//
-// (C) 2001 Ximian, Inc (http://www.ximian.com)
-// (C) 2004 Novell, Inc
+// Copyright 2001 Ximian, Inc (http://www.ximian.com)
+// Copyright 2004-2008 Novell, Inc
using System;
using System.Collections;
public class RootContext {
//
- // Contains the parsed tree
+ // COMPILER OPTIONS CLASS
//
- static RootTypes root;
+ public static Target Target;
+ public static string TargetExt;
+ public static bool VerifyClsCompliance = true;
+ public static bool Optimize = true;
+ public static LanguageVersion Version;
//
- // This hashtable contains all of the #definitions across the source code
- // it is used by the ConditionalAttribute handler.
+ // We keep strongname related info here because
+ // it's also used as complier options from CSC 8.x
+ //
+ public static string StrongNameKeyFile;
+ public static string StrongNameKeyContainer;
+ public static bool StrongNameDelaySign;
+
//
- public static Hashtable AllDefines = new Hashtable ();
+ // If set, enable XML documentation generation
+ //
+ public static Documentation Documentation;
+
+ static public string MainClass;
+
+ //
+ // The default compiler checked state
+ //
+ static public bool Checked;
+
+ //
+ // If true, it means that the compiler is executing as
+ // in eval mode so unresolved variables are resolved in
+ // static classes maintained by the eval engine.
+ //
+ static public bool EvalMode;
+
+ //
+ // If true, the compiler is operating in statement mode,
+ // this currently turns local variable declaration into
+ // static variables of a class
+ //
+ static public bool StatementMode;
+ //
+ // Whether to allow Unsafe code
+ //
+ static public bool Unsafe;
+
//
// Whether we are being linked against the standard libraries.
// This is only used to tell whether `System.Object' should
//
public static bool StdLib;
+ public static bool NeedsEntryPoint {
+ get { return Target == Target.Exe || Target == Target.WinExe; }
+ }
+
+ //
+ // COMPILER OPTIONS CLASS END
+ //
+
+ //
+ // Contains the parsed tree
+ //
+ static RootTypes root;
+
+ //
+ // This hashtable contains all of the #definitions across the source code
+ // it is used by the ConditionalAttribute handler.
+ //
+ static ArrayList AllDefines = new ArrayList ();
+
//
// This keeps track of the order in which classes were defined
// so that we can poulate them in that order.
static TypeBuilder impl_details_class;
- public static Target Target;
- public static string TargetExt;
-
- public static bool VerifyClsCompliance = true;
-
- /// <summary>
- /// Holds /optimize option
- /// </summary>
- public static bool Optimize = true;
-
- public static LanguageVersion Version;
-
- //
- // We keep strongname related info here because
- // it's also used as complier options from CSC 8.x
- //
- public static string StrongNameKeyFile;
- public static string StrongNameKeyContainer;
- public static bool StrongNameDelaySign;
-
- //
- // If set, enable XML documentation generation
- //
- public static Documentation Documentation;
-
- static public string MainClass;
-
//
// Constructor
//
static RootContext ()
{
- Reset ();
+ Reset (true);
}
- public static void Reset ()
+ public static void PartialReset ()
+ {
+ Reset (false);
+ }
+
+ public static void Reset (bool full)
{
- root = new RootTypes ();
+ if (full)
+ root = new RootTypes ();
+
type_container_resolve_order = new ArrayList ();
EntryPoint = null;
- Report.WarningLevel = 3;
+ Report.WarningLevel = 4;
Checked = false;
Unsafe = false;
StdLib = true;
Documentation = null;
impl_details_class = null;
helper_classes = null;
+
+ //
+ // Setup default defines
+ //
+ RootContext.AllDefines = new ArrayList ();
+ RootContext.AddConditional ("__MonoCS__");
}
- public static bool NeedsEntryPoint {
- get { return RootContext.Target == Target.Exe || RootContext.Target == Target.WinExe; }
+ public static void AddConditional (string p)
+ {
+ if (AllDefines.Contains (p))
+ return;
+ AllDefines.Add (p);
+ }
+
+ public static bool IsConditionalDefined (string value)
+ {
+ return AllDefines.Contains (value);
}
static public RootTypes ToplevelTypes {
type_container_resolve_order.Add (tc);
}
- //
- // The default compiler checked state
- //
- static public bool Checked;
-
- //
- // Whether to allow Unsafe code
- //
- static public bool Unsafe;
-
// <remarks>
// This function is used to resolve the hierarchy tree.
// It processes interfaces, structs and classes in that order.
if (ds == null)
return;
- ds.DefineMembers ();
ds.Define ();
}
foreach (TypeContainer tc in type_container_resolve_order)
tc.ResolveType ();
foreach (TypeContainer tc in type_container_resolve_order)
- tc.DefineMembers ();
+ tc.Define ();
}
ArrayList delegates = root.Delegates;
if (delegates != null){
foreach (Delegate d in delegates)
- d.DefineMembers ();
+ d.Define ();
}
//
}
}
- //
- // A generic hook delegate
- //
- public delegate void Hook ();
-
- //
- // A hook invoked when the code has been generated.
- //
- public static event Hook EmitCodeHook;
-
- //
- // DefineTypes is used to fill in the members of each type.
- //
- static public void DefineTypes ()
- {
- ArrayList delegates = root.Delegates;
- if (delegates != null){
- foreach (Delegate d in delegates)
- d.Define ();
- }
-
- if (type_container_resolve_order != null){
- foreach (TypeContainer tc in type_container_resolve_order) {
- // When compiling corlib, these types have already been
- // populated from BootCorlib_PopulateCoreTypes ().
- if (!RootContext.StdLib &&
- ((tc.Name == "System.Object") ||
- (tc.Name == "System.Attribute") ||
- (tc.Name == "System.ValueType") ||
- (tc.Name == "System.Runtime.CompilerServices.IndexerNameAttribute")))
- continue;
-
- tc.Define ();
- }
- }
- }
-
static public void EmitCode ()
{
if (type_container_resolve_order != null) {
foreach (Delegate d in root.Delegates)
d.Emit ();
}
- //
- // Run any hooks after all the types have been defined.
- // This is used to create nested auxiliary classes for example
- //
-
- if (EmitCodeHook != null)
- EmitCodeHook ();
CodeGen.Assembly.Emit (root);
CodeGen.Module.Emit (root);