From b1d1159ae2593439b896d00ad45a03aa16738f78 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 17 May 2002 18:35:54 +0000 Subject: [PATCH] allow methods to be builtins --- tools/qfcc/include/function.h | 3 +++ tools/qfcc/source/function.c | 24 ++++++++++++++++++++++++ tools/qfcc/source/qc-parse.y | 33 +++++++++++++++++---------------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/tools/qfcc/include/function.h b/tools/qfcc/include/function.h index 1d8f780ae..8800e49f9 100644 --- a/tools/qfcc/include/function.h +++ b/tools/qfcc/include/function.h @@ -41,12 +41,15 @@ typedef struct param_s { const char *name; } param_t; +struct expr_s; + param_t *new_param (const char *selector, type_t *type, const char *name); param_t *_reverse_params (param_t *params, param_t *next); param_t *reverse_params (param_t *params); type_t *parse_params (type_t *type, param_t *params); void build_scope (function_t *f, def_t *func, param_t *params); function_t *new_function (void); +void build_builtin_function (def_t *def, struct expr_s *bi_val); void build_function (function_t *f); void finish_function (function_t *f); void emit_function (function_t *f, expr_t *e); diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 430ff3826..8b2e0b2ee 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -135,6 +135,30 @@ new_function (void) return f; } +void +build_builtin_function (def_t *def, expr_t *bi_val) +{ + function_t *f; + + if (def->type->type != ev_func) { + error (bi_val, "%s is not a function", def->name); + return; + } + + if (bi_val->type != ex_integer && bi_val->type != ex_float) { + error (bi_val, "invalid constant for = #"); + return; + } + + f = new_function (); + + f->builtin = bi_val->type == ex_integer ? bi_val->e.integer_val + : (int)bi_val->e.float_val; + f->def = def; + build_function (f); + finish_function (f); +} + void build_function (function_t *f) { diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 577e6ee1e..d5548db22 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -372,22 +372,7 @@ var_initializer } | '=' '#' const { - if (current_type->type != ev_func) { - error (0, "%s is not a function", current_def->name); - } else { - if ($3->type != ex_integer && $3->type != ex_float) { - error (0, "invalid constant for = #"); - } else { - function_t *f; - - f = new_function (); - f->builtin = $3->type == ex_integer - ? $3->e.integer_val : (int)$3->e.float_val; - f->def = current_def; - build_function (f); - finish_function (f); - } - } + build_builtin_function (current_def, $3); } | '=' opt_state_expr begin_function statement_block end_function { @@ -1093,6 +1078,14 @@ methoddef } finish_function ($6); } + | '+' methoddecl '=' '#' const ';' + { + $2->instance = 0; + $2 = class_find_method (current_class, $2); + $2->def = method_def (current_class, $2); + + build_builtin_function ($2->def, $5); + } | '-' methoddecl { $2->instance = 1; @@ -1114,6 +1107,14 @@ methoddef } finish_function ($6); } + | '-' methoddecl '=' '#' const ';' + { + $2->instance = 0; + $2 = class_find_method (current_class, $2); + $2->def = method_def (current_class, $2); + + build_builtin_function ($2->def, $5); + } ; methodprotolist