Example #1
0
 internal FunctionExpression(AST parent, string name,
                             FormalParameterList p,
                             string return_type, Block body, Location location)
     : base(parent, location)
 {
     func_obj = new FunctionObject(name, p, return_type, body, location);
 }
        internal override bool Resolve(Environment env)
        {
            set_function_type();
            env.BeginScope(String.Empty);
            lexical_depth = env.Depth(String.Empty);

            ((ICanModifyContext)func_obj).PopulateContext(env, String.Empty);

            FormalParameterList p = func_obj.parameters;

            if (p != null)
            {
                p.Resolve(env);
            }

            Block body = func_obj.body;

            if (body != null)
            {
                body.Resolve(env);
            }

            locals = env.CurrentLocals(String.Empty);
            env.EndScope(String.Empty);
            return(true);
        }
Example #3
0
        internal override bool Resolve(Environment env)
        {
            set_prefix();
            set_function_type();

            if (func_obj.name != null && func_obj.name != String.Empty)
            {
                env.Enter(String.Empty, Symbol.CreateSymbol(func_obj.name), this);
            }
            env.BeginScope(String.Empty);

            ((ICanModifyContext)func_obj).PopulateContext(env, String.Empty);

            FormalParameterList p = func_obj.parameters;

            if (p != null)
            {
                p.Resolve(env);
            }

            Block body = func_obj.body;

            if (body != null)
            {
                body.Resolve(env);
            }

            locals = env.CurrentLocals(String.Empty);
            env.EndScope(String.Empty);
            return(true);
        }
Example #4
0
		internal FunctionExpression (AST parent, string name, 
					     FormalParameterList p,
					     string return_type, Block body, Location location)
			: base (parent, location)
		{
			func_obj = new FunctionObject (name, p, return_type, body, location);
		}
Example #5
0
        internal FunctionObject(string name, FormalParameterList p, string ret_type, Block body, Location location)
        {
            this._prototype = ObjectConstructor.Ctr.ConstructObject();
            //
            // FIXME
            // 1) Must collect the attributes given.
            // 2) Check if they are semantically correct.
            // 3) Assign those values to 'attr'.
            //
            this.attr = MethodAttributes.Public | MethodAttributes.Static;

            this.name       = name;
            this.parameters = p;

            this.type_annot = ret_type;
            //
            // FIXME: Must check that return_type it's a valid type,
            // and assign that to 'return_type' field.
            //
            this.return_type = typeof(void);

            this.body     = body;
            this.location = location;
        }
Example #6
0
        internal FunctionObject(string name, FormalParameterList p, string ret_type, Block body, Location location)
        {
            this._prototype = ObjectConstructor.Ctr.ConstructObject ();
            //
            // FIXME
            // 1) Must collect the attributes given.
            // 2) Check if they are semantically correct.
            // 3) Assign those values to 'attr'.
            //
            this.attr = MethodAttributes.Public | MethodAttributes.Static;

            this.name = name;
            this.parameters = p;

            this.type_annot = ret_type;
            //
            // FIXME: Must check that return_type it's a valid type,
            // and assign that to 'return_type' field.
            //
            this.return_type = typeof (void);

            this.body = body;
            this.location = location;
        }
