Example #1
0
        public override IAstNode VisitFunctionDefinition(FunctionDefinitionContext context)
        {
            BeginFunctionDefinition( );

            var sig = ( Prototype )context.Signature.Accept(this);

            foreach (var param in sig.Parameters)
            {
                Push(param);
            }

            var body = ( IExpression )context.BodyExpression.Accept(this);

            var retVal = new FunctionDefinition(context.GetSourceSpan( )
                                                , sig
                                                , body
                                                , LocalVariables.ToImmutableArray( )
                                                );

            // only add valid definitions to the runtime state.
            var errors = retVal.CollectErrors( );

            if (errors.Count == 0)
            {
                RuntimeState.FunctionDefinitions.AddOrReplaceItem(retVal);
            }
            else
            {
                // remove the prototype implicitly added for this definition
                // as the definition has errors
                RuntimeState.FunctionDeclarations.Remove(sig);
            }
            return(retVal);
        }
Example #2
0
        public override IAstNode VisitFunctionDefinition([NotNull] FunctionDefinitionContext context)
        {
            BeginFunctionDefinition( );

            var sig = ( Prototype )context.Signature.Accept(this);

            foreach (var param in sig.Parameters)
            {
                Push(param);
            }

            var body = ( IExpression )context.BodyExpression.Accept(this);

            var retVal = new FunctionDefinition(context.GetSourceSpan( )
                                                , sig
                                                , body
                                                , LocalVariables.ToImmutableArray( )
                                                );

            RuntimeState.FunctionDefinitions.AddOrReplaceItem(retVal);
            return(retVal);
        }