Ejemplo n.º 1
0
unsigned AddLiteral (const char* S)
/* Add a literal string to the literal pool. Return the starting offset into
 * the pool
 */
{
    /* Remember the starting offset */
    unsigned Start = SB_GetLen (&LiteralPool);

    /* Copy the string including the terminator growing the buffer if needed */
    SB_AppendBuf (&LiteralPool, S, strlen (S) + 1);

    /* Return the starting offset */
    return Start;
}
Ejemplo n.º 2
0
static Literal* NewLiteral (const void* Buf, unsigned Len)
/* Create a new literal and return it */
{
    /* Allocate memory */
    Literal* L = xmalloc (sizeof (*L));

    /* Initialize the fields */
    L->Label    = GetLocalLabel ();
    L->RefCount = 0;
    L->Output   = 0;
    SB_Init (&L->Data);
    SB_AppendBuf (&L->Data, Buf, Len);

    /* Return the new literal */
    return L;
}
Ejemplo n.º 3
0
Archivo: scanner.c Proyecto: cc65/cc65
static void LineMarkerOrComment ()
/* Handle a line beginning with '#'. Possible interpretations are:
** - #line <lineno> ["<filename>"]          (C preprocessor input)
** - # <lineno> "<filename>" [<flag>]...    (gcc preprocessor output)
** - #<comment>
*/
{
    unsigned long LineNo = 0;
    int LineDirective = 0;
    StrBuf SrcNameBuf = AUTO_STRBUF_INITIALIZER;

    /* Skip the first "# " */
    NextChar ();
    SkipBlanks (1);

    /* Check "line" */
    if (C == 'l') {
        char MaybeLine [6];
        unsigned I;
        for (I = 0; I < sizeof MaybeLine - 1 && C != EOF && IsAlNum (C); ++I) {
            MaybeLine [I] = C;
            NextChar ();
        }
        MaybeLine [I] = 0;
        if (strcmp (MaybeLine, "line") != 0) {
            goto NotMarker;
        }
        LineDirective = 1;
        SkipBlanks (1);
    }

    /* Get line number */
    if (C == EOF || !IsDigit (C)) {
        goto NotMarker;
    }
    LineNo = GetDecimalToken ();
    SkipBlanks (1);

    /* Get the source file name */
    if (C != '\"') {
        /* The source file name is missing */
        if (LineDirective && C == '\n') {
            /* got #line <lineno> */
            NextChar ();
            InputLine = LineNo;
            goto Last;
        } else {
            goto NotMarker;
        }
    }
    NextChar ();
    while (C != EOF && C != '\n' && C != '\"') {
        char DecodeBuf [2];
        unsigned I = 0;
        if (GetEncodedChar (DecodeBuf, &I, sizeof DecodeBuf) < 0) {
            goto BadMarker;
        }
        SB_AppendBuf (&SrcNameBuf, DecodeBuf, I);
    }
    if (C != '\"') {
        goto BadMarker;
    }
    NextChar ();

    /* Ignore until the end of line */
    while (C != EOF && C != '\n') {
        NextChar ();
    }

    /* Accepted a line marker */
    SB_Terminate (&SrcNameBuf);
    xfree (InputSrcName);
    InputSrcName = SB_GetBuf (&SrcNameBuf);
    SB_Init (&SrcNameBuf);
    InputLine = (unsigned)LineNo;
    NextChar ();
    goto Last;

BadMarker:
    InfoWarning ("Bad line marker");
NotMarker:
    while (C != EOF && C != '\n') {
        NextChar ();
    }
    NextChar ();
Last:
    SB_Done (&SrcNameBuf);
}