private static bool ReportError(IRuntimeCodeValidationErrorSink errorSink, SemanticNode node, string errorMessage)
        {
            if (errorSink == null)
            {
                return(false);
            }

            SourceLocation start = SourceLocation.Invalid;
            SourceLocation end   = SourceLocation.Invalid;

            if (node != null)
            {
                var tokens = node.GetTokens();
                if ((tokens != null) && tokens.Any())
                {
                    start = tokens.Min(t => t.StartPosition);
                    end   = tokens.Max(t => t.StopPosition);
                }
                foreach (var sn in node.GetChildNodes())
                {
                    tokens = sn.GetTokens();
                    if ((tokens != null) && tokens.Any())
                    {
                        start = start.Min(tokens.Min(t => t.StartPosition));
                        end   = end.Max(tokens.Max(t => t.StopPosition));
                    }
                }
            }

            return(RuntimeCompiledMethod.ReportError(errorSink, start, end, errorMessage));
        }
 private static bool ReportError(IRuntimeCodeValidationErrorSink errorSink, ErrorLocation errorLocation, string errorMessage)
 {
     if (errorLocation == null)
     {
         return(RuntimeCompiledMethod.ReportError(errorSink, SourceLocation.Invalid, SourceLocation.Invalid, errorMessage));
     }
     else
     {
         return(RuntimeCompiledMethod.ReportError(errorSink, errorLocation.Start, errorLocation.End, errorMessage));
     }
 }
        public bool Validate(SmalltalkNameScope globalNameScope, IRuntimeCodeValidationErrorSink errorSink)
        {
            return(RuntimeCompiledMethod.Validate(this.ParseTree, errorSink, () =>
            {
                Expression self = Expression.Parameter(typeof(object), "self");
                Expression executionContext = Expression.Parameter(typeof(ExecutionContext), "$executionContext");
                Expression[] args = new Expression[this.ParseTree.Arguments.Count];
                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = Expression.Parameter(typeof(object), String.Format("arg{0}", i + 1));
                }

                return this.GetExpression(self, executionContext, args, globalNameScope);
            }));
        }
        internal static bool Validate <TResult>(SemanticNode rootNode, IRuntimeCodeValidationErrorSink errorSink, Func <TResult> compileFunc)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException("rootNode");
            }
            if (compileFunc == null)
            {
                throw new ArgumentNullException("compileFunc");
            }

            try
            {
                TResult result = compileFunc();
                if (result == null)
                {
                    return(RuntimeCompiledMethod.ReportError(errorSink, rootNode, "Could not compile method"));
                }
                return(true);
            }
            catch (IronSmalltalk.ExpressionCompiler.Primitives.Exceptions.PrimitiveInvalidTypeException ex)
            {
                return(RuntimeCompiledMethod.ReportError(errorSink, ex.GetErrorLocation(), ex.Message));
            }
            catch (SemanticCodeGenerationException ex)
            {
                return(RuntimeCompiledMethod.ReportError(errorSink, ex.GetErrorLocation(), ex.Message));
            }
            catch (IronSmalltalk.Runtime.Internal.SmalltalkDefinitionException ex)
            {
                return(RuntimeCompiledMethod.ReportError(errorSink, rootNode, ex.Message));
            }
            catch (IronSmalltalk.Runtime.Internal.SmalltalkRuntimeException ex)
            {
                return(RuntimeCompiledMethod.ReportError(errorSink, rootNode, ex.Message));
            }
            //catch (Exception ex)
            //{
            //    return RuntimeCompiledMethod.ReportError(errorSink, rootNode, ex.Message);
            //}
        }
 public bool Validate(SmalltalkNameScope globalNameScope, IRuntimeCodeValidationErrorSink errorSink)
 {
     return(RuntimeCompiledMethod.Validate(this.ParseTree, errorSink, () => this.Compile(globalNameScope.Runtime, globalNameScope)));
 }