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.c1362
1 files changed, 1014 insertions, 348 deletions
diff --git a/compiler_and_linker/FrontEnd/C/CPrep.c b/compiler_and_linker/FrontEnd/C/CPrep.c
index f38c504..80472b1 100644
--- a/compiler_and_linker/FrontEnd/C/CPrep.c
+++ b/compiler_and_linker/FrontEnd/C/CPrep.c
@@ -1,16 +1,25 @@
-#include "compiler.h"
+#include "compiler/CPrep.h"
+#include "compiler/CBrowse.h"
+#include "compiler/CCompiler.h"
#include "compiler/CError.h"
+#include "compiler/CException.h"
#include "compiler/CInt64.h"
-#include "compiler/objects.h"
-#include "compiler/scopes.h"
-#include "compiler/tokens.h"
-#include "cos.h"
#include "compiler/CMachine.h"
#include "compiler/CParser.h"
-#include "compiler/CPrep.h"
+#include "compiler/CPrec.h"
+#include "compiler/CPreprocess.h"
#include "compiler/CPrepTokenizer.h"
#include "compiler/CScope.h"
+#include "compiler/CSOM.h"
#include "compiler/CodeGen.h"
+#include "compiler/CompilerTools.h"
+#include "compiler/FuncLevelAsmPPC.h"
+#include "compiler/IroPointerAnalysis.h"
+#include "compiler/ObjGenMachO.h"
+#include "compiler/objects.h"
+#include "compiler/scopes.h"
+#include "compiler/tokens.h"
+#include "cos.h"
#ifdef __MWERKS__
#pragma options align=mac68k
@@ -31,17 +40,16 @@ enum {
IfState_1 = 1,
IfState_2 = 2,
IfState_3 = 3,
- IfState_4 = 4,
- IfState_5 = 5
+ IfState_4 = 4
};
// forward declarations
-static PrepValue CPrep_ParseCond();
-static PrepValue CPrep_ParseBinary(PrepValue *rhs, short op);
+static PrepValue CPrep_ParseCond(void);
+static PrepValue CPrep_ParseBinary(PrepValue *rhs, short precLimit);
static char *XpandMacro(Macro *macro);
static void prepmacro(Macro *macro);
-static void prepifskip();
-static void gotonexttoken();
+static void prepifskip(void);
+static void gotonexttoken(void);
extern SInt16 *CLT_filesp;
extern CPrepFileInfo **CLT_filestack;
@@ -305,7 +313,7 @@ static void cannotopenerror(StringPtr filename, Boolean err) {
if (prep_file) {
was_prep_error = 1;
- CError_Error(151, fname);
+ CError_Error(CErrorStr151, fname);
if (err)
longjmp(errorreturn, 1);
} else {
@@ -325,7 +333,7 @@ void CPrep_InsertSpecialMacro(Macro *macro, char *name) {
insertmacro(macro);
}
-void CPrep_InsertSpecialMacros() {
+void CPrep_InsertSpecialMacros(void) {
CPrep_InsertSpecialMacro(&lineM, "__LINE__");
CPrep_InsertSpecialMacro(&fileM, "__FILE__");
CPrep_InsertSpecialMacro(&dateM, "__DATE__");
@@ -343,7 +351,7 @@ void CPrep_InsertSpecialMacros() {
CodeGen_InsertSpecialMacros();
}
-void CPrep_RemoveSpecialMacros() {
+void CPrep_RemoveSpecialMacros(void) {
Macro **scan;
int x;
@@ -359,11 +367,11 @@ void CPrep_RemoveSpecialMacros() {
}
}
-static void CPrep_Reconfig() {
+static void CPrep_Reconfig(void) {
cprep_idarray['$'] = copts.dollar_identifiers != 0;
}
-Boolean setupprep() {
+Boolean setupprep(void) {
int x;
now_time = time(NULL);
@@ -436,7 +444,7 @@ Boolean setupprep() {
return 0;
}
-void cleanupprep() {
+void cleanupprep(void) {
while (filesp >= 0)
popfile();
@@ -494,7 +502,7 @@ static Boolean setupfile(StringPtr filename, Boolean flag1, Boolean flag2) {
if (filesp >= 31) {
was_prep_error = 1;
- CError_ErrorTerm(243);
+ CError_ErrorTerm(CErrorStr243);
return 0;
}
@@ -657,11 +665,10 @@ void CPrep_TokenStreamSetState(SInt32 *state) {
ts_current = ts_first + *state;
}
-void CPrep_UnLex() {
+void CPrep_UnLex(void) {
++ts_preread_elements;
--ts_current;
-#line 900
- CError_ASSERT(ts_current >= ts_first);
+ CError_ASSERT(900, ts_current >= ts_first);
}
void CPrep_TokenStreamSetCurState(SInt32 *state) {
@@ -726,7 +733,7 @@ loop:
}
if (!t)
return 0;
- if (t == TK_NEG7) {
+ if (t == TK_EOL) {
t = lex();
v++;
}
@@ -795,7 +802,7 @@ loop:
return v;
}
-void CPrep_StreamGetBlock(TStream *stream, CPrepStreamFuncPtr func, int arg) {
+void CPrep_StreamGetBlock(TokenStream *stream, CPrepStreamFuncPtr func, int arg) {
Boolean save_eoltokens;
SInt32 start_offset;
Boolean tryflag;
@@ -814,20 +821,20 @@ void CPrep_StreamGetBlock(TStream *stream, CPrepStreamFuncPtr func, int arg) {
tryflag = 1;
case ':':
if (!(count = CPrep_StreamSkipToBrace(func, 0))) {
- CError_Error(121);
+ CError_Error(CErrorStr121);
cprep_eoltokens = save_eoltokens;
return;
}
case '{':
break;
default:
- CError_Error(121);
+ CError_Error(CErrorStr121);
cprep_eoltokens = save_eoltokens;
return;
}
if (!(count = CPrep_StreamSkipBlock(func, count))) {
- CError_Error(121);
+ CError_Error(CErrorStr121);
cprep_eoltokens = save_eoltokens;
return;
}
@@ -835,12 +842,12 @@ void CPrep_StreamGetBlock(TStream *stream, CPrepStreamFuncPtr func, int arg) {
if (tryflag) {
tryloop:
switch (lex()) {
- case TK_NEG7:
+ case TK_EOL:
count++;
goto tryloop;
case TK_CATCH:
if (!(count = CPrep_StreamSkipToBrace(func, count)) || !(count = CPrep_StreamSkipBlock(func, count))) {
- CError_Error(242);
+ CError_Error(CErrorStr242);
cprep_eoltokens = save_eoltokens;
return;
}
@@ -848,7 +855,7 @@ void CPrep_StreamGetBlock(TStream *stream, CPrepStreamFuncPtr func, int arg) {
goto tryloop;
break;
default:
- CError_Error(242);
+ CError_Error(CErrorStr242);
cprep_eoltokens = save_eoltokens;
return;
}
@@ -860,7 +867,7 @@ void CPrep_StreamGetBlock(TStream *stream, CPrepStreamFuncPtr func, int arg) {
memcpy(stream->firsttoken, ts_first + start_offset, count * sizeof(TStreamElement));
}
-void CPrep_StreamGetSemicolon(TStream *stream, CPrepStreamFuncPtr func) {
+void CPrep_StreamGetSemicolon(TokenStream *stream, CPrepStreamFuncPtr func) {
SInt32 count;
SInt32 start_offset;
Boolean save_eoltokens;
@@ -887,7 +894,7 @@ void CPrep_StreamGetSemicolon(TStream *stream, CPrepStreamFuncPtr func) {
cprep_eoltokens = save_eoltokens;
}
-void CPrep_StreamGetTemplate(TStream *stream, CPrepStreamFuncPtr func) {
+void CPrep_StreamGetTemplate(TokenStream *stream, CPrepStreamFuncPtr func) {
SInt32 count;
SInt32 start_offset;
Boolean save_eoltokens;
@@ -903,9 +910,9 @@ void CPrep_StreamGetTemplate(TStream *stream, CPrepStreamFuncPtr func) {
loop:
switch (tk) {
case 0:
- CError_ErrorTerm(102);
+ CError_ErrorTerm(CErrorStr102);
case '}':
- CError_Error(229);
+ CError_Error(CErrorStr229);
return;
case ';':
count++;
@@ -940,7 +947,7 @@ loop:
if (level <= 0)
break;
if (!(tk = lex()))
- CError_ErrorTerm(102);
+ CError_ErrorTerm(CErrorStr102);
} while (1);
if (lookahead() == ';') {
tk = lex();
@@ -954,7 +961,7 @@ loop:
cprep_eoltokens = save_eoltokens;
}
-void CPrep_StreamInsert(TStream *stream, SInt32 *state) {
+void CPrep_StreamInsert(TokenStream *stream, SInt32 *state) {
if (ts_preread_elements + (ts_current - ts_first) + stream->tokens >= ts_elements)
CPrep_TSBufferGrow(stream->tokens);
if (ts_preread_elements)
@@ -964,7 +971,7 @@ void CPrep_StreamInsert(TStream *stream, SInt32 *state) {
CPrep_TokenStreamGetState(state);
}
-void CPrep_StreamRemove(TStream *stream, SInt32 *state) {
+void CPrep_StreamRemove(TokenStream *stream, SInt32 *state) {
TStreamElement *end;
SInt32 amount;
@@ -979,14 +986,13 @@ void CPrep_StreamRemove(TStream *stream, SInt32 *state) {
}
void CPrep_RemoveTokens(SInt32 amount) {
-#line 1296
- CError_ASSERT(ts_preread_elements >= amount);
+ CError_ASSERT(1296, ts_preread_elements >= amount);
ts_preread_elements -= amount;
memmove(ts_current, ts_current + amount, sizeof(TStreamElement) * ts_preread_elements);
}
-void CPrep_TokenStreamFlush() {
+void CPrep_TokenStreamFlush(void) {
if (!ts_preread_elements)
ts_current = ts_first;
}
@@ -1060,7 +1066,7 @@ static int CPrep_TokenSize(char *str) {
return 1;
}
-TStreamElement *CPrep_CurStreamElement() {
+TStreamElement *CPrep_CurStreamElement(void) {
static TStreamElement dummyelement;
if (ts_first < ts_current)
return ts_current - 1;
@@ -1091,10 +1097,8 @@ void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SIn
if (!token && ts_first < ts_current)
prevtoken = ts_current - 1;
- if (prevtoken && !prevtoken->tokenfile) {
-#line 1454
- CError_FATAL();
- }
+ if (prevtoken && !prevtoken->tokenfile)
+ CError_FATAL(1454);
if (was_prep_error || !prevtoken) {
if (!prep_file)
@@ -1147,13 +1151,13 @@ void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SIn
while (r5 < 80 && (r7 - r5) >= r4 && r7[-r5] != '\r')
r5++;
r5--;
- while ((c = r7[-r5]) && (c == ' ' || c == '\t' || c == 4))
+ while ((c = r7[-r5]) && (c == ' ' || c == '\t' || c == TK_4))
r5--;
r6 = 0;
while ((c = r7[-r5]) != '\r' && c && r6 < 126) {
if (!r5)
*tokenoffset = r6;
- if (c != 4) {
+ if (c != TK_4) {
buf1[r6++] = (c != '\t') ? c : ' ';
}
r5--;
@@ -1200,7 +1204,7 @@ void CPrep_ErrorName(short code, const char *name) {
in_assembler = 0;
was_prep_error = 1;
if (code == 102 && (tokenstacklevel > 0 || pos < prep_file_end))
- CError_Error(105, name);
+ CError_Error(CErrorStr105, name);
else
CError_Error(code, name);
in_assembler = save;
@@ -1238,18 +1242,20 @@ void CPrep_ErrorMessageVA(int code, const char *format, va_list list, Boolean fl
in_assembler = save;
}
-void popfile() {
- // r5 and r6 are swapped, not sure why
+void popfile(void) {
+ CPrepFileInfo *file;
+
if (filesp >= 0) {
CWReleaseFileText(cparamblkptr->context, prep_file->textbuffer);
prep_file->textbuffer = NULL;
if (--filesp >= 0) {
- prep_file = filestack[filesp];
- prep_file_start = prep_file->textbuffer;
- prep_file_end = prep_file->textbuffer + prep_file->textlength;
- pos = prep_file_start + prep_file->pos;
- linenumber = prep_file->linenumber;
- cprep_hasprepline = prep_file->hasprepline;
+ file = filestack[filesp];
+ prep_file = file;
+ prep_file_start = file->textbuffer;
+ prep_file_end = file->textbuffer + file->textlength;
+ pos = prep_file_start + file->pos;
+ linenumber = file->linenumber;
+ cprep_hasprepline = file->hasprepline;
at_linestart = 1;
}
if (preprocessing_only && !copts.simple_prepdump)
@@ -1257,7 +1263,7 @@ void popfile() {
}
}
-static SInt32 prepoffset() {
+static SInt32 prepoffset(void) {
if (filesp > 0)
return filestack[0]->pos;
else if (tokenstacklevel)
@@ -1266,7 +1272,7 @@ static SInt32 prepoffset() {
return pos - filestack[0]->textbuffer;
}
-static SInt32 prepoffset2() {
+static SInt32 prepoffset2(void) {
return lineoffset;
}
@@ -1396,8 +1402,7 @@ void CPrep_GetFileOffsetInfo2(FileOffsetInfo *foi, SInt32 *pLine, HashNameNode *
}
*pLine = foi->tokenline;
-#line 2010
- CError_ASSERT(*pLine >= 0);
+ CError_ASSERT(2010, *pLine >= 0);
*pName = foi->file ? foi->file->nameNode : NULL;
}
@@ -1484,14 +1489,14 @@ UInt8 C_Compiler(CParams *param) {
if (tokenstacklevel) {
was_prep_error = 1;
- CError_ErrorTerm(119);
+ CError_ErrorTerm(CErrorStr119);
} else if (iflevel) {
was_prep_error = 0;
ts.tokenfile = ifstack[iflevel - 1].file;
ts.tokenoffset = ifstack[iflevel - 1].pos;
if (iflevel)
CError_SetErrorToken(&ts);
- CError_ErrorTerm(119);
+ CError_ErrorTerm(CErrorStr119);
}
if (!anyerrors) {
@@ -1536,7 +1541,7 @@ UInt8 C_Compiler(CParams *param) {
static void pushtokenseq(Macro *macro) {
if (tokenstacklevel >= 128) {
was_prep_error = 1;
- CError_ErrorTerm(111);
+ CError_ErrorTerm(CErrorStr111);
} else {
tokenstack[tokenstacklevel].pos = pos;
tokenstack[tokenstacklevel].macrostart = macrostart;
@@ -1548,7 +1553,7 @@ static void pushtokenseq(Macro *macro) {
}
}
-void poptokenseq() {
+void poptokenseq(void) {
if (!--tokenstacklevel && dofreeaheap)
freeaheap();
@@ -1586,7 +1591,7 @@ static Boolean is_nextchar(short t) {
return 0;
}
-static Macro *ismacroname() {
+static Macro *ismacroname(void) {
Macro *scan;
Boolean save_macrocheck;
HashNameNode *name = tkidentifier;
@@ -1675,7 +1680,7 @@ static Macro *ismacroname5(char *str) {
return NULL;
}
-static Macro *ismacroname3() {
+static Macro *ismacroname3(void) {
Macro *scan;
HashNameNode *name = tkidentifier;
@@ -1716,7 +1721,7 @@ static Macro *ismacroname4(HashNameNode *name) {
return scan;
}
-void foundnl() {
+void foundnl(void) {
if (!tokenstacklevel) {
if (preprocessing_only)
CPrep_PreprocessDumpNewLine();
@@ -1727,7 +1732,7 @@ void foundnl() {
}
}
-void newline() {
+void newline(void) {
foundnl();
nlflag = 1;
at_linestart = 1;
@@ -1739,7 +1744,7 @@ void newline() {
}
}
-static void gotonexttoken() {
+static void gotonexttoken(void) {
char *save_pos;
Macro *macro;
char c;
@@ -1777,7 +1782,7 @@ loop:
}
}
-short notendofline() {
+short notendofline(void) {
char *save_pos;
Macro *macro;
char c;
@@ -1809,80 +1814,286 @@ loop:
static void CPrep_MacroRedefError(char *name, Boolean *flag) {
if (!*flag) {
if (copts.gcc_extensions) {
- CPrep_WarningName(108, name);
+ CPrep_WarningName(CErrorStr108, name);
} else if (copts.cpp_extensions) {
if (copts.pedantic)
- CPrep_WarningName(108, name);
+ CPrep_WarningName(CErrorStr108, name);
} else {
- CPrep_ErrorName(108, name);
+ CPrep_ErrorName(CErrorStr108, name);
}
*flag = 1;
}
}
-static void goendofline() {
+static void goendofline(void) {
if (notendofline()) {
- CPrep_Error(113);
+ CPrep_Error(CErrorStr113);
skipendofline();
}
}
-static void CPrep_Define() {
+static void CPrep_Define(void) {
Macro *existing_macro; // r31
- HashNameNode *name; // r29
- short r28; // r28
- Boolean r27; // r27
Macro *macro; // r20
+ HashNameNode *name; // r29
+ HashNameNode **names; // r20
short t; // r17
+ short i;
+ short argCount; // r28
+ char *ptr19;
+ char *ptr17;
+ Boolean hasVarArgs; // r27
+ Boolean isPrecedingTokenAnArg;
+ Boolean tokenPasteFlag;
Boolean error_flag;
+ HashNameNode *myNameList[128];
macrocheck = 0;
nlflag = 0;
t = lexidentifier();
if (nlflag) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
skipendofline();
}
if (t != TK_IDENTIFIER) {
- CPrep_Error(107);
+ CPrep_Error(CErrorStr107);
skipendofline();
return;
}
- macro = ismacroname3();
+ existing_macro = ismacroname3();
name = tkidentifier;
error_flag = 0;
- r27 = 0;
+ hasVarArgs = 0;
if (prepcurchar() == '(') {
- r28 = 1;
+ argCount = 1;
pos = nextcharpos;
- // fix me
+ if (existing_macro)
+ names = existing_macro->names;
+ else
+ names = NULL;
+
+ do {
+ t = lexidentifier();
+ if (t != TK_IDENTIFIER)
+ break;
+
+ if (nlflag) {
+ CPrep_Error(CErrorStr112);
+ return;
+ }
+
+ if (!strcmp(tkidentifier->name, "__VA_ARGS__")) {
+ CPrep_ErrorName(CErrorStr365, tkidentifier->name);
+ return;
+ }
+
+ for (i = 1; i < argCount; i++) {
+ if (!strcmp(tkidentifier->name, myNameList[i - 1]->name)) {
+ CPrep_ErrorName(CErrorStr365, tkidentifier->name);
+ return;
+ }
+ }
+
+ myNameList[argCount - 1] = tkidentifier;
+
+ if (existing_macro) {
+ if ((existing_macro->xC & 0x7FFF) < argCount)
+ CPrep_MacroRedefError(name->name, &error_flag);
+ if (names[argCount - 1] != tkidentifier && !copts.cpp_extensions)
+ CPrep_MacroRedefError(name->name, &error_flag);
+ }
+
+ if (argCount >= 128)
+ CError_Error(CErrorStr110);
+ else
+ argCount++;
+
+ t = plex();
+ if (nlflag) {
+ CPrep_Error(CErrorStr112);
+ return;
+ }
+ } while (t == ',');
+
+ if (nlflag) {
+ CPrep_Error(CErrorStr112);
+ return;
+ }
+
+ if (t == TK_ELLIPSIS) {
+ hasVarArgs = 1;
+ myNameList[argCount - 1] = GetHashNameNode("__VA_ARGS__");
+ if (argCount >= 128)
+ CError_Error(CErrorStr110);
+ else
+ argCount++;
+
+ t = plex();
+ if (nlflag) {
+ CPrep_Error(CErrorStr112);
+ return;
+ }
+ }
+
+ if (t != ')') {
+ CPrep_Error(CErrorStr109);
+ skipendofline();
+ return;
+ }
+
+ macro = galloc(sizeof(Macro) + sizeof(HashNameNode *) + sizeof(HashNameNode *) * (argCount - 2));
} else {
macro = galloc(sizeof(Macro));
- r28 = 0;
+ argCount = 0;
}
- if (existing_macro && (existing_macro->xC & 0x7FFF) != r28)
+ if (existing_macro && (existing_macro->xC & 0x7FFF) != argCount)
CPrep_MacroRedefError(name->name, &error_flag);
macro->name = name;
- macro->xC = r27 ? (r28 | 0x8000) : r28;
+ macro->xC = hasVarArgs ? (argCount | 0x8000) : argCount;
macro->is_special = 0;
macro->xF = 0;
- if (r28 > 1) {
- // fix me
- }
+ for (i = 1; i < argCount; i++)
+ macro->names[i - 1] = myNameList[i - 1];
mlist.size = 0;
if (notendofline()) {
- // fix me
+ while (1) {
+ tokenPasteFlag = 0;
+ innerLoop:
+ isPrecedingTokenAnArg = 0;
+ ptr19 = pos;
+ spaceskip = 0;
+ t = prepnextchar();
+
+ switch (t) {
+ case 0:
+ CPrep_Error(CErrorStr102);
+ break;
+
+ case '"':
+ case '\'':
+ CPrep_MatchChar(t, 1);
+ AppendGListData(&mlist, ptr19, pos - ptr19);
+ break;
+
+ case '#':
+ ptr17 = pos;
+ if (prepnextchar() == '#')
+ CPrep_Error(CErrorStr117);
+ pos = ptr17;
+
+ if (notendofline()) {
+ t = prepnextchar();
+ if ((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z') || t == '_') {
+ pos = ReadIdentifier(pos - 1);
+ for (i = 1; i < argCount; i++) {
+ if (tkidentifier == macro->names[i - 1])
+ break;
+ }
+
+ if (i < argCount) {
+ AppendGListByte(&mlist, TK_MACRO_ARG_HASH);
+ AppendGListByte(&mlist, i);
+ break;
+ }
+ }
+ }
+
+ if (copts.ANSI_strict)
+ CPrep_Error(CErrorStr117);
+ AppendGListByte(&mlist, '#');
+ pos = ptr17;
+ break;
+
+ default:
+ if ((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z') || t == '_') {
+ pos = ReadIdentifier(pos - 1);
+ for (i = 1; i < argCount; i++) {
+ if (tkidentifier == macro->names[i - 1])
+ break;
+ }
+
+ if (i < argCount) {
+ AppendGListByte(&mlist, tokenPasteFlag ? TK_MACRO_ARG_2 : TK_MACRO_ARG_1);
+ AppendGListByte(&mlist, i);
+ isPrecedingTokenAnArg = 1;
+ } else {
+ AppendGListName(&mlist, tkidentifier->name);
+ }
+ } else {
+ AppendGListByte(&mlist, t);
+ }
+ }
+
+ if (!notendofline())
+ break;
+
+ ptr17 = pos;
+ if (prepnextchar() == '#' && prepnextchar() == '#') {
+ if (!notendofline())
+ CPrep_Error(CErrorStr117);
+ if (isPrecedingTokenAnArg)
+ (*mlist.data)[mlist.size - 2] = TK_MACRO_ARG_2;
+ tokenPasteFlag = 1;
+ goto innerLoop;
+ }
+ pos = ptr17;
+
+ if (spaceskip)
+ AppendGListByte(&mlist, ' ');
+ }
+ }
+
+ macrocheck = 1;
+
+ if (mlist.size > 0) {
+ AppendGListByte(&mlist, 0);
+ if (mlist.size > 0x20000) {
+ CPrep_Error(CErrorStr111);
+ return;
+ }
+
+ if (existing_macro) {
+ if (!existing_macro->c || memcmp(*mlist.data, existing_macro->c, mlist.size))
+ CPrep_MacroRedefError(name->name, &error_flag);
+ }
+
+ macro->c = galloc(mlist.size);
+ memcpy(macro->c, *mlist.data, mlist.size);
} else {
- // fix me
+ macro->c = NULL;
+ if (existing_macro && existing_macro->c)
+ CPrep_MacroRedefError(name->name, &error_flag);
+ }
+
+ if (existing_macro && error_flag)
+ return;
+
+ macro->next = macrohashtable[macro->name->hashval];
+ macrohashtable[macro->name->hashval] = macro;
+
+ if (cparamblkptr->browseOptions.recordMacros && prep_file->recordbrowseinfo) {
+ CBrowse_NewMacro(macro, prep_file, gDirectiveStart, pos - prep_file_start + 1);
+ }
+
+ if (error_flag) {
+ macro = macrohashtable[macro->name->hashval];
+ while (1) {
+ if (macro->next == existing_macro) {
+ macro->next = macro->next->next;
+ break;
+ }
+ macro = macro->next;
+ CError_ASSERT(2847, macro);
+ }
}
}
-static void prepundefine() {
+static void prepundefine(void) {
short t;
Macro *macro;
Macro **scan;
@@ -1891,10 +2102,10 @@ static void prepundefine() {
nlflag = 0;
t = lexidentifier();
if (nlflag) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
skipendofline();
} else if (t != TK_IDENTIFIER) {
- CPrep_Error(107);
+ CPrep_Error(CErrorStr107);
skipendofline();
} else {
name = tkidentifier;
@@ -1909,12 +2120,121 @@ static void prepundefine() {
}
}
-static Boolean CPrep_CheckTarget() {}
-static Boolean CPrep_CheckOption() {}
-static char *CPrep_XpandDefinedCheck(char *) {}
+static Boolean CPrep_CheckTarget(void) {
+ Boolean result;
+
+ if (!notendofline()) {
+ CError_Error(CErrorStr112);
+ return 0;
+ }
+
+ if (plex() != '(') {
+ CError_Error(CErrorStr114);
+ return 0;
+ }
+
+ if (!notendofline()) {
+ CError_Error(CErrorStr112);
+ return 0;
+ }
+
+ if (plex() != TK_STRING) {
+ CError_Error(CErrorStr120);
+ return 0;
+ }
+
+ result = !strcmp(cparams.targetName, tkstring);
+
+ if (!notendofline()) {
+ CError_Error(CErrorStr112);
+ return 0;
+ }
+
+ if (plex() != ')') {
+ CError_Error(CErrorStr115);
+ return 0;
+ }
+
+ return result;
+}
+
+static Boolean CPrep_CheckOption(void) {
+ UInt16 offset;
+ UInt8 *ptr;
+ struct CompilerOption *option;
+ Boolean result;
+
+ if (!notendofline()) {
+ CError_Error(CErrorStr112);
+ return 0;
+ }
+
+ if (plex() != '(') {
+ CError_Error(CErrorStr114);
+ return 0;
+ }
+
+ if (!notendofline()) {
+ CError_Error(CErrorStr112);
+ return 0;
+ }
+
+ if (lexidentifier() != TK_IDENTIFIER) {
+ CError_Error(CErrorStr107);
+ return 0;
+ }
+
+ if (!strcmp(tkidentifier->name, "scheduling")) {
+ result = copts.schedule_mode != 0;
+ } else if (!strcmp(tkidentifier->name, "precompile")) {
+ result = cparamblkptr->isPrecompiling == 1;
+ } else if (!strcmp(tkidentifier->name, "preprocess")) {
+ result = cparamblkptr->isPreprocessing;
+ } else {
+ for (option = compileroptions; option->name; option++) {
+ if (!strcmp(tkidentifier->name, option->name)) {
+ offset = option->bits & OPT_OFFSET_MASK;
+ ptr = (UInt8 *) (offset + (intptr_t) &copts);
+ result = *ptr;
+ if (offset == OPT_OFFSET(booltruefalse) && !copts.cplusplus)
+ result = 0;
+ goto gotResult;
+ }
+ }
+ result = 0;
+ }
+
+gotResult:
+ if (!notendofline()) {
+ CError_Error(CErrorStr112);
+ return 0;
+ }
+
+ if (plex() != ')') {
+ CError_Error(CErrorStr115);
+ return 0;
+ }
+
+ return result;
+}
+
+static char *CPrep_XpandDefinedCheck(char *str) {
+ while (*str == ' ' || (*str >= 9 && *str <= 12))
+ str++;
+
+ if (*str == '(') {
+ str++;
+ while (*str == ' ' || (*str >= 9 && *str <= 12))
+ str++;
+ }
+
+ if ((*str >= 'a' && *str <= 'z') || (*str >= 'A' && *str <= 'Z') || *str == '_')
+ return ReadIdentifier(str);
+
+ return NULL;
+}
static char *XpandString(Macro *macro, char *somepos) {
- // almost matches, r22 and r23 are swapped at the end
short start_level;
char *curpos;
char *tmp;
@@ -1923,7 +2243,6 @@ static char *XpandString(Macro *macro, char *somepos) {
char *macro_output;
Macro *macro2;
int c;
- char *resultptr;
pushtokenseq(macro);
macropos = somepos;
@@ -1971,7 +2290,7 @@ static char *XpandString(Macro *macro, char *somepos) {
tmplen = mlist.size;
if (tmplen > 0x20000) {
macropos = pos;
- CPrep_Error(111);
+ CPrep_Error(CErrorStr111);
return "";
}
curpos = aalloc(tmplen);
@@ -2049,16 +2368,43 @@ static char *XpandString(Macro *macro, char *somepos) {
AppendGListByte(&mlist, 0);
skip_null_term:
if ((tmplen = mlist.size) > 0x20000) {
- CPrep_Error(111);
+ CPrep_Error(CErrorStr111);
return "";
- } else {
- resultptr = aalloc(tmplen);
- memcpy(resultptr, *mlist.data, tmplen);
- return resultptr;
}
+
+ tmp = aalloc(tmplen);
+ memcpy(tmp, *mlist.data, tmplen);
+ return tmp;
}
char *CPrep_GetFileName(char *buffer, Boolean flag1, Boolean flag2) {
+ FSSpec spec;
+ Str255 filename;
+ int size;
+ char *src;
+ char *dst;
+
+ COS_FileGetFSSpecInfo(&filestack[flag1 ? 0 : filesp]->textfile, NULL, NULL, filename);
+
+ size = filename[0];
+ if (!buffer)
+ buffer = galloc(size + 3);
+
+ dst = buffer;
+
+ if (flag2)
+ *(dst++) = '"';
+
+ src = (char *) filename;
+ while (size-- > 0)
+ *(dst++) = *(++src);
+
+ if (flag2)
+ *(dst++) = '"';
+
+ *(dst++) = 0;
+
+ return buffer;
}
static char *XpandSpecialMacro(Macro *macro) {
@@ -2113,6 +2459,230 @@ static char *XpandSpecialMacro(Macro *macro) {
}
static char *XpandMacro(Macro *macro) {
+ void **buf1;
+ void **buf2;
+ Boolean hasVarArgs;
+ int argCount;
+ int maxArgs;
+ char *p;
+ char *p2;
+ char *input;
+ short ch;
+ short t;
+ short i;
+ short depth;
+ short spaceFlag;
+ Boolean inVarArgs;
+ SInt32 tmplen;
+
+ if (macro->is_special)
+ return XpandSpecialMacro(macro);
+
+ argCount = macro->xC & 0x7FFF;
+ hasVarArgs = (macro->xC & 0x8000) != 0;
+
+ if (argCount) {
+ gotonexttoken();
+ CError_ASSERT(3293, prepnextchar() == '(');
+ if (argCount > 1) {
+ inVarArgs = hasVarArgs && argCount == 2;
+ maxArgs = argCount - 1;
+ buf1 = aalloc(sizeof(void *) * maxArgs);
+ buf2 = aalloc(sizeof(void *) * maxArgs);
+ i = 1;
+ while (i < argCount) {
+ spaceFlag = 1;
+ depth = 0;
+ mlist.size = 0;
+ restart1:
+ spaceskip = 0;
+ restart2:
+ t = prepnextchar();
+ switch (t) {
+ case '\r':
+ foundnl();
+ spaceskip = 1;
+ goto restart2;
+ case '\t':
+ case '\n':
+ case '\v':
+ case '\f':
+ case ' ':
+ spaceskip = 1;
+ goto restart2;
+ case 0:
+ if (tokenstacklevel != 0) {
+ poptokenseq();
+ goto restart2;
+ }
+ CPrep_Error(CErrorStr102);
+ break;
+ case '"':
+ case '\'':
+ p = pos - 1;
+ CPrep_MatchChar(t, 0);
+ AppendGListData(&mlist, p, pos - p);
+ goto restart1;
+ case ')':
+ if (--depth < 0) {
+ if (++i >= argCount)
+ break;
+ macropos = pos;
+ CPrep_Error(CErrorStr116);
+ return "";
+ }
+ goto do_default;
+ case ',':
+ if (depth <= 0 && !inVarArgs) {
+ i++;
+ if (hasVarArgs && i == maxArgs) {
+ inVarArgs = 1;
+ } else if (i >= argCount) {
+ macropos = pos;
+ CPrep_Error(CErrorStr115);
+ return "";
+ }
+ break;
+ }
+ goto do_default;
+ case '(':
+ depth++;
+ default:
+ do_default:
+ if (spaceskip && !spaceFlag)
+ AppendGListByte(&mlist, ' ');
+ AppendGListByte(&mlist, t);
+ spaceFlag = 0;
+ goto restart1;
+ }
+
+ buf2[i - 2] = buf1[i - 2] = NULL;
+ if (mlist.size > 0) {
+ AppendGListByte(&mlist, 0);
+ tmplen = mlist.size;
+ if (tmplen <= 0x20000) {
+ buf1[i - 2] = aalloc(tmplen);
+ memcpy(buf1[i - 2], *mlist.data, tmplen);
+ } else {
+ CPrep_Error(CErrorStr111);
+ }
+ }
+ }
+ } else {
+ gotonexttoken();
+ if (prepnextchar() != ')') {
+ macropos = pos;
+ CPrep_Error(CErrorStr115);
+ }
+ }
+ }
+
+ if (!macro->c)
+ return "";
+
+ if (argCount <= 1 && hasVarArgs == 0)
+ return XpandString(macro, macro->c);
+
+ input = macro->c;
+ mlist.size = 0;
+ while ((ch = *(input++))) {
+ switch (ch) {
+ case '"':
+ case '\'':
+ p = input - 1;
+ input = CPrep_MatchChar2(input, ch, 0);
+ AppendGListData(&mlist, p, input - p);
+ break;
+
+ case TK_MACRO_ARG_2:
+ p = buf1[*(input++) - 1];
+ if (p) {
+ while (1) {
+ switch (*p) {
+ case 0:
+ break;
+ case TK_4:
+ case TK_5:
+ p++;
+ continue;
+ default:
+ AppendGListByte(&mlist, *(p++));
+ continue;
+ }
+ break;
+ }
+ }
+ break;
+
+ case TK_MACRO_ARG_HASH:
+ AppendGListByte(&mlist, '"');
+ p = buf1[*(input++) - 1];
+ if (p) {
+ while ((ch = *(p++))) {
+ switch (ch) {
+ case TK_4:
+ case TK_5:
+ break;
+ case '"':
+ AppendGListByte(&mlist, '\\');
+ case '\'':
+ AppendGListByte(&mlist, ch);
+ while (*p && *p != ch) {
+ if (*p == '"' || *p == '\\')
+ AppendGListByte(&mlist, '\\');
+ AppendGListByte(&mlist, *(p++));
+ }
+ if (*p == '"')
+ AppendGListByte(&mlist, '\\');
+ if (*p)
+ AppendGListByte(&mlist, *(p++));
+ break;
+ default:
+ AppendGListByte(&mlist, ch);
+ break;
+ }
+ }
+ }
+ AppendGListByte(&mlist, '"');
+ break;
+
+ case TK_MACRO_ARG_1:
+ i = *(input++) - 1;
+ p = buf2[i];
+ if (!p) {
+ if (!buf1[i])
+ break;
+
+ tmplen = mlist.size;
+ p2 = aalloc(tmplen);
+ memcpy(p2, *mlist.data, tmplen);
+ p = buf2[i] = XpandString(NULL, buf1[i]);
+ mlist.size = 0;
+ AppendGListData(&mlist, p2, tmplen);
+ }
+
+ while (*p)
+ AppendGListByte(&mlist, *(p++));
+
+ if (p[-1] == '>' && *input == '>')
+ AppendGListByte(&mlist, ' ');
+ break;
+
+ default:
+ AppendGListByte(&mlist, ch);
+ }
+ }
+
+ AppendGListByte(&mlist, 0);
+
+ if (mlist.size > 0x20000) {
+ CPrep_Error(CErrorStr111);
+ return "";
+ } else {
+ p = aalloc(mlist.size);
+ memcpy(p, *mlist.data, mlist.size);
+ return XpandString(macro, p);
+ }
}
static void prepmacro(Macro *macro) {
@@ -2133,7 +2703,7 @@ static void prepmacro(Macro *macro) {
spaceskip = save_spaceskip;
}
-Boolean macrotest() {
+Boolean macrotest(void) {
Macro *macro;
if ((macro = ismacroname())) {
prepmacro(macro);
@@ -2147,7 +2717,7 @@ short CPrep_PragmaLex(Boolean no_err) {
if (notendofline())
return plex();
if (!no_err)
- CPrep_Error(113);
+ CPrep_Error(CErrorStr113);
return 0;
}
@@ -2209,7 +2779,7 @@ static void CPrep_PragmaImExport(int flags) {
OBJECT(list->object)->flags |= flags;
break;
default:
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
return;
}
}
@@ -2222,7 +2792,7 @@ static void CPrep_PragmaImExport(int flags) {
} while (plex() == ',' && notendofline());
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
static void pragma_on_off_reset(UInt32 bits) {
@@ -2258,15 +2828,14 @@ static void pragma_on_off_reset(UInt32 bits) {
else if ((bits & OPT_OFFSET_MASK) == OPT_OFFSET(lib_export))
imex_flags = OBJECT_FLAGS_60;
else
-#line 3610
- CError_FATAL();
+ CError_FATAL(3610);
CPrep_PragmaImExport(imex_flags);
return;
}
}
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
static HashNameNode *CPrep_PragmaOnceName(StringPtr name, Boolean flag) {
@@ -2291,20 +2860,20 @@ static HashNameNode *CPrep_PragmaOnceName(StringPtr name, Boolean flag) {
return GetHashNameNodeExport(myname);
}
-static void pragma_precompile_target() {
+static void pragma_precompile_target(void) {
if (!notendofline()) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
return;
}
if (plex() != TK_STRING) {
- CPrep_Error(117);
+ CPrep_Error(CErrorStr117);
skipendofline();
return;
}
if (ispascalstring) {
- CPrep_Error(101);
+ CPrep_Error(CErrorStr101);
skipendofline();
return;
}
@@ -2319,15 +2888,15 @@ static void CPrep_DefinePragmaOnceMacro(StringPtr name, Boolean flag) {
namenode = CPrep_PragmaOnceName(name, flag);
if (!ismacroname4(namenode)) {
- macro = galloc(sizeof(Macro));
- memclrw(macro, sizeof(Macro));
+ macro = galloc(sizeof(Macro) + sizeof(HashNameNode *));
+ memclrw(macro, sizeof(Macro) + sizeof(HashNameNode *));
macro->name = namenode;
macro->next = macrohashtable[namenode->hashval];
macrohashtable[namenode->hashval] = macro;
}
}
-static void CPrep_PragmaOnce() {
+static void CPrep_PragmaOnce(void) {
if (notendofline()) {
if (plex() == TK_IDENTIFIER) {
if (!strcmp(tkidentifier->name, "on")) {
@@ -2339,7 +2908,7 @@ static void CPrep_PragmaOnce() {
}
}
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
} else {
Str255 filename;
COS_FileGetFSSpecInfo(&prep_file->textfile, NULL, NULL, filename);
@@ -2347,7 +2916,7 @@ static void CPrep_PragmaOnce() {
}
}
-static void CPrep_PragmaUnused() {
+static void CPrep_PragmaUnused(void) {
NameSpace *nspace;
NameSpaceObjectList *list;
short t;
@@ -2366,7 +2935,7 @@ static void CPrep_PragmaUnused() {
list = CScope_GetLocalObject(nspace, tkidentifier);
if (list && list->object->otype == OT_OBJECT && OBJECT(list->object)->datatype == DLOCAL) {
- OBJECT(list->object)->flags |= OBJECT_FLAGS_UNUSED;
+ OBJECT(list->object)->flags |= OBJECT_FLAGS_1;
if (notendofline()) {
t = plex();
if (t == ')')
@@ -2381,17 +2950,17 @@ static void CPrep_PragmaUnused() {
}
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
-static void CPrep_PragmaInlineDepth() {
+static void CPrep_PragmaInlineDepth(void) {
int lv;
if (notendofline() && plex() == '(' && notendofline()) {
switch (plex()) {
case TK_IDENTIFIER:
if (strcmp(tkidentifier->name, "smart"))
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
else
copts.inlinelevel = 0;
break;
@@ -2400,78 +2969,78 @@ static void CPrep_PragmaInlineDepth() {
if (lv >= 0 && lv <= 1024)
copts.inlinelevel = lv ? lv : -1;
else
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
break;
default:
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
if (!notendofline() || plex() != ')') {
- CPrep_Warning(115);
+ CPrep_Warning(CErrorStr115);
}
if (notendofline()) {
- CPrep_Warning(113);
+ CPrep_Warning(CErrorStr113);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
}
-static void CPrep_PragmaInlineMaxSize() {
+static void CPrep_PragmaInlineMaxSize(void) {
if (notendofline() && plex() == '(' && notendofline()) {
switch (plex()) {
case TK_INTCONST:
copts.inline_max_size = CInt64_GetULong(&tkintconst);
break;
default:
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
if (!notendofline() || plex() != ')') {
- CPrep_Warning(115);
+ CPrep_Warning(CErrorStr115);
}
if (notendofline()) {
- CPrep_Warning(113);
+ CPrep_Warning(CErrorStr113);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
}
-static void CPrep_PragmaInlineMaxTotalSize() {
+static void CPrep_PragmaInlineMaxTotalSize(void) {
if (notendofline() && plex() == '(' && notendofline()) {
switch (plex()) {
case TK_INTCONST:
copts.inline_max_total_size = CInt64_GetULong(&tkintconst);
break;
default:
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
if (!notendofline() || plex() != ')') {
- CPrep_Warning(115);
+ CPrep_Warning(CErrorStr115);
}
if (notendofline()) {
- CPrep_Warning(113);
+ CPrep_Warning(CErrorStr113);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
}
-static void pragma_segment() {
+static void pragma_segment(void) {
short i;
short t;
char name[256];
@@ -2490,17 +3059,17 @@ static void pragma_segment() {
name[i] = 0;
if (!i || i >= 255)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
copts.forcedSegment = GetHashNameNodeExport(name);
ObjGen_SegmentName();
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
}
-static void pragma_options() {
+static void pragma_options(void) {
if (notendofline() && plex() == TK_IDENTIFIER && !strcmp(tkidentifier->name, "align") && notendofline() && plex() == '=' && notendofline() && plex() == TK_IDENTIFIER) {
if (!strcmp(tkidentifier->name, "reset")) {
CPrep_PopOption(OPT_OFFSET(align_mode));
@@ -2524,18 +3093,18 @@ static void pragma_options() {
}
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
done:
if (notendofline()) {
- CPrep_Error(113);
+ CPrep_Error(CErrorStr113);
skipendofline();
}
}
-static void pragma_push() {
+static void pragma_push(void) {
struct COptsPush *push;
push = galloc(sizeof(struct COptsPush));
@@ -2545,17 +3114,17 @@ static void pragma_push() {
push->opts = copts;
}
-static void pragma_pop() {
+static void pragma_pop(void) {
if (coptpushs) {
copts = coptpushs->opts;
coptpushs = coptpushs->next;
CMach_Configure();
} else {
- CPrep_Error(237);
+ CPrep_Error(CErrorStr237);
}
}
-static void pragma_overload() {
+static void pragma_overload(void) {
Object *obj;
if (cparamblkptr->isPreprocessing) {
@@ -2567,19 +3136,19 @@ static void pragma_overload() {
tk = lex();
if ((obj = CParser_ParseObject())) {
if (obj->sclass && obj->sclass != 0x103)
- CPrep_Error(177);
+ CPrep_Error(CErrorStr177);
obj->qual |= Q_OVERLOAD;
} else {
- CPrep_Error(186);
+ CPrep_Error(CErrorStr186);
}
if (nlflag)
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
if (tk != ';')
- CPrep_Error(123);
+ CPrep_Error(CErrorStr123);
}
-static void pragma_optimization_level() {
+static void pragma_optimization_level(void) {
short t;
int lv;
@@ -2589,14 +3158,14 @@ static void pragma_optimization_level() {
lv = CInt64_GetULong(&tkintconst);
if (lv >= 0 && lv <= 4) {
if (copts.crippled && lv > 1) {
- CPrep_Warning(385);
+ CPrep_Warning(CErrorStr385);
lv = 1;
}
CPrep_PushOption(OPT_OFFSET(optimizationlevel), lv);
CodeGen_UpdateOptimizerOptions();
CodeGen_UpdateBackEndOptions();
} else {
- CPrep_Error(154);
+ CPrep_Error(CErrorStr154);
skipendofline();
}
} else if (t == TK_IDENTIFIER && !strcmp(tkidentifier->name, "reset")) {
@@ -2604,17 +3173,17 @@ static void pragma_optimization_level() {
CodeGen_UpdateOptimizerOptions();
CodeGen_UpdateBackEndOptions();
} else {
- CPrep_Error(105);
+ CPrep_Error(CErrorStr105);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
}
-static void pragma_opt_unroll_count() {
+static void pragma_opt_unroll_count(void) {
short t;
int lv;
@@ -2627,7 +3196,7 @@ static void pragma_opt_unroll_count() {
CodeGen_UpdateOptimizerOptions();
CodeGen_UpdateBackEndOptions();
} else {
- CPrep_Error(154);
+ CPrep_Error(CErrorStr154);
skipendofline();
}
} else if (t == TK_IDENTIFIER && !strcmp(tkidentifier->name, "reset")) {
@@ -2635,17 +3204,17 @@ static void pragma_opt_unroll_count() {
CodeGen_UpdateOptimizerOptions();
CodeGen_UpdateBackEndOptions();
} else {
- CPrep_Error(105);
+ CPrep_Error(CErrorStr105);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
}
-static void pragma_opt_unroll_instr_count() {
+static void pragma_opt_unroll_instr_count(void) {
short t;
int lv;
@@ -2658,7 +3227,7 @@ static void pragma_opt_unroll_instr_count() {
CodeGen_UpdateOptimizerOptions();
CodeGen_UpdateBackEndOptions();
} else {
- CPrep_Error(154);
+ CPrep_Error(CErrorStr154);
skipendofline();
}
} else if (t == TK_IDENTIFIER && !strcmp(tkidentifier->name, "reset")) {
@@ -2666,17 +3235,17 @@ static void pragma_opt_unroll_instr_count() {
CodeGen_UpdateOptimizerOptions();
CodeGen_UpdateBackEndOptions();
} else {
- CPrep_Error(105);
+ CPrep_Error(CErrorStr105);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
}
-static void pragma_pack() {
+static void pragma_pack(void) {
int t;
int i;
Boolean did_push;
@@ -2697,7 +3266,7 @@ static void pragma_pack() {
cprep_packstack[cprep_packstackp].align_mode = copts.align_mode;
did_push = 1;
} else {
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
} else if (!strcmp(tkidentifier->name, "pop")) {
if (cprep_packstackp < 128) {
@@ -2705,7 +3274,7 @@ static void pragma_pack() {
cprep_packstackp++;
did_pop = 1;
} else {
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
} else {
if (did_push) {
@@ -2719,10 +3288,10 @@ static void pragma_pack() {
copts.align_mode = cprep_packstack[i].align_mode;
cprep_packstackp = i + 1;
} else {
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
} else {
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
did_pop = 0;
did_push = 0;
@@ -2750,7 +3319,7 @@ static void pragma_pack() {
break;
default:
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
}
did_pop = 0;
@@ -2765,15 +3334,15 @@ static void pragma_pack() {
} while (1);
}
if (t != ')' && copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
macrocheck = 0;
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
}
}
-static void pragma_comment() {
+static void pragma_comment(void) {
int t;
short start_tokenstacklevel = tokenstacklevel;
@@ -2799,13 +3368,13 @@ static void pragma_comment() {
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
@@ -2825,25 +3394,25 @@ static void pragma_comment() {
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
return;
}
@@ -2851,17 +3420,17 @@ static void pragma_comment() {
if (t != ')') {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
}
-static void pragma_message() {
+static void pragma_message(void) {
int t;
short start_tokenstacklevel;
char str[128];
@@ -2893,22 +3462,22 @@ static void pragma_message() {
skipendofline();
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
} else if (plex() != ')') {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
}
}
-static void preppragma() {
+static void preppragma(void) {
struct CompilerOption *opt;
Boolean save_eoltokens;
@@ -2998,14 +3567,14 @@ static void preppragma() {
}
} else {
if (copts.warn_illpragma)
- CPrep_Warning(186);
+ CPrep_Warning(CErrorStr186);
skipendofline();
macrocheck = 1;
return;
}
foundOption:
if (notendofline()) {
- CPrep_Error(113);
+ CPrep_Error(CErrorStr113);
skipendofline();
}
CPrep_Reconfig();
@@ -3025,13 +3594,13 @@ static void prepinclude(Boolean flag) {
StringPtr ptr;
if (!notendofline()) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
return;
}
t = prepcurchar();
if (t != '"' && t != '<') {
- CPrep_Error(117);
+ CPrep_Error(CErrorStr117);
skipendofline();
return;
}
@@ -3043,10 +3612,10 @@ static void prepinclude(Boolean flag) {
if (!copts.flat_include)
r29 = 0;
len = 0;
- while ((t = prepnextstringchar(save_pos, 1)) != '>') {
- if (t != 5) {
+ while ((t = prepnextstringchar((StringPtr) save_pos, 1)) != '>') {
+ if (t != TK_5) {
if (len > 254) {
- CPrep_Error(106);
+ CPrep_Error(CErrorStr106);
skipendofline();
return;
}
@@ -3062,7 +3631,7 @@ static void prepinclude(Boolean flag) {
macrocheck = 0;
buf[1] = 0;
if (t != TK_STRING) {
- CPrep_Error(117);
+ CPrep_Error(CErrorStr117);
skipendofline();
return;
}
@@ -3104,19 +3673,19 @@ all_done:
setupfile(ptr, r29, flag);
}
-static void prepline() {
+static void prepline(void) {
short t;
short len;
char buf[256];
cprep_hasprepline = 1;
if (!notendofline()) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
return;
}
if (plex() != TK_INTCONST) {
- CPrep_Error(117);
+ CPrep_Error(CErrorStr117);
skipendofline();
return;
}
@@ -3124,7 +3693,7 @@ static void prepline() {
linenumber = CInt64_GetULong(&tkintconst) - 1;
if (notendofline()) {
if (prepnextchar() != '"') {
- CPrep_Error(117);
+ CPrep_Error(CErrorStr117);
skipendofline();
return;
}
@@ -3134,7 +3703,7 @@ static void prepline() {
if (!t)
break;
if (len > 252) {
- CPrep_Error(106);
+ CPrep_Error(CErrorStr106);
skipendofline();
return;
}
@@ -3152,79 +3721,174 @@ static void prepline() {
}
}
-static TypeIntegral *CPrep_GetPrepType(PrepValue *pv) {
+static Type *CPrep_GetPrepType(PrepValue *pv) {
if (copts.longlong_prepeval || copts.c9x) {
if (pv->is_unsigned)
- return &stunsignedlonglong;
+ return TYPE(&stunsignedlonglong);
else
- return &stsignedlonglong;
+ return TYPE(&stsignedlonglong);
} else {
if (pv->is_unsigned)
- return &stunsignedlong;
+ return TYPE(&stunsignedlong);
else
- return &stsignedlong;
+ return TYPE(&stsignedlong);
}
}
-static PrepValue CPrep_ParseUnary() {
+static PrepValue CPrep_ParseUnary(void) {
+ PrepValue val;
+
+ if (!notendofline()) {
+ CPrep_Error(CErrorStr112);
+ val.val = cint64_zero;
+ val.is_unsigned = 0;
+ } else {
+ switch (plex()) {
+ case '-':
+ val = CPrep_ParseUnary();
+ val.val = CMach_CalcIntMonadic(CPrep_GetPrepType(&val), '-', val.val);
+ return val;
+
+ case '+':
+ val = CPrep_ParseUnary();
+ return val;
+
+ case '!':
+ val = CPrep_ParseUnary();
+ CInt64_SetLong(&val.val, CInt64_IsZero(&val.val));
+ return val;
+
+ case '~':
+ val = CPrep_ParseUnary();
+ val.val = CMach_CalcIntMonadic(CPrep_GetPrepType(&val), '~', val.val);
+ return val;
+
+ case '(':
+ val = CPrep_ParseCond();
+ if (exprtk != ')') {
+ CPrep_Error(CErrorStr115);
+ return val;
+ }
+ break;
+
+ case TK_TRUE:
+ val.val = cint64_one;
+ val.is_unsigned = 1;
+ break;
+
+ default:
+ CPrep_Error(CErrorStr141);
+ case TK_FALSE:
+ val.val = cint64_zero;
+ val.is_unsigned = 1;
+ break;
+
+ case TK_INTCONST:
+ val.val = tkintconst;
+ val.is_unsigned = (tksize == IT_ULONGLONG || tksize == IT_ULONG || tksize == IT_UINT || tksize == IT_UCHAR);
+ break;
+ case TK_IDENTIFIER:
+ val.val = cint64_zero;
+ val.is_unsigned = 0;
+ if (!strcmp("defined", tkidentifier->name)) {
+ macrocheck = 0;
+ if (!notendofline()) {
+ CPrep_Error(CErrorStr112);
+ break;
+ }
+
+ if ((exprtk = plex()) == '(') {
+ if (!notendofline()) {
+ CPrep_Error(CErrorStr112);
+ macrocheck = 1;
+ break;
+ }
+
+ if (lexidentifier() != TK_IDENTIFIER) {
+ CPrep_Error(CErrorStr107);
+ macrocheck = 1;
+ break;
+ }
+
+ if (ismacroname3())
+ val.val = cint64_one;
+
+ if (!notendofline()) {
+ CPrep_Error(CErrorStr112);
+ macrocheck = 1;
+ break;
+ }
+
+ if (plex() != ')')
+ CPrep_Error(CErrorStr115);
+ } else if (exprtk == TK_IDENTIFIER) {
+ if (ismacroname3())
+ val.val = cint64_one;
+ } else {
+ CPrep_Error(CErrorStr107);
+ }
+
+ macrocheck = 1;
+ }
+ break;
+ }
+ }
+
+ exprtk = notendofline() ? plex() : (short) 0;
+ return val;
}
-static PrepValue CPrep_ParseBinary(PrepValue *rhs, short op) {
- // i need a lot of fixing :(
+static PrepValue CPrep_ParseBinary(PrepValue *rhs, short precLimit) {
PrepValue a;
PrepValue b;
- short t;
- short op2;
- short op3;
- short prec2;
- short prec3;
+ short op;
+ short prec;
+ short newprec;
- if (!rhs) {
+ if (!rhs)
a = CPrep_ParseUnary();
- } else {
+ else
a = *rhs;
- }
- op2 = op;
-restart:
- op3 = exprtk;
- prec3 = GetPrec(op3);
- if (!prec3) {
- return a;
- }
- if (!notendofline()) {
- CPrep_Error(112);
- return a;
- }
- b = CPrep_ParseUnary();
- prec3 = prec3; // variable change situation?
- do {
- if (exprtk == ')' || !notendofline()) {
- if (b.is_unsigned)
- a.is_unsigned = 1;
- a.val = CMach_CalcIntDiadic((Type *) CPrep_GetPrepType(&a), a.val, t, b.val);
+ while (1) {
+ if (!(prec = GetPrec(op = exprtk)))
return a;
- }
- op = GetPrec(exprtk);
- if (!op) {
- CPrep_Error(141);
+ if (!notendofline()) {
+ CPrep_Error(CErrorStr112);
return a;
}
- if (prec3 >= prec2) {
- if (b.is_unsigned)
- a.is_unsigned = 1;
- a.val = CMach_CalcIntDiadic((Type *) CPrep_GetPrepType(&a), a.val, t, b.val);
- if (GetPrec(op) > op2)
- goto restart;
- return a;
+
+ b = CPrep_ParseUnary();
+ while (1) {
+ if (exprtk == ')' || !notendofline()) {
+ if (b.is_unsigned)
+ a.is_unsigned = 1;
+ a.val = CMach_CalcIntDiadic(CPrep_GetPrepType(&a), a.val, op, b.val);
+ return a;
+ }
+
+ if (!(newprec = GetPrec(exprtk))) {
+ CPrep_Error(CErrorStr141);
+ return a;
+ }
+
+ if (prec >= newprec) {
+ if (b.is_unsigned)
+ a.is_unsigned = 1;
+ a.val = CMach_CalcIntDiadic(CPrep_GetPrepType(&a), a.val, op, b.val);
+ if (GetPrec(newprec) <= precLimit)
+ return a;
+ break;
+ } else {
+ b = CPrep_ParseBinary(&b, prec);
+ }
}
- b = CPrep_ParseBinary(&b, prec3);
- } while (1);
+ }
}
-static PrepValue CPrep_ParseCond() {
+static PrepValue CPrep_ParseCond(void) {
PrepValue a;
PrepValue b;
PrepValue c;
@@ -3233,15 +3897,15 @@ static PrepValue CPrep_ParseCond() {
if (exprtk == '?') {
b = CPrep_ParseCond();
if (!notendofline()) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
return a;
}
if (exprtk != ':') {
- CPrep_Error(170);
+ CPrep_Error(CErrorStr170);
return a;
}
if (!notendofline()) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
return a;
}
c = CPrep_ParseCond();
@@ -3251,7 +3915,7 @@ static PrepValue CPrep_ParseCond() {
return a;
}
-static void doevalconstexpr() {
+static void doevalconstexpr(void) {
PrepValue v;
macrocheck = 1;
@@ -3259,10 +3923,10 @@ static void doevalconstexpr() {
cprep_incondexpr = 1;
v = CPrep_ParseCond();
if (exprtk)
- CPrep_Error(141);
+ CPrep_Error(CErrorStr141);
cprep_incondexpr = 0;
if (nlflag)
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
else
goendofline();
tkintconst = v.val;
@@ -3270,7 +3934,7 @@ static void doevalconstexpr() {
static void pushifstate(SInt16 state) {
if (iflevel >= 64) {
- CPrep_Error(215);
+ CPrep_Error(CErrorStr215);
} else {
ifstack[iflevel].state = state;
ifstack[iflevel].file = prep_file;
@@ -3279,9 +3943,9 @@ static void pushifstate(SInt16 state) {
}
}
-static void popifstate() {
+static void popifstate(void) {
if (iflevel <= 0) {
- CPrep_Error(117);
+ CPrep_Error(CErrorStr117);
} else {
switch (ifstack[iflevel - 1].state) {
case IfState_1:
@@ -3303,7 +3967,7 @@ static void popifstate() {
}
}
-static void positiveif() {
+static void positiveif(void) {
pushifstate(IfState_0);
}
@@ -3316,7 +3980,7 @@ static void negativeif(Boolean flag) {
}
}
-static void prepif() {
+static void prepif(void) {
if (iflevel > 0) {
switch (ifstack[iflevel - 1].state) {
case IfState_1:
@@ -3335,7 +3999,7 @@ static void prepif() {
positiveif();
}
-static void prepifdef() {
+static void prepifdef(void) {
if (iflevel > 0) {
switch (ifstack[iflevel - 1].state) {
case IfState_1:
@@ -3349,13 +4013,13 @@ static void prepifdef() {
macrocheck = 0;
if (!notendofline()) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
negativeif(1);
return;
}
if (lexidentifier() != TK_IDENTIFIER) {
- CPrep_Error(107);
+ CPrep_Error(CErrorStr107);
negativeif(1);
return;
}
@@ -3368,7 +4032,7 @@ static void prepifdef() {
negativeif(1);
}
-static void prepifndef() {
+static void prepifndef(void) {
if (iflevel > 0) {
switch (ifstack[iflevel - 1].state) {
case IfState_1:
@@ -3382,13 +4046,13 @@ static void prepifndef() {
macrocheck = 0;
if (!notendofline()) {
- CPrep_Error(112);
+ CPrep_Error(CErrorStr112);
negativeif(1);
return;
}
if (lexidentifier() != TK_IDENTIFIER) {
- CPrep_Error(107);
+ CPrep_Error(CErrorStr107);
negativeif(1);
return;
}
@@ -3401,9 +4065,9 @@ static void prepifndef() {
negativeif(1);
}
-static void prepelif() {
+static void prepelif(void) {
if (iflevel <= 0 || ifstack[iflevel - 1].state == IfState_2 || ifstack[iflevel - 1].state == IfState_4) {
- CPrep_Error(118);
+ CPrep_Error(CErrorStr118);
skipendofline();
return;
}
@@ -3423,14 +4087,13 @@ static void prepelif() {
prepifskip();
break;
default:
-#line 5700
- CError_FATAL();
+ CError_FATAL(5700);
}
}
-static void prepelse() {
+static void prepelse(void) {
if (iflevel <= 0 || ifstack[iflevel - 1].state == IfState_2 || ifstack[iflevel - 1].state == IfState_4) {
- CPrep_Error(118);
+ CPrep_Error(CErrorStr118);
skipendofline();
return;
}
@@ -3452,14 +4115,13 @@ static void prepelse() {
ifstack[iflevel - 1].state = IfState_4;
break;
default:
-#line 5738
- CError_FATAL();
+ CError_FATAL(5738);
}
}
-static void prependif() {
+static void prependif(void) {
if (iflevel <= 0) {
- CPrep_Error(118);
+ CPrep_Error(CErrorStr118);
skipendofline();
return;
}
@@ -3474,7 +4136,7 @@ static void prependif() {
popifstate();
}
-static void prepifskip() {
+static void prepifskip(void) {
// this function does something very weird with its code generation that i can't match
TStreamElement ts;
short t;
@@ -3484,70 +4146,74 @@ static void prepifskip() {
case IfState_1:
case IfState_3:
case IfState_4:
- 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 {
- was_prep_error = 0;
- ts.tokenfile = ifstack[iflevel - 1].file;
- ts.tokenoffset = ifstack[iflevel - 1].pos;
- CError_SetErrorToken(&ts);
- CError_ErrorTerm(119);
- iflevel = 0;
- return;
- }
- } else {
- CPrep_Error(105);
- }
- goto restart;
- case '\r':
- newline();
- goto restart;
- case '"':
- skipendoflinematch(pos, '"');
- goto restart;
- case '\'':
- skipendoflinematch(pos, '"');
- goto restart;
- case '#':
- t = prepskipnextchar();
- pos = nextcharpos;
- switch (t) {
- case '\r':
- goto restart;
- case 0:
- CPrep_Error(102);
- 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();
+ 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 {
- skipendofline();
- goto restart;
+ 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();
- goto restart;
+ } 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;
+ }
+ }
+ break;
+ default:
+ skipendofline();
+ continue;
+ }
+ break;
}
+ break;
+ case IfState_2:
default:
return;
}
@@ -3555,7 +4221,7 @@ static void prepifskip() {
}
}
-void preprocessor() {
+void preprocessor(void) {
short t;
gDirectiveStart = pos - prep_file_start;
@@ -3564,7 +4230,7 @@ void preprocessor() {
switch (t) {
case 0:
- CPrep_Error(102);
+ CPrep_Error(CErrorStr102);
case '\r':
return;
}
@@ -3591,7 +4257,7 @@ void preprocessor() {
return;
}
if (!strcmp("error", tkidentifier->name)) {
- CPrep_Error(318);
+ CPrep_Error(CErrorStr318);
CError_ResetErrorSkip();
skipendofline();
macrocheck = 1;
@@ -3604,7 +4270,7 @@ void preprocessor() {
}
if (!copts.ANSI_strict) {
if (!strcmp("warning", tkidentifier->name)) {
- CPrep_Warning(337);
+ CPrep_Warning(CErrorStr337);
skipendofline();
macrocheck = 1;
return;
@@ -3652,7 +4318,7 @@ void preprocessor() {
return;
}
}
- CPrep_Error(104);
+ CPrep_Error(CErrorStr104);
skipendofline();
macrocheck = 1;
}
@@ -3661,7 +4327,7 @@ SInt32 CPrep_BrowserTokenOffset(FileOffsetInfo *foi) {
return foi->tokenoffset;
}
-SInt32 CPrep_BrowserFileOffset() {
+SInt32 CPrep_BrowserFileOffset(void) {
if (ts_first < ts_current)
return ts_current[-1].tokenoffset + 1;
else if (tokenstacklevel)
@@ -3693,6 +4359,6 @@ void CPrep_BrowserFilePosition(CPrepFileInfo **fileinfo, SInt32 *offset) {
}
}
-CPrepFileInfo *CPrep_BrowserCurrentFile() {
+CPrepFileInfo *CPrep_BrowserCurrentFile(void) {
return prep_file;
}