Ejemplo n.º 1
0
        /// <summary>
        /// 拿到异常之后进行后处理,如果处理后可以重编译,将再次编译
        /// </summary>
        /// <param name="errors"></param>
        /// <returns></returns>
        private bool CanRetryCompile(ImmutableArray <Diagnostic> errors)
        {
            if (CanRetry)
            {
                _retryCount += 1;
                if (_retryCount < RetryLimit)
                {
                    Dictionary <string, string> codeMappings = new Dictionary <string, string>();
                    foreach (var item in errors)
                    {
                        if (item.Location.SourceTree != null)
                        {
                            var sourceCode = item.Location.SourceTree.ToString();
                            if (!codeMappings.ContainsKey(sourceCode))
                            {
                                codeMappings[sourceCode] = sourceCode;
                            }
                            if (ErrorHandlers.ContainsKey(item.Id))
                            {
                                codeMappings[sourceCode] = ErrorHandlers[item.Id](item, Syntax, codeMappings[sourceCode]);
                            }
                        }
                    }

                    foreach (var item in codeMappings)
                    {
                        Syntax.Update(item.Key, item.Value);
                    }
                    return(true);
                }
            }
            Exceptions = NatashaException.GetCompileException(Compiler.AssemblyName, errors);
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 拿到异常之后进行后处理,如果处理后可以重编译,将再次编译
        /// </summary>
        /// <param name="errors"></param>
        /// <returns></returns>
        private bool CanRetryCompile(ImmutableArray <Diagnostic> errors)
        {
            Exceptions = NatashaException.GetCompileException(Compiler.AssemblyName, errors);
            Dictionary <string, string> codeMappings = new Dictionary <string, string>();

            foreach (var item in Exceptions)
            {
                if (item.Formatter != default)
                {
                    codeMappings[item.Formatter] = item.Formatter;
                    if (item.HasError)
                    {
                        foreach (var error in item.Diagnostics)
                        {
                            if (ErrorHandlers.ContainsKey(error.Id))
                            {
                                CanRetry = true;
                                ErrorHandlers[error.Id](item, error, Syntax, codeMappings);
                            }
                        }
                    }
                }
            }
            if (CanRetry)
            {
                CanRetry    = false;
                RetryCount += 1;
                if (RetryCount < RetryLimit)
                {
                    foreach (var item in codeMappings)
                    {
                        Syntax.Update(item.Key, item.Value);
                    }
                    return(true);
                }
            }
            return(false);
        }