foralex / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

Error reporting not correct whe using line continuations #98

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Example:

#include <stdio.h>

char* msg = "Hello\
 \
World\
!\
\n";

FakeFunction("%s", msg);

Can be fixed like so:

void PrintSourceTextErrorLine(const char *FileName, const char *SourceText, int 
Line, int CharacterPos)
{
    int LineCount;
    const char *LinePos;
    const char *CPos;
    char lastCh = 0;
    int RealLine = 1;
    int CCount;

    if (SourceText != NULL)
    {
        /* find the source line */
        for (LinePos = SourceText, LineCount = 1; *LinePos != '\0' && LineCount < Line; LinePos++)
        {
            if (*LinePos == '\n')
            {
                RealLine++;
                if(lastCh != '\\')
                    LineCount++;
            }
            if(!isspace(*LinePos)) lastCh = *LinePos;
        }

And of course use RealLine instead of LineCount further below in function.

Original issue reported on code.google.com by duncan.f...@gmail.com on 27 Jul 2010 at 5:46

GoogleCodeExporter commented 8 years ago
I forget to mention that FakeFunction doesn't exist, so picoc will throw error, 
but fancy error reporting will show incorrect line (because of the multi-line 
string constant).

Original comment by duncan.f...@gmail.com on 27 Jul 2010 at 9:33

GoogleCodeExporter commented 8 years ago
Thanks for the bug report. I'll fix this by correcting the lexer line count so 
the reported line corresponds to the correct source file line.

Original comment by zik.sale...@gmail.com on 27 Jul 2010 at 9:35

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r473.

Original comment by zik.sale...@gmail.com on 27 Jul 2010 at 10:36