Author: cesar
Date: 2005-09-02 21:57:17 -0400 (Fri, 02 Sep 2005)
New Revision: 49384

Modified:
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/CodeGenerator.cs
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/SemanticAnalizer.cs
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs
Log:
2005-09-02  Cesar Lopez Nataren  <[EMAIL PROTECTED]>

        * SemanticAnalyser.cs: Added IsDeletable, check if a property is
        in an object's constructor.
        * CodeGenerator.cs: Added JSToken.Delete to GetBoxType.
        * expression.cs: (Unary) Added field deletable. Take care of the
        case when the property that we are trying to delete is not
        deletable, we use late binding's method Delete for that. (Binary)
        Added property IsDeletable. (Args) Do not pop the values of
        arguments which implement Exp.

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog       
2005-09-02 23:27:49 UTC (rev 49383)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog       
2005-09-03 01:57:17 UTC (rev 49384)
@@ -1,3 +1,14 @@
+2005-09-02  Cesar Lopez Nataren  <[EMAIL PROTECTED]>
+
+       * SemanticAnalyser.cs: Added IsDeletable, check if a property is
+       in an object's constructor.
+       * CodeGenerator.cs: Added JSToken.Delete to GetBoxType.
+       * expression.cs: (Unary) Added field deletable. Take care of the
+       case when the property that we are trying to delete is not
+       deletable, we use late binding's method Delete for that. (Binary)
+       Added property IsDeletable. (Args) Do not pop the values of
+       arguments which implement Exp.
+
 2005-08-28  Florian Gross  <[EMAIL PROTECTED]>
 
        * Try.cs: Implemented JScriptExceptionValue

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/CodeGenerator.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/CodeGenerator.cs        
2005-09-02 23:27:49 UTC (rev 49383)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/CodeGenerator.cs        
2005-09-03 01:57:17 UTC (rev 49384)
@@ -607,7 +607,7 @@
                                    oper == JSToken.Increment || oper == 
JSToken.Decrement ||
                                    oper == JSToken.BitwiseNot)
                                        return GetBoxType (operand);
-                               else if (oper == JSToken.LogicalNot)
+                               else if (oper == JSToken.LogicalNot || oper == 
JSToken.Delete)
                                        return typeof (bool);
                        } else if (obj is Identifier) {
                                Identifier id = (Identifier) obj;

Modified: 
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/SemanticAnalizer.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/SemanticAnalizer.cs     
2005-09-02 23:27:49 UTC (rev 49383)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/SemanticAnalizer.cs     
2005-09-03 01:57:17 UTC (rev 49384)
@@ -350,5 +350,18 @@
                                        return true;
                        return false;
                }
