Author: martin
Date: 2008-01-23 12:59:08 -0500 (Wed, 23 Jan 2008)
New Revision: 93679

Modified:
   branches/martin/debugger-terrania/debugger/ChangeLog
   
branches/martin/debugger-terrania/debugger/frontend/CSharpExpressionParser.jay
   branches/martin/debugger-terrania/debugger/frontend/CSharpTokenizer.cs
   branches/martin/debugger-terrania/debugger/frontend/Expression.cs
   
branches/martin/debugger-terrania/debugger/test/testsuite/TestSimpleGenerics.cs
Log:
2008-01-23  Martin Baulig  <[EMAIL PROTECTED]>

        Added `$parent (expr)' and `$parent+N (expr)' syntax.

        * frontend/CSharpExpressionParser.jay
        (PARENT): New token.
        (PARENT opt_parent_level OPAREN expression CPAREN): New rule.

        * frontend/CSharpTokenizer.cs: Add `$parent' => `Token.PARENT'.

        * frontend/Expression.cs
        (ParentExpression): New expression.

        * test/testsuite/TestSimpleGenerics.cs: Added tests.



Modified: branches/martin/debugger-terrania/debugger/ChangeLog
===================================================================
--- branches/martin/debugger-terrania/debugger/ChangeLog        2008-01-23 
17:48:06 UTC (rev 93678)
+++ branches/martin/debugger-terrania/debugger/ChangeLog        2008-01-23 
17:59:08 UTC (rev 93679)
@@ -1,5 +1,20 @@
 2008-01-23  Martin Baulig  <[EMAIL PROTECTED]>
 
+       Added `$parent (expr)' and `$parent+N (expr)' syntax.
+
+       * frontend/CSharpExpressionParser.jay
+       (PARENT): New token.
+       (PARENT opt_parent_level OPAREN expression CPAREN): New rule.
+
+       * frontend/CSharpTokenizer.cs: Add `$parent' => `Token.PARENT'.
+
+       * frontend/Expression.cs
+       (ParentExpression): New expression.
+
+       * test/testsuite/TestSimpleGenerics.cs: Added tests.
+
+2008-01-23  Martin Baulig  <[EMAIL PROTECTED]>
+
        * languages/mono/MonoSymbolFile.cs
        (MonoSymbolFile.GetMethodName): Include type parameters.
 

Modified: 
branches/martin/debugger-terrania/debugger/frontend/CSharpExpressionParser.jay
===================================================================
--- 
branches/martin/debugger-terrania/debugger/frontend/CSharpExpressionParser.jay  
    2008-01-23 17:48:06 UTC (rev 93678)
+++ 
branches/martin/debugger-terrania/debugger/frontend/CSharpExpressionParser.jay  
    2008-01-23 17:59:08 UTC (rev 93679)
@@ -42,7 +42,6 @@
 %token STRING
 %token HASH
 %token AT
-%token DOLLAR
 %token DOT
 %token DOTDOT
 %token NOT
@@ -87,6 +86,8 @@
 %token LOWER
 %token UPPER
 
+%token PARENT
+
 %token NEW
 %token THIS
 %token BASE
@@ -230,12 +231,29 @@
          {
                $$ = new ConditionalExpression ((Expression)$1, (Expression)$3, 
(Expression)$5);
          }
+       | PARENT opt_parent_level OPAREN expression CPAREN
+         {
+               $$ = new ParentExpression ((Expression) $4, (int) $2);
+         }
        | OPAREN expression CPAREN
          {
                $$ = $2;
          }
        ;
 
+opt_parent_level
+       : /* empty */
+         {
+               $$ = 0;
+         }
+       | PLUS INT
+         {
+               if ((int) $2 < 1)
+                       throw new ScriptingException ("syntax error");
+               $$ = (int) $2;
+         }
+       ;
+
 expression_list_0
        : /* empty */
          {

Modified: branches/martin/debugger-terrania/debugger/frontend/CSharpTokenizer.cs
===================================================================
--- branches/martin/debugger-terrania/debugger/frontend/CSharpTokenizer.cs      
2008-01-23 17:48:06 UTC (rev 93678)
+++ branches/martin/debugger-terrania/debugger/frontend/CSharpTokenizer.cs      
2008-01-23 17:59:08 UTC (rev 93679)
@@ -71,6 +71,7 @@
                        keywords.Add ("True", Token.TRUE);
                        keywords.Add ("False", Token.FALSE);
                        keywords.Add ("null", Token.NULL);
+                       keywords.Add ("@parent", Token.PARENT);
                }
 
                public string error {
@@ -576,12 +577,26 @@
                                        return ReadDigit ((char)c);
                                }
 
-                               if (c == '#')
+                               if (c == '$') {
+                                       id_builder.Length = 0;
+                                       
+                                       while ((c = PeekChar ()) != -1) {
+                                               if (Char.IsLetterOrDigit 
((char)c) || c == '_') {
+                                                       id_builder.Append 
((char)GetChar ());
+                                                       col++;
+                                               } else 
+                                                       break;
+                                       }
+
+                                       string ids = id_builder.ToString ();
+                                       if (ids == "parent")
+                                               return Token.PARENT;
+                                       else
+                                               throw new ScriptingException 
("Unknown #-expression");
+                               } else if (c == '@')
+                                       return Token.AT;
+                               else if (c == '#')
                                        return Token.HASH;
