[xbuild] Add new reserved properties $(MSBuildThisFile*).
[mono.git] / mcs / mcs / symbolwriter.cs
index b42b0e2dd72ea647b72bf24743528ff3469ce67d..ce19cfc492acb6c54b129d1e6a6d915c8e7d134b 100644 (file)
@@ -1,42 +1,45 @@
 //
-// symbolwriter.cs: The symbol writer
+// symbolwriter.cs: The debug symbol writer
 //
-// Author:
-//   Martin Baulig (martin@ximian.com)
+// Authors: Martin Baulig (martin@ximian.com)
+//          Marek Safar (marek.safar@gmail.com)
 //
-// (C) 2003 Ximian, Inc.
+// Dual licensed under the terms of the MIT X11 or GNU GPL
+//
+// Copyright 2003 Ximian, Inc (http://www.ximian.com)
+// Copyright 2004-2010 Novell, Inc
 //
 
 using System;
-using System.Collections;
+
+#if STATIC
+using IKVM.Reflection;
+using IKVM.Reflection.Emit;
+#else
 using System.Reflection;
 using System.Reflection.Emit;
+#endif
 
 using Mono.CompilerServices.SymbolWriter;
 
-namespace Mono.CSharp {
-       public class SymbolWriter : MonoSymbolWriter {
+namespace Mono.CSharp
+{
+       static class SymbolWriter
+       {
+#if !NET_4_0 && !STATIC
                delegate int GetILOffsetFunc (ILGenerator ig);
-               delegate Guid GetGuidFunc (ModuleBuilder mb);
-
-               GetILOffsetFunc get_il_offset_func;
-               GetGuidFunc get_guid_func;
+               static GetILOffsetFunc get_il_offset_func;
 
-               ModuleBuilder module_builder;
-
-               protected SymbolWriter (ModuleBuilder module_builder, string filename)
-                       : base (filename)
-               {
-                       this.module_builder = module_builder;
-               }
+               delegate Guid GetGuidFunc (ModuleBuilder mb);
+               static GetGuidFunc get_guid_func;
 
-               bool Initialize ()
+               static void Initialize ()
                {
-                       MethodInfo mi = typeof (ILGenerator).GetMethod (
+                       var mi = typeof (ILGenerator).GetMethod (
                                "Mono_GetCurrentOffset",
                                BindingFlags.Static | BindingFlags.NonPublic);
                        if (mi == null)
-                               return false;
+                               throw new MissingMethodException ("Mono_GetCurrentOffset");
 
                        get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
                                typeof (GetILOffsetFunc), mi);
@@ -45,60 +48,198 @@ namespace Mono.CSharp {
                                "Mono_GetGuid",
                                BindingFlags.Static | BindingFlags.NonPublic);
                        if (mi == null)
-                               return false;
+                               throw new MissingMethodException ("Mono_GetGuid");
 
                        get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
                                typeof (GetGuidFunc), mi);
+               }
+#endif
+
+               static int GetILOffset (ILGenerator ig)
+               {
+#if NET_4_0 || STATIC
+                       return ig.ILOffset;
+#else
+                       if (get_il_offset_func == null)
+                               Initialize ();
+
+                       return get_il_offset_func (ig);
+#endif
+               }
+
+               public static Guid GetGuid (ModuleBuilder module)
+               {
+#if NET_4_0 || STATIC
+                       return module.ModuleVersionId;
+#else
+                       if (get_guid_func == null)
+                               Initialize ();
+
+                       return get_guid_func (module);
+#endif
+               }
 
-                       Location.DefineSymbolDocuments (this);
+               public static bool HasSymbolWriter {
+                       get { return symwriter != null; }
+               }
+
+               public static MonoSymbolWriter symwriter;
 
-                       return true;
+               public static void DefineLocalVariable (string name, LocalBuilder builder)
+               {
+                       if (symwriter != null) {
+                               symwriter.DefineLocalVariable (builder.LocalIndex, name);
+                       }
                }
 
-               public void DefineLocalVariable (string name, LocalBuilder builder)
+               public static SourceMethodBuilder OpenMethod (ICompileUnit file, int ns_id,
+                                                             IMethodDef method)
                {
-                       SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (
-                               module_builder);
-                       sighelper.AddArgument (builder.LocalType);
-                       byte[] signature = sighelper.GetSignature ();
+                       if (symwriter != null)
+                               return symwriter.OpenMethod (file, ns_id, method);
+                       else
+                               return null;
+               }
 
-                       int index = MonoDebuggerSupport.GetLocalIndex (builder);
+               public static void CloseMethod ()
+               {
+                       if (symwriter != null)
+                               symwriter.CloseMethod ();
+               }
 
-                       DefineLocalVariable (index, name, signature);
+               public static int OpenScope (ILGenerator ig)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ig);
+                               return symwriter.OpenScope (offset);
+                       } else {
+                               return -1;
+                       }
                }
 
