示例#1
0
		// ReturnStmt
		public virtual bool Walk(ReturnStmt node) { return true; }
示例#2
0
		public virtual void PostWalk(ReturnStmt node) { }
示例#3
0
		// ReturnStmt
		public override bool Walk(ReturnStmt node) { return false; }
示例#4
0
		public override void PostWalk(ReturnStmt node) { }
示例#5
0
        private Stmt ParseReturnStmt()
        {
            Expr expr = null;
            Eat(TokenType.KeywordReturn);
            int start = GetStart();
            if (!MaybeEat(TokenType.Semicolon))
                expr = ParseExpr();
            EatSemiOrInteractiveEndOfFile();

            var ret = new ReturnStmt(expr);
            ret.SetLoc(_globalParent, start, GetEnd());
            return ret;
        }
示例#6
0
 internal TotemAst ParseTopExpression()
 {
     try
     {
         _globalParent = new TotemAst(false, _languageFeatures, false, _context);
         ReturnStmt ret = new ReturnStmt(ParseExpr());
         ret.SetLoc(_globalParent, 0, 0);
         return FinishParsing(ret);
     }
     catch (BadSourceException bse)
     {
         throw BadSourceError(bse);
     }
 }
示例#7
0
        private TotemAst ParseFileWorker(bool makeModule, bool returnValue)
        {
            _globalParent = new TotemAst(makeModule, _languageFeatures, false, _context);
            StartParsing();

            List<Stmt> l = new List<Stmt>();
            List<string> imports = new List<string>();

            // import-statements are only allowed in the start of the module
            while (PeekToken(TokenType.KeywordImport))
            {
                imports.Add(ParseImport());
            }
            _importAllowed = false;

            while (true)
            {
                if (MaybeEat(TokenType.EndOfFile)) break;
                if (MaybeEatNewLine()) continue;

                Stmt s = ParseStmt();
                l.Add(s);
            }


            Stmt[] stmts = l.ToArray();
            string[] imps = imports.ToArray();

            if (returnValue && stmts.Length > 0)
            {
                ExprStmt exprStmt = stmts[stmts.Length - 1] as ExprStmt;
                if (exprStmt != null)
                {
                    var retStmt = new ReturnStmt(exprStmt.Expr);
                    stmts[stmts.Length - 1] = retStmt;
                    retStmt.SetLoc(_globalParent, exprStmt.Expr.IndexSpan);
                }
            }

            BlockStmt ret = new BlockStmt(stmts);
            ret.SetLoc(_globalParent, 0, GetEnd());
            return FinishParsing(ret);
        }
示例#8
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;
        }
		// ReturnStmt
		public override bool Walk(ReturnStmt node)
		{
			node.Parent = _currentScope;
			if(_currentFunc != null) _currentFunc._hasReturn = true;

			return base.Walk(node);
		}