1 /*****************************************************************************/
5 /* cc65 preprocessor */
9 /* (C) 1998-2005, Ullrich von Bassewitz */
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 */
136 /* Preprocessor keyword to token mapping table */
137 static const struct PPToken {
138 const char* Key; /* Keyword */
139 pptoken_t Tok; /* Token */
141 { "define", PP_DEFINE },
144 { "endif", PP_ENDIF },
145 { "error", PP_ERROR },
147 { "ifdef", PP_IFDEF },
148 { "ifndef", PP_IFNDEF },
149 { "include", PP_INCLUDE },
151 { "pragma", PP_PRAGMA },
152 { "undef", PP_UNDEF },
155 /* Number of preprocessor tokens */
156 #define PPTOKEN_COUNT (sizeof(PPTokens) / sizeof(PPTokens[0]))
160 static int CmpToken (const void* Key, const void* Elem)
161 /* Compare function for bsearch */
163 return strcmp ((const char*) Key, ((const struct PPToken*) Elem)->Key);
168 static pptoken_t FindPPToken (const char* Ident)
169 /* Find a preprocessor token and return it. Return PP_ILLEGAL if the identifier
170 * is not a valid preprocessor token.
174 P = bsearch (Ident, PPTokens, PPTOKEN_COUNT, sizeof (PPTokens[0]), CmpToken);
175 return P? P->Tok : PP_ILLEGAL;
180 /*****************************************************************************/
181 /* struct MacroExp */
182 /*****************************************************************************/
186 static MacroExp* InitMacroExp (MacroExp* E, Macro* M)
187 /* Initialize a MacroExp structure */
189 InitCollection (&E->ActualArgs);
190 InitStrBuf (&E->Replacement);
197 static void DoneMacroExp (MacroExp* E)
198 /* Cleanup after use of a MacroExp structure */
202 /* Delete the list with actual arguments */
203 for (I = 0; I < CollCount (&E->ActualArgs); ++I) {
204 FreeStrBuf (CollAtUnchecked (&E->ActualArgs, I));
206 DoneCollection (&E->ActualArgs);
207 DoneStrBuf (&E->Replacement);
212 static void ME_AppendActual (MacroExp* E, StrBuf* Arg)
213 /* Add a copy of Arg to the list of actual macro arguments.
214 * NOTE: This function will clear Arg!
217 /* Create a new string buffer */
218 StrBuf* A = NewStrBuf ();
220 /* Move the contents of Arg to A */
223 /* Add A to the actual arguments */
224 CollAppend (&E->ActualArgs, A);
229 static StrBuf* ME_GetActual (MacroExp* E, unsigned Index)
230 /* Return an actual macro argument with the given index */
232 return CollAt (&E->ActualArgs, Index);
237 static int ME_ArgIsVariadic (const MacroExp* E)
238 /* Return true if the next actual argument we will add is a variadic one */
240 return (E->M->Variadic &&
241 E->M->ArgCount == (int) CollCount (&E->ActualArgs) + 1);
246 /*****************************************************************************/
248 /*****************************************************************************/
252 static void Stringize (StrBuf* Source, StrBuf* Target)
253 /* Stringize the given string: Add double quotes at start and end and preceed
254 * each occurance of " and \ by a backslash.
259 /* Add a starting quote */
260 SB_AppendChar (Target, '\"');
262 /* Replace any characters inside the string may not be part of a string
265 while ((C = SB_Get (Source)) != '\0') {
269 SB_AppendChar (Target, '\\');
272 SB_AppendChar (Target, C);
277 /* Add the closing quote */
278 SB_AppendChar (Target, '\"');
283 static void OldStyleComment (void)
284 /* Remove an old style C comment from line. */
286 /* Remember the current line number, so we can output better error
287 * messages if the comment is not terminated in the current file.
289 unsigned StartingLine = GetCurrentLine();
291 /* Skip the start of comment chars */
295 /* Skip the comment */
296 while (CurC != '*' || NextC != '/') {
298 if (NextLine () == 0) {
299 PPError ("End-of-file reached in comment starting at line %u",
304 if (CurC == '/' && NextC == '*') {
305 PPWarning ("`/*' found inside a comment");
311 /* Skip the end of comment chars */
318 static void NewStyleComment (void)
319 /* Remove a new style C comment from line. */
321 /* Beware: Because line continuation chars are handled when reading
322 * lines, we may only skip til the end of the source line, which
323 * may not be the same as the end of the input line. The end of the
324 * source line is denoted by a lf (\n) character.
328 } while (CurC != '\n' && CurC != '\0');
336 static void SkipWhitespace (void)
337 /* Skip white space in the input stream. */
339 while (IsSpace (CurC)) {
346 static void CopyQuotedString (StrBuf* Target)
347 /* Copy a single or double quoted string from the input to Target. */
349 /* Remember the quote character, copy it to the target buffer and skip it */
351 SB_AppendChar (Target, CurC);
354 /* Copy the characters inside the string */
355 while (CurC != '\0' && CurC != Quote) {
356 /* Keep an escaped char */
358 SB_AppendChar (Target, CurC);
361 /* Copy the character */
362 SB_AppendChar (Target, CurC);
366 /* If we had a terminating quote, copy it */
368 SB_AppendChar (Target, CurC);
375 /*****************************************************************************/
377 /*****************************************************************************/
381 static int MacName (char* Ident)
382 /* Get a macro symbol name into Ident. If we have an error, print a
383 * diagnostic message and clear the line.
386 if (IsSym (Ident) == 0) {
387 PPError ("Identifier expected");
397 static void ReadMacroArgs (MacroExp* E)
398 /* Identify the arguments to a macro call */
400 unsigned Parens; /* Number of open parenthesis */
401 StrBuf Arg = STATIC_STRBUF_INITIALIZER;
403 /* Read the actual macro arguments */
408 /* Nested parenthesis */
409 SB_AppendChar (&Arg, CurC);
413 } else if (IsQuote (CurC)) {
415 /* Quoted string - just copy */
416 CopyQuotedString (&Arg);
418 } else if (CurC == ',' || CurC == ')') {
421 /* Comma or right paren inside nested parenthesis */
425 SB_AppendChar (&Arg, CurC);
427 } else if (CurC == ',' && ME_ArgIsVariadic (E)) {
428 /* It's a comma, but we're inside a variadic macro argument, so
429 * just copy it and proceed.
431 SB_AppendChar (&Arg, CurC);
434 /* End of actual argument. Remove whitespace from the end. */
435 while (IsSpace (SB_LookAtLast (&Arg))) {
439 /* If this is not the single empty argument for a macro with
440 * an empty argument list, remember it.
442 if (CurC != ')' || SB_NotEmpty (&Arg) || E->M->ArgCount > 0) {
443 ME_AppendActual (E, &Arg);
446 /* Check for end of macro param list */
452 /* Start the next param */
456 } else if (IsSpace (CurC)) {
457 /* Squeeze runs of blanks within an arg */
458 if (SB_NotEmpty (&Arg)) {
459 SB_AppendChar (&Arg, ' ');
462 } else if (CurC == '/' && NextC == '*') {
463 if (SB_NotEmpty (&Arg)) {
464 SB_AppendChar (&Arg, ' ');
467 } else if (IS_Get (&Standard) >= STD_C99 && CurC == '/' && NextC == '/') {
468 if (SB_NotEmpty (&Arg)) {
469 SB_AppendChar (&Arg, ' ');
472 } else if (CurC == '\0') {
473 /* End of line inside macro argument list - read next line */
474 if (SB_NotEmpty (&Arg)) {
475 SB_AppendChar (&Arg, ' ');
477 if (NextLine () == 0) {
482 /* Just copy the character */
483 SB_AppendChar (&Arg, CurC);
488 /* Deallocate string buf resources */
494 static void MacroArgSubst (MacroExp* E)
495 /* Argument substitution according to ISO/IEC 9899:1999 (E), 6.10.3.1ff */
504 /* Remember the current input and switch to the macro replacement. */
505 SB_Reset (&E->M->Replacement);
506 OldSource = InitLine (&E->M->Replacement);
508 /* Argument handling loop */
509 while (CurC != '\0') {
511 /* If we have an identifier, check if it's a macro */
514 /* Check if it's a macro argument */
515 if ((ArgIdx = FindMacroArg (E->M, Ident)) >= 0) {
517 /* A macro argument. Get the corresponding actual argument. */
518 Arg = ME_GetActual (E, ArgIdx);
520 /* Copy any following whitespace */
521 HaveSpace = IsSpace (CurC);
526 /* If a ## operator follows, we have to insert the actual
527 * argument as is, otherwise it must be macro replaced.
529 if (CurC == '#' && NextC == '#') {
531 /* ### Add placemarker if necessary */
532 SB_Append (&E->Replacement, Arg);
536 /* Replace the formal argument by a macro replaced copy
540 MacroReplacement (Arg, &E->Replacement);
542 /* If we skipped whitespace before, re-add it now */
544 SB_AppendChar (&E->Replacement, ' ');
551 /* An identifier, keep it */
552 SB_AppendStr (&E->Replacement, Ident);
556 } else if (CurC == '#' && NextC == '#') {
563 /* Since we need to concatenate the token sequences, remove
564 * any whitespace that was added to target, since it must come
567 while (IsSpace (SB_LookAtLast (&E->Replacement))) {
568 SB_Drop (&E->Replacement, 1);
571 /* If the next token is an identifier which is a macro argument,
572 * replace it, otherwise do nothing.
576 /* Check if it's a macro argument */
577 if ((ArgIdx = FindMacroArg (E->M, Ident)) >= 0) {
579 /* Get the corresponding actual argument and add it. */
580 SB_Append (&E->Replacement, ME_GetActual (E, ArgIdx));
584 /* Just an ordinary identifier - add as is */
585 SB_AppendStr (&E->Replacement, Ident);
590 } else if (CurC == '#' && E->M->ArgCount >= 0) {
592 /* A # operator within a macro expansion of a function like
593 * macro. Read the following identifier and check if it's a
598 if (!IsSym (Ident) || (ArgIdx = FindMacroArg (E->M, Ident)) < 0) {
599 PPError ("`#' is not followed by a macro parameter");
601 /* Make a valid string from Replacement */
602 Arg = ME_GetActual (E, ArgIdx);
604 Stringize (Arg, &E->Replacement);
607 } else if (IsQuote (CurC)) {
608 CopyQuotedString (&E->Replacement);
610 SB_AppendChar (&E->Replacement, CurC);
616 /* Remove whitespace from the end of the line */
617 while (IsSpace (SB_LookAtLast (&E->Replacement))) {
618 SB_Drop (&E->Replacement, 1);
622 /* Switch back the input */
623 InitLine (OldSource);
628 static void MacroCall (StrBuf* Target, Macro* M)
629 /* Process a function like macro */
633 /* Eat the left paren */
636 /* Initialize our MacroExp structure */
637 InitMacroExp (&E, M);
639 /* Read the actual macro arguments */
642 /* Compare formal and actual argument count */
643 if (CollCount (&E.ActualArgs) != (unsigned) M->ArgCount) {
645 StrBuf Arg = STATIC_STRBUF_INITIALIZER;
647 /* Argument count mismatch */
648 PPError ("Macro argument count mismatch");
650 /* Be sure to make enough empty arguments available */
651 while (CollCount (&E.ActualArgs) < (unsigned) M->ArgCount) {
652 ME_AppendActual (&E, &Arg);
656 /* Replace macro arguments handling the # and ## operators */
659 /* Do macro replacement on the macro that already has the parameters
663 MacroReplacement (&E.Replacement, Target);
666 /* Free memory allocated for the macro expansion structure */
672 static void ExpandMacro (StrBuf* Target, Macro* M)
673 /* Expand a macro into Target */
675 /* Check if this is a function like macro */
676 //printf ("Expanding %s(%u)\n", M->Name, ++V);
677 if (M->ArgCount >= 0) {
679 int Whitespace = IsSpace (CurC);
684 /* Function like macro but no parameter list */
685 SB_AppendStr (Target, M->Name);
687 SB_AppendChar (Target, ' ');
690 /* Function like macro */
691 MacroCall (Target, M);
697 InitMacroExp (&E, M);
699 /* Handle # and ## operators for object like macros */
702 /* Do macro replacement on the macro that already has the parameters
706 MacroReplacement (&E.Replacement, Target);
709 /* Free memory allocated for the macro expansion structure */
713 //printf ("Done with %s(%u)\n", M->Name, V--);
718 static void DefineMacro (void)
719 /* Handle a macro definition. */
726 /* Read the macro name */
728 if (!MacName (Ident)) {
732 /* Remember if we're in C89 mode */
733 C89 = (IS_Get (&Standard) == STD_C89);
735 /* Get an existing macro definition with this name */
736 Existing = FindMacro (Ident);
738 /* Create a new macro definition */
739 M = NewMacro (Ident);
741 /* Check if this is a function like macro */
744 /* Skip the left paren */
747 /* Set the marker that this is a function like macro */
750 /* Read the formal parameter list */
753 /* Skip white space and check for end of parameter list */
759 /* The next token must be either an identifier, or - if not in
760 * C89 mode - the ellipsis.
762 if (!C89 && CurC == '.') {
765 if (CurC != '.' || NextC != '.') {
766 PPError ("`...' expected");
773 /* Remember that the macro is variadic and use __VA_ARGS__ as
776 AddMacroArg (M, "__VA_ARGS__");
780 /* Must be macro argument name */
781 if (MacName (Ident) == 0) {
785 /* __VA_ARGS__ is only allowed in C89 mode */
786 if (!C89 && strcmp (Ident, "__VA_ARGS__") == 0) {
787 PPWarning ("`__VA_ARGS__' can only appear in the expansion "
788 "of a C99 variadic macro");
791 /* Add the macro argument */
792 AddMacroArg (M, Ident);
795 /* If we had an ellipsis, or the next char is not a comma, we've
796 * reached the end of the macro argument list.
799 if (M->Variadic || CurC != ',') {
805 /* Check for a right paren and eat it if we find one */
807 PPError ("`)' expected");
814 /* Skip whitespace before the macro replacement */
817 /* Insert the macro into the macro table and allocate the ActualArgs array */
820 /* Remove whitespace and comments from the line, store the preprocessed
821 * line into the macro replacement buffer.
823 Pass1 (Line, &M->Replacement);
825 /* Remove whitespace from the end of the line */
826 while (IsSpace (SB_LookAtLast (&M->Replacement))) {
827 SB_Drop (&M->Replacement, 1);
830 //printf ("%s: <%.*s>\n", M->Name, SB_GetLen (&M->Replacement), SB_GetConstBuf (&M->Replacement));
832 /* If we have an existing macro, check if the redefinition is identical.
833 * Print a diagnostic if not.
835 if (Existing && MacroCmp (M, Existing) != 0) {
836 PPError ("Macro redefinition is not identical");
842 /*****************************************************************************/
844 /*****************************************************************************/
848 static unsigned Pass1 (StrBuf* Source, StrBuf* Target)
849 /* Preprocessor pass 1. Remove whitespace. Handle old and new style comments
850 * and the "defined" operator.
857 /* Switch to the new input source */
858 StrBuf* OldSource = InitLine (Source);
860 /* Loop removing ws and comments */
862 while (CurC != '\0') {
863 if (IsSpace (CurC)) {
864 /* Squeeze runs of blanks */
865 if (!IsSpace (SB_LookAtLast (Target))) {
866 SB_AppendChar (Target, ' ');
869 } else if (IsSym (Ident)) {
870 if (Preprocessing && strcmp (Ident, "defined") == 0) {
871 /* Handle the "defined" operator */
880 SB_AppendChar (Target, IsMacro (Ident)? '1' : '0');
884 PPError ("`)' expected");
890 PPError ("Identifier expected");
891 SB_AppendChar (Target, '0');
895 SB_AppendStr (Target, Ident);
897 } else if (IsQuote (CurC)) {
898 CopyQuotedString (Target);
899 } else if (CurC == '/' && NextC == '*') {
900 if (!IsSpace (SB_LookAtLast (Target))) {
901 SB_AppendChar (Target, ' ');
904 } else if (IS_Get (&Standard) >= STD_C99 && CurC == '/' && NextC == '/') {
905 if (!IsSpace (SB_LookAtLast (Target))) {
906 SB_AppendChar (Target, ' ');
910 SB_AppendChar (Target, CurC);
915 /* Switch back to the old source */
916 InitLine (OldSource);
918 /* Return the number of identifiers found in the line */
924 static void MacroReplacement (StrBuf* Source, StrBuf* Target)
925 /* Perform macro replacement. */
930 /* Remember the current input and switch to Source */
931 StrBuf* OldSource = InitLine (Source);
933 /* Loop substituting macros */
934 while (CurC != '\0') {
935 /* If we have an identifier, check if it's a macro */
937 /* Check if it's a macro */
938 if ((M = FindMacro (Ident)) != 0 && !M->Expanding) {
939 /* It's a macro, expand it */
940 ExpandMacro (Target, M);
942 /* An identifier, keep it */
943 SB_AppendStr (Target, Ident);
945 } else if (IsQuote (CurC)) {
946 CopyQuotedString (Target);
947 } else if (IsSpace (CurC)) {
948 if (!IsSpace (SB_LookAtLast (Target))) {
949 SB_AppendChar (Target, CurC);
953 SB_AppendChar (Target, CurC);
958 /* Switch back the input */
959 InitLine (OldSource);
964 static void PreprocessLine (void)
965 /* Translate one line. */
967 /* Trim whitespace and remove comments. The function returns the number of
968 * identifiers found. If there were any, we will have to check for macros.
971 if (Pass1 (Line, MLine) > 0) {
972 MLine = InitLine (MLine);
975 MacroReplacement (Line, MLine);
978 /* Read from the new line */
980 MLine = InitLine (MLine);
985 static void DoUndef (void)
986 /* Process the #undef directive */
991 if (MacName (Ident)) {
992 UndefineMacro (Ident);
998 static int PushIf (int Skip, int Invert, int Cond)
999 /* Push a new if level onto the if stack */
1001 /* Check for an overflow of the if stack */
1002 if (IfIndex >= MAX_IFS-1) {
1003 PPError ("Too many nested #if clauses");
1007 /* Push the #if condition */
1010 IfStack[IfIndex] = IFCOND_SKIP | IFCOND_NEEDTERM;
1013 IfStack[IfIndex] = IFCOND_NONE | IFCOND_NEEDTERM;
1014 return (Invert ^ Cond);
1020 static int DoIf (int Skip)
1021 /* Process #if directive */
1025 /* We're about to abuse the compiler expression parser to evaluate the
1026 * #if expression. Save the current tokens to come back here later.
1027 * NOTE: Yes, this is a hack, but it saves a complete separate expression
1028 * evaluation for the preprocessor.
1030 Token SavedCurTok = CurTok;
1031 Token SavedNextTok = NextTok;
1033 /* Make sure the line infos for the tokens won't get removed */
1034 if (SavedCurTok.LI) {
1035 UseLineInfo (SavedCurTok.LI);
1037 if (SavedNextTok.LI) {
1038 UseLineInfo (SavedNextTok.LI);
1042 /* Remove the #if from the line */
1045 while (CurC != '\0') {
1051 /* Start over parsing from line */
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, ";;");
1067 /* Load CurTok and NextTok with tokens from the new input */
1071 /* Call the expression parser */
1072 ConstExpr (hie1, &Expr);
1074 /* End preprocessing mode */
1077 /* Reset the old tokens */
1078 CurTok = SavedCurTok;
1079 NextTok = SavedNextTok;
1081 /* Set the #if condition according to the expression result */
1082 return PushIf (Skip, 1, Expr.IVal != 0);
1087 static int DoIfDef (int skip, int flag)
1088 /* Process #ifdef if flag == 1, or #ifndef if flag == 0. */
1093 if (MacName (Ident) == 0) {
1096 return PushIf (skip, flag, IsMacro(Ident));
1102 static void DoInclude (void)
1103 /* Open an include file. */
1107 StrBuf Filename = STATIC_STRBUF_INITIALIZER;
1113 /* Get the next char and check for a valid file name terminator. Setup
1114 * the include directory spec (SYS/USR) by looking at the terminator.
1129 PPError ("`\"' or `<' expected");
1134 /* Get a copy of the filename */
1135 while (CurC != '\0' && CurC != RTerm) {
1136 SB_AppendChar (&Filename, CurC);
1139 SB_Terminate (&Filename);
1141 /* Check if we got a terminator */
1142 if (CurC != RTerm) {
1143 /* No terminator found */
1144 PPError ("Missing terminator or file name too long");
1148 /* Open the include file */
1149 OpenIncludeFile (SB_GetConstBuf (&Filename), DirSpec);
1152 /* Free the allocated filename data */
1153 DoneStrBuf (&Filename);
1155 /* Clear the remaining line so the next input will come from the new
1163 static void DoError (void)
1164 /* Print an error */
1168 PPError ("Invalid #error directive");
1170 PPError ("#error: %s", SB_GetConstBuf (Line) + SB_GetIndex (Line));
1173 /* Clear the rest of line */
1179 static void DoPragma (void)
1180 /* Handle a #pragma line by converting the #pragma preprocessor directive into
1181 * the _Pragma() compiler operator.
1184 /* Skip blanks following the #pragma directive */
1187 /* Copy the remainder of the line into MLine removing comments and ws */
1189 Pass1 (Line, MLine);
1191 /* Convert the directive into the operator */
1192 SB_CopyStr (Line, "_Pragma (");
1194 Stringize (MLine, Line);
1195 SB_AppendChar (Line, ')');
1197 /* Initialize reading from line */
1204 void Preprocess (void)
1205 /* Preprocess a line */
1210 /* Create the output buffer if we don't already have one */
1212 MLine = NewStrBuf ();
1215 /* Skip white space at the beginning of the line */
1218 /* Check for stuff to skip */
1220 while (CurC == '\0' || CurC == '#' || Skip) {
1222 /* Check for preprocessor lines lines */
1227 /* Ignore the empty preprocessor directive */
1230 if (!IsSym (Directive)) {
1231 PPError ("Preprocessor directive expected");
1234 switch (FindPPToken (Directive)) {
1244 if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) {
1246 /* Handle as #else/#if combination */
1247 if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) {
1250 IfStack[IfIndex] |= IFCOND_ELSE;
1253 /* #elif doesn't need a terminator */
1254 IfStack[IfIndex] &= ~IFCOND_NEEDTERM;
1256 PPError ("Duplicate #else/#elif");
1259 PPError ("Unexpected #elif");
1265 if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) {
1266 if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) {
1269 IfStack[IfIndex] |= IFCOND_ELSE;
1271 PPError ("Duplicate #else");
1274 PPError ("Unexpected `#else'");
1280 /* Remove any clauses on top of stack that do not
1281 * need a terminating #endif.
1283 while (IfIndex >= 0 && (IfStack[IfIndex] & IFCOND_NEEDTERM) == 0) {
1287 /* Stack may not be empty here or something is wrong */
1288 CHECK (IfIndex >= 0);
1290 /* Remove the clause that needs a terminator */
1291 Skip = (IfStack[IfIndex--] & IFCOND_SKIP) != 0;
1293 PPError ("Unexpected `#endif'");
1308 Skip = DoIfDef (Skip, 1);
1312 Skip = DoIfDef (Skip, 0);
1322 /* Should do something in C99 at least, but we ignore it */
1342 PPError ("Preprocessor directive expected");
1348 if (NextLine () == 0) {
1350 PPError ("`#endif' expected");
1360 if (Verbosity > 1 && SB_NotEmpty (Line)) {
1361 printf ("%s(%u): %.*s\n", GetCurrentFile (), GetCurrentLine (),
1362 SB_GetLen (Line), SB_GetConstBuf (Line));