2003-09-20 <cesar@ciencias.unam.mx>
authorCésar Natarén <cesar@mono-cvs.ximian.com>
Sun, 21 Sep 2003 00:44:08 +0000 (00:44 -0000)
committerCésar Natarén <cesar@mono-cvs.ximian.com>
Sun, 21 Sep 2003 00:44:08 +0000 (00:44 -0000)
* jscript-lexer-parser.g: Build ast for FunctionExpression.

* JSObject.cs: we don't throw NotImplementedException anymore,
this let us use FunctionExpression to build the ast.

* FunctionExpression.cs: Added a FunctionObject as field, a
default constructor.

* FunctionObject.cs: Added default constructor.

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

mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionExpression.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionObject.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/JSObject.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/JScriptParser.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/jscript-lexer-parser.g

index 49ded9ab82d8519aca35aef2b776fcfa9a0ef3d0..3b3a997f8bd8dedda2b745af218b13af5d7989c0 100644 (file)
@@ -1,5 +1,15 @@
 2003-09-20    <cesar@ciencias.unam.mx>
 
+       * jscript-lexer-parser.g: Build ast for FunctionExpression.
+
+       * JSObject.cs: we don't throw NotImplementedException anymore,
+       this let us use FunctionExpression to build the ast.
+
+       * FunctionExpression.cs: Added a FunctionObject as field, a
+       default constructor.
+
+       * FunctionObject.cs: Added default constructor.
+
        * driver.cs: Deleted the Jsc class. We are not generating code
        now. I'm moving to provide something like mcs's EmitContext
        instead of the CodeGenerator class having the Reflection.Emit
index 06ebf456cf2323ce89f0701f4eccca29470a04fe..7d37c659cf7a029260385ebf6bf697adf451abaf 100644 (file)
@@ -12,6 +12,13 @@ namespace Microsoft.JScript.Tmp {
 
        public class FunctionExpression : AST {
 
+               internal FunctionObject Function;
+
+               internal FunctionExpression ()
+               {
+                       Function = new FunctionObject ();
+               }
+
                public static FunctionObject JScriptFunctionExpression (RuntimeTypeHandle handle, string name,
                                                                        string methodName, string [] formalParams,
                                                                        JSLocalField [] fields)
index df01cfb86455f42b90d3b2c2ccf3df63d573894c..57b392871589bd88a37b1a8be1a9c01996dbc446 100644 (file)
@@ -7,17 +7,23 @@
 // (C) 2003, Cesar Octavio Lopez Nataren, <cesar@ciencias.unam.mx>
 //
 
-namespace Microsoft.JScript.Tmp
-{
-       using System;
+using System;
+
+namespace Microsoft.JScript.Tmp {
+
+       public class FunctionObject : ScriptFunction {
 
-       public class FunctionObject : ScriptFunction
-       {
                internal string Name;
                internal string ReturnType;
                internal FormalParameterList Params;
                internal Block Body;
            
+               internal FunctionObject ()
+               {
+                       Params = new FormalParameterList ();
+                       Body = new Block ();
+               }
+
                public override string ToString ()
                {
                        throw new NotImplementedException ();
index 15655b4f604ed6430020ff5566a1cdcbf0d2efaf..f38628a54d7ae8e4a31aa229df2be32c6cc9d781 100644 (file)
@@ -16,9 +16,7 @@ namespace Microsoft.JScript.Tmp
        public class JSObject : ScriptObject, IEnumerable, IExpando
        {
                public JSObject ()
-               {
-                       throw new NotImplementedException ();
-               }
+               {}
 
                public FieldInfo AddField (string name)
                {
@@ -65,4 +63,4 @@ namespace Microsoft.JScript.Tmp
                        throw new NotImplementedException ();
                }
        }
-}
\ No newline at end of file
+}
index 56d38a7aa8f799a95fd431e61ab918390124e450..23bf870ea7ab3a7fe69bc1f5f7f13ee064826c93 100644 (file)
@@ -4417,9 +4417,12 @@ _loop147_breakloop:                              ;
                }\r
        }\r
        \r
-       public void function_expression() //throws RecognitionException, TokenStreamException\r
+       public FunctionExpression  function_expression() //throws RecognitionException, TokenStreamException\r
 {\r
+               FunctionExpression fe;\r
                \r
+               Token  id = null;\r
+               fe = new FunctionExpression ();\r
                \r
                try {      // for error handling\r
                        match(LITERAL_function);\r
@@ -4428,7 +4431,12 @@ _loop147_breakloop:                              ;
                                {\r
                                case IDENTIFIER:\r
                                {\r
+                                       id = LT(1);\r
                                        match(IDENTIFIER);\r
+                                       if (0==inputState.guessing)\r
+                                       {\r
+                                               fe.Function.Name = id.getText ();\r
+                                       }\r
                                        break;\r
                                }\r
                                case LPAREN:\r
@@ -4447,7 +4455,7 @@ _loop147_breakloop:                               ;
                                {\r
                                case IDENTIFIER:\r
                                {\r
-                                       formal_parameter_list(null);\r
+                                       formal_parameter_list(fe.Function.Params);\r
                                        break;\r
                                }\r
                                case RPAREN:\r
@@ -4462,7 +4470,7 @@ _loop147_breakloop:                               ;
                        }\r
                        match(RPAREN);\r
                        match(LBRACE);\r
-                       function_body(null);\r
+                       function_body(fe.Function.Body);\r
                        match(RBRACE);\r
                }\r
                catch (RecognitionException ex)\r
@@ -4478,6 +4486,7 @@ _loop147_breakloop:                               ;
                                throw;\r
                        }\r
                }\r
+               return fe;\r
        }\r
        \r
        public void argument_list() //throws RecognitionException, TokenStreamException\r
index 4427c66924f3bea7c7b5b2c4245ad51c98ce3074..df60606b301d1d46e0190f0fcff404d6b1f04522 100644 (file)
@@ -628,9 +628,13 @@ property_name
 expression: assignment_expression (COMMA  expression | ) ;
 
 
-function_expression
+function_expression returns [FunctionExpression fe]
+{ fe = new FunctionExpression (); }
     :
-       "function" (IDENTIFIER | ) LPAREN (formal_parameter_list [null] | ) RPAREN LBRACE function_body [null] RBRACE
+       "function" 
+       (id:IDENTIFIER { fe.Function.Name = id.getText (); } | ) 
+       LPAREN (formal_parameter_list [fe.Function.Params] | ) RPAREN 
+       LBRACE function_body [fe.Function.Body] RBRACE
     ;