1 /*****************************************************************************/
5 /* cc65 preprocessor */
9 /* (C) 1998-2009, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
64 /*****************************************************************************/
66 /*****************************************************************************/
70 /* Set when the preprocessor calls expr() recursively */
71 unsigned char Preprocessing = 0;
73 /* Management data for #if */
75 #define IFCOND_NONE 0x00U
76 #define IFCOND_SKIP 0x01U
77 #define IFCOND_ELSE 0x02U
78 #define IFCOND_NEEDTERM 0x04U
79 static unsigned char IfStack[MAX_IFS];
80 static int IfIndex = -1;
82 /* Buffer for macro expansion */
85 /* Structure used when expanding macros */
86 typedef struct MacroExp MacroExp;
88 Collection ActualArgs; /* Actual arguments */
89 StrBuf Replacement; /* Replacement with arguments substituted */
90 Macro* M; /* The macro we're handling */
95 /*****************************************************************************/
97 /*****************************************************************************/
101 static unsigned Pass1 (StrBuf* Source, StrBuf* Target);
102 /* Preprocessor pass 1. Remove whitespace. Handle old and new style comments
103 * and the "defined" operator.
106 static void MacroReplacement (StrBuf* Source, StrBuf* Target);
107 /* Perform macro replacement. */
111 /*****************************************************************************/
112 /* Low level preprocessor token handling */
113 /*****************************************************************************/
117 /* Types of preprocessor tokens */
137 /* Preprocessor keyword to token mapping table */
138 static const struct PPToken {
139 const char* Key; /* Keyword */
140 pptoken_t Tok; /* Token */
142 { "define", PP_DEFINE },
145 { "endif", PP_ENDIF },
146 { "error", PP_ERROR },
148 { "ifdef", PP_IFDEF },
149 { "ifndef", PP_IFNDEF },
150 { "include", PP_INCLUDE },
152 { "pragma", PP_PRAGMA },
153 { "undef", PP_UNDEF },
154 { "warning", PP_WARNING },
157 /* Number of preprocessor tokens */
158 #define PPTOKEN_COUNT (sizeof(PPTokens) / sizeof(PPTokens[0]))
162 static int CmpToken (const void* Key, const void* Elem)
163 /* Compare function for bsearch */
165 return strcmp ((const char*) Key, ((const struct PPToken*) Elem)->Key);
170 static pptoken_t FindPPToken (const char* Ident)
171 /* Find a preprocessor token and return it. Return PP_ILLEGAL if the identifier
172 * is not a valid preprocessor token.
176 P = bsearch (Ident, PPTokens, PPTOKEN_COUNT, sizeof (PPTokens[0]), CmpToken);
177 return P? P->Tok : PP_ILLEGAL;
182 /*****************************************************************************/
183 /* struct MacroExp */
184 /*****************************************************************************/
188 static MacroExp* InitMacroExp (MacroExp* E, Macro* M)
189 /* Initialize a MacroExp structure */
191 InitCollection (&E->ActualArgs);
192 SB_Init (&E->Replacement);
199 static void DoneMacroExp (MacroExp* E)
200 /* Cleanup after use of a MacroExp structure */
204 /* Delete the list with actual arguments */
205 for (I = 0; I < CollCount (&E->ActualArgs); ++I) {
206 FreeStrBuf (CollAtUnchecked (&E->ActualArgs, I));
208 DoneCollection (&E->ActualArgs);
209 SB_Done (&E->Replacement);
214 static void ME_AppendActual (MacroExp* E, StrBuf* Arg)
215 /* Add a copy of Arg to the list of actual macro arguments.
216 * NOTE: This function will clear Arg!
219 /* Create a new string buffer */
220 StrBuf* A = NewStrBuf ();
222 /* Move the contents of Arg to A */
225 /* Add A to the actual arguments */
226 CollAppend (&E->ActualArgs, A);
231 static StrBuf* ME_GetActual (MacroExp* E, unsigned Index)
232 /* Return an actual macro argument with the given index */
234 return CollAt (&E->ActualArgs, Index);
239 static int ME_ArgIsVariadic (const MacroExp* E)
240 /* Return true if the next actual argument we will add is a variadic one */
242 return (E->M->Variadic &&
243 E->M->ArgCount == (int) CollCount (&E->ActualArgs) + 1);
248 /*****************************************************************************/
250 /*****************************************************************************/
254 static void Stringize (StrBuf* Source, StrBuf* Target)
255 /* Stringize the given string: Add double quotes at start and end and preceed
256 * each occurance of " and \ by a backslash.
261 /* Add a starting quote */
262 SB_AppendChar (Target, '\"');
264 /* Replace any characters inside the string may not be part of a string
267 while ((C = SB_Get (Source)) != '\0') {
271 SB_AppendChar (Target, '\\');
274 SB_AppendChar (Target, C);
279 /* Add the closing quote */
280 SB_AppendChar (Target, '\"');
285 static void OldStyleComment (void)
286 /* Remove an old style C comment from line. */
288 /* Remember the current line number, so we can output better error
289 * messages if the comment is not terminated in the current file.
291 unsigned StartingLine = GetCurrentLine();
293 /* Skip the start of comment chars */
297 /* Skip the comment */
298 while (CurC != '*' || NextC != '/') {
300 if (NextLine () == 0) {
301 PPError ("End-of-file reached in comment starting at line %u",
306 if (CurC == '/' && NextC == '*') {
307 PPWarning ("`/*' found inside a comment");
313 /* Skip the end of comment chars */
320 static void NewStyleComment (void)
321 /* Remove a new style C comment from line. */
323 /* Beware: Because line continuation chars are handled when reading
324 * lines, we may only skip til the end of the source line, which
325 * may not be the same as the end of the input line. The end of the
326 * source line is denoted by a lf (\n) character.
330 } while (CurC != '\n' && CurC != '\0');
338 static void SkipWhitespace (void)
339 /* Skip white space in the input stream. */
341 while (IsSpace (CurC)) {
348 static void CopyQuotedString (StrBuf* Target)
349 /* Copy a single or double quoted string from the input to Target. */
351 /* Remember the quote character, copy it to the target buffer and skip it */
353 SB_AppendChar (Target, CurC);
356 /* Copy the characters inside the string */
357 while (CurC != '\0' && CurC != Quote) {
358 /* Keep an escaped char */
360 SB_AppendChar (Target, CurC);
363 /* Copy the character */
364 SB_AppendChar (Target, CurC);
368 /* If we had a terminating quote, copy it */
370 SB_AppendChar (Target, CurC);
377 /*****************************************************************************/
379 /*****************************************************************************/
383 static int MacName (char* Ident)
384 /* Get a macro symbol name into Ident. If we have an error, print a
385 * diagnostic message and clear the line.
388 if (IsSym (Ident) == 0) {
389 PPError ("Identifier expected");
399 static void ReadMacroArgs (MacroExp* E)
400 /* Identify the arguments to a macro call */
402 unsigned Parens; /* Number of open parenthesis */
403 StrBuf Arg = STATIC_STRBUF_INITIALIZER;
405 /* Read the actual macro arguments */
410 /* Nested parenthesis */
411 SB_AppendChar (&Arg, CurC);
415 } else if (IsQuote (CurC)) {
417 /* Quoted string - just copy */
418 CopyQuotedString (&Arg);
420 } else if (CurC == ',' || CurC == ')') {
423 /* Comma or right paren inside nested parenthesis */
427 SB_AppendChar (&Arg, CurC);
429 } else if (CurC == ',' && ME_ArgIsVariadic (E)) {
430 /* It's a comma, but we're inside a variadic macro argument, so
431 * just copy it and proceed.
433 SB_AppendChar (&Arg, CurC);
436 /* End of actual argument. Remove whitespace from the end. */
437 while (IsSpace (SB_LookAtLast (&Arg))) {
441 /* If this is not the single empty argument for a macro with
442 * an empty argument list, remember it.
444 if (CurC != ')' || SB_NotEmpty (&Arg) || E->M->ArgCount > 0) {
445 ME_AppendActual (E, &Arg);
448 /* Check for end of macro param list */
454 /* Start the next param */
458 } else if (IsSpace (CurC)) {
459 /* Squeeze runs of blanks within an arg */
460 if (SB_NotEmpty (&Arg)) {
461 SB_AppendChar (&Arg, ' ');
464 } else if (CurC == '/' && NextC == '*') {
465 if (SB_NotEmpty (&Arg)) {
466 SB_AppendChar (&Arg, ' ');
469 } else if (IS_Get (&Standard) >= STD_C99 && CurC == '/' && NextC == '/') {
470 if (SB_NotEmpty (&Arg)) {
471 SB_AppendChar (&Arg, ' ');
474 } else if (CurC == '\0') {
475 /* End of line inside macro argument list - read next line */
476 if (SB_NotEmpty (&Arg)) {
477 SB_AppendChar (&Arg, ' ');
479 if (NextLine () == 0) {
484 /* Just copy the character */
485 SB_AppendChar (&Arg, CurC);
490 /* Deallocate string buf resources */
496 static void MacroArgSubst (MacroExp* E)
497 /* Argument substitution according to ISO/IEC 9899:1999 (E), 6.10.3.1ff */
506 /* Remember the current input and switch to the macro replacement. */
507 int OldIndex = SB_GetIndex (&E->M->Replacement);
508 SB_Reset (&E->M->Replacement);
509 OldSource = InitLine (&E->M->Replacement);
511 /* Argument handling loop */
512 while (CurC != '\0') {
514 /* If we have an identifier, check if it's a macro */
517 /* Check if it's a macro argument */
518 if ((ArgIdx = FindMacroArg (E->M, Ident)) >= 0) {
520 /* A macro argument. Get the corresponding actual argument. */
521 Arg = ME_GetActual (E, ArgIdx);
523 /* Copy any following whitespace */
524 HaveSpace = IsSpace (CurC);
529 /* If a ## operator follows, we have to insert the actual
530 * argument as is, otherwise it must be macro replaced.
532 if (CurC == '#' && NextC == '#') {
534 /* ### Add placemarker if necessary */
535 SB_Append (&E->Replacement, Arg);
539 /* Replace the formal argument by a macro replaced copy
543 MacroReplacement (Arg, &E->Replacement);
545 /* If we skipped whitespace before, re-add it now */
547 SB_AppendChar (&E->Replacement, ' ');
554 /* An identifier, keep it */
555 SB_AppendStr (&E->Replacement, Ident);
559 } else if (CurC == '#' && NextC == '#') {
566 /* Since we need to concatenate the token sequences, remove
567 * any whitespace that was added to target, since it must come
570 while (IsSpace (SB_LookAtLast (&E->Replacement))) {
571 SB_Drop (&E->Replacement, 1);
574 /* If the next token is an identifier which is a macro argument,
575 * replace it, otherwise do nothing.
579 /* Check if it's a macro argument */
580 if ((ArgIdx = FindMacroArg (E->M, Ident)) >= 0) {
582 /* Get the corresponding actual argument and add it. */
583 SB_Append (&E->Replacement, ME_GetActual (E, ArgIdx));
587 /* Just an ordinary identifier - add as is */
588 SB_AppendStr (&E->Replacement, Ident);
593 } else if (CurC == '#' && E->M->ArgCount >= 0) {
595 /* A # operator within a macro expansion of a function like
596 * macro. Read the following identifier and check if it's a
601 if (!IsSym (Ident) || (ArgIdx = FindMacroArg (E->M, Ident)) < 0) {
602 PPError ("`#' is not followed by a macro parameter");
604 /* Make a valid string from Replacement */
605 Arg = ME_GetActual (E, ArgIdx);
607 Stringize (Arg, &E->Replacement);
610 } else if (IsQuote (CurC)) {
611 CopyQuotedString (&E->Replacement);
613 SB_AppendChar (&E->Replacement, CurC);
619 /* Remove whitespace from the end of the line */
620 while (IsSpace (SB_LookAtLast (&E->Replacement))) {
621 SB_Drop (&E->Replacement, 1);
625 /* Switch back the input */
626 InitLine (OldSource);
627 SB_SetIndex (&E->M->Replacement, OldIndex);
632 static void MacroCall (StrBuf* Target, Macro* M)
633 /* Process a function like macro */
637 /* Eat the left paren */
640 /* Initialize our MacroExp structure */
641 InitMacroExp (&E, M);
643 /* Read the actual macro arguments */
646 /* Compare formal and actual argument count */
647 if (CollCount (&E.ActualArgs) != (unsigned) M->ArgCount) {
649 StrBuf Arg = STATIC_STRBUF_INITIALIZER;
651 /* Argument count mismatch */
652 PPError ("Macro argument count mismatch");
654 /* Be sure to make enough empty arguments available */
655 while (CollCount (&E.ActualArgs) < (unsigned) M->ArgCount) {
656 ME_AppendActual (&E, &Arg);
660 /* Replace macro arguments handling the # and ## operators */
663 /* Do macro replacement on the macro that already has the parameters
667 MacroReplacement (&E.Replacement, Target);
670 /* Free memory allocated for the macro expansion structure */
676 static void ExpandMacro (StrBuf* Target, Macro* M)
677 /* Expand a macro into Target */
680 static unsigned V = 0;
681 printf ("Expanding %s(%u)\n", M->Name, ++V);
684 /* Check if this is a function like macro */
685 if (M->ArgCount >= 0) {
687 int Whitespace = IsSpace (CurC);
692 /* Function like macro but no parameter list */
693 SB_AppendStr (Target, M->Name);
695 SB_AppendChar (Target, ' ');
698 /* Function like macro */
699 MacroCall (Target, M);
705 InitMacroExp (&E, M);
707 /* Handle # and ## operators for object like macros */
710 /* Do macro replacement on the macro that already has the parameters
714 MacroReplacement (&E.Replacement, Target);
717 /* Free memory allocated for the macro expansion structure */
722 printf ("Done with %s(%u)\n", M->Name, V--);
728 static void DefineMacro (void)
729 /* Handle a macro definition. */
736 /* Read the macro name */
738 if (!MacName (Ident)) {
742 /* Remember if we're in C89 mode */
743 C89 = (IS_Get (&Standard) == STD_C89);
745 /* Get an existing macro definition with this name */
746 Existing = FindMacro (Ident);
748 /* Create a new macro definition */
749 M = NewMacro (Ident);
751 /* Check if this is a function like macro */
754 /* Skip the left paren */
757 /* Set the marker that this is a function like macro */
760 /* Read the formal parameter list */
763 /* Skip white space and check for end of parameter list */
769 /* The next token must be either an identifier, or - if not in
770 * C89 mode - the ellipsis.
772 if (!C89 && CurC == '.') {
775 if (CurC != '.' || NextC != '.') {
776 PPError ("`...' expected");
783 /* Remember that the macro is variadic and use __VA_ARGS__ as
786 AddMacroArg (M, "__VA_ARGS__");
790 /* Must be macro argument name */
791 if (MacName (Ident) == 0) {
795 /* __VA_ARGS__ is only allowed in C89 mode */
796 if (!C89 && strcmp (Ident, "__VA_ARGS__") == 0) {
797 PPWarning ("`__VA_ARGS__' can only appear in the expansion "
798 "of a C99 variadic macro");
801 /* Add the macro argument */
802 AddMacroArg (M, Ident);
805 /* If we had an ellipsis, or the next char is not a comma, we've
806 * reached the end of the macro argument list.
809 if (M->Variadic || CurC != ',') {
815 /* Check for a right paren and eat it if we find one */
817 PPError ("`)' expected");
824 /* Skip whitespace before the macro replacement */
827 /* Insert the macro into the macro table and allocate the ActualArgs array */
830 /* Remove whitespace and comments from the line, store the preprocessed
831 * line into the macro replacement buffer.
833 Pass1 (Line, &M->Replacement);
835 /* Remove whitespace from the end of the line */
836 while (IsSpace (SB_LookAtLast (&M->Replacement))) {
837 SB_Drop (&M->Replacement, 1);
840 printf ("%s: <%.*s>\n", M->Name, SB_GetLen (&M->Replacement), SB_GetConstBuf (&M->Replacement));
843 /* If we have an existing macro, check if the redefinition is identical.
844 * Print a diagnostic if not.
846 if (Existing && MacroCmp (M, Existing) != 0) {
847 PPError ("Macro redefinition is not identical");
853 /*****************************************************************************/
855 /*****************************************************************************/
859 static unsigned Pass1 (StrBuf* Source, StrBuf* Target)
860 /* Preprocessor pass 1. Remove whitespace. Handle old and new style comments
861 * and the "defined" operator.
868 /* Switch to the new input source */
869 StrBuf* OldSource = InitLine (Source);
871 /* Loop removing ws and comments */
873 while (CurC != '\0') {
874 if (IsSpace (CurC)) {
875 /* Squeeze runs of blanks */
876 if (!IsSpace (SB_LookAtLast (Target))) {
877 SB_AppendChar (Target, ' ');
880 } else if (IsSym (Ident)) {
881 if (Preprocessing && strcmp (Ident, "defined") == 0) {
882 /* Handle the "defined" operator */
891 SB_AppendChar (Target, IsMacro (Ident)? '1' : '0');
895 PPError ("`)' expected");
901 PPError ("Identifier expected");
902 SB_AppendChar (Target, '0');
906 SB_AppendStr (Target, Ident);
908 } else if (IsQuote (CurC)) {
909 CopyQuotedString (Target);
910 } else if (CurC == '/' && NextC == '*') {
911 if (!IsSpace (SB_LookAtLast (Target))) {
912 SB_AppendChar (Target, ' ');
915 } else if (IS_Get (&Standard) >= STD_C99 && CurC == '/' && NextC == '/') {
916 if (!IsSpace (SB_LookAtLast (Target))) {
917 SB_AppendChar (Target, ' ');
921 SB_AppendChar (Target, CurC);
926 /* Switch back to the old source */
927 InitLine (OldSource);
929 /* Return the number of identifiers found in the line */
935 static void MacroReplacement (StrBuf* Source, StrBuf* Target)
936 /* Perform macro replacement. */
941 /* Remember the current input and switch to Source */
942 StrBuf* OldSource = InitLine (Source);
944 /* Loop substituting macros */
945 while (CurC != '\0') {
946 /* If we have an identifier, check if it's a macro */
948 /* Check if it's a macro */
949 if ((M = FindMacro (Ident)) != 0 && !M->Expanding) {
950 /* It's a macro, expand it */
951 ExpandMacro (Target, M);
953 /* An identifier, keep it */
954 SB_AppendStr (Target, Ident);
956 } else if (IsQuote (CurC)) {
957 CopyQuotedString (Target);
958 } else if (IsSpace (CurC)) {
959 if (!IsSpace (SB_LookAtLast (Target))) {
960 SB_AppendChar (Target, CurC);
964 SB_AppendChar (Target, CurC);
969 /* Switch back the input */
970 InitLine (OldSource);
975 static void PreprocessLine (void)
976 /* Translate one line. */
978 /* Trim whitespace and remove comments. The function returns the number of
979 * identifiers found. If there were any, we will have to check for macros.
982 if (Pass1 (Line, MLine) > 0) {
983 MLine = InitLine (MLine);
986 MacroReplacement (Line, MLine);
989 /* Read from the new line */
991 MLine = InitLine (MLine);
996 static int PushIf (int Skip, int Invert, int Cond)
997 /* Push a new if level onto the if stack */
999 /* Check for an overflow of the if stack */
1000 if (IfIndex >= MAX_IFS-1) {
1001 PPError ("Too many nested #if clauses");
1005 /* Push the #if condition */
1008 IfStack[IfIndex] = IFCOND_SKIP | IFCOND_NEEDTERM;
1011 IfStack[IfIndex] = IFCOND_NONE | IFCOND_NEEDTERM;
1012 return (Invert ^ Cond);
1018 static void DoError (void)
1019 /* Print an error */
1023 PPError ("Invalid #error directive");
1025 PPError ("#error: %s", SB_GetConstBuf (Line) + SB_GetIndex (Line));
1028 /* Clear the rest of line */
1034 static int DoIf (int Skip)
1035 /* Process #if directive */
1039 /* We're about to abuse the compiler expression parser to evaluate the
1040 * #if expression. Save the current tokens to come back here later.
1041 * NOTE: Yes, this is a hack, but it saves a complete separate expression
1042 * evaluation for the preprocessor.
1044 Token SavedCurTok = CurTok;
1045 Token SavedNextTok = NextTok;
1047 /* Make sure the line infos for the tokens won't get removed */
1048 if (SavedCurTok.LI) {
1049 UseLineInfo (SavedCurTok.LI);
1051 if (SavedNextTok.LI) {
1052 UseLineInfo (SavedNextTok.LI);
1055 /* Switch into special preprocessing mode */
1058 /* Expand macros in this line */
1061 /* Add two semicolons as sentinels to the line, so the following
1062 * expression evaluation will eat these two tokens but nothing from
1063 * the following line.
1065 SB_AppendStr (Line, ";;");
1066 SB_Terminate (Line);
1068 /* Load CurTok and NextTok with tokens from the new input */
1072 /* Call the expression parser */
1073 ConstExpr (hie1, &Expr);
1075 /* End preprocessing mode */
1078 /* Reset the old tokens */
1079 CurTok = SavedCurTok;
1080 NextTok = SavedNextTok;
1082 /* Set the #if condition according to the expression result */
1083 return PushIf (Skip, 1, Expr.IVal != 0);
1088 static int DoIfDef (int skip, int flag)
1089 /* Process #ifdef if flag == 1, or #ifndef if flag == 0. */
1094 if (MacName (Ident) == 0) {
1097 return PushIf (skip, flag, IsMacro(Ident));
1103 static void DoInclude (void)
1104 /* Open an include file. */
1108 StrBuf Filename = STATIC_STRBUF_INITIALIZER;
1111 /* Preprocess the remainder of the line */
1117 /* Get the next char and check for a valid file name terminator. Setup
1118 * the include directory spec (SYS/USR) by looking at the terminator.
1133 PPError ("`\"' or `<' expected");
1138 /* Get a copy of the filename */
1139 while (CurC != '\0' && CurC != RTerm) {
1140 SB_AppendChar (&Filename, CurC);
1143 SB_Terminate (&Filename);
1145 /* Check if we got a terminator */
1146 if (CurC == RTerm) {
1147 /* Open the include file */
1148 OpenIncludeFile (SB_GetConstBuf (&Filename), DirSpec);
1149 } else if (CurC == '\0') {
1150 /* No terminator found */
1151 PPError ("#include expects \"FILENAME\" or <FILENAME>");
1155 /* Free the allocated filename data */
1156 SB_Done (&Filename);
1158 /* Clear the remaining line so the next input will come from the new
1166 static void DoPragma (void)
1167 /* Handle a #pragma line by converting the #pragma preprocessor directive into
1168 * the _Pragma() compiler operator.
1171 /* Skip blanks following the #pragma directive */
1174 /* Copy the remainder of the line into MLine removing comments and ws */
1176 Pass1 (Line, MLine);
1178 /* Convert the directive into the operator */
1179 SB_CopyStr (Line, "_Pragma (");
1181 Stringize (MLine, Line);
1182 SB_AppendChar (Line, ')');
1184 /* Initialize reading from line */
1191 static void DoUndef (void)
1192 /* Process the #undef directive */
1197 if (MacName (Ident)) {
1198 UndefineMacro (Ident);
1204 static void DoWarning (void)
1205 /* Print a warning */
1209 PPError ("Invalid #warning directive");
1211 PPWarning ("#warning: %s", SB_GetConstBuf (Line) + SB_GetIndex (Line));
1214 /* Clear the rest of line */
1220 void Preprocess (void)
1221 /* Preprocess a line */
1226 /* Create the output buffer if we don't already have one */
1228 MLine = NewStrBuf ();
1231 /* Skip white space at the beginning of the line */
1234 /* Check for stuff to skip */
1236 while (CurC == '\0' || CurC == '#' || Skip) {
1238 /* Check for preprocessor lines lines */
1243 /* Ignore the empty preprocessor directive */
1246 if (!IsSym (Directive)) {
1247 PPError ("Preprocessor directive expected");
1250 switch (FindPPToken (Directive)) {
1260 if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) {
1262 /* Handle as #else/#if combination */
1263 if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) {
1266 IfStack[IfIndex] |= IFCOND_ELSE;
1269 /* #elif doesn't need a terminator */
1270 IfStack[IfIndex] &= ~IFCOND_NEEDTERM;
1272 PPError ("Duplicate #else/#elif");
1275 PPError ("Unexpected #elif");
1281 if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) {
1282 if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) {
1285 IfStack[IfIndex] |= IFCOND_ELSE;
1287 PPError ("Duplicate #else");
1290 PPError ("Unexpected `#else'");
1296 /* Remove any clauses on top of stack that do not
1297 * need a terminating #endif.
1299 while (IfIndex >= 0 && (IfStack[IfIndex] & IFCOND_NEEDTERM) == 0) {
1303 /* Stack may not be empty here or something is wrong */
1304 CHECK (IfIndex >= 0);
1306 /* Remove the clause that needs a terminator */
1307 Skip = (IfStack[IfIndex--] & IFCOND_SKIP) != 0;
1309 PPError ("Unexpected `#endif'");
1324 Skip = DoIfDef (Skip, 1);
1328 Skip = DoIfDef (Skip, 0);
1338 /* Should do something in C99 at least, but we ignore it */
1358 /* #warning is a non standard extension */
1359 if (IS_Get (&Standard) > STD_C99) {
1364 PPError ("Preprocessor directive expected");
1370 PPError ("Preprocessor directive expected");
1376 if (NextLine () == 0) {
1378 PPError ("`#endif' expected");
1388 if (Verbosity > 1 && SB_NotEmpty (Line)) {
1389 printf ("%s(%u): %.*s\n", GetCurrentFile (), GetCurrentLine (),
1390 (int) SB_GetLen (Line), SB_GetConstBuf (Line));