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