Ejemplo n.º 1
0
        private static void _error <T>(ErrorToken <T> token, string source)
        {
            var col = token.ErrorResult.Remainder.Column;
            var lin = token.ErrorResult.Remainder.Line;
            var exp = token.ErrorResult.Expectations.First();
            var rem = token.ErrorResult.Remainder.Current;

            var nestedLine  = source.Split('\n')[lin - 1];
            var f**k        = getFromMiddle(nestedLine, col, nestedLine.Length - col, true);
            var startOffset = source.IndexOf(nestedLine, StringComparison.InvariantCultureIgnoreCase);
            var nameOffset  = (startOffset + col - 1);

            var doc2            = new StringDocument("", source);
            var highlightRegion = new SourceRegion(new SourceSpan(doc2, startOffset, nestedLine.Length));

            var focusRegion = new SourceRegion(
                new SourceSpan(doc2, nameOffset, f**k.Length));
            var title   = $"{token.ErrorResult.getWarningCode().To<string>().Pastel(Color.Orange)}";
            var message = $"character '{exp}' expected".Pastel(Color.Orange);

            string Render(MarkupNode node, params NodeRenderer[] extraRenderers)
Ejemplo n.º 2
0
        /// <summary>
        /// Returns mapping of method address to source code location.
        /// </summary>
        public static List <SourceRegion> GetSourceRegions(MethodData data)
        {
            var method  = data.Method;
            var regions = new List <SourceRegion>(data.LabelRegions.Count + 1);

            // Add method header
            if (method.Code.Count > 0)
            {
                var firstInstruction = method.Code[0];

                var region = new SourceRegion
                {
                    Address     = 0,
                    Length      = data.LabelRegions.Count > 0 ? data.LabelRegions[0].Start : 0,
                    StartLine   = firstInstruction.StartLine,
                    EndLine     = firstInstruction.EndLine,
                    StartColumn = firstInstruction.StartColumn,
                    EndColumn   = firstInstruction.EndColumn,
                    Filename    = firstInstruction.Document
                };
                if (region.IsValid)
                {
                    regions.Add(region);
                }
            }

            var startLine   = 0;
            var endLine     = 0;
            var startColumn = 0;
            var endColumn   = 0;
            var filename    = "";

            foreach (var labelRegion in data.LabelRegions)
            {
                foreach (var instruction in method.Code)
                {
                    // special case: the return label is always 0xFFFFF
                    var searchForLabel = labelRegion.Label;
                    if (labelRegion.Label == 0xFFFFF)
                    {
                        searchForLabel = method.Code.Last().Offset;
                    }

                    if (instruction.StartLine > 0)
                    {
                        startLine   = instruction.StartLine;
                        endLine     = instruction.EndLine;
                        startColumn = instruction.StartColumn;
                        endColumn   = instruction.EndColumn;
                        filename    = instruction.Document;
                    }

                    if (instruction.Offset != searchForLabel)
                    {
                        continue;
                    }

                    var region = new SourceRegion()
                    {
                        Address     = labelRegion.Start,
                        Length      = labelRegion.Length,
                        StartLine   = startLine,
                        EndLine     = endLine,
                        StartColumn = startColumn,
                        EndColumn   = endColumn,
                        Filename    = filename
                    };

                    if (region.IsValid)
                    {
                        regions.Add(region);
                    }
                }
            }

            return(regions);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns mapping of method address to source code location.
        /// </summary>
        public static List <SourceRegion> GetSourceRegions(MethodData methodData)
        {
            if (methodData.IsMethodImplementationReplaced && methodData.Symbol.IsExternalSymbol)
            {
                var regions = new List <SourceRegion>(1);

                var headerRegion = new SourceRegion
                {
                    Address     = (int)methodData.Symbol.VirtualAddress,
                    Length      = (int)methodData.Symbol.Size,
                    StartLine   = 0,
                    EndLine     = 0,
                    StartColumn = 0,
                    EndColumn   = 0,
                    Filename    = string.Empty
                };

                regions.Add(headerRegion);

                return(regions);
            }

            if (methodData.Method.HasImplementation &&
                methodData.HasCode &&
                !methodData.IsMethodImplementationReplaced &&
                !methodData.IsCompilerGenerated)
            {
                // Add method header
                var regions = new List <SourceRegion>(methodData.LabelRegions.Count + 1);

                var firstInstruction = methodData.Method.Code[0];

                var headerRegion = new SourceRegion
                {
                    Address     = 0,
                    Length      = methodData.LabelRegions.Count > 0 ? methodData.LabelRegions[0].Start : 0,
                    StartLine   = firstInstruction.StartLine,
                    EndLine     = firstInstruction.EndLine,
                    StartColumn = firstInstruction.StartColumn,
                    EndColumn   = firstInstruction.EndColumn,
                    Filename    = firstInstruction.Document
                };

                if (headerRegion.IsValid)
                {
                    regions.Add(headerRegion);
                }

                var startLine   = 0;
                var endLine     = 0;
                var startColumn = 0;
                var endColumn   = 0;
                var filename    = string.Empty;

                foreach (var labelRegion in methodData.LabelRegions)
                {
                    var code = methodData.Method.Code;

                    foreach (var instruction in code)
                    {
                        // special case: the return label is always 0xFFFFF
                        var searchForLabel = labelRegion.Label;

                        if (labelRegion.Label == 0xFFFFF)
                        {
                            searchForLabel = code.Last().Offset;
                        }

                        if (instruction.StartLine > 0)
                        {
                            startLine   = instruction.StartLine;
                            endLine     = instruction.EndLine;
                            startColumn = instruction.StartColumn;
                            endColumn   = instruction.EndColumn;
                            filename    = instruction.Document;
                        }

                        if (instruction.Offset != searchForLabel)
                        {
                            continue;
                        }

                        var region = new SourceRegion()
                        {
                            Address     = labelRegion.Start,
                            Length      = labelRegion.Length,
                            StartLine   = startLine,
                            EndLine     = endLine,
                            StartColumn = startColumn,
                            EndColumn   = endColumn,
                            Filename    = filename
                        };

                        if (region.IsValid)
                        {
                            regions.Add(region);
                        }
                    }
                }

                return(regions);
            }

            return(null);
        }