Esempio n. 1
0
        internal void DumpAll(ScanBuff buff, TextWriter wrtr)
        {
            int line = 1;
            int eNum = 0;
            int eLin = 0;
            int nxtC = (int)'\n';
            //
            //  Initialize the error group
            //
            int groupFirst  = 0;
            int currentCol  = 0;
            int currentLine = 0;

            //
            //  Reset the source file buffer to the start
            //
            buff.Pos = 0;
            wrtr.WriteLine("Error Summary --- ");
            //
            //  Initialize the error group
            //
            groupFirst  = 0;
            currentCol  = 0;
            currentLine = 0;
            //
            //  Now, for each error do
            //
            for (eNum = 0; eNum < errors.Count; eNum++)
            {
                eLin = errors[eNum].span.startLine;
                if (eLin > currentLine)
                {
                    //
                    // Spill all the waiting messages
                    //
                    if (currentCol > 0)
                    {
                        wrtr.WriteLine();
                        currentCol = 0;
                    }
                    for (int i = groupFirst; i < eNum; i++)
                    {
                        Error err = errors[i];
                        wrtr.Write((err.isWarn ? "Warning: " : "Error: "));
                        wrtr.Write(err.message);
                        wrtr.WriteLine();
                    }
                    currentLine = eLin;
                    groupFirst  = eNum;
                }
                //
                //  Skip lines up to *but not including* the error line
                //
                while (line < eLin)
                {
                    nxtC = buff.Read();
                    if (nxtC == (int)'\n')
                    {
                        line++;
                    }
                    else if (nxtC == ScanBuff.EndOfFile)
                    {
                        break;
                    }
                }
                //
                //  Emit the error line
                //
                if (line <= eLin)
                {
                    wrtr.Write((char)((eLin / 1000) % 10 + (int)'0'));
                    wrtr.Write((char)((eLin / 100) % 10 + (int)'0'));
                    wrtr.Write((char)((eLin / 10) % 10 + (int)'0'));
                    wrtr.Write((char)((eLin) % 10 + (int)'0'));
                    wrtr.Write(' ');
                    while (line <= eLin)
                    {
                        nxtC = buff.Read();
                        if (nxtC == (int)'\n')
                        {
                            line++;
                        }
                        else if (nxtC == ScanBuff.EndOfFile)
                        {
                            break;
                        }
                        wrtr.Write((char)nxtC);
                    }
                }
                //
                //  Now emit the error message(s)
                //
                if (errors[eNum].span.startColumn >= 0 && errors[eNum].span.startColumn < 75)
                {
                    if (currentCol == 0)
                    {
                        wrtr.Write("-----");
                    }
                    for (int i = currentCol; i < errors[eNum].span.startColumn; i++, currentCol++)
                    {
                        wrtr.Write('-');
                    }
                    for (; currentCol < errors[eNum].span.endColumn && currentCol < 75; currentCol++)
                    {
                        wrtr.Write('^');
                    }
                }
            }
            //
            //  Clean up after last message listing
            //  Spill all the waiting messages
            //
            if (currentCol > 0)
            {
                wrtr.WriteLine();
            }
            for (int i = groupFirst; i < errors.Count; i++)
            {
                Error err = errors[i];
                wrtr.Write((err.isWarn ? "Warning: " : "Error: "));
                wrtr.Write(errors[i].message);
                wrtr.WriteLine();
            }
        }
Esempio n. 2
0
        // -----------------------------------------------------
        //   Error Listfile Reporting Method
        // -----------------------------------------------------

        internal void MakeListing(ScanBuff buff, StreamWriter sWrtr, string name, string version)
        {
            int line = 1;
            int eNum = 0;
            int eLin = 0;

            int nxtC = (int)'\n';
            int groupFirst;
            int currentCol;
            int currentLine;

            //
            //  Errors are sorted by line number
            //
            errors = SortedErrorList();
            //
            //  Reset the source file buffer to the start
            //
            buff.Pos = 0;
            sWrtr.WriteLine();
            ListDivider(sWrtr);
            sWrtr.WriteLine("//  GPLEX error listing for lex source file <"
                            + name + ">");
            ListDivider(sWrtr);
            sWrtr.WriteLine("//  Version:  " + version);
            sWrtr.WriteLine("//  Machine:  " + Environment.MachineName);
            sWrtr.WriteLine("//  DateTime: " + DateTime.Now.ToString());
            sWrtr.WriteLine("//  UserName: "******"// Warning: " : "// Error: ");
                        string msg    = StringUtilities.MakeComment(3, prefix + err.message);
                        if (StringUtilities.MaxWidth(msg) > maxGroupWidth)
                        {
                            maxGroupWidth = StringUtilities.MaxWidth(msg);
                        }
                        sWrtr.Write(msg);
                        sWrtr.WriteLine();
                    }
                    if (groupFirst < eNum)
                    {
                        sWrtr.Write("// ");
                        Spaces(sWrtr, maxGroupWidth - 3);
                        sWrtr.WriteLine();
                    }
                    currentLine = eLin;
                    groupFirst  = eNum;
                }
                //
                //  Emit lines up to *and including* the error line
                //
                while (line <= eLin)
                {
                    nxtC = buff.Read();
                    if (nxtC == (int)'\n')
                    {
                        line++;
                    }
                    else if (nxtC == ScanBuff.EndOfFile)
                    {
                        break;
                    }
                    sWrtr.Write((char)nxtC);
                }
                //
                //  Now emit the error message(s)
                //
                if (errN.span.endColumn > 3 && errN.span.startColumn < 80)
                {
                    if (currentCol == 0)
                    {
                        sWrtr.Write("//");
                        currentCol = 2;
                    }
                    if (errN.span.startColumn > currentCol)
                    {
                        Spaces(sWrtr, errN.span.startColumn - currentCol);
                        currentCol = errN.span.startColumn;
                    }
                    for (; currentCol < errN.span.endColumn && currentCol < 80; currentCol++)
                    {
                        sWrtr.Write('^');
                    }
                }
            }
            //
            //  Clean up after last message listing
            //  Spill all the waiting messages
            //
            int maxEpilogWidth = 0;

            if (currentCol > 0)
            {
                sWrtr.WriteLine();
            }
            for (int i = groupFirst; i < errors.Count; i++)
            {
                Error  err    = errors[i];
                string prefix = (err.isWarn ? "// Warning: " : "// Error: ");
                string msg    = StringUtilities.MakeComment(3, prefix + err.message);
                if (StringUtilities.MaxWidth(msg) > maxEpilogWidth)
                {
                    maxEpilogWidth = StringUtilities.MaxWidth(msg);
                }
                sWrtr.Write(msg);
                sWrtr.WriteLine();
            }
            if (groupFirst < errors.Count)
            {
                sWrtr.Write("// ");
                Spaces(sWrtr, maxEpilogWidth - 3);
                sWrtr.WriteLine();
            }
            //
            //  And dump the tail of the file
            //
            nxtC = buff.Read();
            while (nxtC != ScanBuff.EndOfFile)
            {
                sWrtr.Write((char)nxtC);
                nxtC = buff.Read();
            }
            ListDivider(sWrtr); sWrtr.WriteLine();
            sWrtr.Flush();
            // sWrtr.Close();
        }