]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - misc/source/fteqcc-src/qcc.h
Update fteqcc source
[voretournament/voretournament.git] / misc / source / fteqcc-src / qcc.h
1 #define COMPILER
2 #define PROGSUSED
3
4 //#define COMMONINLINES
5 //#define inline _inline
6
7 #include "cmdlib.h"
8 #include <setjmp.h>
9 /*
10 #include <stdio.h>
11 #include <conio.h>
12
13
14 #include "pr_comp.h"
15 */
16
17 //this is for testing
18 #define WRITEASM
19
20 #ifdef __MINGW32_VERSION
21 #define MINGW
22 #endif
23
24 #define progfuncs qccprogfuncs
25 extern progfuncs_t *qccprogfuncs;
26
27 #ifndef _WIN32
28 #define stricmp strcasecmp
29 #define strnicmp strncasecmp
30 #endif
31
32 void *qccHunkAlloc(size_t mem);
33 void qccClearHunk(void);
34
35 extern short   (*PRBigShort) (short l);
36 extern short   (*PRLittleShort) (short l);
37 extern int     (*PRBigLong) (int l);
38 extern int     (*PRLittleLong) (int l);
39 extern float   (*PRBigFloat) (float l);
40 extern float   (*PRLittleFloat) (float l);
41
42
43 #define MAX_ERRORS              10
44
45 #define MAX_NAME                256             // chars long
46
47 extern unsigned int MAX_REGS;
48
49 extern int      MAX_STRINGS;
50 extern int      MAX_GLOBALS;
51 extern int      MAX_FIELDS;
52 extern int      MAX_STATEMENTS;
53 extern int      MAX_FUNCTIONS;
54
55 #define MAX_SOUNDS              1024    //convert to int?
56 #define MAX_TEXTURES    1024    //convert to int?
57 #define MAX_MODELS              1024    //convert to int?
58 #define MAX_FILES               1024    //convert to int?
59 #define MAX_DATA_PATH   64
60
61 extern int MAX_CONSTANTS;
62 #define MAXCONSTANTNAMELENGTH 64
63 #define MAXCONSTANTPARAMLENGTH 32
64 #define MAXCONSTANTPARAMS 32
65
66 typedef enum {QCF_STANDARD, QCF_HEXEN2, QCF_DARKPLACES, QCF_FTE, QCF_FTEDEBUG, QCF_KK7, QCF_QTEST} qcc_targetformat_t;
67 extern qcc_targetformat_t qcc_targetformat;
68
69
70 /*
71
72 TODO:
73
74 "stopped at 10 errors"
75
76 other pointer types for models and clients?
77
78 compact string heap?
79
80 always initialize all variables to something safe
81
82 the def->type->type arrangement is really silly.
83
84 return type checking
85
86 parm count type checking
87
88 immediate overflow checking
89
90 pass the first two parms in call->b and call->c
91
92 */
93
94 /*
95
96 comments
97 --------
98 // comments discard text until the end of line
99 / *  * / comments discard all enclosed text (spaced out on this line because this documentation is in a regular C comment block, and typing them in normally causes a parse error)
100
101 code structure
102 --------------
103 A definition is:
104         <type> <name> [ = <immediate>] {, <name> [ = <immediate>] };
105
106
107 types
108 -----
109 simple types: void, float, vector, string, or entity
110         float           width, height;
111         string          name;
112         entity          self, other;
113
114 vector types:
115         vector          org;    // also creates org_x, org_y, and org_z float defs
116         
117         
118 A function type is specified as:        simpletype ( type name {,type name} )
119 The names are ignored except when the function is initialized.  
120         void()          think;
121         entity()        FindTarget;
122         void(vector destination, float speed, void() callback)  SUB_CalcMove;
123         void(...)       dprint;         // variable argument builtin
124
125 A field type is specified as:  .type
126         .vector         origin;
127         .string         netname;
128         .void()         think, touch, use;
129         
130
131 names
132 -----
133 Names are a maximum of 64 characters, must begin with A-Z,a-z, or _, and can continue with those characters or 0-9.
134
135 There are two levels of scoping: global, and function.  The parameter list of a function and any vars declared inside a function with the "local" statement are only visible within that function, 
136
137
138 immediates
139 ----------
140 Float immediates must begin with 0-9 or minus sign.  .5 is illegal.
141         
142 A parsing ambiguity is present with negative constants. "a-5" will be parsed as "a", then "-5", causing an error.  Seperate the - from the digits with a space "a - 5" to get the proper behavior.
143         12
144         1.6
145         0.5
146         -100
147
148 Vector immediates are three float immediates enclosed in single quotes.
149         '0 0 0'
150         '20.5 -10 0.00001'
151         
152 String immediates are characters enclosed in double quotes.  The string cannot contain explicit newlines, but the escape character \n can embed one.  The \" escape can be used to include a quote in the string.
153         "maps/jrwiz1.bsp"
154         "sound/nin/pain.wav"
155         "ouch!\n"
156
157 Code immediates are statements enclosed in {} braces.
158 statement:
159         { <multiple statements> }
160         <expression>;
161         local <type> <name> [ = <immediate>] {, <name> [ = <immediate>] };
162         return <expression>;
163         if ( <expression> ) <statement> [ else <statement> ];
164         while ( <expression> ) <statement>;
165         do <statement> while ( <expression> );
166         <function name> ( <function parms> );
167         
168 expression:
169         combiations of names and these operators with standard C precedence:
170         "&&", "||", "<=", ">=","==", "!=", "!", "*", "/", "-", "+", "=", ".", "<", ">", "&", "|"
171         Parenthesis can be used to alter order of operation.
172         The & and | operations perform integral bit ops on floats
173         
174 A built in function immediate is a number sign followed by an integer.
175         #1
176         #12
177
178
179 compilation
180 -----------
181 Source files are processed sequentially without dumping any state, so if a defs file is the first one processed, the definitions will be available to all other files.
182
183 The language is strongly typed and there are no casts.
184
185 Anything that is initialized is assumed to be constant, and will have immediates folded into it.  If you change the value, your program will malfunction.  All uninitialized globals will be saved to savegame files.
186
187 Functions cannot have more than eight parameters.
188
189 Error recovery during compilation is minimal.  It will skip to the next global definition, so you will never see more than one error at a time in a given function.  All compilation aborts after ten error messages.
190
191 Names can be defined multiple times until they are defined with an initialization, allowing functions to be prototyped before their definition.
192
193 void()  MyFunction;                     // the prototype
194
195 void()  MyFunction =            // the initialization
196 {
197         dprint ("we're here\n");
198 };
199
200
201 entities and fields
202 -------------------
203
204
205 execution
206 ---------
207 Code execution is initiated by C code in quake from two main places:  the timed think routines for periodic control, and the touch function when two objects impact each other.
208
209 There are three global variables that are set before beginning code execution:
210         entity  world;          // the server's world object, which holds all global
211                                                 // state for the server, like the deathmatch flags
212                                                 // and the body ques.
213         entity  self;           // the entity the function is executing for
214         entity  other;          // the other object in an impact, not used for thinks
215         float   time;           // the current game time.  Note that because the
216                                                 // entities in the world are simulated sequentially,
217                                                 // time is NOT strictly increasing.  An impact late
218                                                 // in one entity's time slice may set time higher
219                                                 // than the think function of the next entity. 
220                                                 // The difference is limited to 0.1 seconds.
221 Execution is also caused by a few uncommon events, like the addition of a new client to an existing server.
222         
223 There is a runnaway counter that stops a program if 100000 statements are executed, assuming it is in an infinite loop.
224
225 It is acceptable to change the system set global variables.  This is usually done to pose as another entity by changing self and calling a function.
226
227 The interpretation is fairly efficient, but it is still over an order of magnitude slower than compiled C code.  All time consuming operations should be made into built in functions.
228
229 A profile counter is kept for each function, and incremented for each interpreted instruction inside that function.  The "profile" console command in Quake will dump out the top 10 functions, then clear all the counters.  The "profile all" command will dump sorted stats for every function that has been executed.
230
231
232 afunc ( 4, bfunc(1,2,3));
233 will fail because there is a shared parameter marshaling area, which will cause the 1 from bfunc to overwrite the 4 already placed in parm0.  When a function is called, it copies the parms from the globals into it's privately scoped variables, so there is no collision when calling another function.
234
235 total = factorial(3) + factorial(4);
236 Will fail because the return value from functions is held in a single global area.  If this really gets on your nerves, tell me and I can work around it at a slight performance and space penalty by allocating a new register for the function call and copying it out.
237
238
239 built in functions
240 ------------------
241 void(string text)       dprint;
242 Prints the string to the server console.
243
244 void(entity client, string text)        cprint;
245 Prints a message to a specific client.
246
247 void(string text)       bprint;
248 Broadcast prints a message to all clients on the current server.
249
250 entity()        spawn;
251 Returns a totally empty entity.  You can manually set everything up, or just set the origin and call one of the existing entity setup functions.
252
253 entity(entity start, .string field, string match) find;
254 Searches the server entity list beginning at start, looking for an entity that has entity.field = match.  To start at the beginning of the list, pass world.  World is returned when the end of the list is reached.
255
256 <FIXME: define all the other functions...>
257
258
259 gotchas
260 -------
261
262 The && and || operators DO NOT EARLY OUT like C!
263
264 Don't confuse single quoted vectors with double quoted strings
265
266 The function declaration syntax takes a little getting used to.
267
268 Don't forget the ; after the trailing brace of a function initialization.
269
270 Don't forget the "local" before defining local variables.
271
272 There are no ++ / -- operators, or operate/assign operators.
273
274 */
275
276
277 #if 1
278 #include "hash.h"
279 extern hashtable_t compconstantstable;
280 extern hashtable_t globalstable, localstable;
281 #endif
282
283 #ifdef WRITEASM
284 extern FILE *asmfile;
285 #endif
286 //=============================================================================
287
288 // offsets are always multiplied by 4 before using
289 typedef unsigned int    gofs_t;                         // offset in global data block
290 typedef struct QCC_function_s QCC_function_t;
291
292 #define MAX_PARMS       8
293
294 typedef struct QCC_type_s
295 {
296         etype_t                 type;
297
298         struct QCC_type_s       *parentclass;   //type_entity...
299         struct QCC_type_s       *next;
300 // function types are more complex
301         struct QCC_type_s       *aux_type;      // return type or field type
302         struct QCC_type_s       *param;
303         int                             num_parms;      // -1 = variable args
304 //      struct QCC_type_s       *parm_types[MAX_PARMS]; // only [num_parms] allocated   
305
306         unsigned int ofs;       //inside a structure.
307         unsigned int size;
308         unsigned int arraysize;
309         pbool typedefed;
310         char *name;
311 } QCC_type_t;
312 int typecmp(QCC_type_t *a, QCC_type_t *b);
313
314 typedef struct temp_s {
315         gofs_t ofs;
316         struct QCC_def_s        *scope;
317 #ifdef WRITEASM
318         struct QCC_def_s        *lastfunc;
319 #endif
320         struct temp_s   *next;
321         pbool used;
322         unsigned int size;
323 } temp_t;
324 void QCC_PurgeTemps(void);
325
326 //not written
327 typedef struct QCC_def_s
328 {
329         QCC_type_t              *type;
330         char            *name;
331         struct QCC_def_s        *next;
332         struct QCC_def_s        *nextlocal;     //provides a chain of local variables for the opt_locals_marshalling optimisation.
333         gofs_t          ofs;
334         struct QCC_def_s        *scope;         // function the var was defined in, or NULL
335         struct QCC_def_s        *deftail;       // arrays and structs create multiple globaldef objects providing different types at the different parts of the single object (struct), or alternative names (vectors). this allows us to correctly set the const type based upon how its initialised.
336         int                     initialized;    // 1 when a declaration included "= immediate"
337         int                     constant;               // 1 says we can use the value over and over again
338
339         int references;
340         int timescalled;        //part of the opt_stripfunctions optimisation.
341
342         int s_file;
343         int s_line;
344
345         int arraysize;
346         pbool shared:1;
347         pbool saved:1;
348         pbool isstatic:1;
349         pbool subscoped_away:1;
350         pbool followptr:1;
351
352         temp_t *temp;
353 } QCC_def_t;
354
355 //============================================================================
356
357 // pr_loc.h -- program local defs
358
359
360 //=============================================================================
361 extern char QCC_copyright[1024];
362 extern char QCC_Packname[5][128];
363 extern int QCC_packid;
364
365 typedef union QCC_eval_s
366 {
367         QCC_string_t                    string;
368         float                           _float;
369         float                           vector[3];
370         func_t                          function;
371         int                                     _int;
372         union QCC_eval_s                *ptr;
373 } QCC_eval_t;
374
375 const extern    unsigned int            type_size[];
376 //extern        QCC_def_t       *def_for_type[9];
377
378 extern  QCC_type_t      *type_void, *type_string, *type_float, *type_vector, *type_entity, *type_field, *type_function, *type_pointer, *type_floatpointer, *type_intpointer, *type_integer, *type_variant, *type_floatfield;
379
380 struct QCC_function_s
381 {
382         int                                     builtin;        // if non 0, call an internal function
383         int                                     code;           // first statement
384         char                            *file;          // source file with definition
385         int                                     file_line;
386         struct QCC_def_s                *def;
387         unsigned int            parm_ofs[MAX_PARMS];    // always contiguous, right?
388 };
389
390
391 //
392 // output generated by prog parsing
393 //
394 typedef struct
395 {
396         char            *memory;
397         int                     max_memory;
398         int                     current_memory;
399         QCC_type_t              *types;
400         
401         QCC_def_t               def_head;               // unused head of linked list
402         QCC_def_t               *def_tail;              // add new defs after this and move it
403         QCC_def_t               *localvars;             // chain of variables which need to be pushed and stuff.
404         
405         int                     size_fields;
406 } QCC_pr_info_t;
407
408 extern  QCC_pr_info_t   pr;
409
410
411 typedef struct
412 {
413         char name[MAXCONSTANTNAMELENGTH];
414         char *value;
415         char params[MAXCONSTANTPARAMS][MAXCONSTANTPARAMLENGTH];
416         int numparams;
417         pbool used;
418         pbool inside;
419
420         int namelen;
421 } CompilerConstant_t;
422 extern CompilerConstant_t *CompilerConstant;
423
424 //============================================================================
425
426 extern  pbool   pr_dumpasm;
427
428 //extern        QCC_def_t               **pr_global_defs;       // to find def for a global variable
429
430 typedef enum {
431 tt_eof,                 // end of file reached
432 tt_name,                // an alphanumeric name token
433 tt_punct,               // code punctuation
434 tt_immediate,   // string, float, vector
435 } token_type_t;
436
437 extern  char            pr_token[8192];
438 extern  token_type_t    pr_token_type;
439 extern  QCC_type_t              *pr_immediate_type;
440 extern  QCC_eval_t              pr_immediate;
441
442 extern pbool keyword_asm;
443 extern pbool keyword_break;
444 extern pbool keyword_case;
445 extern pbool keyword_class;
446 extern pbool keyword_const;
447 extern pbool keyword_optional;
448 extern pbool keyword_continue;
449 extern pbool keyword_default;
450 extern pbool keyword_do;
451 extern pbool keyword_entity;
452 extern pbool keyword_float;
453 extern pbool keyword_for;
454 extern pbool keyword_goto;
455 extern pbool keyword_int;
456 extern pbool keyword_integer;
457 extern pbool keyword_state;
458 extern pbool keyword_string;
459 extern pbool keyword_struct;
460 extern pbool keyword_switch;
461 extern pbool keyword_thinktime;
462 extern pbool keyword_var;
463 extern pbool keyword_vector;
464 extern pbool keyword_union;
465 extern pbool keyword_enum;      //kinda like in c, but typedef not supported.
466 extern pbool keyword_enumflags; //like enum, but doubles instead of adds 1.
467 extern pbool keyword_typedef;   //fixme
468 extern pbool keyword_extern;    //function is external, don't error or warn if the body was not found
469 extern pbool keyword_shared;    //mark global to be copied over when progs changes (part of FTE_MULTIPROGS)
470 extern pbool keyword_noref;     //nowhere else references this, don't strip it.
471 extern pbool keyword_nosave;    //don't write the def to the output.
472 extern pbool keyword_union;     //you surly know what a union is!
473
474
475 extern pbool keywords_coexist;
476 extern pbool output_parms;
477 extern pbool autoprototype;
478 extern pbool pr_subscopedlocals;
479 extern pbool flag_ifstring;
480 extern pbool flag_iffloat;
481 extern pbool flag_acc;
482 extern pbool flag_caseinsensative;
483 extern pbool flag_laxcasts;
484 extern pbool flag_hashonly;
485 extern pbool flag_fasttrackarrays;
486 extern pbool flag_assume_integer;
487 extern pbool flag_msvcstyle;
488 extern pbool flag_filetimes;
489 extern pbool flag_typeexplicit;
490
491 extern pbool opt_overlaptemps;
492 extern pbool opt_shortenifnots;
493 extern pbool opt_noduplicatestrings;
494 extern pbool opt_constantarithmatic;
495 extern pbool opt_nonvec_parms;
496 extern pbool opt_constant_names;
497 extern pbool opt_precache_file;
498 extern pbool opt_filenames;
499 extern pbool opt_assignments;
500 extern pbool opt_unreferenced;
501 extern pbool opt_function_names;
502 extern pbool opt_locals;
503 extern pbool opt_dupconstdefs;
504 extern pbool opt_constant_names_strings;
505 extern pbool opt_return_only;
506 extern pbool opt_compound_jumps;
507 //extern pbool opt_comexprremoval;
508 extern pbool opt_stripfunctions;
509 extern pbool opt_locals_marshalling;
510 extern pbool opt_logicops;
511 extern pbool opt_vectorcalls;
512
513 extern int optres_shortenifnots;
514 extern int optres_overlaptemps;
515 extern int optres_noduplicatestrings;
516 extern int optres_constantarithmatic;
517 extern int optres_nonvec_parms;
518 extern int optres_constant_names;
519 extern int optres_precache_file;
520 extern int optres_filenames;
521 extern int optres_assignments;
522 extern int optres_unreferenced;
523 extern int optres_function_names;
524 extern int optres_locals;
525 extern int optres_dupconstdefs;
526 extern int optres_constant_names_strings;
527 extern int optres_return_only;
528 extern int optres_compound_jumps;
529 //extern int optres_comexprremoval;
530 extern int optres_stripfunctions;
531 extern int optres_locals_marshalling;
532 extern int optres_logicops;
533
534 pbool CompileParams(progfuncs_t *progfuncs, int doall, int nump, char **parms);
535
536 void QCC_PR_PrintStatement (QCC_dstatement_t *s);
537
538 void QCC_PR_Lex (void);
539 // reads the next token into pr_token and classifies its type
540
541 QCC_type_t *QCC_PR_NewType (char *name, int basictype, pbool typedefed);
542 QCC_type_t *QCC_PointerTypeTo(QCC_type_t *type);
543 QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail);
544 extern pbool type_inlinefunction;
545 QCC_type_t *QCC_TypeForName(char *name);
546 QCC_type_t *QCC_PR_ParseFunctionType (int newtype, QCC_type_t *returntype);
547 QCC_type_t *QCC_PR_ParseFunctionTypeReacc (int newtype, QCC_type_t *returntype);
548 char *QCC_PR_ParseName (void);
549 CompilerConstant_t *QCC_PR_DefineName(char *name);
550
551 void QCC_RemapOffsets(unsigned int firststatement, unsigned int laststatement, unsigned int min, unsigned int max, unsigned int newmin);
552
553 int QCC_PR_IntConstExpr(void);
554
555 #ifndef COMMONINLINES
556 pbool QCC_PR_CheckImmediate (char *string);
557 pbool QCC_PR_CheckToken (char *string);
558 pbool QCC_PR_CheckName (char *string);
559 void QCC_PR_Expect (char *string);
560 pbool QCC_PR_CheckKeyword(int keywordenabled, char *string);
561 #endif
562 void VARGS QCC_PR_ParseError (int errortype, char *error, ...);
563 void VARGS QCC_PR_ParseWarning (int warningtype, char *error, ...);
564 pbool VARGS QCC_PR_Warning (int type, char *file, int line, char *error, ...);
565 void VARGS QCC_PR_Note (int type, char *file, int line, char *error, ...);
566 void QCC_PR_ParsePrintDef (int warningtype, QCC_def_t *def);
567 void VARGS QCC_PR_ParseErrorPrintDef (int errortype, QCC_def_t *def, char *error, ...);
568
569 int QCC_WarningForName(char *name);
570
571 //QccMain.c must be changed if this is changed.
572 enum {
573         WARN_DEBUGGING,
574         WARN_ERROR,
575         WARN_NOTREFERENCED,
576         WARN_NOTREFERENCEDCONST,
577         WARN_CONFLICTINGRETURNS,
578         WARN_TOOFEWPARAMS,
579         WARN_TOOMANYPARAMS,
580         WARN_UNEXPECTEDPUNCT,
581         WARN_ASSIGNMENTTOCONSTANT,
582         WARN_ASSIGNMENTTOCONSTANTFUNC,
583         WARN_MISSINGRETURNVALUE,
584         WARN_WRONGRETURNTYPE,
585         WARN_CORRECTEDRETURNTYPE,
586         WARN_POINTLESSSTATEMENT,
587         WARN_MISSINGRETURN,
588         WARN_DUPLICATEDEFINITION,
589         WARN_UNDEFNOTDEFINED,
590         WARN_PRECOMPILERMESSAGE,
591         WARN_TOOMANYPARAMETERSFORFUNC,
592         WARN_STRINGTOOLONG,
593         WARN_BADTARGET,
594         WARN_BADPRAGMA,
595         WARN_HANGINGSLASHR,
596         WARN_NOTDEFINED,
597         WARN_NOTCONSTANT,
598         WARN_SWITCHTYPEMISMATCH,
599         WARN_CONFLICTINGUNIONMEMBER,
600         WARN_KEYWORDDISABLED,
601         WARN_ENUMFLAGS_NOTINTEGER,
602         WARN_ENUMFLAGS_NOTBINARY,
603         WARN_CASEINSENSATIVEFRAMEMACRO,
604         WARN_DUPLICATELABEL,
605         WARN_DUPLICATEMACRO,
606         WARN_ASSIGNMENTINCONDITIONAL,
607         WARN_MACROINSTRING,
608         WARN_BADPARAMS,
609         WARN_IMPLICITCONVERSION,
610         WARN_FIXEDRETURNVALUECONFLICT,
611         WARN_EXTRAPRECACHE,
612         WARN_NOTPRECACHED,
613         WARN_DEADCODE,
614         WARN_UNREACHABLECODE,
615         WARN_NOTSTANDARDBEHAVIOUR,
616         WARN_INEFFICIENTPLUSPLUS,
617         WARN_DUPLICATEPRECOMPILER,
618         WARN_IDENTICALPRECOMPILER,
619         WARN_FTE_SPECIFIC,      //extension that only FTEQCC will have a clue about.
620         WARN_EXTENSION_USED,    //extension that frikqcc also understands
621         WARN_IFSTRING_USED,
622         WARN_LAXCAST,   //some errors become this with a compiler flag
623         WARN_UNDESIRABLECONVENTION,
624         WARN_SAMENAMEASGLOBAL,
625         WARN_CONSTANTCOMPARISON,
626         WARN_UNSAFEFUNCTIONRETURNTYPE,
627         WARN_MISSINGOPTIONAL,
628
629         ERR_PARSEERRORS,        //caused by qcc_pr_parseerror being called.
630
631         //these are definatly my fault...
632         ERR_INTERNAL,
633         ERR_TOOCOMPLEX,
634         ERR_BADOPCODE,
635         ERR_TOOMANYSTATEMENTS,
636         ERR_TOOMANYSTRINGS,
637         ERR_BADTARGETSWITCH,
638         ERR_TOOMANYTYPES,
639         ERR_TOOMANYPAKFILES,
640         ERR_PRECOMPILERCONSTANTTOOLONG,
641         ERR_MACROTOOMANYPARMS,
642         ERR_TOOMANYFRAMEMACROS,
643
644         //limitations, some are imposed by compiler, some arn't.
645         ERR_TOOMANYGLOBALS,
646         ERR_TOOMANYGOTOS,
647         ERR_TOOMANYBREAKS,
648         ERR_TOOMANYCONTINUES,
649         ERR_TOOMANYCASES,
650         ERR_TOOMANYLABELS,
651         ERR_TOOMANYOPENFILES,
652         ERR_TOOMANYPARAMETERSVARARGS,
653         ERR_TOOMANYTOTALPARAMETERS,
654
655         //these are probably yours, or qcc being fussy.
656         ERR_BADEXTENSION,
657         ERR_BADIMMEDIATETYPE,
658         ERR_NOOUTPUT,
659         ERR_NOTAFUNCTION,
660         ERR_FUNCTIONWITHVARGS,
661         ERR_BADHEX,
662         ERR_UNKNOWNPUCTUATION,
663         ERR_EXPECTED,
664         ERR_NOTANAME,
665         ERR_NAMETOOLONG,
666         ERR_NOFUNC,
667         ERR_COULDNTOPENFILE,
668         ERR_NOTFUNCTIONTYPE,
669         ERR_TOOFEWPARAMS,
670         ERR_TOOMANYPARAMS,
671         ERR_CONSTANTNOTDEFINED,
672         ERR_BADFRAMEMACRO,
673         ERR_TYPEMISMATCH,
674         ERR_TYPEMISMATCHREDEC,
675         ERR_TYPEMISMATCHPARM,
676         ERR_TYPEMISMATCHARRAYSIZE,
677         ERR_UNEXPECTEDPUNCTUATION,
678         ERR_NOTACONSTANT,
679         ERR_REDECLARATION,
680         ERR_INITIALISEDLOCALFUNCTION,
681         ERR_NOTDEFINED,
682         ERR_ARRAYNEEDSSIZE,
683         ERR_ARRAYNEEDSBRACES,
684         ERR_TOOMANYINITIALISERS,
685         ERR_TYPEINVALIDINSTRUCT,
686         ERR_NOSHAREDLOCALS,
687         ERR_TYPEWITHNONAME,
688         ERR_BADARRAYSIZE,
689         ERR_NONAME,
690         ERR_SHAREDINITIALISED,
691         ERR_UNKNOWNVALUE,
692         ERR_BADARRAYINDEXTYPE,
693         ERR_NOVALIDOPCODES,
694         ERR_MEMBERNOTVALID,
695         ERR_BADPLUSPLUSOPERATOR,
696         ERR_BADNOTTYPE,
697         ERR_BADTYPECAST,
698         ERR_MULTIPLEDEFAULTS,
699         ERR_CASENOTIMMEDIATE,
700         ERR_BADSWITCHTYPE,
701         ERR_BADLABELNAME,
702         ERR_NOLABEL,
703         ERR_THINKTIMETYPEMISMATCH,
704         ERR_STATETYPEMISMATCH,
705         ERR_BADBUILTINIMMEDIATE,
706         ERR_PARAMWITHNONAME,
707         ERR_BADPARAMORDER,
708         ERR_ILLEGALCONTINUES,
709         ERR_ILLEGALBREAKS,
710         ERR_ILLEGALCASES,
711         ERR_NOTANUMBER,
712         ERR_WRONGSUBTYPE,
713         ERR_EOF,
714         ERR_NOPRECOMPILERIF,
715         ERR_NOENDIF,
716         ERR_HASHERROR,
717         ERR_NOTATYPE,
718         ERR_TOOMANYPACKFILES,
719         ERR_INVALIDVECTORIMMEDIATE,
720         ERR_INVALIDSTRINGIMMEDIATE,
721         ERR_BADCHARACTERCODE,
722         ERR_BADPARMS,
723         ERR_WERROR,
724
725         WARN_MAX
726 };
727
728 #define FLAG_KILLSDEBUGGERS     1
729 #define FLAG_ASDEFAULT          2
730 #define FLAG_SETINGUI           4
731 #define FLAG_HIDDENINGUI        8
732 #define FLAG_MIDCOMPILE         16      //option can be changed mid-compile with the special pragma
733 typedef struct {
734         pbool *enabled;
735         char *abbrev;
736         int optimisationlevel;
737         int flags;      //1: kills debuggers. 2: applied as default.
738         char *fullname;
739         char *description;
740         void *guiinfo;
741 } optimisations_t;
742 extern optimisations_t optimisations[];
743
744 typedef struct {
745         pbool *enabled;
746         int flags;      //2 applied as default
747         char *abbrev;
748         char *fullname;
749         char *description;
750         void *guiinfo;
751 } compiler_flag_t;
752 extern compiler_flag_t compiler_flag[];
753
754 extern pbool qccwarningdisabled[WARN_MAX];
755
756 extern  jmp_buf         pr_parse_abort;         // longjump with this on parse error
757 extern  int                     pr_source_line;
758 extern  char            *pr_file_p;
759
760 void *QCC_PR_Malloc (int size);
761
762
763 #define OFS_NULL                0
764 #define OFS_RETURN              1
765 #define OFS_PARM0               4               // leave 3 ofs for each parm to hold vectors
766 #define OFS_PARM1               7
767 #define OFS_PARM2               10
768 #define OFS_PARM3               13
769 #define OFS_PARM4               16
770 #define RESERVED_OFS    28
771
772
773 extern  QCC_def_t       *pr_scope;
774 extern  int             pr_error_count, pr_warning_count;
775
776 void QCC_PR_NewLine (pbool incomment);
777 QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool allocate, int arraysize, pbool saved);
778
779 void QCC_PR_PrintDefs (void);
780
781 void QCC_PR_SkipToSemicolon (void);
782
783 #define MAX_EXTRA_PARMS 128
784 #ifdef MAX_EXTRA_PARMS
785 extern  char            pr_parm_names[MAX_PARMS+MAX_EXTRA_PARMS][MAX_NAME];
786 extern QCC_def_t *extra_parms[MAX_EXTRA_PARMS];
787 #else
788 extern  char            pr_parm_names[MAX_PARMS][MAX_NAME];
789 #endif
790 extern  pbool   pr_trace;
791
792 #define G_FLOAT(o) (qcc_pr_globals[o])
793 #define G_INT(o) (*(int *)&qcc_pr_globals[o])
794 #define G_VECTOR(o) (&qcc_pr_globals[o])
795 #define G_STRING(o) (strings + *(QCC_string_t *)&qcc_pr_globals[o])
796 #define G_FUNCTION(o) (*(func_t *)&qcc_pr_globals[o])
797
798 char *QCC_PR_ValueString (etype_t type, void *val);
799
800 void QCC_PR_ClearGrabMacros (void);
801
802 pbool   QCC_PR_CompileFile (char *string, char *filename);
803 void QCC_PR_ResetErrorScope(void);
804
805 extern  pbool   pr_dumpasm;
806
807 extern  QCC_string_t    s_file;                 // filename for function definition
808
809 extern  QCC_def_t       def_ret, def_parms[MAX_PARMS];
810
811 void QCC_PR_EmitArrayGetFunction(QCC_def_t *scope, char *arrayname);
812 void QCC_PR_EmitArraySetFunction(QCC_def_t *scope, char *arrayname);
813 void QCC_PR_EmitClassFromFunction(QCC_def_t *scope, char *tname);
814
815 void PostCompile(void);
816 pbool PreCompile(void);
817
818 //=============================================================================
819
820 extern char     pr_immediate_string[8192];
821
822 extern float            *qcc_pr_globals;
823 extern unsigned int     numpr_globals;
824
825 extern char             *strings;
826 extern int                      strofs;
827
828 extern QCC_dstatement_t *statements;
829 extern int                      numstatements;
830 extern int                      *statement_linenums;
831
832 extern QCC_dfunction_t  *functions;
833 extern int                      numfunctions;
834
835 extern QCC_ddef_t               *qcc_globals;
836 extern int                      numglobaldefs;
837
838 extern QCC_def_t                *activetemps;
839
840 extern QCC_ddef_t               *fields;
841 extern int                      numfielddefs;
842
843 extern QCC_type_t *qcc_typeinfo;
844 extern int numtypeinfos;
845 extern int maxtypeinfos;
846
847 extern int ForcedCRC;
848 extern pbool defaultnoref;
849 extern pbool defaultstatic;
850
851 extern int *qcc_tempofs;
852 extern int max_temps;
853 //extern int qcc_functioncalled;        //unuse temps if this is true - don't want to reuse the same space.
854
855 extern int tempsstart;
856 extern int numtemps;
857
858 typedef char PATHSTRING[MAX_DATA_PATH];
859
860 extern PATHSTRING               *precache_sounds;
861 extern int                      *precache_sounds_block;
862 extern int                      *precache_sounds_used;
863 extern int                      numsounds;
864
865 extern PATHSTRING               *precache_textures;
866 extern int                      *precache_textures_block;
867 extern int                      numtextures;
868
869 extern PATHSTRING               *precache_models;
870 extern int                      *precache_models_block;
871 extern int                      *precache_models_used;
872 extern int                      nummodels;
873
874 extern PATHSTRING               *precache_files;
875 extern int                      *precache_files_block;
876 extern int                      numfiles;
877
878 typedef struct qcc_includechunk_s {
879         struct qcc_includechunk_s *prev;
880         char *filename;
881         char *currentdatapoint;
882         int currentlinenumber;
883         CompilerConstant_t *cnst;
884 } qcc_includechunk_t;
885 extern qcc_includechunk_t *currentchunk;
886
887 int     QCC_CopyString (char *str);
888
889
890
891
892 typedef struct qcc_cachedsourcefile_s {
893         char filename[128];
894         int size;
895         char *file;
896         enum{FT_CODE, FT_DATA} type;    //quakec source file or not.
897         struct qcc_cachedsourcefile_s *next;
898 } qcc_cachedsourcefile_t;
899 extern qcc_cachedsourcefile_t *qcc_sourcefile;
900
901
902
903
904
905 #ifdef COMMONINLINES
906 static bool inline QCC_PR_CheckToken (char *string)
907 {
908         if (pr_token_type != tt_punct)
909                 return false;
910
911         if (STRCMP (string, pr_token))
912                 return false;
913
914         QCC_PR_Lex ();
915         return true;
916 }
917
918 static void inline QCC_PR_Expect (char *string)
919 {
920         if (strcmp (string, pr_token))
921                 QCC_PR_ParseError ("expected %s, found %s",string, pr_token);
922         QCC_PR_Lex ();
923 }
924 #endif
925
926 void editbadfile(char *fname, int line);
927 char *TypeName(QCC_type_t *type);
928 void QCC_PR_IncludeChunk (char *data, pbool duplicate, char *filename);
929 void QCC_PR_IncludeChunkEx(char *data, pbool duplicate, char *filename, CompilerConstant_t *cnst);
930 pbool QCC_PR_UnInclude(void);
931 extern void *(*pHash_Get)(hashtable_t *table, const char *name);
932 extern void *(*pHash_GetNext)(hashtable_t *table, const char *name, void *old);
933 extern void *(*pHash_Add)(hashtable_t *table, const char *name, void *data, bucket_t *);