diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index 846d07966..b7edc05de 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 1998-2005, Ullrich von Bassewitz */ -/* Römerstraße 52 */ +/* (C) 1998-2007, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -128,7 +128,8 @@ typedef enum { PP_INCLUDE, PP_LINE, PP_PRAGMA, - PP_UNDEF + PP_UNDEF, + PP_WARNING, } pptoken_t; @@ -150,6 +151,7 @@ static const struct PPToken { { "line", PP_LINE }, { "pragma", PP_PRAGMA }, { "undef", PP_UNDEF }, + { "warning", PP_WARNING }, }; /* Number of preprocessor tokens */ @@ -983,19 +985,6 @@ static void PreprocessLine (void) -static void DoUndef (void) -/* Process the #undef directive */ -{ - ident Ident; - - SkipWhitespace (); - if (MacName (Ident)) { - UndefineMacro (Ident); - } -} - - - static int PushIf (int Skip, int Invert, int Cond) /* Push a new if level onto the if stack */ { @@ -1018,6 +1007,22 @@ static int PushIf (int Skip, int Invert, int Cond) +static void DoError (void) +/* Print an error */ +{ + SkipWhitespace (); + if (CurC == '\0') { + PPError ("Invalid #error directive"); + } else { + PPError ("#error: %s", SB_GetConstBuf (Line) + SB_GetIndex (Line)); + } + + /* Clear the rest of line */ + ClearLine (); +} + + + static int DoIf (int Skip) /* Process #if directive */ { @@ -1162,22 +1167,6 @@ Done: -static void DoError (void) -/* Print an error */ -{ - SkipWhitespace (); - if (CurC == '\0') { - PPError ("Invalid #error directive"); - } else { - PPError ("#error: %s", SB_GetConstBuf (Line) + SB_GetIndex (Line)); - } - - /* Clear the rest of line */ - ClearLine (); -} - - - static void DoPragma (void) /* Handle a #pragma line by converting the #pragma preprocessor directive into * the _Pragma() compiler operator. @@ -1203,6 +1192,35 @@ static void DoPragma (void) +static void DoUndef (void) +/* Process the #undef directive */ +{ + ident Ident; + + SkipWhitespace (); + if (MacName (Ident)) { + UndefineMacro (Ident); + } +} + + + +static void DoWarning (void) +/* Print a warning */ +{ + SkipWhitespace (); + if (CurC == '\0') { + PPError ("Invalid #warning directive"); + } else { + PPWarning ("#warning: %s", SB_GetConstBuf (Line) + SB_GetIndex (Line)); + } + + /* Clear the rest of line */ + ClearLine (); +} + + + void Preprocess (void) /* Preprocess a line */ { @@ -1340,6 +1358,18 @@ void Preprocess (void) } break; + case PP_WARNING: + /* #warning is a non standard extension */ + if (IS_Get (&Standard) > STD_C99) { + if (!Skip) { + DoWarning (); + } + } else { + PPError ("Preprocessor directive expected"); + ClearLine (); + } + break; + default: PPError ("Preprocessor directive expected"); ClearLine ();