diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 058a2aa1a..367ea2cb3 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -286,7 +286,6 @@ typedef struct function_s function_t; typedef struct type_s { etype_t type; - struct def_s *def; // a def that points to this type struct type_s *next; // function/pointer/struct types are more complex struct type_s *aux_type; // return type or field type @@ -353,8 +352,6 @@ typedef union eval_s union eval_s *ptr; } eval_t; -extern def_t *def_for_type[8]; - extern type_t type_void; extern type_t type_string; extern type_t type_float; @@ -370,21 +367,10 @@ extern type_t type_uinteger; extern type_t type_short; extern type_t type_struct; extern type_t type_id; +extern type_t type_SEL; extern def_t def_void; -extern def_t def_string; -extern def_t def_float; -extern def_t def_vector; -extern def_t def_entity; -extern def_t def_field; extern def_t def_function; -extern def_t def_pointer; -extern def_t def_quaternion; -extern def_t def_integer; -extern def_t def_uinteger; -extern def_t def_short; -extern def_t def_struct; -extern def_t def_id; struct function_s { @@ -444,42 +430,15 @@ void PR_Opcode_Init_Tables (void); #include "expr.h" -extern qboolean pr_dumpasm; - extern def_t *pr_global_defs[MAX_REGS]; // to find def for a global - // variable -// reads the next token into pr_token and classifies its type - -type_t *PR_ParseType (void); -char *PR_ParseName (void); -def_t *PR_ParseImmediate (def_t *def); def_t *PR_ReuseConstant (expr_t *expr, def_t *def); -type_t *PR_FindType (type_t *new); -void PR_ParseError (const char *error, ...)__attribute__((format(printf, 1,2))); - - -extern jmp_buf pr_parse_abort; // longjump with this on parse error extern int pr_source_line; -void *PR_Malloc (int size); - - -#define OFS_NULL 0 -#define OFS_RETURN 1 -#define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors -#define OFS_PARM1 7 -#define OFS_PARM2 10 -#define OFS_PARM3 13 -#define OFS_PARM4 16 -#define RESERVED_OFS 28 - - extern def_t *pr_scope; extern int pr_error_count; -void PR_NewLine (void); int PR_GetTypeSize (type_t *type); def_t *PR_GetArray (type_t *etype, const char *name, int size, def_t *scope, int *allocate); @@ -495,24 +454,12 @@ void PR_ResetTempDefs (); void PR_FlushScope (def_t *scope, int force_used); void PR_DefInitialized (def_t *d); -void PR_PrintDefs (void); -void PR_PrintFunction (def_t *def); -void PR_SkipToSemicolon (void); - -extern qboolean pr_trace; - #define G_FLOAT(o) (pr_globals[o]) #define G_INT(o) (*(int *)&pr_globals[o]) #define G_VECTOR(o) (&pr_globals[o]) #define G_STRING(o) (strings + *(string_t *)&pr_globals[o]) #define G_FUNCTION(o) (*(func_t *)&pr_globals[o]) -void PR_ClearGrabMacros (void); - -qboolean PR_CompileFile (char *string, const char *filename); - -extern qboolean pr_dumpasm; - extern string_t s_file; // filename for function definition extern def_t def_ret, def_parms[MAX_PARMS]; @@ -543,8 +490,6 @@ extern int numfunctions; extern float pr_globals[MAX_REGS]; extern int numpr_globals; -extern char pr_immediate_string[2048]; - extern char precache_sounds[MAX_SOUNDS][MAX_DATA_PATH]; extern int precache_sounds_block[MAX_SOUNDS]; extern int numsounds; diff --git a/tools/qfcc/include/type.h b/tools/qfcc/include/type.h index b444747e8..9fa805349 100644 --- a/tools/qfcc/include/type.h +++ b/tools/qfcc/include/type.h @@ -32,6 +32,7 @@ #ifndef __type_h #define __type_h +type_t *find_type (type_t *new); void new_typedef (const char *name, struct type_s *type); struct type_s *get_typedef (const char *name); struct type_s *pointer_type (struct type_s *aux); diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 9d3c59683..97f719864 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -153,7 +153,7 @@ get_type (expr_t *e) memset (&new, 0, sizeof (new)); new.type = ev_pointer; new.aux_type = e->e.pointer.type; - return PR_FindType (&new); + return find_type (&new); } case ex_integer: if (options.code.progsversion == PROG_ID_VERSION) { diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 329f9f238..8dddce113 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -96,7 +96,7 @@ parse_params (type_t *type, param_t *parms) } } //print_type (&new); puts(""); - return PR_FindType (&new); + return find_type (&new); } void diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c index 1597d8594..b1d0a7ae9 100644 --- a/tools/qfcc/source/method.c +++ b/tools/qfcc/source/method.c @@ -38,8 +38,9 @@ static const char rcsid[] = #include "method.h" #include "type.h" +static type_t *send_message_type; static def_t *send_message_def; -static expr_t *send_message_expr; +static function_t *send_message_func; method_t * new_method (type_t *ret_type, param_t *selector, param_t *opt_parms) @@ -107,10 +108,23 @@ new_keywordarg (const char *selector, struct expr_s *expr) expr_t * send_message (void) { + expr_t *e; + if (!send_message_def) { - send_message_expr = new_expr (); - send_message_expr->type = ex_def; - send_message_expr->e.def = send_message_def; + send_message_type = parse_params (&type_id, + _reverse_params (new_param (0, &type_id, "receiver"), + _reverse_params (new_param (0, &type_SEL, "selector"), + new_param (0, 0, 0)))); + send_message_def = PR_GetDef (send_message_type, "obj_msgSend", + 0, &numpr_globals); + send_message_func = new_function (); + send_message_func->builtin = 0; + send_message_func->def = send_message_def; + build_function (send_message_func); + finish_function (send_message_func); } - return send_message_expr; + e = new_expr (); + e->type = ex_def; + e->e.def = send_message_def; + return e; } diff --git a/tools/qfcc/source/pr_def.c b/tools/qfcc/source/pr_def.c index 95dec688a..f72d504ee 100644 --- a/tools/qfcc/source/pr_def.c +++ b/tools/qfcc/source/pr_def.c @@ -28,6 +28,7 @@ static const char rcsid[] = #include "qfcc.h" #include "expr.h" #include "struct.h" +#include "type.h" extern expr_t *local_expr; // FIXME just where should this go? @@ -80,23 +81,11 @@ check_for_name (type_t *type, const char *name, def_t *scope, int *allocate) return 0; } -static inline type_t * -find_type (type_t *type, type_t *aux_type) -{ - type_t new; - - memset (&new, 0, sizeof (new)); - new.type = type->type; - new.aux_type = aux_type; - new.num_parms = 0; - return PR_FindType (&new); -} - def_t * PR_GetArray (type_t *etype, const char *name, int size, def_t *scope, int *allocate) { - type_t *type = find_type (&type_pointer, etype); + type_t *type = pointer_type (etype); def_t *def = check_for_name (type, name, scope, allocate); if (def || !allocate) diff --git a/tools/qfcc/source/pr_lex.c b/tools/qfcc/source/pr_lex.c index 5a4d68426..ace0ccc9e 100644 --- a/tools/qfcc/source/pr_lex.c +++ b/tools/qfcc/source/pr_lex.c @@ -34,7 +34,6 @@ static const char rcsid[] = #include #include "qfcc.h" -#include "function.h" int pr_source_line; @@ -48,102 +47,4 @@ int pr_token_len; type_t *pr_immediate_type; eval_t pr_immediate; -char pr_immediate_string[2048]; - int pr_error_count; - -// simple types. function types are dynamically allocated -type_t type_void = { ev_void, &def_void }; -type_t type_string = { ev_string, &def_string }; -type_t type_float = { ev_float, &def_float }; -type_t type_vector = { ev_vector, &def_vector }; -type_t type_entity = { ev_entity, &def_entity }; -type_t type_field = { ev_field, &def_field }; - -// type_function is a void() function used for state defs -type_t type_function = { ev_func, &def_function, NULL, &type_void }; -type_t type_pointer = { ev_pointer, &def_pointer }; -type_t type_quaternion = { ev_quaternion, &def_quaternion }; -type_t type_integer = { ev_integer, &def_integer }; -type_t type_uinteger = { ev_uinteger, &def_uinteger }; -type_t type_short = { ev_short, &def_short }; -type_t type_struct = { ev_struct, &def_struct }; -type_t type_id = {ev_pointer, &def_id }; - -type_t type_floatfield = { ev_field, &def_field, NULL, &type_float }; - -def_t def_void = { &type_void, "temp" }; -def_t def_string = { &type_string, "temp" }; -def_t def_float = { &type_float, "temp" }; -def_t def_vector = { &type_vector, "temp" }; -def_t def_entity = { &type_entity, "temp" }; -def_t def_field = { &type_field, "temp" }; -def_t def_function = { &type_function, "temp" }; -def_t def_pointer = { &type_pointer, "temp" }; -def_t def_quaternion = { &type_quaternion, "temp" }; -def_t def_integer = { &type_integer, "temp" }; -def_t def_uinteger = { &type_uinteger, "temp" }; -def_t def_short = { &type_short, "temp" }; -def_t def_struct = { &type_struct, "temp" }; -def_t def_id = { &type_id, "temp" }; - -def_t def_ret, def_parms[MAX_PARMS]; - -def_t *def_for_type[8] = { - &def_void, &def_string, &def_float, &def_vector, - &def_entity, &def_field, &def_function, &def_pointer -}; - -/* - PR_FindType - - Returns a preexisting complex type that matches the parm, or allocates - a new one and copies it out. -*/ -type_t * -PR_FindType (type_t *type) -{ - def_t *def; - type_t *check; - int c, i; - - for (check = pr.types; check; check = check->next) { - if (check->type != type->type - || check->aux_type != type->aux_type - || check->num_parms != type->num_parms) - continue; - - if (check->type != ev_func) - return check; - - if (check->num_parms == -1) - return check; - - if ((c = check->num_parms) < 0) - c = -c - 1; - - for (i = 0; i < c; i++) - if (check->parm_types[i] != type->parm_types[i]) - break; - - if (i == c) - return check; - } - - // allocate a new one - check = malloc (sizeof (*check)); - if (!check) - Sys_Error ("PR_FindType: Memory Allocation Failure\n"); - *check = *type; - check->next = pr.types; - pr.types = check; - - // allocate a generic def for the type, so fields can reference it - def = malloc (sizeof (def_t)); - if (!def) - Sys_Error ("PR_FindType: Memory Allocation Failure\n"); - def->name = "COMPLEX TYPE"; - def->type = check; - check->def = def; - return check; -} diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index a1b35c86c..814035a5d 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -55,7 +55,6 @@ yyerror (const char *s) } int yylex (void); -type_t *PR_FindType (type_t *new); type_t *build_type (int is_field, type_t *type); type_t *build_array_type (type_t *type, int size); @@ -1228,7 +1227,7 @@ build_type (int is_field, type_t *type) memset (&new, 0, sizeof (new)); new.type = ev_field; new.aux_type = type; - return PR_FindType (&new); + return find_type (&new); } else { return type; } @@ -1243,7 +1242,7 @@ build_array_type (type_t *type, int size) new.type = ev_pointer; new.aux_type = type; new.num_parms = size; - return PR_FindType (&new); + return find_type (&new); } typedef struct { diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index 22700c897..878e4b880 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -33,6 +33,7 @@ static const char rcsid[] = #include #include "QF/hash.h" +#include "QF/sys.h" #include "qfcc.h" #include "function.h" @@ -42,6 +43,78 @@ typedef struct { type_t *type; } typedef_t; +// simple types. function types are dynamically allocated +type_t type_void = { ev_void }; +type_t type_string = { ev_string }; +type_t type_float = { ev_float }; +type_t type_vector = { ev_vector }; +type_t type_entity = { ev_entity }; +type_t type_field = { ev_field }; + +// type_function is a void() function used for state defs +type_t type_function = { ev_func, NULL, &type_void }; +type_t type_pointer = { ev_pointer }; +type_t type_quaternion = { ev_quaternion }; +type_t type_integer = { ev_integer }; +type_t type_uinteger = { ev_uinteger }; +type_t type_short = { ev_short }; +type_t type_struct = { ev_struct }; +type_t type_id = {ev_pointer }; +type_t type_SEL = {ev_pointer }; + +type_t type_floatfield = { ev_field, NULL, &type_float }; + +def_t def_void = { &type_void, "temp" }; +def_t def_function = { &type_function, "temp" }; + +def_t def_ret, def_parms[MAX_PARMS]; + +/* + find_type + + Returns a preexisting complex type that matches the parm, or allocates + a new one and copies it out. +*/ +type_t * +find_type (type_t *type) +{ + type_t *check; + int c, i; + + for (check = pr.types; check; check = check->next) { + if (check->type != type->type + || check->aux_type != type->aux_type + || check->num_parms != type->num_parms) + continue; + + if (check->type != ev_func) + return check; + + if (check->num_parms == -1) + return check; + + if ((c = check->num_parms) < 0) + c = -c - 1; + + for (i = 0; i < c; i++) + if (check->parm_types[i] != type->parm_types[i]) + break; + + if (i == c) + return check; + } + + // allocate a new one + check = malloc (sizeof (*check)); + if (!check) + Sys_Error ("find_type: Memory Allocation Failure\n"); + *check = *type; + check->next = pr.types; + pr.types = check; + + return check; +} + static hashtab_t *typedef_hash; static const char * @@ -89,7 +162,7 @@ pointer_type (type_t *aux) memset (&new, 0, sizeof (new)); new.type = ev_pointer; new.aux_type = aux; - return PR_FindType (&new); + return find_type (&new); } void