public dynamic Visit(ReturnStm stm) { var node = new TreeNode("ReturnStm") { Tag = stm.Node }; if (stm.ReturnExpression != null) { node.Nodes.Add(new TreeNode("ReturnExpr") { Nodes = { Visit((dynamic)stm.ReturnExpression) } }); } return(node); }
public dynamic Visit(ReturnStm stm) { var type = stm.ReturnExpression.GetExprType(); if (type == SymbolType.Void || type == SymbolType.Unknown) { _codeGen.Return(); } else { var operand = Visit((dynamic)stm.ReturnExpression); _codeGen.Return(operand); } return(null); }
/// <summary> /// Rule: ReturnStm -> RETURN (Expr)? ; /// </summary> protected override object EvalReturnStm(ParseTree tree, params object[] paramlist) { var returnStm = new ReturnStm { Node = this }; var exprNode = GetNode(TokenType.Expr); var returnType = SymbolType.Void; var funcImpl = AstCreator.FuncImplementation.Peek(); if (exprNode != null) { var expr = (ExpressionBase)exprNode.Eval(tree); returnType = expr.GetExprType(); returnStm.ReturnExpression = expr; } if (funcImpl.ReturnType != SymbolType.Unknown && funcImpl.ReturnType != returnType) { throw new ParseException("Возвращаемые значения должны быть одинакового типа", GetNode(TokenType.RETURN)); } AstCreator.FuncImplementation.Peek().ReturnType = returnType; return(returnStm); }
public dynamic Visit(ReturnStm stm) { stm.OrderNumber = _count; //Visit((dynamic)NextReturnStm()); return(null); }
public dynamic Visit(ReturnStm stm) { stm.ReturnExpression = (ExpressionBase)stm.ReturnExpression.Optimize(); return(stm); }