-               public int OpenScope (ILGenerator ig)
+               public static void CloseScope (ILGenerator ig)
                {
-                       int offset = get_il_offset_func (ig);
-                       return OpenScope (offset);
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ig);
+                               symwriter.CloseScope (offset);
+                       }
                }
 
-               public void CloseScope (ILGenerator ig)
+               public static int DefineNamespace (string name, CompileUnitEntry source,
+                                                  string[] using_clauses, int parent)
                {
-                       int offset = get_il_offset_func (ig);
-                       CloseScope (offset);
+                       if (symwriter != null)
+                               return symwriter.DefineNamespace (name, source, using_clauses, parent);
+                       else
+                               return -1;
                }
 
-               public void MarkSequencePoint (ILGenerator ig, int row, int column)
+               public static void DefineAnonymousScope (int id)
                {
-                       int offset = get_il_offset_func (ig);
-                       MarkSequencePoint (offset, row, column);
+                       if (symwriter != null)
+                               symwriter.DefineAnonymousScope (id);
                }
 
-               public void WriteSymbolFile ()
+               public static void DefineScopeVariable (int scope, LocalBuilder builder)
                {
-                       Guid guid = get_guid_func (module_builder);
-                       WriteSymbolFile (guid);
+                       if (symwriter != null) {
+                               symwriter.DefineScopeVariable (scope, builder.LocalIndex);
+                       }
                }
 
-               public static SymbolWriter GetSymbolWriter (ModuleBuilder module,
-                                                           string filename)
+               public static void DefineScopeVariable (int scope)
                {
-                       SymbolWriter writer = new SymbolWriter (module, filename);
-                       if (!writer.Initialize ())
-                               return null;
+                       if (symwriter != null)
+                               symwriter.DefineScopeVariable (scope, -1);
+               }
 
-                       return writer;
+               public static void DefineCapturedLocal (int scope_id, string name,
+                                                       string captured_name)
+               {
+                       if (symwriter != null)
+                               symwriter.DefineCapturedLocal (scope_id, name, captured_name);
+               }
+
+               public static void DefineCapturedParameter (int scope_id, string name,
+                                                           string captured_name)
+               {
+                       if (symwriter != null)
+                               symwriter.DefineCapturedParameter (scope_id, name, captured_name);
+               }
+
+               public static void DefineCapturedThis (int scope_id, string captured_name)
+               {
+                       if (symwriter != null)
+                               symwriter.DefineCapturedThis (scope_id, captured_name);
+               }
+
+               public static void DefineCapturedScope (int scope_id, int id, string captured_name)
+               {
+                       if (symwriter != null)
+                               symwriter.DefineCapturedScope (scope_id, id, captured_name);
+               }
+
+               public static void OpenCompilerGeneratedBlock (EmitContext ec)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ec.ig);
+                               symwriter.OpenCompilerGeneratedBlock (offset);
+                       }
+               }
+
+               public static void CloseCompilerGeneratedBlock (EmitContext ec)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ec.ig);
+                               symwriter.CloseCompilerGeneratedBlock (offset);
+                       }
+               }
+
+               public static void StartIteratorBody (EmitContext ec)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ec.ig);
+                               symwriter.StartIteratorBody (offset);
+                       }
+               }
+
+               public static void EndIteratorBody (EmitContext ec)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ec.ig);
+                               symwriter.EndIteratorBody (offset);
+                       }
+               }
+
+               public static void StartIteratorDispatcher (EmitContext ec)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ec.ig);
+                               symwriter.StartIteratorDispatcher (offset);
+                       }
+               }
+
+               public static void EndIteratorDispatcher (EmitContext ec)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ec.ig);
+                               symwriter.EndIteratorDispatcher (offset);
+                       }
+               }
+
+               public static void MarkSequencePoint (ILGenerator ig, Location loc)
+               {
+                       if (symwriter != null) {
+                               SourceFileEntry file = loc.SourceFile.SourceFileEntry;
+                               int offset = GetILOffset (ig);
+                               symwriter.MarkSequencePoint (
+                                       offset, file, loc.Row, loc.Column, loc.Hidden);
+                       }
+               }
+
+               public static void Reset ()
+               {
+                       symwriter = null;
                }
        }
 }