-                               else if (c == '@')
-                                       return Token.AT;
-                               else if (c == '$')
-                                       return Token.DOLLAR;
                                else if (c == '.') {
                                        if (Char.IsDigit ((char)PeekChar())) {
                                                putback(c);

Modified: branches/martin/debugger-terrania/debugger/frontend/Expression.cs
===================================================================
--- branches/martin/debugger-terrania/debugger/frontend/Expression.cs   
2008-01-23 17:48:06 UTC (rev 93678)
+++ branches/martin/debugger-terrania/debugger/frontend/Expression.cs   
2008-01-23 17:59:08 UTC (rev 93679)
@@ -3121,4 +3121,56 @@
                        return obj;
                }
        }
+
+       public class ParentExpression : Expression
+       {
+               Expression expr;
+               int level;
+               string name;
+
+               public ParentExpression (Expression expr, int level)
+               {
+                       this.expr = expr;
+                       this.level = level;
+
+                       if (level > 0)
+                               name = String.Format ("$parent+{0} ({1})", 
level, expr.Name);
+                       else
+                               name = String.Format ("$parent ({0})", 
expr.Name);
+               }
+
+               public override string Name {
+                       get { return name; }
+               }
+
+               protected override Expression DoResolve (ScriptingContext 
context)
+               {
+                       expr = expr.Resolve (context);
+                       if (expr == null)
+                               return null;
+
+                       resolved = true;
+                       return this;
+               }
+
+               protected override TargetObject DoEvaluateObject 
(ScriptingContext context)
+               {
+                       TargetVariable var = expr.EvaluateVariable (context);
+                       if (var == null)
+                               return null;
+
+                       TargetObject obj = var.GetObject (context.CurrentFrame);
+                       if (obj == null)
+                               return null;
+
+                       TargetStructObject sobj = (TargetStructObject) obj;
+                       for (int i = 0; i <= level; i++) {
+                               sobj = sobj.GetParentObject 
(context.CurrentThread);
+                               if (sobj == null)
+                                       return null;
+                       }
+
+                       return sobj;
+               }
+       }
 }

Modified: 
branches/martin/debugger-terrania/debugger/test/testsuite/TestSimpleGenerics.cs
===================================================================
--- 
branches/martin/debugger-terrania/debugger/test/testsuite/TestSimpleGenerics.cs 
    2008-01-23 17:48:06 UTC (rev 93678)
+++ 
branches/martin/debugger-terrania/debugger/test/testsuite/TestSimpleGenerics.cs 
    2008-01-23 17:59:08 UTC (rev 93679)
@@ -44,6 +44,7 @@
                        AssertStopped (thread, "X.Main()", LineMain + 1);
 
                        AssertPrint (thread, "foo", "(Foo`1<int>) { Data = 5 
}");
+                       AssertPrint (thread, "$parent (foo)", "(System.Object) 
{ }");
                        AssertType (thread, "foo",
                                    "class Foo`1<int> = Foo`1<T> : 
System.Object\n" +
                                    "{\n   T Data;\n   void Hello ();\n   .ctor 
(T);\n}");
@@ -61,8 +62,12 @@
                        AssertHitBreakpoint (thread, bpt_main_2, "X.Main()", 
LineMain2);
 
                        AssertPrint (thread, "bar", "(Bar`1<int>) { 
<Foo`1<int>> = { Data = 5 } }");
+                       AssertPrint (thread, "$parent (bar)", "(Foo`1<int>) { 
Data = 5 }");
                        AssertType (thread, "bar",
                                    "class Bar`1<int> = Bar`1<U> : 
Foo`1<U>\n{\n   .ctor (U);\n}");
+                       AssertType (thread, "$parent (bar)",
+                                   "class Foo`1<int> = Foo`1<T> : 
System.Object\n" +
+                                   "{\n   T Data;\n   void Hello ();\n   .ctor 
(T);\n}");
 
                        AssertExecute ("step");
 
@@ -78,6 +83,10 @@
 
                        AssertPrintRegex (thread, DisplayFormat.Object, "baz",
                                          @"\(Baz`1<int>\) { 
<Foo`1<Hello`1<int>>> = { Data = \(Hello`1<int>\) 0x[0-9a-f]+ } }");
+                       AssertPrintRegex (thread, DisplayFormat.Object, 
"$parent (baz)",
+                                         @"\(Foo`1<Hello`1<int>>\) { Data = 
\(Hello`1<int>\) 0x[0-9a-f]+ }");
+                       AssertPrint (thread, "$parent+1 (baz)", 
"(System.Object) { }");
+
                        AssertType (thread, "baz",
                                    "class Baz`1<int> = Baz`1<U> : 
Foo`1<Hello`1<U>>\n{\n   .ctor (U);\n}");
 
@@ -87,9 +96,13 @@
                        AssertHitBreakpoint (thread, bpt_main_4, "X.Main()", 
LineMain4);
 
                        AssertPrint (thread, "test", "(Test) { <Foo`1<int>> = { 
Data = 9 } }");
+                       AssertPrint (thread, "$parent (test)", "(Foo`1<int>) { 
Data = 9 }");
                        AssertType (thread, "test",
                                    "class Test : Foo`1<int>\n{\n   static void 
Hello`1 (T);\n" +
                                    "   .ctor ();\n}");
+                       AssertType (thread, "$parent (test)",
+                                   "class Foo`1<int> = Foo`1<T> : 
System.Object\n" +
+                                   "{\n   T Data;\n   void Hello ();\n   .ctor 
(T);\n}");
 
                        AssertExecute ("continue");
                        AssertTargetOutput ("9");

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to