summaryrefslogtreecommitdiff
path: root/compiler_and_linker/FrontEnd/C/CPrep.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-01-13 01:38:15 +0000
committerAsh Wolf <ninji@wuffs.org>2023-01-13 01:38:15 +0000
commit08d21a052b9afc37292ec3fad390502610e2cb32 (patch)
tree270737c790f5d1bb05f68498f8233640ada6a0c5 /compiler_and_linker/FrontEnd/C/CPrep.c
parent54628993e0038c7bea9c064491974985b6699502 (diff)
parent9d985413ce2b60a1a8cf001913ee8dac81c03aac (diff)
downloadMWCC-08d21a052b9afc37292ec3fad390502610e2cb32.tar.gz
MWCC-08d21a052b9afc37292ec3fad390502610e2cb32.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '')
-rw-r--r--compiler_and_linker/FrontEnd/C/CPrep.c126
1 files changed, 61 insertions, 65 deletions
diff --git a/compiler_and_linker/FrontEnd/C/CPrep.c b/compiler_and_linker/FrontEnd/C/CPrep.c
index 80472b1..36ba0f9 100644
--- a/compiler_and_linker/FrontEnd/C/CPrep.c
+++ b/compiler_and_linker/FrontEnd/C/CPrep.c
@@ -4137,7 +4137,6 @@ static void prependif(void) {
}
static void prepifskip(void) {
- // this function does something very weird with its code generation that i can't match
TStreamElement ts;
short t;
@@ -4146,78 +4145,75 @@ static void prepifskip(void) {
case IfState_1:
case IfState_3:
case IfState_4:
- while (1) {
- t = prepskipnextchar();
- pos = nextcharpos;
- switch (t) {
- case 0:
- if (tokenstacklevel > 0) {
- poptokenseq();
- } else if (tokenstacklevel > 0 || pos >= prep_file_end) {
- if (filesp > 0) {
- popfile();
- } else {
- was_prep_error = 0;
- ts.tokenfile = ifstack[iflevel - 1].file;
- ts.tokenoffset = ifstack[iflevel - 1].pos;
- CError_SetErrorToken(&ts);
- CError_ErrorTerm(CErrorStr119);
- iflevel = 0;
- return;
- }
+ restart:
+ t = prepskipnextchar();
+ pos = nextcharpos;
+ switch (t) {
+ case 0:
+ if (tokenstacklevel > 0) {
+ poptokenseq();
+ } else if (tokenstacklevel > 0 || pos >= prep_file_end) {
+ if (filesp > 0) {
+ popfile();
} else {
- CPrep_Error(CErrorStr105);
- }
- continue;
- case '\r':
- newline();
- continue;
- case '"':
- skipendoflinematch((StringPtr) pos, '"');
- continue;
- case '\'':
- skipendoflinematch((StringPtr) pos, '"');
- continue;
- case '#':
- t = prepskipnextchar();
- pos = nextcharpos;
- switch (t) {
- case '\r':
- continue;
- case 0:
- CPrep_Error(CErrorStr102);
- default:
- pos = ReadIdentifier(pos - 1);
- if (!strcmp("if", tkidentifier->name)) {
- prepif();
- } else if (!strcmp("ifdef", tkidentifier->name)) {
- prepifdef();
- } else if (!strcmp("ifndef", tkidentifier->name)) {
- prepifndef();
- } else if (!strcmp("elif", tkidentifier->name)) {
- prepelif();
- } else if (!strcmp("else", tkidentifier->name)) {
- prepelse();
- } else if (!strcmp("endif", tkidentifier->name)) {
- prependif();
- } else {
- skipendofline();
- continue;
- }
+ was_prep_error = 0;
+ ts.tokenfile = ifstack[iflevel - 1].file;
+ ts.tokenoffset = ifstack[iflevel - 1].pos;
+ CError_SetErrorToken(&ts);
+ CError_ErrorTerm(CErrorStr119);
+ iflevel = 0;
+ return;
}
- break;
- default:
- skipendofline();
- continue;
- }
- break;
+ } else {
+ CPrep_Error(CErrorStr105);
+ }
+ goto restart;
+ case '\r':
+ newline();
+ goto restart;
+ case '"':
+ skipendoflinematch((StringPtr) pos, '"');
+ goto restart;
+ case '\'':
+ skipendoflinematch((StringPtr) pos, '"');
+ goto restart;
+ case '#':
+ t = prepskipnextchar();
+ pos = nextcharpos;
+ switch (t) {
+ case '\r':
+ goto restart;
+ case 0:
+ CPrep_Error(CErrorStr102);
+ default:
+ pos = ReadIdentifier(pos - 1);
+ if (!strcmp("if", tkidentifier->name)) {
+ prepif();
+ } else if (!strcmp("ifdef", tkidentifier->name)) {
+ prepifdef();
+ } else if (!strcmp("ifndef", tkidentifier->name)) {
+ prepifndef();
+ } else if (!strcmp("elif", tkidentifier->name)) {
+ prepelif();
+ } else if (!strcmp("else", tkidentifier->name)) {
+ prepelse();
+ } else if (!strcmp("endif", tkidentifier->name)) {
+ prependif();
+ } else {
+ skipendofline();
+ goto restart;
+ }
+ }
+ break;
+ default:
+ skipendofline();
+ goto restart;
}
break;
case IfState_2:
default:
return;
}
- return;
}
}