Example #7
0
        AST Function(AST parent, FunctionType ft)
        {
            FunctionType synthetic_type = ft;
            string name;
            AST member_expr = null;

            if (ts.MatchToken (Token.NAME)) {
                name = ts.GetString;
                if (!ts.MatchToken (Token.LP)) {
                    if (allow_member_expr_as_function_name) {
                        // Extension to ECMA: if 'function <name>' does not follow
                        // by '(', assume <name> starts memberExpr
                        // FIXME: is StringLiteral the correct AST to build?
                        decompiler.AddName (name);
                        AST member_expr_head = new StringLiteral (null, name,
                                      new Location (ts.SourceName, ts.LineNumber));
                        name = "";
                        member_expr = MemberExprTail (parent, false, member_expr_head);
                    }
                    MustMatchToken (Token.LP, "msg.no.paren.parms");
                }
            } else if (ts.MatchToken (Token.LP)) {
                // Anonymous function
                name = "";
            } else {
                name = "";
                if (allow_member_expr_as_function_name) {
                    // Note that memberExpr can not start with '(' like
                    // in function (1+2).toString(), because 'function (' already
                    // processed as anonymous function
                    member_expr = MemberExpr (parent, false);
                }
                MustMatchToken (Token.LP, "msg.no.paren.parms");
            }

            if (member_expr != null) {
                synthetic_type = FunctionType.Expression;
                decompiler.AddToken (Token.ASSIGN);
            }

            bool nested = InsideFunction;
            Function fn = CreateFunction (parent, synthetic_type, name);

            if (nested)
                fn.CheckThis = true;

            if (nested || nesting_of_with > 0) {
                // 1. Nested functions are not affected by the dynamic scope flag
                // as dynamic scope is already a parent of their scope.
                // 2. Functions defined under the with statement also immune to
                // this setup, in which case dynamic scope is ignored in favor
                // of with object.
                fn.IgnoreDynamicScope = true;
            }

            // FIXME: which is old version of Decompiler.MarkFunctionStart
            int functionSourceStart = decompiler.MarkFunctionStart ((int) synthetic_type);

            if (name != "")
                decompiler.AddName (name);

            int saved_nesting_of_with = nesting_of_with;
            nesting_of_with = 0;

            FormalParameterList _params = new FormalParameterList (new Location (ts.SourceName, ts.LineNumber));
            Block body;

            try {
                decompiler.AddToken (Token.LP);
                if (!ts.MatchToken (Token.RP)) {
                    bool first = true;
                    do {
                        if (!first)
                            decompiler.AddToken (Token.COMMA);
                        first = false;
                        MustMatchToken (Token.NAME, "msg.no.parm");
                        string s = ts.GetString;
                        _params.Add (s, String.Empty, new Location (ts.SourceName, ts.LineNumber));
                        decompiler.AddName (s);
                    } while (ts.MatchToken (Token.COMMA));
                    MustMatchToken (Token.RP, "msg.no.paren.after.parms");
                }
                decompiler.AddToken (Token.RP);

                MustMatchToken (Token.LC, "msg.no.brace.body");
                decompiler.AddEOL (Token.LC);
                body = ParseFunctionBody (fn);
                MustMatchToken (Token.RC, "msg.no.brace.after.body");

                decompiler.AddToken (Token.RC);
                decompiler.MarkFunctionEnd (functionSourceStart);

                fn.func_obj.source = decompiler.SourceToString (functionSourceStart);

                if (ft != FunctionType.Expression) {
                    CheckWellTerminatedFunction ();
                    if (member_expr == null)
                        decompiler.AddToken (Token.EOL);
                    else
                        decompiler.AddEOL (Token.SEMI);
                }
            } finally {
                nesting_of_with = saved_nesting_of_with;
            }

            fn.Init (body, _params);
            AST pn;

            if (member_expr == null) {
                // FIXME
                pn = fn;

                // FIXME, research about createExprStatementNoReturn
                if (ft == FunctionType.ExpressionStatement)
                    pn = null;
            } else {
                // FIXME
                pn = fn;
                Assign assign = new Assign (null, JSToken.Assign, new Location (ts.SourceName, ts.LineNumber));
                assign.Init (member_expr, pn, false);
                pn = assign;

            #if false
                // FIXME, research about createExprStatement
                if (ft != FunctionType.Expression)
                    ;
            #endif
            }
            return pn;
        }
Example #8
0
File: ast.cs Project: nickchal/pash
		internal void Init (Block body, FormalParameterList p)
		{
			func_obj.body = body;
			func_obj.parameters = p;
		}
Example #9
0
File: ast.cs Project: raj581/Marvin
 internal void Init(Block body, FormalParameterList p)
 {
     func_obj.body       = body;
     func_obj.parameters = p;
 }