]> git.sur5r.net Git - cc65/commitdiff
Added #warning (suggestion by Rudolf Schubert).
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 28 Aug 2007 12:53:43 +0000 (12:53 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 28 Aug 2007 12:53:43 +0000 (12:53 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3799 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/preproc.c

index 846d07966b938a1c95cb9bb97a9d3929bd0e8777..b7edc05de79154b65e7061aaa1c1214ee565ac4f 100644 (file)
@@ -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 ();