summaryrefslogtreecommitdiff
path: root/compiler_and_linker/FrontEnd/C/CPrep.c
diff options
context:
space:
mode:
Diffstat (limited to 'compiler_and_linker/FrontEnd/C/CPrep.c')
-rw-r--r--compiler_and_linker/FrontEnd/C/CPrep.c136
1 files changed, 78 insertions, 58 deletions
diff --git a/compiler_and_linker/FrontEnd/C/CPrep.c b/compiler_and_linker/FrontEnd/C/CPrep.c
index 7b6ece7..cf2a4cd 100644
--- a/compiler_and_linker/FrontEnd/C/CPrep.c
+++ b/compiler_and_linker/FrontEnd/C/CPrep.c
@@ -51,8 +51,10 @@ static void prepmacro(Macro *macro);
static void prepifskip(void);
static void gotonexttoken(void);
+#ifdef CW_CLT
extern SInt16 *CLT_filesp;
extern CPrepFileInfo **CLT_filestack;
+#endif
struct CompilerOption {
char *name;
@@ -390,8 +392,10 @@ Boolean setupprep(void) {
tokenstacklevel = 0;
cprep_cursymfile = 0;
cprep_files = 0;
+#ifdef CW_CLT
CLT_filesp = &filesp;
CLT_filestack = filestack;
+#endif
anyerrors = 0;
fatalerrors = 0;
was_prep_error = 0;
@@ -403,11 +407,9 @@ Boolean setupprep(void) {
if (InitGList(&mlist, 10000))
CError_NoMem();
- stringmem = COS_NewHandle(256);
- if (!stringmem)
+ if (!(stringmem = COS_NewHandle(256)))
CError_NoMem();
- ts_buffer = COS_NewHandle(1024 * sizeof(TStreamElement));
- if (!ts_buffer)
+ if (!(ts_buffer = COS_NewHandle(1024 * sizeof(TStreamElement))))
CError_NoMem();
COS_LockHandleHi(ts_buffer);
ts_first = (TStreamElement *) *ts_buffer;
@@ -495,7 +497,7 @@ static Boolean setupfile(StringPtr filename, Boolean flag1, Boolean flag2) {
SInt16 refnum;
SInt16 file_vrefnum;
char *extpos;
- unsigned char *src;
+ char *src;
char *append;
char *dst;
int len;
@@ -519,7 +521,7 @@ static Boolean setupfile(StringPtr filename, Boolean flag1, Boolean flag2) {
if (CWFindAndLoadFile(cparamblkptr->context, myfilename, &fileinfo) != cwNoErr) {
if (filename[0] + strlen(".framework/Headers") < 255) {
if ((extpos = strchr(myfilename, '/'))) {
- src = filename + 1;
+ src = (char *) filename + 1;
append = ".framework/Headers";
dst = myfilename;
len = filename[0];
@@ -804,8 +806,8 @@ loop:
void CPrep_StreamGetBlock(TokenStream *stream, CPrepStreamFuncPtr func, int arg) {
Boolean save_eoltokens;
- SInt32 start_offset;
Boolean tryflag;
+ SInt32 start_offset;
SInt32 count;
start_offset = ts_current - ts_first - 1;
@@ -997,8 +999,8 @@ void CPrep_TokenStreamFlush(void) {
ts_current = ts_first;
}
-static int CPrep_TokenSize(char *str) {
- int len;
+static short CPrep_TokenSize(char *str) {
+ short len;
int c;
if ((str[0] >= 'a' && str[0] <= 'z') || (str[0] >= 'A' && str[0] <= 'Z') || (str[0] == '_')) {
@@ -1028,16 +1030,31 @@ static int CPrep_TokenSize(char *str) {
if (str[1] == '=' || str[1] == '+') return 2;
break;
case '-':
- if (str[1] == '>') return (str[2] == '*') ? 3 : 2;
+ if (str[1] == '>') {
+ if (str[2] == '*')
+ return 3;
+ else
+ return 2;
+ }
if (str[1] == '=' || str[1] == '-') return 2;
break;
case '<':
if (str[1] == '=') return 2;
- if (str[1] == '<') return (str[2] == '=') ? 3 : 2;
+ if (str[1] == '<') {
+ if (str[2] == '=')
+ return 3;
+ else
+ return 2;
+ }
break;
case '>':
if (str[1] == '=') return 2;
- if (str[1] == '>') return (str[2] == '=') ? 3 : 2;
+ if (str[1] == '>') {
+ if (str[2] == '=')
+ return 3;
+ else
+ return 2;
+ }
break;
case '&':
if (str[1] == '=' || str[1] == '&') return 2;
@@ -1087,7 +1104,7 @@ void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SIn
int r5;
int r6;
char *r7;
- char *r5x;
+ const char *r5x;
SInt16 c;
if (token && !token->tokenfile)
@@ -1129,7 +1146,7 @@ void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SIn
if (!cprep_hasprepline) {
line = 1;
for (i = 0; i < p; i++) {
- if (filedata[i] == '\r')
+ if (filedata[i] == 13)
line++;
}
*plinenumber = line;
@@ -1148,17 +1165,19 @@ void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SIn
}
*tokenoffset = 0;
r5 = 1;
- while (r5 < 80 && (r7 - r5) >= r4 && r7[-r5] != '\r')
+ while (r5 < 80 && (r7 - r5) >= r4 && r7[-r5] != 13)
r5++;
r5--;
while ((c = r7[-r5]) && (c == ' ' || c == '\t' || c == TK_4))
r5--;
r6 = 0;
- while ((c = r7[-r5]) != '\r' && c && r6 < 126) {
+ while ((c = r7[-r5]) != 13 && c && r6 < 126) {
if (!r5)
*tokenoffset = r6;
if (c != TK_4) {
- buf1[r6++] = (c != '\t') ? c : ' ';
+ if (c == '\t')
+ c = ' ';
+ buf1[r6++] = c;
}
r5--;
}
@@ -1179,8 +1198,8 @@ void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SIn
r5x = filedata;
*lastarg = p;
}
- for (i = 0; i < 31 && *r5x; i++) {
- buf2[i] = *(r5x++);
+ for (i = 0; i < 31 && r5x[i]; i++) {
+ buf2[i] = r5x[i];
}
buf2[i] = 0;
@@ -1577,7 +1596,7 @@ static Boolean is_nextchar(short t) {
return 0;
p = tokenstack[--level].pos;
continue;
- case '\r':
+ case 13:
p++;
continue;
}
@@ -1765,7 +1784,7 @@ loop:
}
pos = nextcharpos;
goto loop;
- case '\r':
+ case 13:
newline();
pos = nextcharpos;
goto loop;
@@ -1794,7 +1813,7 @@ loop:
poptokenseq();
goto loop;
}
- case '\r':
+ case 13:
return 0;
}
@@ -2159,7 +2178,7 @@ static Boolean CPrep_CheckTarget(void) {
}
static Boolean CPrep_CheckOption(void) {
- UInt16 offset;
+ UInt32 offset;
UInt8 *ptr;
struct CompilerOption *option;
Boolean result;
@@ -2381,7 +2400,7 @@ char *CPrep_GetFileName(char *buffer, Boolean flag1, Boolean flag2) {
FSSpec spec;
Str255 filename;
int size;
- char *src;
+ StringPtr src;
char *dst;
COS_FileGetFSSpecInfo(&filestack[flag1 ? 0 : filesp]->textfile, NULL, NULL, filename);
@@ -2395,7 +2414,7 @@ char *CPrep_GetFileName(char *buffer, Boolean flag1, Boolean flag2) {
if (flag2)
*(dst++) = '"';
- src = (char *) filename;
+ src = filename;
while (size-- > 0)
*(dst++) = *(++src);
@@ -2759,32 +2778,29 @@ void CPrep_PopOption(SInt32 id) {
}
static void CPrep_PragmaImExport(int flags) {
- // does not match - weirdness with the branching inside the loop
NameSpaceObjectList *list;
do {
- if (!notendofline())
- break;
- if (plex() != TK_IDENTIFIER)
+ if (
+ !notendofline() ||
+ plex() != TK_IDENTIFIER ||
+ !(list = CScope_GetLocalObject(cscope_root, tkidentifier))
+ )
break;
- if (!(list = CScope_GetLocalObject(cscope_root, tkidentifier))) {
- break;
- } else {
- while (list) {
- if (list->object->otype == OT_OBJECT) {
- switch (OBJECT(list->object)->datatype) {
- case DDATA:
- case DFUNC:
- OBJECT(list->object)->flags |= flags;
- break;
- default:
- CPrep_Warning(CErrorStr186);
- return;
- }
+ while (list) {
+ if (list->object->otype == OT_OBJECT) {
+ switch (OBJECT(list->object)->datatype) {
+ case DDATA:
+ case DFUNC:
+ OBJECT(list->object)->flags |= flags;
+ break;
+ default:
+ CPrep_Warning(CErrorStr186);
+ return;
}
- list = list->next;
}
+ list = list->next;
}
if (!notendofline())
@@ -2839,24 +2855,25 @@ static void pragma_on_off_reset(UInt32 bits) {
}
static HashNameNode *CPrep_PragmaOnceName(StringPtr name, Boolean flag) {
- // does not match, can't be bothered to fix it atm
- short len;
- char myname[256];
- unsigned char *src;
+ char buf[256];
+ char *myname;
+ char *src;
char *dst;
+ short len;
len = name[0];
if (len > 250)
len = 250;
- dst = &myname[1];
- src = &name[1];
+ myname = &buf[1];
+ dst = myname;
+ src = (char *) &name[1];
while (len-- > 0) {
*(dst++) = tolower(*(src++));
}
*dst = 0;
- myname[0] = (copts.syspath_once && flag) ? '$' : -'\\';
+ *(--myname) = (copts.syspath_once && flag) ? '$' : -'\\';
return GetHashNameNodeExport(myname);
}
@@ -2935,7 +2952,7 @@ static void CPrep_PragmaUnused(void) {
list = CScope_GetLocalObject(nspace, tkidentifier);
if (list && list->object->otype == OT_OBJECT && OBJECT(list->object)->datatype == DLOCAL) {
- OBJECT(list->object)->flags |= OBJECT_FLAGS_1;
+ OBJECT(list->object)->flags = OBJECT(list->object)->flags | OBJECT_FLAGS_1;
if (notendofline()) {
t = plex();
if (t == ')')
@@ -2966,10 +2983,13 @@ static void CPrep_PragmaInlineDepth(void) {
break;
case TK_INTCONST:
lv = CInt64_GetULong(&tkintconst);
- if (lv >= 0 && lv <= 1024)
- copts.inlinelevel = lv ? lv : -1;
- else
+ if (lv >= 0 && lv <= 1024) {
+ if (!lv)
+ lv = -1;
+ copts.inlinelevel = lv;
+ } else {
CPrep_Warning(CErrorStr186);
+ }
break;
default:
CPrep_Warning(CErrorStr186);
@@ -4168,7 +4188,7 @@ static void prepifskip(void) {
CPrep_Error(CErrorStr105);
}
goto restart;
- case '\r':
+ case 13:
newline();
goto restart;
case '"':
@@ -4181,7 +4201,7 @@ static void prepifskip(void) {
t = prepskipnextchar();
pos = nextcharpos;
switch (t) {
- case '\r':
+ case 13:
goto restart;
case 0:
CPrep_Error(CErrorStr102);
@@ -4227,7 +4247,7 @@ void preprocessor(void) {
switch (t) {
case 0:
CPrep_Error(CErrorStr102);
- case '\r':
+ case 13:
return;
}