public override void ExitReturnStatement([NotNull] SBP.ReturnStatementContext context) { if (context.ChildCount == 2) { m_scopeStack.Peek().AddStatementCode(Expression.Return(m_currentProcedure.ReturnLabel)); return; } if (m_currentProcedure.ReturnType == null) { m_errors.SymanticError(context.Start.Line, context.Start.Column, false, "Return value missing."); return; } var stack = m_expressionData.PopStackLevel(); if (stack.Count == 0) { m_errors.InternalError(context.Start.Line, context.Start.Column, ""); return; } var exp = stack.Pop(); exp = this.ResolveForGetOperation(exp).NarrowGetValueType(); var code = exp.ExpressionCode; if (exp.IsError()) { code = Expression.Default(m_currentProcedure.ReturnType.Type); return; } // If container, get the value of the container. if (exp.ExpressionCode.Type.IsGenericType && exp.ExpressionCode.Type.GetGenericTypeDefinition() == typeof(IValueContainer <>)) { code = Expression.Call( code, code.Type.GetMethod("GetTypedValue"), Expression.Convert(Expression.Constant(null), typeof(Logging.ILogger))); } m_scopeStack.Peek().AddStatementCode(Expression.Return(m_currentProcedure.ReturnLabel, code)); }
public override void EnterReturnStatement([NotNull] SBP.ReturnStatementContext context) { this.AddEnterStatement(context); m_expressionData.PushStackLevel("Return Statement"); }