summaryrefslogtreecommitdiff
path: root/compiler_and_linker/FrontEnd/C/CPrepTokenizer.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-01-20 00:39:43 +0000
committerAsh Wolf <ninji@wuffs.org>2023-01-20 00:39:43 +0000
commit7d986adf37220e1981a707745b784b078de4e3bc (patch)
tree831dea5f470c0c6b3c373f38d3a5f0354bc22600 /compiler_and_linker/FrontEnd/C/CPrepTokenizer.c
parent4d670146b4054e11e90227f96a3a1c66410e8d0b (diff)
downloadMWCC-7d986adf37220e1981a707745b784b078de4e3bc.tar.gz
MWCC-7d986adf37220e1981a707745b784b078de4e3bc.zip
fix various inaccuracies exposed by the mach ppc plugin
Diffstat (limited to '')
-rw-r--r--compiler_and_linker/FrontEnd/C/CPrepTokenizer.c160
1 files changed, 80 insertions, 80 deletions
diff --git a/compiler_and_linker/FrontEnd/C/CPrepTokenizer.c b/compiler_and_linker/FrontEnd/C/CPrepTokenizer.c
index 6d66b9d..8890be7 100644
--- a/compiler_and_linker/FrontEnd/C/CPrepTokenizer.c
+++ b/compiler_and_linker/FrontEnd/C/CPrepTokenizer.c
@@ -37,11 +37,11 @@ loop:
goto loop;
case ' ':
case '\t':
- case '\n':
+ case LF:
case '\v':
case '\f':
- spaceskip = 1;
p++;
+ spaceskip = 1;
goto loop;
case ';':
pos = (char *) p++;
@@ -64,17 +64,17 @@ loop:
case '/':
pos = (char *) p++;
if (copts.multibyteaware) {
- while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == '\r') {
+ while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
}
} else {
- while (p[0] == '\\' && p[1] == '\r') {
+ while (p[0] == '\\' && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -99,17 +99,17 @@ loop:
}
if (c == '*') {
if (copts.multibyteaware) {
- while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == '\r') {
+ while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
}
} else {
- while (p[0] == '\\' && p[1] == '\r') {
+ while (p[0] == '\\' && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -120,7 +120,7 @@ loop:
goto loop;
}
}
- if (c == '\r')
+ if (c == CR)
foundnl();
}
}
@@ -138,10 +138,10 @@ loop:
case '\\':
pos = (char *) p++;
mid_backslash:
- if (*p == '\r') {
+ if (*p == CR) {
if (!copts.multibyteaware || !COS_IsMultiByte(start, p - 1)) {
foundnl();
- if (p[1] == '\n')
+ if (p[1] == LF)
p += 2;
else
p += 1;
@@ -208,17 +208,17 @@ loop:
return c;
case '/':
if (copts.multibyteaware) {
- while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == '\r') {
+ while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
}
} else {
- while (p[0] == '\\' && p[1] == '\r') {
+ while (p[0] == '\\' && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -242,17 +242,17 @@ loop:
}
if (c == '*') {
if (copts.multibyteaware) {
- while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == '\r') {
+ while (p[0] == '\\' && !COS_IsMultiByte(start, p) && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
}
} else {
- while (p[0] == '\\' && p[1] == '\r') {
+ while (p[0] == '\\' && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -261,7 +261,7 @@ loop:
if (*p == '/')
break;
}
- if (c == '\r')
+ if (c == CR)
foundnl();
}
pos = (char *) p + 1;
@@ -272,10 +272,10 @@ loop:
}
case '\\':
backslash:
- if (*p == '\r') {
+ if (*p == CR) {
if (!copts.multibyteaware || !COS_IsMultiByte(start, p - 1)) {
foundnl();
- if (p[1] == '\n')
+ if (p[1] == LF)
p += 2;
else
p += 1;
@@ -345,12 +345,12 @@ loop:
return c;
case '\\':
backslash:
- if (p[0] == '\r' && (!copts.multibyteaware || !COS_IsMultiByte(str, p - 1))) {
+ if (p[0] == CR && (!copts.multibyteaware || !COS_IsMultiByte(str, p - 1))) {
if (flag)
foundnl();
else
prepnextstringchar_foundnl = 1;
- if (p[1] == '\n')
+ if (p[1] == LF)
p += 2;
else
p += 1;
@@ -421,11 +421,11 @@ loop:
return;
}
- if (c == '\r') {
+ if (c == CR) {
if (!copts.multibyteaware || !COS_IsMultiByte(start, p - 1)) {
if (flag)
foundnl();
- if (*p == '\n')
+ if (*p == LF)
p++;
CPrep_Error(CErrorStr112);
pos = p;
@@ -445,8 +445,8 @@ loop:
case '<':
case '=':
case '>':
- haveBackslash = 0;
p += 2;
+ haveBackslash = 0;
goto loop;
case '/':
p += 2;
@@ -456,10 +456,10 @@ loop:
if (c == '\\' && !haveBackslash && (!copts.multibyteaware || !COS_IsMultiByte(start, p - 1))) {
backslash:
- if (*p == '\r') {
+ if (*p == CR) {
if (flag)
foundnl();
- if (*(++p) == '\n')
+ if (*(++p) == LF)
p++;
haveBackslash = 0;
} else {
@@ -496,11 +496,11 @@ loop:
return p - 1;
}
- if (c == '\r') {
+ if (c == CR) {
if (!copts.multibyteaware || !COS_IsMultiByte(start, p - 1)) {
if (flag)
foundnl();
- if (*p == '\n')
+ if (*p == LF)
p++;
CPrep_Error(CErrorStr112);
return p;
@@ -519,8 +519,8 @@ loop:
case '<':
case '=':
case '>':
- haveBackslash = 0;
p += 2;
+ haveBackslash = 0;
goto loop;
case '/':
p += 2;
@@ -530,10 +530,10 @@ loop:
if (c == '\\' && !haveBackslash && (!copts.multibyteaware || !COS_IsMultiByte(start, p - 1))) {
backslash:
- if (*p == '\r') {
+ if (*p == CR) {
if (flag)
foundnl();
- if (*(++p) == '\n')
+ if (*(++p) == LF)
p++;
haveBackslash = 0;
} else {
@@ -582,7 +582,7 @@ static void prepcurstringchar_skip(void) {
}
char *ReadIdentifier(const char *p) {
- char buf[256];
+ unsigned char buf[256];
const char *start;
unsigned int ch;
int len;
@@ -590,15 +590,15 @@ char *ReadIdentifier(const char *p) {
start = p;
len = 0;
for (;;) {
- ch = (unsigned char) *p;
- if (cprep_idarray[ch]) {
+ ch = *p;
+ if (cprep_idarray[(unsigned char) *p]) {
if (len < 255)
buf[len++] = *p;
p++;
} else {
if (copts.multibyteaware) {
- if ((unsigned char) *p == '\\' && !COS_IsMultiByte(start, p) && p[1] == '\r') {
- if (p[2] == '\n')
+ if ((unsigned char) *p == '\\' && !COS_IsMultiByte(start, p) && p[1] == CR) {
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -607,8 +607,8 @@ char *ReadIdentifier(const char *p) {
break;
}
} else {
- if ((unsigned char) *p == '\\' && p[1] == '\r') {
- if (p[2] == '\n')
+ if ((unsigned char) *p == '\\' && p[1] == CR) {
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -621,7 +621,7 @@ char *ReadIdentifier(const char *p) {
}
buf[len] = 0;
- tkidentifier = GetHashNameNodeExport(buf);
+ tkidentifier = GetHashNameNodeExport((char *) buf);
return (char *) p;
}
@@ -807,14 +807,14 @@ static SInt32 nextchar(StringPtr str) {
case 'f': return 12;
case 'n':
if (copts.mpwc_newline)
- return 13;
+ return CR;
else
- return 10;
+ return LF;
case 'r':
if (copts.mpwc_newline)
- return 10;
+ return LF;
else
- return 13;
+ return CR;
case 'e': return 27;
case 'x':
chr = tohex(prepnextstringchar(str, 1));
@@ -874,26 +874,26 @@ StringPtr CPrep_SkipNewComment(StringPtr str) {
p[-1] = ' ';
continue;
- case '\r':
- CPrep_SkipNewCommentChar = '\r';
+ case CR:
+ CPrep_SkipNewCommentChar = CR;
return p;
case '\\':
if (copts.multibyteaware && COS_IsMultiByte(str, p - 1))
continue;
- if (*p == '\r') {
+ if (*p == CR) {
++p;
foundnl();
}
- if (*p == '\n')
+ if (*p == LF)
p++;
continue;
case '"':
if (InlineAsm_gccmode) {
- CPrep_SkipNewCommentChar = '\r';
+ CPrep_SkipNewCommentChar = CR;
return p - 1;
}
continue;
@@ -910,7 +910,7 @@ Boolean skipendoflinematch(StringPtr str, short token) {
while (1) {
switch (*(str++)) {
case 0:
- case '\r':
+ case CR:
pos = (char *) str - 1;
return 0;
@@ -937,16 +937,16 @@ Boolean skipendoflinematch(StringPtr str, short token) {
pos = (char *) str - 1;
return 0;
- case '\r':
+ case CR:
foundnl();
- if (*str == '\n')
+ if (*str == LF)
str++;
break;
}
break;
case '?':
- if (copts.trigraphs && str[0] == '?' && str[1] == '/' && str[2] == '\r') {
+ if (copts.trigraphs && str[0] == '?' && str[1] == '/' && str[2] == CR) {
foundnl();
str += 3;
}
@@ -966,7 +966,7 @@ void skipendofline(void) {
while (1) {
switch (*(p++)) {
case 0:
- case '\r':
+ case CR:
pos = (char *) p - 1;
return;
@@ -984,17 +984,17 @@ void skipendofline(void) {
case '/':
if (copts.multibyteaware) {
- while (*p == '\\' && !COS_IsMultiByte(start, p) && p[1] == '\r') {
+ while (*p == '\\' && !COS_IsMultiByte(start, p) && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
}
} else {
- while (*p == '\\' && p[1] == '\r') {
+ while (*p == '\\' && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -1004,7 +1004,7 @@ void skipendofline(void) {
if (*p == '/' && (!copts.ANSIstrict || copts.cplusplus)) {
// EOL comment
pos = (char *) CPrep_SkipNewComment(p + 1);
- if (CPrep_SkipNewCommentChar == '\r')
+ if (CPrep_SkipNewCommentChar == CR)
pos--;
return;
}
@@ -1026,17 +1026,17 @@ void skipendofline(void) {
if (ch == '*') {
if (copts.multibyteaware) {
- while (*p == '\\' && !COS_IsMultiByte(start, p) && p[1] == '\r') {
+ while (*p == '\\' && !COS_IsMultiByte(start, p) && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
}
} else {
- while (*p == '\\' && p[1] == '\r') {
+ while (*p == '\\' && p[1] == CR) {
foundnl();
- if (p[2] == '\n')
+ if (p[2] == LF)
p += 3;
else
p += 2;
@@ -1049,7 +1049,7 @@ void skipendofline(void) {
}
}
- if (ch == '\r')
+ if (ch == CR)
foundnl();
}
}
@@ -1059,9 +1059,9 @@ void skipendofline(void) {
if (copts.multibyteaware && COS_IsMultiByte(start, p - 1))
continue;
- if (*p == '\r') {
+ if (*p == CR) {
foundnl();
- if (p[1] == '\n')
+ if (p[1] == LF)
p += 2;
else
p += 1;
@@ -1069,7 +1069,7 @@ void skipendofline(void) {
break;
case '?':
- if (copts.trigraphs && p[0] == '?' && p[1] == '/' && p[2] == '\r') {
+ if (copts.trigraphs && p[0] == '?' && p[1] == '/' && p[2] == CR) {
foundnl();
p += 3;
}
@@ -1106,7 +1106,7 @@ static short tapos(short _t) {
start = (StringPtr) pos;
t = nextchar((StringPtr) pos);
- if ((t == '\'' || t == 0 || t == '\r') && !was_escchar) {
+ if ((t == '\'' || t == 0 || t == CR) && !was_escchar) {
CPrep_Error(CErrorStr100);
tkintconst = cint64_zero;
tksize = IT_INT;
@@ -1169,7 +1169,7 @@ static short tapos(short _t) {
i = bytecount;
while (1) {
- if ((t2 == 0 || t2 == '\r') && !was_escchar) {
+ if ((t2 == 0 || t2 == CR) && !was_escchar) {
CPrep_Error(CErrorStr100);
break;
}
@@ -1201,7 +1201,7 @@ static short tapos(short _t) {
static short tquot(short t) {
Type *type;
- StringPtr string_ptr;
+ char *string_ptr;
SInt32 size;
short c;
StringPtr save_pos;
@@ -1213,7 +1213,7 @@ static short tquot(short t) {
if (cprep_nostring)
return '"';
- string_ptr = (StringPtr) *stringmem;
+ string_ptr = *stringmem;
ispascalstring = 0;
size = 0;
if (widestring)
@@ -1235,7 +1235,7 @@ static short tquot(short t) {
while (1) {
c = nextchar(start_pos);
- if ((c == '"' || c == '\r' || c == 0) && !was_escchar) {
+ if ((c == '"' || c == CR || c == 0) && !was_escchar) {
if (c == 0 && (tokenstacklevel > 0 || pos >= prep_file_end))
CPrep_Error(CErrorStr102);
else if (c != '"')
@@ -1243,10 +1243,10 @@ static short tquot(short t) {
break;
}
if ((size + type->size) >= maxstringsize) {
- SInt32 offset = string_ptr - (StringPtr) *stringmem;
+ SInt32 offset = string_ptr - *stringmem;
if (!COS_ResizeHandle(stringmem, maxstringsize += 256))
CError_NoMem();
- string_ptr = (StringPtr) *stringmem + offset;
+ string_ptr = *stringmem + offset;
}
if (type->size != 1) {
CInt64_SetLong(&ch64, c);
@@ -2242,7 +2242,7 @@ typedef struct StringChunk {
} StringChunk;
static void CPrep_StringConCat(Boolean flag) {
- StringPtr buffer;
+ char *buffer;
StringChunk *chunks;
StringChunk *chunk;
char *saveString;
@@ -2287,7 +2287,7 @@ static void CPrep_StringConCat(Boolean flag) {
}
elem = ts_current - 1;
- elem->data.tkstring.data = (char *) buffer;
+ elem->data.tkstring.data = buffer;
elem->data.tkstring.size = offset;
elem->subtype = ispascalstring;
cprep_strconcat = 0;