mirror of
https://git.wuffs.org/MWCC
synced 2025-07-21 04:35:51 +00:00
922 lines
29 KiB
C
922 lines
29 KiB
C
#include "compiler.h"
|
|
#include "compiler/CError.h"
|
|
#include "compiler/tokens.h"
|
|
#include "cos.h"
|
|
|
|
extern SInt16 *CLT_filesp;
|
|
extern CPrepFileInfo **CLT_filestack;
|
|
|
|
//#define OPT_OFFSET(optname) ((short) (((char *) (&copts.optname)) - ((char *) &copts)))
|
|
#define OPT_OFFSET(optname) ((short) ( &((COpts *)0)->optname ))
|
|
enum {
|
|
OPT_FLAG_2000 = 0x2000,
|
|
OPT_FLAG_4000 = 0x4000
|
|
};
|
|
|
|
struct {
|
|
char *name;
|
|
short bits;
|
|
} compileroptions[138] = {
|
|
"little_endian", OPT_FLAG_4000 | OPT_OFFSET(little_endian),
|
|
"longlong", OPT_OFFSET(longlong),
|
|
"traceback", OPT_OFFSET(traceback),
|
|
"disable_registers", OPT_OFFSET(disable_registers),
|
|
"fp_contract", OPT_OFFSET(fp_contract),
|
|
"no_common", OPT_OFFSET(no_common),
|
|
"no_implicit_templates", OPT_OFFSET(no_implicit_templates),
|
|
"absolutepath", OPT_OFFSET(absolutepath),
|
|
"debug_listing", OPT_OFFSET(debuglisting),
|
|
"profile", OPT_OFFSET(profile),
|
|
"optimizewithasm", OPT_OFFSET(optimizewithasm),
|
|
"use_lmw_stmw", OPT_OFFSET(use_lmw_stmw),
|
|
"no_register_save_helpers", OPT_OFFSET(no_register_save_helpers),
|
|
"ppc_opt_bclr_bcctr", OPT_OFFSET(ppc_opt_bclr_bcctr),
|
|
"misaligned_mem_access", OPT_OFFSET(misaligned_mem_access),
|
|
"switch_tables", OPT_OFFSET(switch_tables),
|
|
"prepare_compress", OPT_OFFSET(prepare_compress),
|
|
"asmsemicolcomment", OPT_OFFSET(asmsemicolcomment),
|
|
"asmpoundcomment", OPT_OFFSET(asmpoundcomment),
|
|
"cplusplus", OPT_OFFSET(cplusplus),
|
|
"ecplusplus", OPT_OFFSET(ecplusplus),
|
|
"objective_c", OPT_OFFSET(objective_c),
|
|
"objc_strict", OPT_OFFSET(objc_strict),
|
|
"ARM_conform", OPT_OFFSET(ARM_conform),
|
|
"ARM_scoping", OPT_OFFSET(ARM_scoping),
|
|
"require_prototypes", OPT_OFFSET(require_prototypes),
|
|
"trigraphs", OPT_OFFSET(trigraphs),
|
|
"only_std_keywords", OPT_OFFSET(only_std_keywords),
|
|
"enumsalwaysint", OPT_OFFSET(enumsalwaysint),
|
|
"ANSI_strict", OPT_OFFSET(ANSI_strict),
|
|
"mpwc_relax", OPT_OFFSET(mpwc_relax),
|
|
"mpwc_newline", OPT_OFFSET(mpwc_newline),
|
|
"ignore_oldstyle", OPT_OFFSET(ignore_oldstyle),
|
|
"cpp_extensions", OPT_OFFSET(cpp_extensions),
|
|
"pointercast_lvalue", OPT_OFFSET(pointercast_lvalue),
|
|
"RTTI", OPT_OFFSET(useRTTI),
|
|
"delete_exception", OPT_OFFSET(delete_exception),
|
|
"oldalignment", OPT_OFFSET(oldalignment),
|
|
"multibyteaware", OPT_OFFSET(multibyteaware),
|
|
"unsigned_char", OPT_OFFSET(unsignedchars),
|
|
"auto_inline", OPT_OFFSET(autoinline),
|
|
"inline_bottom_up", OPT_OFFSET(inline_bottom_up),
|
|
"defer_codegen", OPT_OFFSET(defer_codegen),
|
|
"direct_to_som", OPT_OFFSET(direct_to_som),
|
|
"SOMCheckEnvironment", OPT_OFFSET(som_env_check),
|
|
"SOMCallOptimization", OPT_OFFSET(som_call_opt),
|
|
"bool", OPT_OFFSET(booltruefalse),
|
|
"old_enum_mangler", OPT_OFFSET(old_enum_mangler),
|
|
"longlong_enums", OPT_OFFSET(longlong_enums),
|
|
"no_tfuncinline", OPT_OFFSET(no_tfuncinline),
|
|
"flat_include", OPT_OFFSET(flat_include),
|
|
"syspath_once", OPT_OFFSET(syspath_once),
|
|
"always_import", OPT_OFFSET(always_import),
|
|
"simple_class_byval", OPT_OFFSET(simple_class_byval),
|
|
"wchar_type", OPT_OFFSET(wchar_type),
|
|
"vbase_ctor_offset", OPT_OFFSET(vbase_ctor_offset),
|
|
"vbase_abi_v2", OPT_OFFSET(vbase_abi_v2),
|
|
"def_inherited", OPT_OFFSET(def_inherited),
|
|
"template_patch", OPT_OFFSET(template_patch),
|
|
"template_friends", OPT_OFFSET(template_friends),
|
|
"faster_pch_gen", OPT_OFFSET(faster_pch_gen),
|
|
"array_new_delete", OPT_OFFSET(array_new_delete),
|
|
"dollar_identifiers", OPT_OFFSET(dollar_identifiers),
|
|
"def_inline_tfuncs", OPT_OFFSET(def_inline_tfuncs),
|
|
"arg_dep_lookup", OPT_OFFSET(arg_dep_lookup),
|
|
"simple_prepdump", OPT_OFFSET(simple_prepdump),
|
|
"line_prepdump", OPT_OFFSET(line_prepdump),
|
|
"fullpath_prepdump", OPT_OFFSET(fullpath_prepdump),
|
|
"old_mtemplparser", OPT_OFFSET(old_mtemplparser),
|
|
"suppress_init_code", OPT_OFFSET(suppress_init_code),
|
|
"reverse_bitfields", OPT_OFFSET(reverse_bitfields),
|
|
"c9x", OPT_OFFSET(c9x),
|
|
"float_constants", OPT_OFFSET(float_constants),
|
|
"no_static_dtors", OPT_OFFSET(no_static_dtors),
|
|
"longlong_prepeval", OPT_OFFSET(longlong_prepeval),
|
|
"const_strings", OPT_OFFSET(const_strings),
|
|
"dumpir", OPT_OFFSET(dumpir),
|
|
"experimental", OPT_OFFSET(experimental),
|
|
"gcc_extensions", OPT_OFFSET(gcc_extensions),
|
|
"stdc_fp_contract", OPT_OFFSET(stdc_fp_contract),
|
|
"stdc_fenv_access", OPT_OFFSET(stdc_fenv_access),
|
|
"stdc_cx_limitedr", OPT_OFFSET(stdc_cx_limitedr),
|
|
"old_argmatch", OPT_OFFSET(old_argmatch),
|
|
"optEH", OPT_OFFSET(optEH),
|
|
"optEH2", OPT_OFFSET(optEH2),
|
|
"new_mangler", OPT_OFFSET(new_mangler),
|
|
"microsoft_exceptions", OPT_OFFSET(microsoft),
|
|
"microsoft_RTTI", OPT_OFFSET(microsoft),
|
|
"warning_errors", OPT_OFFSET(warningerrors),
|
|
"extended_errorcheck", OPT_OFFSET(pedantic),
|
|
"check_header_flags", OPT_OFFSET(check_header_flags),
|
|
"supress_warnings", OPT_OFFSET(supress_warnings),
|
|
"warn_illpragma", OPT_OFFSET(warn_illpragma),
|
|
"warn_emptydecl", OPT_OFFSET(warn_emptydecl),
|
|
"warn_possunwant", OPT_OFFSET(warn_possunwant),
|
|
"warn_unusedvar", OPT_OFFSET(warn_unusedvar),
|
|
"warn_unusedarg", OPT_OFFSET(warn_unusedarg),
|
|
"warn_extracomma", OPT_OFFSET(warn_extracomma),
|
|
"warn_hidevirtual", OPT_OFFSET(warn_hidevirtual),
|
|
"warn_largeargs", OPT_OFFSET(warn_largeargs),
|
|
"warn_implicitconv", OPT_OFFSET(warn_implicitconv),
|
|
"warn_notinlined", OPT_OFFSET(warn_notinlined),
|
|
"warn_structclass", OPT_OFFSET(warn_structclass),
|
|
"warn_padding", OPT_OFFSET(warn_padding),
|
|
"warn_no_side_effect", OPT_OFFSET(warn_no_side_effect),
|
|
"warn_resultnotused", OPT_OFFSET(warn_resultnotused),
|
|
"warn_ptr_int_conv", OPT_OFFSET(warn_ptr_int_conv),
|
|
"align_array_members", OPT_OFFSET(align_array_members),
|
|
"dont_reuse_strings", OPT_OFFSET(dont_reuse_strings),
|
|
"pool_strings", OPT_OFFSET(pool_strings),
|
|
"explicit_zero_data", OPT_OFFSET(explicit_zero_data),
|
|
"readonly_strings", OPT_OFFSET(readonly_strings),
|
|
"opt_common_subs", OPT_OFFSET(opt_common_subs),
|
|
"opt_loop_invariants", OPT_OFFSET(opt_loop_invariants),
|
|
"opt_propagation", OPT_OFFSET(opt_propagation),
|
|
"opt_unroll_loops", OPT_OFFSET(opt_unroll_loops),
|
|
"opt_lifetimes", OPT_OFFSET(opt_lifetimes),
|
|
"opt_strength_reduction", OPT_OFFSET(opt_strength_reduction),
|
|
"opt_strength_reduction_strict", OPT_OFFSET(opt_strength_reduction_strict),
|
|
"opt_dead_code", OPT_OFFSET(opt_dead_code),
|
|
"opt_dead_assignments", OPT_OFFSET(opt_dead_assignments),
|
|
"opt_vectorize_loops", OPT_OFFSET(opt_vectorize_loops),
|
|
"opt_pointer_analysis", OPT_OFFSET(opt_pointer_analysis),
|
|
"exceptions", OPT_OFFSET(exceptions),
|
|
"dont_inline", OPT_OFFSET(dont_inline),
|
|
"always_inline", OPT_OFFSET(always_inline),
|
|
"optimize_for_size", OPT_OFFSET(optimize_for_size),
|
|
"peephole", OPT_OFFSET(peephole),
|
|
"global_optimizer", OPT_OFFSET(global_optimizer),
|
|
"side_effects", OPT_OFFSET(side_effects),
|
|
"internal", OPT_FLAG_2000 | OPT_OFFSET(internal),
|
|
"import", OPT_FLAG_2000 | OPT_OFFSET(import),
|
|
"export", OPT_FLAG_2000 | OPT_OFFSET(export),
|
|
"lib_export", OPT_FLAG_2000 | OPT_OFFSET(lib_export),
|
|
"nosyminline", OPT_OFFSET(nosyminline),
|
|
"force_active", OPT_OFFSET(force_active),
|
|
"sym", OPT_OFFSET(isGeneratingDebugInfo),
|
|
NULL, 0
|
|
};
|
|
|
|
CParams *cparamblkptr;
|
|
short tk;
|
|
CInt64 tkintconst;
|
|
Float tkfloatconst;
|
|
char *tkstring;
|
|
HashNameNode *tkidentifier;
|
|
SInt32 tksize;
|
|
short ispascalstring;
|
|
short nlflag;
|
|
SInt32 lines;
|
|
Boolean spaceskip;
|
|
Macro **macrohashtable;
|
|
Boolean cprep_nomem_exit;
|
|
Boolean cprep_nostring;
|
|
Boolean cprep_eoltokens;
|
|
static void *ifstack[100]; // TODO type+size
|
|
static short iflevel;
|
|
TokenStack tokenstack[128];
|
|
short tokenstacklevel;
|
|
SInt32 cprep_cursymfile; // might be a ptr?
|
|
char *pos;
|
|
char *macropos;
|
|
char *nextcharpos;
|
|
char CPrep_SkipNewCommentChar;
|
|
Boolean preprocessing_only;
|
|
Handle stringmem;
|
|
SInt32 maxstringsize;
|
|
char cprep_idarray[256];
|
|
Boolean was_escchar;
|
|
Boolean macrocheck;
|
|
Boolean widestring;
|
|
Boolean at_linestart;
|
|
char *prep_file_start;
|
|
char *prep_file_end;
|
|
char *macrostart;
|
|
Boolean cprep_strconcat;
|
|
CPrepFileInfo *prep_file;
|
|
short filesp;
|
|
SInt32 linenumber;
|
|
static CPrepFileInfo *filestack[32];
|
|
static void *cprep_files; // TODO type
|
|
static SInt32 linetick;
|
|
static Boolean waslockedmacro;
|
|
static Boolean include_once;
|
|
static time_t now_time;
|
|
static SInt32 lineoffset;
|
|
static Boolean was_prep_error;
|
|
static Boolean cprep_hasprepline;
|
|
static Boolean cprep_incondexpr;
|
|
static void *cprep_packstack[100]; // TODO type+size
|
|
static short cprep_packstackp;
|
|
static Macro lineM;
|
|
static Macro fileM;
|
|
static Macro dateM;
|
|
static Macro timeM;
|
|
static Macro stdcM;
|
|
static Macro stcvM;
|
|
static Macro stchM;
|
|
static Macro casmM;
|
|
static Macro cpplM;
|
|
static Macro MWRSM;
|
|
static Macro dtsomM;
|
|
static Macro ecppM;
|
|
static Macro optiM;
|
|
static Macro trgtM;
|
|
GList pplist;
|
|
struct COptsPush {
|
|
struct COptsPush *next;
|
|
COpts opts;
|
|
};
|
|
static struct COptsPush *coptpushs;
|
|
static void *coptpush; // TODO type
|
|
static void *coptssave; // TODO type
|
|
static Boolean dofreeaheap;
|
|
static GList mlist;
|
|
static Handle ts_buffer;
|
|
static TStreamElement *ts_first;
|
|
static TStreamElement *ts_last;
|
|
TStreamElement *ts_current;
|
|
static SInt32 ts_elements;
|
|
SInt32 ts_preread_elements;
|
|
static SInt32 gDirectiveStart;
|
|
static SInt32 high_mem_mark;
|
|
// static TStreamElement dummyelement; // in CPrep_CurStreamElement
|
|
static short exprtk;
|
|
|
|
static void cannotopenerror(StringPtr filename, Boolean err) {
|
|
static char fname[64];
|
|
|
|
short len = filename[0];
|
|
if (len > 63)
|
|
len = 63;
|
|
memcpy(fname, filename + 1, len);
|
|
fname[len] = 0;
|
|
|
|
CError_ResetErrorSkip();
|
|
|
|
if (prep_file) {
|
|
was_prep_error = 1;
|
|
CError_Error(151, fname);
|
|
if (err)
|
|
longjmp(errorreturn, 1);
|
|
} else {
|
|
CError_CannotOpen();
|
|
}
|
|
}
|
|
|
|
static void insertmacro(Macro *macro) {
|
|
macro->next = macrohashtable[macro->name->hashval];
|
|
macrohashtable[macro->name->hashval] = macro;
|
|
macro->xF = 0;
|
|
}
|
|
|
|
void CPrep_InsertSpecialMacro(Macro *macro, char *name) {
|
|
macro->name = GetHashNameNodeExport(name);
|
|
macro->is_special = 1;
|
|
insertmacro(macro);
|
|
}
|
|
|
|
void CPrep_InsertSpecialMacros() {
|
|
CPrep_InsertSpecialMacro(&lineM, "__LINE__");
|
|
CPrep_InsertSpecialMacro(&fileM, "__FILE__");
|
|
CPrep_InsertSpecialMacro(&dateM, "__DATE__");
|
|
CPrep_InsertSpecialMacro(&timeM, "__TIME__");
|
|
CPrep_InsertSpecialMacro(&stdcM, "__STDC__");
|
|
CPrep_InsertSpecialMacro(&stcvM, "__STDC_VERSION__");
|
|
CPrep_InsertSpecialMacro(&stchM, "__STDC_HOSTED__");
|
|
CPrep_InsertSpecialMacro(&casmM, "__CASM__");
|
|
CPrep_InsertSpecialMacro(&cpplM, "__cplusplus");
|
|
CPrep_InsertSpecialMacro(&MWRSM, "__MWERKS__");
|
|
CPrep_InsertSpecialMacro(&dtsomM, "__SOM_ENABLED__");
|
|
CPrep_InsertSpecialMacro(&ecppM, "__embedded_cplusplus");
|
|
CPrep_InsertSpecialMacro(&optiM, "__option");
|
|
CPrep_InsertSpecialMacro(&trgtM, "__ide_target");
|
|
CodeGen_InsertSpecialMacros();
|
|
}
|
|
|
|
void CPrep_RemoveSpecialMacros() {
|
|
Macro **scan;
|
|
int x;
|
|
|
|
for (x = 0; x < 2048; x++) {
|
|
scan = ¯ohashtable[x];
|
|
while (*scan) {
|
|
if ((*scan)->is_special) {
|
|
*scan = (*scan)->next;
|
|
} else {
|
|
scan = &(*scan)->next;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void CPrep_Reconfig() {
|
|
cprep_idarray['$'] = copts.dollar_identifiers != 0;
|
|
}
|
|
|
|
Boolean setupprep() {
|
|
int x;
|
|
|
|
now_time = time(NULL);
|
|
lineoffset = 0;
|
|
include_once = 0;
|
|
cprep_eoltokens = 0;
|
|
cprep_nostring = 0;
|
|
cprep_incondexpr = 0;
|
|
filesp = -1;
|
|
linetick = 0;
|
|
lines = 0;
|
|
dofreeaheap = 1;
|
|
macrocheck = 1;
|
|
maxstringsize = 256;
|
|
iflevel = 0;
|
|
tokenstacklevel = 0;
|
|
cprep_cursymfile = 0;
|
|
cprep_files = 0;
|
|
CLT_filesp = &filesp;
|
|
CLT_filestack = filestack;
|
|
anyerrors = 0;
|
|
fatalerrors = 0;
|
|
was_prep_error = 0;
|
|
cprep_strconcat = 0;
|
|
|
|
GListErrorProc = CError_NoMem;
|
|
mlist.data = NULL;
|
|
pplist.data = NULL;
|
|
if (InitGList(&mlist, 10000))
|
|
CError_NoMem();
|
|
|
|
stringmem = COS_NewHandle(256);
|
|
if (!stringmem)
|
|
CError_NoMem();
|
|
ts_buffer = COS_NewHandle(1024 * sizeof(TStreamElement));
|
|
if (!ts_buffer)
|
|
CError_NoMem();
|
|
COS_LockHandleHi(ts_buffer);
|
|
ts_first = (TStreamElement *) *ts_buffer;
|
|
ts_last = ts_first + 1023;
|
|
ts_current = ts_first;
|
|
ts_elements = 1024;
|
|
ts_preread_elements = 0;
|
|
|
|
macrohashtable = galloc(sizeof(Macro *) * 2048);
|
|
memclrw(macrohashtable, sizeof(Macro *) * 2048);
|
|
CPrep_InsertSpecialMacros();
|
|
|
|
for (x = 0; x < 256; x++)
|
|
cprep_idarray[x] = 0;
|
|
|
|
for (x = 'a'; ; x++) {
|
|
cprep_idarray[x] = 1;
|
|
if (x == 'z') break;
|
|
}
|
|
|
|
for (x = 'A'; ; x++) {
|
|
cprep_idarray[x] = 1;
|
|
if (x == 'Z') break;
|
|
}
|
|
|
|
for (x = '0'; ; x++) {
|
|
cprep_idarray[x] = 2;
|
|
if (x == '9') break;
|
|
}
|
|
|
|
cprep_idarray['_'] = 1;
|
|
|
|
CPrep_Reconfig();
|
|
return 0;
|
|
}
|
|
|
|
void cleanupprep() {
|
|
while (filesp >= 0)
|
|
popfile();
|
|
|
|
high_mem_mark = CTool_TotalHeapSize();
|
|
releaseheaps();
|
|
GListErrorProc = NULL;
|
|
FreeGList(&mlist);
|
|
FreeGList(&pplist);
|
|
|
|
if (stringmem) {
|
|
COS_FreeHandle(stringmem);
|
|
stringmem = NULL;
|
|
}
|
|
|
|
if (ts_buffer) {
|
|
COS_FreeHandle(ts_buffer);
|
|
ts_buffer = NULL;
|
|
}
|
|
ts_current = NULL;
|
|
ts_first = ts_last = NULL;
|
|
}
|
|
|
|
static char *getfiledata(FSSpec *spec) {
|
|
const char *text;
|
|
SInt32 textlength;
|
|
short filedatatype;
|
|
|
|
if (CWGetFileText(cparamblkptr->context, spec, &text, &textlength, &filedatatype) != cwNoErr) {
|
|
Str255 filename;
|
|
COS_FileGetFSSpecInfo(spec, NULL, NULL, filename);
|
|
cannotopenerror(filename, 1);
|
|
return NULL;
|
|
} else {
|
|
return (char *) text;
|
|
}
|
|
}
|
|
|
|
static Boolean setupfile(StringPtr filename, Boolean flag1, Boolean flag2) {
|
|
CPrepFileInfo prepinfo;
|
|
CWFileInfo fileinfo;
|
|
Str255 file_filename;
|
|
char myfilename[256];
|
|
OSType file_type;
|
|
SInt32 file_size;
|
|
SInt32 file_dirid;
|
|
CWMemHandle cache_hnd;
|
|
void *cache;
|
|
SInt16 refnum;
|
|
SInt16 file_vrefnum;
|
|
char *extpos;
|
|
|
|
if (filesp >= 31) {
|
|
was_prep_error = 1;
|
|
CError_ErrorTerm(243);
|
|
return 0;
|
|
}
|
|
|
|
memclrw(&prepinfo, sizeof(CPrepFileInfo));
|
|
prepinfo.unkfield126 = !flag1; // may be wrong field!
|
|
if (filename) {
|
|
memclrw(&fileinfo, sizeof(CWFileInfo));
|
|
fileinfo.fullsearch = flag2;
|
|
fileinfo.dependencyType = cwNormalDependency;
|
|
fileinfo.isdependentoffile = -1;
|
|
memcpy(myfilename, &filename[1], filename[0]);
|
|
myfilename[filename[0]] = 0;
|
|
|
|
if (CWFindAndLoadFile(cparamblkptr->context, myfilename, &fileinfo) != cwNoErr) {
|
|
if (filename[0] + strlen(".framework/Headers") < 255) {
|
|
if ((extpos = strchr(myfilename, '/'))) {
|
|
// Do Me! 37D8C
|
|
} else {
|
|
cannotopenerror(filename, 0);
|
|
return 0;
|
|
}
|
|
} else {
|
|
cannotopenerror(filename, 0);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
if ((flag2 || include_once) && fileinfo.alreadyincluded)
|
|
return 1;
|
|
|
|
prepinfo.textfile = fileinfo.filespec;
|
|
prepinfo.nameNode = CTool_GetPathName(&fileinfo.filespec, &prepinfo.fileModDate);
|
|
if (fileinfo.filedata) {
|
|
if (fileinfo.filedatatype == cwFileTypeText) {
|
|
prepinfo.textbuffer = (char *) fileinfo.filedata;
|
|
prepinfo.textlength = fileinfo.filedatalength;
|
|
prepinfo.fileID = fileinfo.fileID;
|
|
prepinfo.recordbrowseinfo = fileinfo.recordbrowseinfo;
|
|
} else if (fileinfo.filedatatype == cwFileTypePrecompiledHeader) {
|
|
PrecompilerRead(0, (void *) fileinfo.filedata);
|
|
return 1;
|
|
} else {
|
|
cannotopenerror(filename, 0);
|
|
return 0;
|
|
}
|
|
} else {
|
|
COS_FileGetFSSpecInfo(&prepinfo.textfile, &file_vrefnum, &file_dirid, file_filename);
|
|
if (COS_FileOpen(&prepinfo.textfile, &refnum)) {
|
|
cannotopenerror(filename, 0);
|
|
return 0;
|
|
}
|
|
if (COS_FileGetType(&prepinfo.textfile, &file_type) || COS_FileGetSize(refnum, &file_size)) {
|
|
COS_FileClose(refnum);
|
|
cannotopenerror(filename, 0);
|
|
return 0;
|
|
}
|
|
if (file_type == copts.pchType) {
|
|
if (cparamblkptr->isCachingPrecompiledHeaders) {
|
|
if (CWAllocMemHandle(cparamblkptr->context, file_size, 1, &cache_hnd) != cwNoErr) {
|
|
if (CWAllocMemHandle(cparamblkptr->context, file_size, 0, &cache_hnd) != cwNoErr) {
|
|
COS_FileClose(refnum);
|
|
CError_NoMem();
|
|
}
|
|
}
|
|
|
|
CWLockMemHandle(cparamblkptr->context, cache_hnd, 0, &cache);
|
|
if (COS_FileRead(refnum, cache, file_size)) {
|
|
COS_FileClose(refnum);
|
|
CWFreeMemHandle(cparamblkptr->context, cache_hnd);
|
|
cannotopenerror(filename, 0);
|
|
return 0;
|
|
}
|
|
COS_FileClose(refnum);
|
|
CWCachePrecompiledHeader(cparamblkptr->context, &prepinfo.textfile, cache_hnd);
|
|
PrecompilerRead(0, cache);
|
|
CWUnlockMemHandle(cparamblkptr->context, cache_hnd);
|
|
return 1;
|
|
} else {
|
|
PrecompilerRead(refnum, 0);
|
|
COS_FileClose(refnum);
|
|
return 1;
|
|
}
|
|
} else {
|
|
COS_FileClose(refnum);
|
|
cannotopenerror(filename, 0);
|
|
return 0;
|
|
}
|
|
}
|
|
} else {
|
|
if (!cparamblkptr->mainFileText) {
|
|
COS_FileGetFSSpecInfo(&cparamblkptr->mainFileSpec, &file_vrefnum, &file_dirid, file_filename);
|
|
cannotopenerror(file_filename, 1);
|
|
return 0;
|
|
}
|
|
|
|
prepinfo.textfile = cparamblkptr->mainFileSpec;
|
|
prepinfo.textbuffer = (char *) cparamblkptr->mainFileText;
|
|
prepinfo.textlength = cparamblkptr->mainFileTextLength;
|
|
prepinfo.fileID = cparamblkptr->mainFileID;
|
|
prepinfo.recordbrowseinfo = cparamblkptr->field276;
|
|
}
|
|
|
|
if (filesp >= 0) {
|
|
filestack[filesp]->linenumber = linenumber;
|
|
filestack[filesp]->hasprepline = cprep_hasprepline;
|
|
filestack[filesp]->pos = pos - filestack[filesp]->textbuffer;
|
|
}
|
|
|
|
pos = prepinfo.textbuffer;
|
|
linenumber = 1;
|
|
at_linestart = 1;
|
|
filestack[++filesp] = galloc(sizeof(CPrepFileInfo));
|
|
*filestack[filesp] = prepinfo;
|
|
prep_file = filestack[filesp];
|
|
prep_file_start = prep_file->textbuffer;
|
|
prep_file_end = prep_file->textbuffer + prep_file->textlength;
|
|
if (preprocessing_only && !copts.simple_prepdump)
|
|
CPrep_PreprocessDumpFileInfo(1);
|
|
|
|
return 1;
|
|
}
|
|
|
|
void CPrep_TSBufferGrow(int amount) {
|
|
int current_offset = ts_current - ts_first;
|
|
COS_UnlockHandle(ts_buffer);
|
|
if (!COS_ResizeHandle(ts_buffer, sizeof(TStreamElement) * (ts_elements + amount)))
|
|
CError_NoMem();
|
|
COS_LockHandleHi(ts_buffer);
|
|
ts_elements += amount;
|
|
ts_first = (TStreamElement *) *ts_buffer;
|
|
ts_last = ts_first + (ts_elements - 1);
|
|
ts_current = ts_first + current_offset;
|
|
}
|
|
|
|
void CPrep_TokenStreamGetState(SInt32 *state) {
|
|
*state = ts_current - ts_first;
|
|
}
|
|
|
|
void CPrep_TokenStreamSetState(SInt32 *state) {
|
|
ts_preread_elements += ts_current - ts_first - *state;
|
|
ts_current = ts_first + *state;
|
|
}
|
|
|
|
void CPrep_UnLex() {
|
|
++ts_preread_elements;
|
|
--ts_current;
|
|
#line 900
|
|
CError_ASSERT(ts_current >= ts_first);
|
|
}
|
|
|
|
void CPrep_TokenStreamSetCurState(SInt32 *state) {
|
|
ts_preread_elements += ts_current - ts_first - (*state - 1);
|
|
ts_current = ts_first + (*state - 1);
|
|
tk = lex();
|
|
}
|
|
|
|
static void CPrep_StreamSkipToBrace() {}
|
|
static void CPrep_StreamSkipBlock() {}
|
|
void CPrep_StreamGetBlock() {}
|
|
void CPrep_StreamGetSemicolon() {}
|
|
void CPrep_StreamGetTemplate() {}
|
|
void CPrep_StreamInsert() {}
|
|
void CPrep_StreamRemove() {}
|
|
void CPrep_RemoveTokens() {}
|
|
void CPrep_TokenStreamFlush() {}
|
|
static void CPrep_TokenSize() {}
|
|
void CPrep_CurStreamElement() {}
|
|
|
|
void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SInt32 *selectionoffset, short *tokensize, SInt32 *linenumber, char *buf1, short *tokenoffset, short *tokenlength, char *buf2, short *lastarg) {
|
|
}
|
|
|
|
void CPrep_Error(short code) {
|
|
Boolean save = in_assembler;
|
|
in_assembler = 0;
|
|
if (code == 102 && (tokenstacklevel > 0 || pos < prep_file_end))
|
|
code = 105;
|
|
was_prep_error = 1;
|
|
CError_Error(code);
|
|
in_assembler = save;
|
|
}
|
|
|
|
void CPrep_ErrorName(short code, const char *name) {
|
|
Boolean save = in_assembler;
|
|
in_assembler = 0;
|
|
was_prep_error = 1;
|
|
if (code == 102 && (tokenstacklevel > 0 || pos < prep_file_end))
|
|
CError_Error(105, name);
|
|
else
|
|
CError_Error(code, name);
|
|
in_assembler = save;
|
|
}
|
|
|
|
void CPrep_Warning(short code) {
|
|
Boolean save = in_assembler;
|
|
in_assembler = 0;
|
|
was_prep_error = 1;
|
|
CError_Warning(code);
|
|
in_assembler = save;
|
|
}
|
|
|
|
void CPrep_WarningName(short code, const char *name) {
|
|
Boolean save = in_assembler;
|
|
in_assembler = 0;
|
|
was_prep_error = 1;
|
|
CError_Warning(code, name);
|
|
in_assembler = save;
|
|
}
|
|
|
|
void CPrep_ErrorMessage(int errTable, char *str, Boolean flag1, Boolean flag2) {
|
|
Boolean save = in_assembler;
|
|
in_assembler = 0;
|
|
was_prep_error = 1;
|
|
CError_ErrorMessage(errTable, str, flag1, flag2);
|
|
in_assembler = save;
|
|
}
|
|
|
|
void CPrep_ErrorMessageVA(int code, const char *format, va_list list, Boolean flag1, Boolean flag2) {
|
|
Boolean save = in_assembler;
|
|
in_assembler = 0;
|
|
was_prep_error = 1;
|
|
CError_ErrorMessageVA(code, format, list, flag1, flag2);
|
|
in_assembler = save;
|
|
}
|
|
|
|
void popfile() {
|
|
// r5 and r6 are swapped, not sure why
|
|
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;
|
|
at_linestart = 1;
|
|
}
|
|
if (preprocessing_only && !copts.simple_prepdump)
|
|
CPrep_PreprocessDumpFileInfo(1);
|
|
}
|
|
}
|
|
|
|
static void prepoffset() {}
|
|
static void prepoffset2() {}
|
|
void CPrep_SetSourceFile() {}
|
|
void CPrep_GetSourceFilePath() {}
|
|
void CPrep_NewFileOffsetInfo() {}
|
|
void CPrep_GetFileOffsetInfo() {}
|
|
void CPrep_GetFileOffsetInfo2() {}
|
|
void CPrep_ResetFileInfo() {}
|
|
void CPrep_GetPrepPos() {}
|
|
Boolean C_Compiler(CParams *param) {}
|
|
|
|
static void pushtokenseq(Macro *macro) {
|
|
if (tokenstacklevel >= 128) {
|
|
was_prep_error = 1;
|
|
CError_ErrorTerm(111);
|
|
} else {
|
|
tokenstack[tokenstacklevel].pos = pos;
|
|
tokenstack[tokenstacklevel].macrostart = macrostart;
|
|
tokenstack[tokenstacklevel].macro = macro;
|
|
if (macro)
|
|
macro->xF = 1;
|
|
tokenstack[tokenstacklevel].macrocheck = macrocheck;
|
|
tokenstacklevel++;
|
|
}
|
|
}
|
|
|
|
void poptokenseq() {
|
|
if (!--tokenstacklevel && dofreeaheap)
|
|
freeaheap();
|
|
|
|
pos = tokenstack[tokenstacklevel].pos;
|
|
macrostart = tokenstack[tokenstacklevel].macrostart;
|
|
if (tokenstack[tokenstacklevel].macro)
|
|
tokenstack[tokenstacklevel].macro->xF = 0;
|
|
macrocheck = tokenstack[tokenstacklevel].macrocheck;
|
|
spaceskip = 1;
|
|
}
|
|
|
|
static void is_nextchar() {}
|
|
static void ismacroname() {}
|
|
static void ismacroname2() {}
|
|
static void ismacroname5() {}
|
|
static void ismacroname3() {}
|
|
static void ismacroname4() {}
|
|
void foundnl() {}
|
|
void newline() {}
|
|
static void gotonexttoken() {}
|
|
short notendofline() {}
|
|
static void CPrep_MacroRedefError() {}
|
|
static void goendofline() {}
|
|
static void CPrep_Define() {}
|
|
static void prepundefine() {}
|
|
static Boolean CPrep_CheckTarget() {}
|
|
static Boolean CPrep_CheckOption() {}
|
|
static void CPrep_XpandDefinedCheck() {}
|
|
static void XpandString() {}
|
|
char *CPrep_GetFileName(char *buffer, Boolean flag1, Boolean flag2) {
|
|
}
|
|
|
|
static char *XpandSpecialMacro(Macro *macro) {
|
|
char buf[512];
|
|
char smallbuf[32];
|
|
char *strptr;
|
|
struct tm *tm;
|
|
|
|
if (macro == &optiM) {
|
|
return CPrep_CheckOption() ? "1" : "0";
|
|
} else if (macro == &trgtM) {
|
|
return CPrep_CheckTarget() ? "1" : "0";
|
|
} else if (macro == &lineM) {
|
|
sprintf(buf, "%ld", linenumber);
|
|
do_string:
|
|
strptr = aalloc(strlen(buf) + 1);
|
|
strcpy(strptr, buf);
|
|
return strptr;
|
|
} else if (macro == &fileM) {
|
|
CPrep_GetFileName(buf, 0, 1);
|
|
goto do_string;
|
|
} else if (macro == &dateM) {
|
|
tm = localtime(&now_time);
|
|
strftime(buf, 64, "\"%b ", tm);
|
|
strftime(smallbuf, 32, "%d", tm);
|
|
if (smallbuf[0] == '0')
|
|
smallbuf[0] = ' ';
|
|
strcat(buf, smallbuf);
|
|
strftime(smallbuf, 32, " %Y\"", tm);
|
|
strcat(buf, smallbuf);
|
|
goto do_string;
|
|
} else if (macro == &timeM) {
|
|
strftime(buf, 64, "\"%H:%M:%S\"", localtime(&now_time));
|
|
goto do_string;
|
|
} else if (macro == &stdcM) {
|
|
return "1";
|
|
} else if (macro == &casmM || macro == &MWRSM) {
|
|
return "0x2405";
|
|
} else if (macro == &cpplM) {
|
|
return "199711L";
|
|
} else if (macro == &dtsomM) {
|
|
return copts.direct_to_som ? "1" : "0";
|
|
} else if (macro == &ecppM) {
|
|
return copts.ecplusplus ? "1" : "0";
|
|
} else if (macro == &stcvM) {
|
|
return copts.c9x ? "199901L" : "199409L";
|
|
} else if (macro == &stchM) {
|
|
return "0";
|
|
} else {
|
|
return CodeGen_ExpandSpecialMacro(macro);
|
|
}
|
|
}
|
|
|
|
static void XpandMacro() {}
|
|
static void prepmacro() {}
|
|
void macrotest() {}
|
|
void CPrep_PragmaLex() {}
|
|
void CPrep_PushOption() {}
|
|
void CPrep_PopOption() {}
|
|
static void CPrep_PragmaImExport() {}
|
|
static void pragma_on_off_reset() {}
|
|
static void CPrep_PragmaOnceName() {}
|
|
static void pragma_precompile_target() {}
|
|
static void CPrep_DefinePragmaOnceMacro() {}
|
|
static void CPrep_PragmaOnce() {}
|
|
static void CPrep_PragmaUnused() {}
|
|
static void CPrep_PragmaInlineDepth() {}
|
|
static void CPrep_PragmaInlineMaxSize() {}
|
|
static void CPrep_PragmaInlineMaxTotalSize() {}
|
|
|
|
static void pragma_segment() {
|
|
short i;
|
|
short t;
|
|
char name[256];
|
|
|
|
if (notendofline()) {
|
|
for (i = 0; i < 255; i++) {
|
|
spaceskip = 0;
|
|
t = prepskipnextchar();
|
|
if (spaceskip)
|
|
break;
|
|
if (t <= ' ')
|
|
break;
|
|
name[i] = t;
|
|
pos = nextcharpos;
|
|
}
|
|
name[i] = 0;
|
|
|
|
if (!i || i >= 255)
|
|
CPrep_Warning(186);
|
|
|
|
copts.forcedSegment = GetHashNameNodeExport(name);
|
|
ObjGen_SegmentName();
|
|
} else {
|
|
if (copts.warn_illpragma)
|
|
CPrep_Warning(186);
|
|
}
|
|
}
|
|
|
|
static void pragma_options() {}
|
|
|
|
static void pragma_push() {
|
|
struct COptsPush *push;
|
|
|
|
push = galloc(sizeof(struct COptsPush));
|
|
push->next = coptpushs;
|
|
coptpushs = push;
|
|
|
|
push->opts = copts;
|
|
}
|
|
|
|
static void pragma_pop() {
|
|
if (coptpushs) {
|
|
copts = coptpushs->opts;
|
|
coptpushs = coptpushs->next;
|
|
CMach_Configure();
|
|
} else {
|
|
CPrep_Error(237);
|
|
}
|
|
}
|
|
|
|
static void pragma_overload() {}
|
|
static void pragma_optimization_level() {}
|
|
static void pragma_opt_unroll_count() {}
|
|
static void pragma_opt_unroll_instr_count() {}
|
|
static void pragma_pack() {}
|
|
static void pragma_comment() {}
|
|
static void pragma_message() {}
|
|
static void preppragma() {}
|
|
static void prepinclude() {}
|
|
static void prepline() {}
|
|
static void CPrep_GetPrepType() {}
|
|
static void CPrep_ParseUnary() {}
|
|
static void CPrep_ParseBinary() {}
|
|
static void CPrep_ParseCond() {}
|
|
static void doevalconstexpr() {}
|
|
static void pushifstate() {}
|
|
static void popifstate() {}
|
|
static void positiveif() {}
|
|
static void negativeif() {}
|
|
static void prepif() {}
|
|
static void prepifdef() {}
|
|
static void prepifndef() {}
|
|
static void prepelif() {}
|
|
static void prepelse() {}
|
|
static void prependif() {}
|
|
static void prepifskip() {}
|
|
void preprocessor() {}
|
|
void CPrep_BrowserTokenOffset() {}
|
|
void CPrep_BrowserFileOffset() {}
|
|
|
|
void CPrep_BrowserFilePosition(CPrepFileInfo **fileinfo, SInt32 *offset) {
|
|
CPrepFileInfo *file;
|
|
|
|
if (ts_first < ts_current) {
|
|
file = ts_current[-1].tokenfile;
|
|
*offset = ts_current[-1].tokenoffset + 1;
|
|
} else {
|
|
file = filestack[filesp];
|
|
if (tokenstacklevel) {
|
|
*offset = tokenstack[0].pos - filestack[filesp]->textbuffer;
|
|
} else {
|
|
*offset = pos - filestack[filesp]->textbuffer;
|
|
}
|
|
}
|
|
|
|
if (file && file->fileID > 0 && (file->recordbrowseinfo || gForceSourceLoc)) {
|
|
*fileinfo = file;
|
|
} else {
|
|
*fileinfo = NULL;
|
|
*offset = 0;
|
|
}
|
|
}
|
|
|
|
CPrepFileInfo *CPrep_BrowserCurrentFile() {
|
|
return prep_file;
|
|
}
|