// Возвращает ExpressionTree
        public override object VisitVariableInitializer([NotNull] DoshikParser.VariableInitializerContext context)
        {
            _compilationContext.SetParsingAntlrContext(context);

            var expressionCtx = context.expression();

            if (expressionCtx != null)
            {
                var expressionTree = ExpressionCreationVisitor.Apply(_compilationContext, _currentExpressionParent, expressionCtx);

                if (_declaringVariable.Type != expressionTree.RootExpression.ReturnOutputSlot.Type)
                {
                    throw _compilationContext.ThrowCompilationError("declaring variable type differs from initialization expression return type");
                }

                return(expressionTree);
            }
            else
            {
                throw _compilationContext.ThrowCompilationError("variables can only be initialized using expressions (no special initializer support yet)");
            }
        }
Пример #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DoshikParser.variableInitializer"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitVariableInitializer([NotNull] DoshikParser.VariableInitializerContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="DoshikParser.variableInitializer"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitVariableInitializer([NotNull] DoshikParser.VariableInitializerContext context)
 {
 }