fixed a problem with #ifdef/#else/#endif

This commit is contained in:
ceriel 1988-03-08 11:42:00 +00:00
parent 1a259744af
commit 4b79636b8f
4 changed files with 14 additions and 10 deletions

View file

@ -32,6 +32,8 @@ PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
/* 1 if a corresponding ELSE has been */ /* 1 if a corresponding ELSE has been */
/* encountered. */ /* encountered. */
int nestlevel = -1;
PRIVATE struct idf * PRIVATE struct idf *
GetIdentifier() GetIdentifier()
{ {
@ -184,7 +186,7 @@ skip_block()
} }
break; break;
case K_ENDIF: case K_ENDIF:
ASSERT(nestlevel >= 0); ASSERT(nestlevel > nestlow);
if (nestlevel == skiplevel) { if (nestlevel == skiplevel) {
SkipRestOfLine(); SkipRestOfLine();
nestlevel--; nestlevel--;
@ -249,7 +251,7 @@ do_include()
File_Inserted = 1; File_Inserted = 1;
FileName = result; FileName = result;
LineNumber = 0; LineNumber = 0;
nestlevel = -1; nestlow = nestlevel;
} }
} }
} }
@ -314,7 +316,7 @@ push_if()
PRIVATE PRIVATE
do_elif() do_elif()
{ {
if (nestlevel < 0 || (ifstack[nestlevel])) { if (nestlevel <= nestlow || (ifstack[nestlevel])) {
lexerror("#elif without corresponding #if"); lexerror("#elif without corresponding #if");
SkipRestOfLine(); SkipRestOfLine();
} }
@ -329,7 +331,7 @@ PRIVATE
do_else() do_else()
{ {
SkipRestOfLine(); SkipRestOfLine();
if (nestlevel < 0 || (ifstack[nestlevel])) if (nestlevel <= nestlow || (ifstack[nestlevel]))
lexerror("#else without corresponding #if"); lexerror("#else without corresponding #if");
else { /* mark this level as else-d */ else { /* mark this level as else-d */
++(ifstack[nestlevel]); ++(ifstack[nestlevel]);
@ -341,7 +343,7 @@ PRIVATE
do_endif() do_endif()
{ {
SkipRestOfLine(); SkipRestOfLine();
if (nestlevel < 0) { if (nestlevel <= nestlow) {
lexerror("#endif without corresponding #if"); lexerror("#endif without corresponding #if");
} }
else nestlevel--; else nestlevel--;

View file

@ -7,12 +7,12 @@
struct file_info { struct file_info {
unsigned int fil_lino; unsigned int fil_lino;
int fil_nestlevel; int fil_nestlow;
char *fil_name; char *fil_name;
char *fil_wdir; char *fil_wdir;
}; };
#define nestlevel finfo.fil_nestlevel #define nestlow finfo.fil_nestlow
#define LineNumber finfo.fil_lino #define LineNumber finfo.fil_lino
#define FileName finfo.fil_name #define FileName finfo.fil_name
#define WorkingDir finfo.fil_wdir #define WorkingDir finfo.fil_wdir

View file

@ -10,6 +10,7 @@
#define INP_TYPE struct file_info #define INP_TYPE struct file_info
#define INP_VAR finfo #define INP_VAR finfo
struct file_info finfo; struct file_info finfo;
extern int nestlevel;
#include "nopp.h" #include "nopp.h"
#include <inp_pkg.body> #include <inp_pkg.body>
@ -44,7 +45,7 @@ int NoUnstack;
AtEoIT() AtEoIT()
{ {
#ifndef NOPP #ifndef NOPP
if (NoUnstack) lexwarning("unexpected EOF"); /* if (NoUnstack) lexwarning("unexpected EOF"); ??? */
DoUnstack(); DoUnstack();
#endif NOPP #endif NOPP
return 0; return 0;
@ -54,9 +55,10 @@ AtEoIF()
{ {
#ifndef NOPP #ifndef NOPP
if (nestlevel != -1) lexwarning("missing #endif"); if (nestlevel != nestlow) lexwarning("missing #endif");
else else
#endif NOPP #endif NOPP
if (NoUnstack) lexwarning("unexpected EOF"); if (NoUnstack) lexwarning("unexpected EOF");
nestlevel = nestlow;
return 0; return 0;
} }

View file

@ -171,7 +171,7 @@ compile(argc, argv)
File_Inserted = 1; File_Inserted = 1;
init(); init();
LineNumber = 0; LineNumber = 0;
nestlevel = -1; nestlow = -1;
#ifndef NOPP #ifndef NOPP
WorkingDir = getwdir(source); WorkingDir = getwdir(source);
#endif NOPP #endif NOPP