From 8cfa80b5d4858fdaf94fc5180dd0ef53754276d0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 5 Mar 2011 18:01:37 +0900 Subject: [PATCH] Implement think expressions. --- tools/qfcc/include/expr.h | 1 + tools/qfcc/source/expr.c | 21 +++++++++++++++++++++ tools/qfcc/source/qc-parse.y | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index e35dc7cd8..7ca0ca251 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -566,6 +566,7 @@ expr_t *build_for_statement (expr_t *init, expr_t *test, expr_t *next, expr_t *statement, expr_t *break_label, expr_t *continue_label); expr_t *build_state_expr (expr_t *frame, expr_t *think, expr_t *step); +expr_t *think_expr (struct symbol_s *think_sym); expr_t *assign_expr (expr_t *e1, expr_t *e2); expr_t *cast_expr (struct type_s *t, expr_t *e); diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index be92f2647..f55f9d556 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2305,6 +2305,27 @@ build_state_expr (expr_t *frame, expr_t *think, expr_t *step) return new_state_expr (frame, think, step); } +expr_t * +think_expr (symbol_t *think_sym) +{ + symbol_t *sym; + + if (think_sym->table) + return new_symbol_expr (think_sym); + + sym = symtab_lookup (current_symtab, "think"); + if (sym && sym->sy_type == sy_var && sym->type + && sym->type->type == ev_field + && sym->type->t.fldptr.type->type == ev_func) { + think_sym->type = sym->type->t.fldptr.type; + } else { + think_sym->type = &type_function; + } + think_sym = function_symbol (think_sym, 0, 1); + make_function (think_sym, 0, current_symtab->space, current_storage); + return new_symbol_expr (think_sym); +} + static int is_indirect (expr_t *e) { diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index cf5067182..140951d13 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -913,7 +913,7 @@ optional_state_expr think : identifier { - internal_error (0, "FIXME"); + $$ = think_expr ($1); } | '(' fexpr ')' {