Check whether parent struct field is assigned when assigning to child field. Fixes...
[mono.git] / mcs / mcs / symbolwriter.cs
index 49466b56d314e055e7d70769d9fa594336ee70bc..ce19cfc492acb6c54b129d1e6a6d915c8e7d134b 100644 (file)
 //
-// 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;
-using System.Diagnostics.SymbolStore;
+#endif
+
+using Mono.CompilerServices.SymbolWriter;
 
-namespace Mono.CSharp {
-       public class SymbolWriter {
-               ISymbolWriter symwriter;
+namespace Mono.CSharp
+{
+       static class SymbolWriter
+       {
+#if !NET_4_0 && !STATIC
+               delegate int GetILOffsetFunc (ILGenerator ig);
+               static GetILOffsetFunc get_il_offset_func;
 
-               protected SymbolWriter (ISymbolWriter symwriter)
+               delegate Guid GetGuidFunc (ModuleBuilder mb);
+               static GetGuidFunc get_guid_func;
+
+               static void Initialize ()
                {
-                       this.symwriter = symwriter;
+                       var mi = typeof (ILGenerator).GetMethod (
+                               "Mono_GetCurrentOffset",
+                               BindingFlags.Static | BindingFlags.NonPublic);
+                       if (mi == null)
+                               throw new MissingMethodException ("Mono_GetCurrentOffset");
+
+                       get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
+                               typeof (GetILOffsetFunc), mi);
+
+                       mi = typeof (ModuleBuilder).GetMethod (
+                               "Mono_GetGuid",
+                               BindingFlags.Static | BindingFlags.NonPublic);
+                       if (mi == null)
+                               throw new MissingMethodException ("Mono_GetGuid");
+
+                       get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
+                               typeof (GetGuidFunc), mi);
                }
+#endif
 
-               bool Initialize ()
+               static int GetILOffset (ILGenerator ig)
                {
-                       Location.DefineSymbolDocuments (this);
+#if NET_4_0 || STATIC
+                       return ig.ILOffset;
+#else
+                       if (get_il_offset_func == null)
+                               Initialize ();
 
-                       return true;
+                       return get_il_offset_func (ig);
+#endif
                }
 
-               public ISymbolDocumentWriter DefineDocument (string path)
+               public static Guid GetGuid (ModuleBuilder module)
                {
-                       return symwriter.DefineDocument (
-                               path, SymLanguageType.CSharp, SymLanguageVendor.Microsoft,
-                               SymDocumentType.Text);
+#if NET_4_0 || STATIC
+                       return module.ModuleVersionId;
+#else
+                       if (get_guid_func == null)
+                               Initialize ();
+
+                       return get_guid_func (module);
+#endif
                }
 
-               public void OpenMethod (MethodToken token, Location start, Location end)
+               public static bool HasSymbolWriter {
+                       get { return symwriter != null; }
+               }
+
+               public static MonoSymbolWriter symwriter;
+
+               public static void DefineLocalVariable (string name, LocalBuilder builder)
                {
-                       symwriter.OpenMethod (new SymbolToken (token.Token));
-                       symwriter.SetMethodSourceRange (
-                               start.SymbolDocument, start.Row, 0, end.SymbolDocument, end.Row, 0);
+                       if (symwriter != null) {
+                               symwriter.DefineLocalVariable (builder.LocalIndex, name);
+                       }
                }
 
-               public void CloseMethod ()
+               public static SourceMethodBuilder OpenMethod (ICompileUnit file, int ns_id,
+                                                             IMethodDef method)
                {
-                       symwriter.CloseMethod ();
+                       if (symwriter != null)
+                               return symwriter.OpenMethod (file, ns_id, method);
+                       else
+                               return null;
                }
 
-               public static SymbolWriter GetSymbolWriter (ModuleBuilder module)
+               public static void CloseMethod ()
                {
-                       ISymbolWriter symwriter = module.GetSymWriter ();
+                       if (symwriter != null)
+                               symwriter.CloseMethod ();
+               }
 
-                       if (symwriter == null)
-                               return null;
+               public static int OpenScope (ILGenerator ig)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ig);
+                               return symwriter.OpenScope (offset);
+                       } else {
+                               return -1;
+                       }
+               }
 
-                       SymbolWriter writer = new SymbolWriter (symwriter);
-                       if (!writer.Initialize ())
-                               return null;
+               public static void CloseScope (ILGenerator ig)
+               {
+                       if (symwriter != null) {
+                               int offset = GetILOffset (ig);
+                               symwriter.CloseScope (offset);
+                       }
+               }
+
+               public static int DefineNamespace (string name, CompileUnitEntry source,
+                                                  string[] using_clauses, int parent)
+               {
+                       if (symwriter != null)
+                               return symwriter.DefineNamespace (name, source, using_clauses, parent);
+                       else
+                               return -1;
+               }
+
+               public static void DefineAnonymousScope (int id)
+               {
+                       if (symwriter != null)
+                               symwriter.DefineAnonymousScope (id);
+               }
 
-                       return writer;
+               public static void DefineScopeVariable (int scope, LocalBuilder builder)
+               {
+                       if (symwriter != null) {
+                               symwriter.DefineScopeVariable (scope, builder.LocalIndex);
+                       }
+               }
+
+               public static void DefineScopeVariable (int scope)
+               {
+                       if (symwriter != null)
+                               symwriter.DefineScopeVariable (scope, -1);
+               }
+
+               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;
                }
        }
 }