X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fsymbolwriter.cs;h=51ab4c9b2c505aabf7e4a76667db45fb11b0da0f;hb=cc21ca3500fc936982e24d92f616165106c9e628;hp=b42b0e2dd72ea647b72bf24743528ff3469ce67d;hpb=d49951ccf584ba637afb1dab7fff714478e3174d;p=mono.git diff --git a/mcs/mcs/symbolwriter.cs b/mcs/mcs/symbolwriter.cs index b42b0e2dd72..51ab4c9b2c5 100644 --- a/mcs/mcs/symbolwriter.cs +++ b/mcs/mcs/symbolwriter.cs @@ -4,7 +4,8 @@ // Author: // Martin Baulig (martin@ximian.com) // -// (C) 2003 Ximian, Inc. +// Copyright 2003 Ximian, Inc. +// Copyright 2003-2008 Novell, Inc. // using System; @@ -15,90 +16,237 @@ using System.Reflection.Emit; using Mono.CompilerServices.SymbolWriter; namespace Mono.CSharp { - public class SymbolWriter : MonoSymbolWriter { - delegate int GetILOffsetFunc (ILGenerator ig); - delegate Guid GetGuidFunc (ModuleBuilder mb); + public static class SymbolWriter + { + public static bool HasSymbolWriter { + get { return symwriter != null; } + } + + private static SymbolWriterImpl symwriter; + + class SymbolWriterImpl : MonoSymbolWriter { + delegate int GetILOffsetFunc (ILGenerator ig); + delegate Guid GetGuidFunc (ModuleBuilder mb); + + GetILOffsetFunc get_il_offset_func; + GetGuidFunc get_guid_func; + + ModuleBuilder module_builder; + + public SymbolWriterImpl (ModuleBuilder module_builder, string filename) + : base (filename) + { + this.module_builder = module_builder; + } + + public int GetILOffset (ILGenerator ig) + { + return get_il_offset_func (ig); + } - GetILOffsetFunc get_il_offset_func; - GetGuidFunc get_guid_func; + public void WriteSymbolFile () + { + Guid guid = get_guid_func (module_builder); + WriteSymbolFile (guid); + } - ModuleBuilder module_builder; + public bool Initialize () + { + MethodInfo mi = typeof (ILGenerator).GetMethod ( + "Mono_GetCurrentOffset", + BindingFlags.Static | BindingFlags.NonPublic); + if (mi == null) + return false; - protected SymbolWriter (ModuleBuilder module_builder, string filename) - : base (filename) + get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate ( + typeof (GetILOffsetFunc), mi); + + mi = typeof (ModuleBuilder).GetMethod ( + "Mono_GetGuid", + BindingFlags.Static | BindingFlags.NonPublic); + if (mi == null) + return false; + + get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate ( + typeof (GetGuidFunc), mi); + + Location.DefineSymbolDocuments (this); + + return true; + } + } + + public static void DefineLocalVariable (string name, LocalBuilder builder) { - this.module_builder = module_builder; + if (symwriter != null) { + int index = MonoDebuggerSupport.GetLocalIndex (builder); + symwriter.DefineLocalVariable (index, name); + } } - bool Initialize () + public static SourceMethodBuilder OpenMethod (ICompileUnit file, int ns_id, + IMethodDef method) { - MethodInfo mi = typeof (ILGenerator).GetMethod ( - "Mono_GetCurrentOffset", - BindingFlags.Static | BindingFlags.NonPublic); - if (mi == null) - return false; + if (symwriter != null) + return symwriter.OpenMethod (file, ns_id, method); + else + return null; + } - get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate ( - typeof (GetILOffsetFunc), mi); + public static void CloseMethod () + { + if (symwriter != null) + symwriter.CloseMethod (); + } - mi = typeof (ModuleBuilder).GetMethod ( - "Mono_GetGuid", - BindingFlags.Static | BindingFlags.NonPublic); - if (mi == null) - return false; + public static int OpenScope (ILGenerator ig) + { + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + return symwriter.OpenScope (offset); + } else { + return -1; + } + } - get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate ( - typeof (GetGuidFunc), mi); + public static void CloseScope (ILGenerator ig) + { + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + symwriter.CloseScope (offset); + } + } - Location.DefineSymbolDocuments (this); + 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; + } - return true; +#region Terrania additions + public static void DefineAnonymousScope (int id) + { + if (symwriter != null) + symwriter.DefineAnonymousScope (id); } - public void DefineLocalVariable (string name, LocalBuilder builder) + public static void DefineScopeVariable (int scope, LocalBuilder builder) { - SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper ( - module_builder); - sighelper.AddArgument (builder.LocalType); - byte[] signature = sighelper.GetSignature (); + if (symwriter != null) { + int index = MonoDebuggerSupport.GetLocalIndex (builder); + symwriter.DefineScopeVariable (scope, index); + } + } - int index = MonoDebuggerSupport.GetLocalIndex (builder); + public static void DefineScopeVariable (int scope) + { + if (symwriter != null) + symwriter.DefineScopeVariable (scope, -1); + } - DefineLocalVariable (index, name, signature); + public static void DefineCapturedLocal (int scope_id, string name, + string captured_name) + { + if (symwriter != null) + symwriter.DefineCapturedLocal (scope_id, name, captured_name); } - public int OpenScope (ILGenerator ig) + public static void DefineCapturedParameter (int scope_id, string name, + string captured_name) { - int offset = get_il_offset_func (ig); - return OpenScope (offset); + if (symwriter != null) + symwriter.DefineCapturedParameter (scope_id, name, captured_name); } - public void CloseScope (ILGenerator ig) + public static void DefineCapturedThis (int scope_id, string captured_name) { - int offset = get_il_offset_func (ig); - CloseScope (offset); + if (symwriter != null) + symwriter.DefineCapturedThis (scope_id, captured_name); } - public void MarkSequencePoint (ILGenerator ig, int row, int column) + public static void DefineCapturedScope (int scope_id, int id, string captured_name) { - int offset = get_il_offset_func (ig); - MarkSequencePoint (offset, row, column); + if (symwriter != null) + symwriter.DefineCapturedScope (scope_id, id, captured_name); } - public void WriteSymbolFile () + public static void OpenCompilerGeneratedBlock (ILGenerator ig) { - Guid guid = get_guid_func (module_builder); - WriteSymbolFile (guid); + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + symwriter.OpenCompilerGeneratedBlock (offset); + } } - public static SymbolWriter GetSymbolWriter (ModuleBuilder module, - string filename) + public static void CloseCompilerGeneratedBlock (ILGenerator ig) { - SymbolWriter writer = new SymbolWriter (module, filename); - if (!writer.Initialize ()) - return null; + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + symwriter.CloseCompilerGeneratedBlock (offset); + } + } + + public static void StartIteratorBody (ILGenerator ig) + { + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + symwriter.StartIteratorBody (offset); + } + } + + public static void EndIteratorBody (ILGenerator ig) + { + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + symwriter.EndIteratorBody (offset); + } + } + + public static void StartIteratorDispatcher (ILGenerator ig) + { + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + symwriter.StartIteratorDispatcher (offset); + } + } - return writer; + public static void EndIteratorDispatcher (ILGenerator ig) + { + if (symwriter != null) { + int offset = symwriter.GetILOffset (ig); + symwriter.EndIteratorDispatcher (offset); + } + } +#endregion + + public static void MarkSequencePoint (ILGenerator ig, Location loc) + { + if (symwriter != null) { + SourceFileEntry file = loc.SourceFile.SourceFileEntry; + int offset = symwriter.GetILOffset (ig); + symwriter.MarkSequencePoint ( + offset, file, loc.Row, loc.Column, loc.Hidden); + } + } + + public static void WriteSymbolFile () + { + if (symwriter != null) + symwriter.WriteSymbolFile (); + } + + public static bool Initialize (ModuleBuilder module, string filename) + { + symwriter = new SymbolWriterImpl (module, filename); + if (!symwriter.Initialize ()) { + symwriter = null; + return false; + } + + return true; } } }