2008-02-19 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Fri, 14 Mar 2008 18:06:49 +0000 (18:06 -0000)
committerMartin Baulig <martin@novell.com>
Fri, 14 Mar 2008 18:06:49 +0000 (18:06 -0000)
* class.cs
(IMethodData.EmitExtraSymbolInfo): New interface method.
(MethodData.Emit): Call method.EmitExtraSymbolInfo().
(MethodOrOperator.EmitExtraSymbolInfo): Implement this new
interface method here as an empty public virtual method.

* anonymous.cs
(AnonymousMethodMethod.ctor): Added `string real_name' argument.
(AnonymousMethodMethod.EmitExtraSymbolInfo): Override and call
CodeGen.SymbolWriter.SetRealMethodName().

2008-02-18  Martin Baulig  <martin@ximian.com>

* anonymous.cs
(ScopeInfo.EmitType): Override this and emit debugging
information for captured variables.
(RootScopeInfo.EmitType): Override this and emit symbol
information for a captured `this'.

2008-02-15  Martin Baulig  <martin@ximian.com>

* iterators.cs: Emit debugging info.

* codegen.cs
(EmitContext.Flags): Add `OmitDebuggingInfo'.
(EmitContext.OmitDebuggingInfo): New public property.

* statement.cs
(While): Override Emit() and don't emit symbol info there; do it
inside DoEmit() instead.
(Block.Emit): Omit symbol information while emitting the scope
initializers; don't ec.Mark() the `EndLocation'.  Fix the lexical
block logic.
(ExplicitBlock.IsIterator): Moved here from `ToplevelBlock'.
(ToplevelBlock.MakeIterator): Pass the `flags' to `ExplicitBlock's
.ctor to make `IsIterator' work.

svn path=/trunk/mcs/; revision=98305

mcs/mcs/ChangeLog
mcs/mcs/anonymous.cs
mcs/mcs/class.cs
mcs/mcs/codegen.cs
mcs/mcs/iterators.cs
mcs/mcs/statement.cs

index bf3439bbd079b719d189a51e096f3fcaa19bb857..5c7cada68664a65e3071dde46a86dcb110ec352d 100644 (file)
@@ -1,3 +1,42 @@
+2008-02-19  Martin Baulig  <martin@ximian.com>
+
+       * class.cs
+       (IMethodData.EmitExtraSymbolInfo): New interface method.
+       (MethodData.Emit): Call method.EmitExtraSymbolInfo().
+       (MethodOrOperator.EmitExtraSymbolInfo): Implement this new
+       interface method here as an empty public virtual method.
+
+       * anonymous.cs
+       (AnonymousMethodMethod.ctor): Added `string real_name' argument.
+       (AnonymousMethodMethod.EmitExtraSymbolInfo): Override and call
+       CodeGen.SymbolWriter.SetRealMethodName().       
+
+2008-02-18  Martin Baulig  <martin@ximian.com>
+
+       * anonymous.cs
+       (ScopeInfo.EmitType): Override this and emit debugging
+       information for captured variables.
+       (RootScopeInfo.EmitType): Override this and emit symbol
+       information for a captured `this'.
+
+2008-02-15  Martin Baulig  <martin@ximian.com>
+
+       * iterators.cs: Emit debugging info.
+
+       * codegen.cs
+       (EmitContext.Flags): Add `OmitDebuggingInfo'.
+       (EmitContext.OmitDebuggingInfo): New public property.
+
+       * statement.cs
+       (While): Override Emit() and don't emit symbol info there; do it
+       inside DoEmit() instead.
+       (Block.Emit): Omit symbol information while emitting the scope
+       initializers; don't ec.Mark() the `EndLocation'.  Fix the lexical
+       block logic.
+       (ExplicitBlock.IsIterator): Moved here from `ToplevelBlock'.
+       (ToplevelBlock.MakeIterator): Pass the `flags' to `ExplicitBlock's
+       .ctor to make `IsIterator' work.
+
 2008-03-14  Martin Baulig  <martin@ximian.com>
 
        * symbolwriter.cs: Added the new symbol writer function from the
index 2ae8df1dd65843c0a077e5ccaa6a7599a4b5fdd0..1f57b84505a011e3a6cdb56d7ec2d88a5ce9ade5 100644 (file)
@@ -410,6 +410,24 @@ namespace Mono.CSharp {
                        return var;
                }
 
+               public override void EmitType ()
+               {
+                       SymbolWriter.DefineAnonymousScope (ID);
+                       foreach (CapturedLocal local in locals.Values)
+                               local.EmitSymbolInfo ();
+
+                       if (captured_params != null) {
+                               foreach (CapturedParameter param in captured_params.Values)
+                                       param.EmitSymbolInfo ();
+                       }
+
+                       foreach (CapturedScope scope in CapturedScopes) {
+                               scope.EmitSymbolInfo ();
+                       }
+
+                       base.EmitType ();
+               }
+
                protected string MakeFieldName (string local_name)
                {
                        return "<" + ID + ":" + local_name + ">";
@@ -466,6 +484,8 @@ namespace Mono.CSharp {
                                        return FieldInstance.FieldInfo;
                        }
 
+                       public abstract void EmitSymbolInfo ();
+
                        public override void EmitInstance (EmitContext ec)
                        {
                                if ((ec.CurrentAnonymousMethod != null) &&
@@ -504,6 +524,12 @@ namespace Mono.CSharp {
                                this.Idx = idx;
                        }
 
+                       public override void EmitSymbolInfo ()
+                       {
+                               SymbolWriter.DefineCapturedParameter (
+                                       Scope.ID, Parameter.Name, Field.Name);
+                       }
+
                        public override string ToString ()
                        {
                                return String.Format ("{0} ({1}:{2}:{3})", GetType (), Field,
@@ -520,6 +546,12 @@ namespace Mono.CSharp {
                                this.Local = local;
                        }
 
+                       public override void EmitSymbolInfo ()
+                       {
+                               SymbolWriter.DefineCapturedLocal (
+                                       Scope.ID, Local.Name, Field.Name);
+                       }
+
                        public override string ToString ()
                        {
                                return String.Format ("{0} ({1}:{2})", GetType (), Field,
@@ -531,6 +563,11 @@ namespace Mono.CSharp {
                        public CapturedThis (RootScopeInfo host)
                                : base (host, "<>THIS", host.ParentType)
                        { }
+
+                       public override void EmitSymbolInfo ()
+                       {
+                               SymbolWriter.DefineCapturedThis (Scope.ID, Field.Name);
+                       }
                }
 
                protected class CapturedScope : CapturedVariable {
@@ -542,6 +579,11 @@ namespace Mono.CSharp {
                                this.ChildScope = child;
                        }
 
+                       public override void EmitSymbolInfo ()
+                       {
+                               SymbolWriter.DefineCapturedScope (Scope.ID, ChildScope.ID, Field.Name);
+                       }
+
                        public bool DefineMembers ()
                        {
                                Type type = ChildScope.IsGeneric ?
@@ -643,8 +685,11 @@ namespace Mono.CSharp {
 
                                        Report.Debug (128, "RESOLVE THE INIT #1", this,
                                                      captured_scope, fe);
-                               } else
+                               } else {
                                        scope_instance = ec.ig.DeclareLocal (type);
+                                       if (!Scope.RootScope.IsIterator)
+                                               SymbolWriter.DefineScopeVariable (Scope.ID, scope_instance);
+                               }
 
                                foreach (CapturedLocal local in Scope.locals.Values) {
                                        FieldExpr fe = (FieldExpr) Expression.MemberLookup (
@@ -958,6 +1003,13 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override void EmitType ()
+               {
+                       base.EmitType ();
+                       if (THIS != null)
+                               THIS.EmitSymbolInfo ();
+               }
+
                protected class TheCtor : Statement
                {
                        RootScopeInfo host;
@@ -1643,15 +1695,18 @@ namespace Mono.CSharp {
                {
                        public readonly AnonymousContainer AnonymousMethod;
                        public readonly ScopeInfo Scope;
+                       public readonly string RealName;
 
                        public AnonymousMethodMethod (AnonymousContainer am, ScopeInfo scope,
                                                      GenericMethod generic, TypeExpr return_type,
-                                                     int mod, MemberName name, Parameters parameters)
+                                                     int mod, string real_name, MemberName name,
+                                                     Parameters parameters)
                                : base (scope != null ? scope : am.Host,
                                        generic, return_type, mod | Modifiers.COMPILER_GENERATED, false, name, parameters, null)
                        {
                                this.AnonymousMethod = am;
                                this.Scope = scope;
+                               this.RealName = real_name;
 
                                if (scope != null) {
                                        scope.CheckMembersDefined ();
@@ -1670,6 +1725,11 @@ namespace Mono.CSharp {
                                aec.MethodIsStatic = Scope == null;
                                return aec;
                        }
+
+                       public override void EmitExtraSymbolInfo ()
+                       {
+                               SymbolWriter.SetRealMethodName (RealName);
+                       }
                }
        }
 
@@ -1789,9 +1849,14 @@ namespace Mono.CSharp {
 #endif
                                member_name = new MemberName (name, Location);
 
+                       string real_name = String.Format (
+                               "{0}~{1}{2}", mc.GetSignatureForError (), GetSignatureForError (),
+                               Parameters.GetSignatureForError ());
+
                        return new AnonymousMethodMethod (
                                this, scope, generic_method, new TypeExpression (ReturnType, Location),
-                               scope == null ? Modifiers.PRIVATE : Modifiers.INTERNAL, member_name, Parameters);
+                               scope == null ? Modifiers.PRIVATE : Modifiers.INTERNAL,
+                               real_name, member_name, Parameters);
                }
 
                public override Expression DoResolve (EmitContext ec)
index b0b620e48e07674685c3b9019e88b7ed52a07e83..7d1c93fc93741de4622d24f350376178e75236ae 100644 (file)
@@ -4200,6 +4200,9 @@ namespace Mono.CSharp {
                        }
                }
 
+               public virtual void EmitExtraSymbolInfo ()
+               { }
+
                #endregion
 
        }
@@ -5080,6 +5083,9 @@ namespace Mono.CSharp {
                        }
                }
 
+               void IMethodData.EmitExtraSymbolInfo ()
+               { }
+
                #endregion
        }
 
@@ -5106,6 +5112,7 @@ namespace Mono.CSharp {
                bool IsExcluded ();
                bool IsClsComplianceRequired ();
                void SetMemberIsUsed ();
+               void EmitExtraSymbolInfo ();
        }
 
        //
@@ -5388,7 +5395,7 @@ namespace Mono.CSharp {
 
                        if (GenericMethod != null)
                                GenericMethod.EmitAttributes ();
-                       
+
                        SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
 
                        //
@@ -5401,8 +5408,10 @@ namespace Mono.CSharp {
                        else
                                ec.EmitTopBlock (method, block);
 
-                       if (source != null)
+                       if (source != null) {
+                               method.EmitExtraSymbolInfo ();
                                source.CloseMethod ();
+                       }
                }
 
                void EmitDestructor (EmitContext ec, ToplevelBlock block)
@@ -6355,6 +6364,8 @@ namespace Mono.CSharp {
                        get { throw new InvalidOperationException ("Unexpected attempt to get doc comment from " + this.GetType () + "."); }
                }
 
+               void IMethodData.EmitExtraSymbolInfo ()
+               { }
        }
 
        //
index 32e18518b13b39a3406c66e9add7e9ce37423280..5e49c5d687ff50b2ce9a375cc6414f940a3646f0 100644 (file)
@@ -285,7 +285,9 @@ namespace Mono.CSharp {
                        
                        InferReturnType = 1 << 9,
                        
-                       InCompoundAssignment = 1 << 10
+                       InCompoundAssignment = 1 << 10,
+
+                       OmitDebuggingInfo = 1 << 11
                }
 
                Flags flags;
@@ -592,6 +594,16 @@ namespace Mono.CSharp {
                        get { return current_flow_branching; }
                }
 
+               public bool OmitDebuggingInfo {
+                       get { return (flags & Flags.OmitDebuggingInfo) != 0; }
+                       set {
+                               if (value)
+                                       flags |= Flags.OmitDebuggingInfo;
+                               else
+                                       flags &= ~Flags.OmitDebuggingInfo;
+                       }
+               }
+
                // <summary>
                //   Starts a new code branching.  This inherits the state of all local
                //   variables and parameters from the current branching.
@@ -844,7 +856,7 @@ namespace Mono.CSharp {
                /// </summary>
                public void Mark (Location loc, bool check_file)
                {
-                       if (!SymbolWriter.HasSymbolWriter || loc.IsNull)
+                       if (!SymbolWriter.HasSymbolWriter || OmitDebuggingInfo || loc.IsNull)
                                return;
 
                        if (check_file && (CurrentFile != loc.File))
index 04ebc2e28f672efe2e9bb38651bba6171583b222..5420b693d425617aeb60f20c1499f0f31f76b093 100644 (file)
@@ -671,10 +671,16 @@ namespace Mono.CSharp {
                        resume_points.Add (entry_point);
                        entry_point.Define (ig);
 
+                       SymbolWriter.StartIteratorBody (ec.ig);
+
                        original_block.Emit (ec);
 
+                       SymbolWriter.EndIteratorBody (ec.ig);
+
                        EmitYieldBreak (ig);
 
+                       SymbolWriter.StartIteratorDispatcher (ec.ig);
+
                        ig.MarkLabel (dispatcher);
 
                        Label [] labels = new Label [resume_points.Count];
@@ -685,8 +691,12 @@ namespace Mono.CSharp {
                        ig.Emit (OpCodes.Ldfld, IteratorHost.PC.FieldBuilder);
                        ig.Emit (OpCodes.Switch, labels);
 
+                       SymbolWriter.EndIteratorDispatcher (ec.ig);
+
                        Label end = ig.DefineLabel ();
 
+                       SymbolWriter.StartIteratorDispatcher (ec.ig);
+
                        ig.MarkLabel (move_next_error);
                        ig.Emit (OpCodes.Ldc_I4_0); 
                        ig.Emit (OpCodes.Stloc, retval);
@@ -697,6 +707,8 @@ namespace Mono.CSharp {
                        ig.Emit (OpCodes.Stloc, retval);
                        ig.Emit (OpCodes.Leave, end);
 
+                       SymbolWriter.EndIteratorDispatcher (ec.ig);
+
                        ig.BeginFaultBlock ();
 
                        ig.Emit (OpCodes.Ldarg_0);
@@ -938,11 +950,14 @@ namespace Mono.CSharp {
                {
                        Report.Debug (128, "CREATE METHOD HOST", this, IteratorHost);
 
+                       MemberCore mc = ec.ResolveContext as MemberCore;
+
                        IteratorHost.CaptureScopes ();
 
                        return new AnonymousMethodMethod (
                                this, RootScope, null, TypeManager.system_boolean_expr,
-                               Modifiers.PUBLIC, new MemberName ("MoveNext", Location),
+                               Modifiers.PUBLIC, mc.GetSignatureForError (),
+                               new MemberName ("MoveNext", Location),
                                Parameters.EmptyReadOnlyParameters);
                }
 
index ec5d267ee3a5482a3713f8ac01552708bb012bd4..9a3121ecae27fc9f2cd6ecef0fde5f0eaae55588 100644 (file)
@@ -540,6 +540,7 @@ namespace Mono.CSharp {
                                Statement.Emit (ec);
                        
                                ig.MarkLabel (ec.LoopBegin);
+                               ec.Mark (loc, true);
 
                                expr.EmitBranchable (ec, while_loop, true);
                                
@@ -550,6 +551,11 @@ namespace Mono.CSharp {
                        ec.LoopEnd = old_end;
                }
 
+               public override void Emit (EmitContext ec)
+               {
+                       DoEmit (ec);
+               }
+
                protected override void CloneTo (CloneContext clonectx, Statement t)
                {
                        While target = (While) t;
@@ -1287,7 +1293,7 @@ namespace Mono.CSharp {
                public void EmitSymbolInfo (EmitContext ec, string name)
                {
                        if (builder != null)
-                               ec.DefineLocalVariable (name, builder);
+                               ec.DefineLocalVariable (Name, builder);
                }
 
                public bool IsThisAssigned (EmitContext ec)
@@ -2311,38 +2317,57 @@ namespace Mono.CSharp {
                        ec.CurrentBlock = this;
 
                        bool emit_debug_info = SymbolWriter.HasSymbolWriter;
-                       bool is_lexical_block = this == Explicit && Parent != null;
+                       bool is_lexical_block = (this == Explicit) && (Parent != null) &&
+                               ((flags & Flags.IsIterator) == 0);
+
+                       bool omit_debug_info = ec.OmitDebuggingInfo;
 
                        if (emit_debug_info) {
                                if (is_lexical_block)
                                        ec.BeginScope ();
                        }
-                       ec.Mark (StartLocation, true);
-                       if (scope_init != null)
+
+                       if ((scope_init != null) || (scope_initializers != null))
+                               SymbolWriter.OpenCompilerGeneratedBlock (ec.ig);
+
+                       if (scope_init != null) {
+                               ec.OmitDebuggingInfo = true;
                                scope_init.EmitStatement (ec);
+                               ec.OmitDebuggingInfo = omit_debug_info;
+                       }
                        if (scope_initializers != null) {
+                               ec.OmitDebuggingInfo = true;
                                foreach (StatementExpression s in scope_initializers)
                                        s.Emit (ec);
+                               ec.OmitDebuggingInfo = omit_debug_info;
                        }
 
+                       if ((scope_init != null) || (scope_initializers != null))
+                               SymbolWriter.CloseCompilerGeneratedBlock (ec.ig);
+
+                       ec.Mark (StartLocation, true);
                        DoEmit (ec);
-                       ec.Mark (EndLocation, true); 
 
                        if (emit_debug_info) {
+                               EmitSymbolInfo (ec);
+
                                if (is_lexical_block)
                                        ec.EndScope ();
+                       }
 
-                               if (variables != null) {
-                                       foreach (DictionaryEntry de in variables) {
-                                               string name = (string) de.Key;
-                                               LocalInfo vi = (LocalInfo) de.Value;
+                       ec.CurrentBlock = prev_block;
+               }
 
-                                               vi.EmitSymbolInfo (ec, name);
-                                       }
+               protected virtual void EmitSymbolInfo (EmitContext ec)
+               {
+                       if (variables != null) {
+                               foreach (DictionaryEntry de in variables) {
+                                       string name = (string) de.Key;
+                                       LocalInfo vi = (LocalInfo) de.Value;
+
+                                       vi.EmitSymbolInfo (ec, name);
                                }
                        }
-
-                       ec.CurrentBlock = prev_block;
                }
 
                public override string ToString ()
@@ -2400,6 +2425,10 @@ namespace Mono.CSharp {
                        this.Explicit = this;
                }
 
+               public bool IsIterator {
+                       get { return (flags & Flags.IsIterator) != 0; }
+               }
+
                HybridDictionary known_variables;
 
                // <summary>
@@ -2474,10 +2503,6 @@ namespace Mono.CSharp {
                        set { flags |= Flags.HasVarargs; }
                }
 
-               public bool IsIterator {
-                       get { return (flags & Flags.IsIterator) != 0; }
-               }
-
                //
                // The parameters for the block.
                //
@@ -2830,11 +2855,19 @@ namespace Mono.CSharp {
                        parameters.ResolveVariable (this);
                }
 
+               protected override void EmitSymbolInfo (EmitContext ec)
+               {
+                       if ((AnonymousContainer != null) && (AnonymousContainer.Scope != null))
+                               SymbolWriter.DefineScopeVariable (AnonymousContainer.Scope.ID);
+
+                       base.EmitSymbolInfo (ec);
+               }
+
                public void MakeIterator (Iterator iterator)
                {
                        flags |= Flags.IsIterator;
 
-                       Block block = new ExplicitBlock (this, StartLocation, EndLocation);
+                       Block block = new ExplicitBlock (this, flags, StartLocation, EndLocation);
                        foreach (Statement stmt in statements)
                                block.AddStatement (stmt);
                        statements.Clear ();