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)); } }
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); //} }