+
+               internal static bool IsDeletable (Identifier left, Identifier 
right)
+               {
+                       Type ctr = SemanticAnalyser.map_to_ctr 
(left.name.Value);
+
+                       if (ctr != null) {
+                               if (right.name.Value == "prototype")
+                                       return false;
+                       }
+                       Console.WriteLine ("left = {0}...left.Type = {1} ... 
right = {2}...right.Type = {3}",
+                                  left, left.GetType (), right, right.GetType 
());
+                       throw new NotImplementedException ();
+               }
        }
 }

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs   
2005-09-02 23:27:49 UTC (rev 49383)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs   
2005-09-03 01:57:17 UTC (rev 49384)
@@ -50,6 +50,8 @@
        
        internal class Unary : UnaryOp {
 
+               private bool deletable = false;
+
                internal Unary (AST parent, JSToken oper, Location location)
                        : base (parent, location)
                {               
@@ -73,7 +75,12 @@
                {
                        bool r = false;                
 
-                       if (operand is Exp) {
+                       if (operand is Binary) {
+                               Binary bin = (Binary) operand;
+                               if (oper == JSToken.Delete && bin.AccessField)
+                                       this.deletable = bin.IsDeletable;
+                               bin.Resolve (context);
+                       } else if (operand is Exp) {
                                if (oper != JSToken.Increment && oper != 
JSToken.Decrement)
                                        r = ((Exp) operand).Resolve (context, 
no_effect);
                        } else 
@@ -111,9 +118,36 @@
 
                                Binary arg = operand as Binary;
                                if (arg != null) {
-                                       if (arg.op == JSToken.LeftBracket || 
arg.op == JSToken.AccessField) {
-                                               arg.left.Emit (ec);
-                                               arg.right.Emit (ec);
+                                       if (arg.op == JSToken.LeftBracket || 
arg.op == JSToken.AccessField ) {
+                                               if (deletable) {
+                                                       arg.left.Emit (ec);
+                                                       arg.right.Emit (ec);
+                                                       ig.Emit 
(OpCodes.Ldc_I4_1);
+                                                       ig.Emit (OpCodes.Call, 
typeof (Convert).GetMethod ("ToString",
+                                                                               
                           new Type [] { typeof (object), typeof (bool) }));
+                                                       ig.Emit (OpCodes.Call, 
typeof (LateBinding).GetMethod ("DeleteMember",
+                                                                               
                               new Type [] { typeof (object), typeof (string) 
}));
+                                               } else {
+                                                       Console.WriteLine 
("{0}({1},0) : warning: JS1164: '{2}' is not deletable",
+                                                                  
location.SourceName, location.LineNumber, arg.ToString ());
+
+                                                       if (arg.left is 
Identifier && arg.right is Identifier) {
+                                                               string _base = 
((Identifier) arg.left).name.Value;
+                                                               string property 
= ((Identifier) arg.right).name.Value;
+
+                                                               Type lb_type = 
typeof (LateBinding);
+                                                               LocalBuilder lb 
= ig.DeclareLocal (lb_type);
+                                                               
+                                                               ig.Emit 
(OpCodes.Ldstr, property);
+                                                               ig.Emit 
(OpCodes.Newobj, lb_type.GetConstructor (new Type [] { typeof (string) }));
+                                                               ig.Emit 
(OpCodes.Stloc, lb);
+                                                               ig.Emit 
(OpCodes.Ldloc, lb);
+                                                               ig.Emit 
(OpCodes.Dup);
+                                                               arg.left.Emit 
(ec);
+                                                               ig.Emit 
(OpCodes.Stfld, lb_type.GetField ("obj"));
+                                                               ig.Emit 
(OpCodes.Call, lb_type.GetMethod ("Delete"));
+                                                       }
+                                               }
                                        } else {
                                                Console.WriteLine 
("emit_unary_op: Delete: unknown operand type {0}", arg.op);
                                                throw new 
NotImplementedException ();
@@ -123,12 +157,9 @@
                                        throw new NotImplementedException ();
                                }
 
-                               ig.Emit (OpCodes.Ldc_I4_1);
-                               ig.Emit (OpCodes.Call, typeof 
(Convert).GetMethod ("ToString",
-                                       new Type [] { typeof (object), typeof 
(bool) }));
-                               ig.Emit (OpCodes.Call, typeof 
(LateBinding).GetMethod ("DeleteMember",
-                                       new Type [] { typeof (object), typeof 
(string) }));
-                               ig.Emit (OpCodes.Pop);
+
+                               if (no_effect)
+                                       ig.Emit (OpCodes.Pop);
                                break;
 
                        case JSToken.Plus:
@@ -215,10 +246,11 @@
                public override string ToString ()
                {
                        StringBuilder sb = new StringBuilder ();
-                       sb.Append (left.ToString () + " ");
+                       sb.Append (left.ToString ());
                        
-                       if (op != JSToken.None)
-                               sb.Append (op + " ");
+                       if (op == JSToken.AccessField)
+                               sb.Append (".");
+                       else sb.Append (op);
                        
                        if (right != null)
                                sb.Append (right.ToString ());
@@ -511,8 +543,8 @@
                        case JSToken.RightShift:
                        case JSToken.UnsignedRightShift:
                                ig.Emit (OpCodes.Call, typeof 
(BitwiseBinary).GetMethod ("EvaluateBitwiseBinary"));
-                                        break;
-                       }                       
+                               break;
+                       }
                }
 
                internal void emit_jumping_code (EmitContext ec)
@@ -588,6 +620,14 @@
                        ig.Emit (OpCodes.Stloc, local_builder);
                        ig.Emit (OpCodes.Ldloc, local_builder);
                }
+
+               internal bool IsDeletable {
+                       get {
+                               if (left is Identifier && right is Identifier)
+                                       return SemanticAnalyser.IsDeletable 
((Identifier) left, (Identifier) right);
+                               return false;
+                       }
+               }
        }
 
        internal class Conditional : Exp {
@@ -1626,6 +1666,8 @@
                        for (int i = 0; i < n; i++) {
                                tmp = (AST) elems [i];
                                if (tmp != null)
+                                       if (tmp is Exp)
+                                               r &= ((Exp) tmp).Resolve 
(context, false);
                                        r &= tmp.Resolve (context);
                        }
                        return r;

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

Reply via email to