Ejemplo n.º 1
0
 public LambdaExpr(Parameter[] parameters, Stmt body)
 {
     _function = new FunctionDefinition(null, parameters, body);
 }
Ejemplo n.º 2
0
 public override void PostWalk(FunctionDefinition node)
 {
     Debug.Assert(_currentFunc == node);
     Debug.Assert(_currentScope == node);
     PopScope();
 }
Ejemplo n.º 3
0
 internal LambdaExpr(FunctionDefinition function)
 {
     _function = function;
 }
Ejemplo n.º 4
0
 private void PopScope()
 {
     _scopes.Add(_currentScope);
     _currentScope = _currentScope.Parent;
     _finallyCount.RemoveAt(_finallyCount.Count - 1);
     if (_currentScope is FunctionDefinition)
         _currentFunc = (FunctionDefinition)_currentScope;
 }
Ejemplo n.º 5
0
        public override bool Walk(FunctionDefinition node)
        {
            if (!node.IsLambda)
                node.TotemVariable = DefineVariable(node.Name);

            foreach (Parameter p in node.Parameters)
                if (p.DefaultValue != null)
                    p.DefaultValue.Walk(this);

            PushScope(node);

            foreach (Parameter p in node.Parameters)
                p.Walk(_parameter);

            node.Body.Walk(this);
            return false;
        }
Ejemplo n.º 6
0
		public virtual void PostWalk(FunctionDefinition node) { }
Ejemplo n.º 7
0
 private void PushScope(ScopeStmt node)
 {
     node.Parent = _currentScope;
     _currentScope = node;
     _finallyCount.Add(0);
     if (_currentScope is FunctionDefinition)
         _currentFunc = (FunctionDefinition)_currentScope;
 }
Ejemplo n.º 8
0
		public override void PostWalk(FunctionDefinition node) { }
Ejemplo n.º 9
0
		// FunctionDefinition
		public virtual bool Walk(FunctionDefinition node) { return true; }
Ejemplo n.º 10
0
		// FunctionDefinition
		public override bool Walk(FunctionDefinition node) { return false; }
Ejemplo n.º 11
0
        private Stmt ParseFuncDeclaration(bool requireName = true)
        {
            Eat(TokenType.KeywordFunc);
            int gstart = GetStart();
            string name = null;
            if (!PeekToken(TokenType.Name) && requireName)
            {
                ReportSyntaxError(gstart, GetEnd(), "Function has no name.");
                return null;
            }
            else if (PeekToken(TokenType.Name))
            {
                NameToken nt = (NameToken)NextToken();
                name = nt.Name;
            }

            Eat(TokenType.LeftParenthesis);

            int lStart = GetStart(),
                lEnd = GetEnd(),
                grouping = _tokenizer.GroupingLevel;

            Parameter[] parameters = ParseVarArgsList();
            FunctionDefinition ret;
            if (parameters == null)
            {
                // error in parameters
                ret = new FunctionDefinition(name, new Parameter[0]);
                ret.SetLoc(_globalParent, gstart, lEnd);
                return ret;
            }

            int rStart = GetStart(),
                rEnd = GetEnd();

            ret = new FunctionDefinition(name, parameters);
            PushFunction(ret);

            Stmt body = ParseFuncBody();
            FunctionDefinition ret2 = PopFunction();
            Debug.Assert(ret == ret2);

            ret.Body = body;

            if (_sink != null)
            {
                _sink.MatchPair(
                    new SourceSpan(_tokenizer.IndexToLocation(lStart), _tokenizer.IndexToLocation(lEnd)),
                    new SourceSpan(_tokenizer.IndexToLocation(rStart), _tokenizer.IndexToLocation(rEnd)),
                    grouping
                );
            }

            ret.SetLoc(_globalParent, gstart, GetEnd());

            return ret;
        }
Ejemplo n.º 12
0
 private void PushFunction(FunctionDefinition function)
 {
     if (_functions == null)
     {
         _functions = new Stack<FunctionDefinition>();
     }
     _functions.Push(function);
 }
Ejemplo n.º 13
0
        private LambdaExpr ParseLambdaBody(int startPosition, Parameter[] parameters)
        {
            Expr exp;
            LambdaExpr ret;
            Stmt st;
            if (PeekToken(TokenType.LeftBrace))
            {
                var inFinally = _inFinally;
                var inLoop = _inLoop;
                var return_ = _return;
                var isGenerator = _isGenerator;
                var isAsync = _isAsync;
                _inLoop = false;
                _inFinally = false;
                _return = false;
                _isGenerator = false;
                _isAsync = false;
                FunctionDefinition fnDef = new FunctionDefinition(null, parameters);
                PushFunction(fnDef);

                st = ParseBlock();

                FunctionDefinition fnDef2 = PopFunction();
                Debug.Assert(fnDef == fnDef2);

                fnDef.Body = st;

                ret = new LambdaExpr(fnDef);

                _inLoop = inLoop;
                _inFinally = inFinally;
                _return = return_;
                _isGenerator = isGenerator;
                _isAsync = isAsync;
            }
            else
            {
                exp = ParseExpr();
                st = new ReturnStmt(exp);
                st.SetLoc(_globalParent, exp.IndexSpan);

                ret = new LambdaExpr(parameters, st);
            }

            ret.SetLoc(_globalParent, startPosition, GetEnd());
            return ret;
        }
Ejemplo n.º 14
0
 public override bool Walk(FunctionDefinition node)
 {
     UpdateLoops(node);
     return base.Walk(node);
 }