// Copyright 2004-2008 Novell, Inc
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Diagnostics;
public enum LanguageVersion
{
ISO_1 = 1,
- Default_MCS = 2,
- ISO_2 = 3,
- LINQ = 4,
+ ISO_2 = 2,
+ V_3 = 3,
+ V_4 = 4,
+ Future = 100,
-#if GMCS_SOURCE
- Default = LINQ
-#else
- Default = Default_MCS
-#endif
+ Default = LanguageVersion.V_4,
+ }
+
+ public enum MetadataVersion
+ {
+ v1,
+ v2,
+ v4
}
public class RootContext {
// COMPILER OPTIONS CLASS
//
public static Target Target;
+ public static Platform Platform;
public static string TargetExt;
public static bool VerifyClsCompliance = true;
public static bool Optimize = true;
public static LanguageVersion Version;
+ public static bool EnhancedWarnings;
+
+ public static MetadataVersion MetadataCompatibilityVersion;
//
// We keep strongname related info here because
//
// Contains the parsed tree
//
- static RootTypes root;
+ static ModuleCompiled root;
//
// This hashtable contains all of the #definitions across the source code
// it is used by the ConditionalAttribute handler.
//
- static ArrayList AllDefines = new ArrayList ();
+ static List<string> AllDefines;
//
// This keeps track of the order in which classes were defined
// or abstract as well as the parent names (to implement new,
// override).
//
- static ArrayList type_container_resolve_order;
+ static List<TypeContainer> type_container_resolve_order;
//
// Holds a reference to the Private Implementation Details
// class.
//
- static ArrayList helper_classes;
+ static List<TypeBuilder> helper_classes;
static TypeBuilder impl_details_class;
public static void Reset (bool full)
{
if (full)
- root = new RootTypes ();
+ root = null;
- type_container_resolve_order = new ArrayList ();
+ type_container_resolve_order = new List<TypeContainer> ();
EntryPoint = null;
- Report.WarningLevel = 4;
Checked = false;
Unsafe = false;
StdLib = true;
MainClass = null;
Target = Target.Exe;
TargetExt = ".exe";
+ Platform = Platform.AnyCPU;
Version = LanguageVersion.Default;
Documentation = null;
impl_details_class = null;
helper_classes = null;
+#if NET_4_0
+ MetadataCompatibilityVersion = MetadataVersion.v4;
+#else
+ MetadataCompatibilityVersion = MetadataVersion.v2;
+#endif
+
//
// Setup default defines
//
- RootContext.AllDefines = new ArrayList ();
- RootContext.AddConditional ("__MonoCS__");
+ AllDefines = new List<string> ();
+ AddConditional ("__MonoCS__");
}
public static void AddConditional (string p)
return AllDefines.Contains (value);
}
- static public RootTypes ToplevelTypes {
+ static public ModuleCompiled ToplevelTypes {
get { return root; }
+ set { root = value; }
}
public static void RegisterOrder (TypeContainer tc)
// </remarks>
static public void ResolveTree ()
{
+ root.Resolve ();
+
//
// Interfaces are processed next, as classes and
// structs might inherit from an object or implement
// make sure that we define the structs in order as well.
//
foreach (TypeContainer tc in type_container_resolve_order){
- if (tc.Kind == Kind.Struct && tc.Parent == root){
+ if (tc.Kind == MemberKind.Struct && tc.Parent == root){
tc.CloseType ();
}
}
foreach (TypeContainer tc in type_container_resolve_order){
- if (!(tc.Kind == Kind.Struct && tc.Parent == root))
+ if (!(tc.Kind == MemberKind.Struct && tc.Parent == root))
tc.CloseType ();
}
//
if (helper_classes != null){
foreach (TypeBuilder type_builder in helper_classes) {
-#if GMCS_SOURCE
- type_builder.SetCustomAttribute (TypeManager.GetCompilerGeneratedAttribute (Location.Null));
-#endif
+ PredefinedAttributes.Get.CompilerGenerated.EmitAttribute (type_builder);
type_builder.CreateType ();
}
}
public static void RegisterCompilerGeneratedType (TypeBuilder helper_class)
{
if (helper_classes == null)
- helper_classes = new ArrayList ();
+ helper_classes = new List<TypeBuilder> ();
helper_classes.Add (helper_class);
}
- static public void PopulateCoreType (TypeContainer root, string name)
+ static public DeclSpace PopulateCoreType (TypeContainer root, string name)
{
DeclSpace ds = (DeclSpace) root.GetDefinition (name);
// Core type was imported
if (ds == null)
- return;
+ return null;
- ds.DefineMembers ();
ds.Define ();
+ return ds;
}
static public void BootCorlib_PopulateCoreTypes ()
{
- PopulateCoreType (root, "System.Object");
+ // Clear -nostdlib flag when object type is imported
+ if (PopulateCoreType (root, "System.Object") == null)
+ RootContext.StdLib = true;
+
PopulateCoreType (root, "System.ValueType");
PopulateCoreType (root, "System.Attribute");
PopulateCoreType (root, "System.Runtime.CompilerServices.IndexerNameAttribute");
if (type_container_resolve_order != null){
foreach (TypeContainer tc in type_container_resolve_order)
tc.ResolveType ();
- foreach (TypeContainer tc in type_container_resolve_order)
- tc.DefineMembers ();
+ foreach (TypeContainer tc in type_container_resolve_order) {
+ try {
+ tc.Define ();
+ } catch (Exception e) {
+ throw new InternalErrorException (tc, e);
+ }
+ }
}
- ArrayList delegates = root.Delegates;
+ var delegates = root.Delegates;
if (delegates != null){
foreach (Delegate d in delegates)
- d.DefineMembers ();
+ d.Define ();
}
//
// Check for cycles in the struct layout
//
if (type_container_resolve_order != null){
- Hashtable seen = new Hashtable ();
+ var seen = new Dictionary<TypeContainer, object> ();
foreach (TypeContainer tc in type_container_resolve_order)
TypeManager.CheckStructCycles (tc, seen);
}
}
- //
- // 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 (TypeContainer tc in type_container_resolve_order)
tc.EmitType ();
- if (Report.Errors > 0)
+ if (ToplevelTypes.Compiler.Report.Errors > 0)
return;
foreach (TypeContainer tc in type_container_resolve_order)
}
CodeGen.Assembly.Emit (root);
- CodeGen.Module.Emit (root);
+ root.Emit ();
}
//
// Public Field, used to track which method is the public entry
// point.
//
- static public MethodInfo EntryPoint;
-
- //
- // Track the location of the entry point.
- //
- static public Location EntryPointLocation;
+ static public Method EntryPoint;
//
// These are used to generate unique names on the structs and fields.
FieldBuilder fb;
if (impl_details_class == null){
- impl_details_class = CodeGen.Module.Builder.DefineType (
+ impl_details_class = ToplevelTypes.Builder.DefineType (
"<PrivateImplementationDetails>",
TypeAttributes.NotPublic,
TypeManager.object_type);
return fb;
}
- public static void CheckUnsafeOption (Location loc)
+ public static void CheckUnsafeOption (Location loc, Report Report)
{
if (!Unsafe) {
Report.Error (227, loc,
}
}
}
-
-