2001-12-08 20:40:50 +00:00
|
|
|
/*
|
2002-10-22 14:53:18 +00:00
|
|
|
expr.h
|
2001-12-08 20:40:50 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
expression construction and manipulations
|
2001-12-08 20:40:50 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
2001-12-08 20:40:50 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/06/15
|
2001-12-08 20:40:50 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __expr_h
|
|
|
|
#define __expr_h
|
|
|
|
|
2004-01-25 08:55:03 +00:00
|
|
|
#include "QF/pr_comp.h"
|
|
|
|
|
2001-06-20 07:02:36 +00:00
|
|
|
typedef enum {
|
2002-05-01 22:08:59 +00:00
|
|
|
ex_error,
|
2004-02-11 01:43:33 +00:00
|
|
|
ex_state,
|
2003-10-22 08:05:17 +00:00
|
|
|
ex_bool,
|
2001-06-25 22:11:20 +00:00
|
|
|
ex_label,
|
2001-06-26 03:33:01 +00:00
|
|
|
ex_block,
|
2001-06-20 21:18:04 +00:00
|
|
|
ex_expr, // binary expression
|
|
|
|
ex_uexpr, // unary expression
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_def,
|
2001-08-11 21:15:24 +00:00
|
|
|
ex_temp, // temporary variable
|
2001-12-08 08:19:48 +00:00
|
|
|
ex_name,
|
2001-07-18 06:37:14 +00:00
|
|
|
|
2010-11-17 09:49:39 +00:00
|
|
|
ex_nil, // umm, nil, null. nuff said
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_string,
|
2001-07-18 06:37:14 +00:00
|
|
|
ex_float,
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_vector,
|
2001-07-18 06:37:14 +00:00
|
|
|
ex_entity,
|
|
|
|
ex_field,
|
|
|
|
ex_func,
|
|
|
|
ex_pointer,
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_quaternion,
|
2001-07-22 06:59:12 +00:00
|
|
|
ex_integer,
|
2001-11-13 08:58:54 +00:00
|
|
|
ex_uinteger,
|
2001-12-07 20:10:30 +00:00
|
|
|
ex_short,
|
2001-06-20 07:02:36 +00:00
|
|
|
} expr_type;
|
|
|
|
|
2002-06-07 17:29:30 +00:00
|
|
|
typedef struct ex_label_s {
|
|
|
|
struct ex_label_s *next;
|
|
|
|
struct reloc_s *refs;
|
2002-06-05 17:12:55 +00:00
|
|
|
int ofs;
|
2001-11-13 08:58:54 +00:00
|
|
|
const char *name;
|
2002-05-11 03:37:36 +00:00
|
|
|
} ex_label_t;
|
2001-06-25 22:11:20 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
typedef struct {
|
|
|
|
struct expr_s *head;
|
|
|
|
struct expr_s **tail;
|
2001-08-11 21:15:24 +00:00
|
|
|
struct expr_s *result;
|
2001-08-24 21:47:52 +00:00
|
|
|
int is_call;
|
2002-05-11 03:37:36 +00:00
|
|
|
} ex_block_t;
|
2001-06-26 03:33:01 +00:00
|
|
|
|
2001-08-11 21:15:24 +00:00
|
|
|
typedef struct {
|
|
|
|
struct expr_s *expr;
|
2002-06-04 18:44:03 +00:00
|
|
|
struct def_s *def;
|
|
|
|
struct type_s *type;
|
2001-08-11 21:15:24 +00:00
|
|
|
int users;
|
2002-05-11 03:37:36 +00:00
|
|
|
} ex_temp_t;
|
2001-08-11 21:15:24 +00:00
|
|
|
|
2001-12-12 08:39:47 +00:00
|
|
|
typedef struct {
|
|
|
|
int val;
|
2002-06-04 18:44:03 +00:00
|
|
|
struct type_s *type;
|
2002-07-14 03:41:13 +00:00
|
|
|
struct def_s *def;
|
2002-05-11 03:37:36 +00:00
|
|
|
} ex_pointer_t;
|
2001-12-12 08:39:47 +00:00
|
|
|
|
2003-10-22 08:05:17 +00:00
|
|
|
typedef struct {
|
|
|
|
int size;
|
|
|
|
struct expr_s *e[1];
|
|
|
|
} ex_list_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ex_list_t *true_list;
|
|
|
|
ex_list_t *false_list;
|
|
|
|
struct expr_s *e;
|
|
|
|
} ex_bool_t;
|
|
|
|
|
2004-02-11 01:43:33 +00:00
|
|
|
typedef struct {
|
|
|
|
struct expr_s *frame;
|
|
|
|
struct expr_s *think;
|
|
|
|
struct expr_s *step;
|
|
|
|
} ex_state_t;
|
|
|
|
|
2003-05-15 05:58:31 +00:00
|
|
|
#define POINTER_VAL(p) (((p).def ? (p).def->ofs : 0) + (p).val)
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
typedef struct expr_s {
|
2001-06-20 21:18:04 +00:00
|
|
|
struct expr_s *next;
|
2001-06-20 07:02:36 +00:00
|
|
|
expr_type type;
|
2001-06-26 16:23:21 +00:00
|
|
|
int line;
|
|
|
|
string_t file;
|
2002-02-21 20:34:04 +00:00
|
|
|
unsigned paren:1;
|
|
|
|
unsigned rvalue:1;
|
2001-06-15 19:38:43 +00:00
|
|
|
union {
|
2002-05-11 03:37:36 +00:00
|
|
|
ex_label_t label;
|
2004-02-11 01:43:33 +00:00
|
|
|
ex_state_t state;
|
2003-10-22 08:05:17 +00:00
|
|
|
ex_bool_t bool;
|
2002-05-11 03:37:36 +00:00
|
|
|
ex_block_t block;
|
2001-06-15 19:38:43 +00:00
|
|
|
struct {
|
|
|
|
int op;
|
2002-06-04 18:44:03 +00:00
|
|
|
struct type_s *type;
|
2001-06-15 19:38:43 +00:00
|
|
|
struct expr_s *e1;
|
|
|
|
struct expr_s *e2;
|
|
|
|
} expr;
|
2002-06-04 18:44:03 +00:00
|
|
|
struct def_s *def;
|
2002-05-11 03:37:36 +00:00
|
|
|
ex_temp_t temp;
|
2001-07-18 06:37:14 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
const char *string_val;
|
2001-07-18 06:37:14 +00:00
|
|
|
float float_val;
|
2001-06-15 19:38:43 +00:00
|
|
|
float vector_val[3];
|
2001-07-18 06:37:14 +00:00
|
|
|
int entity_val;
|
|
|
|
int func_val;
|
2002-05-11 03:37:36 +00:00
|
|
|
ex_pointer_t pointer;
|
2001-06-15 19:38:43 +00:00
|
|
|
float quaternion_val[4];
|
2001-07-23 01:31:22 +00:00
|
|
|
int integer_val;
|
2001-11-15 00:46:36 +00:00
|
|
|
unsigned int uinteger_val;
|
2001-12-07 20:10:30 +00:00
|
|
|
short short_val;
|
2001-06-15 19:38:43 +00:00
|
|
|
} e;
|
|
|
|
} expr_t;
|
|
|
|
|
2001-07-26 05:15:34 +00:00
|
|
|
extern etype_t qc_types[];
|
2003-08-22 19:48:14 +00:00
|
|
|
extern struct type_s *ev_types[];
|
2001-07-26 05:15:34 +00:00
|
|
|
extern expr_type expr_types[];
|
|
|
|
|
2004-01-25 08:55:03 +00:00
|
|
|
expr_t *type_mismatch (expr_t *e1, expr_t *e2, int op);
|
|
|
|
|
2002-05-17 17:37:44 +00:00
|
|
|
extern expr_t *local_expr;
|
|
|
|
|
2002-06-04 18:44:03 +00:00
|
|
|
struct type_s *get_type (expr_t *e);
|
2002-05-02 05:03:57 +00:00
|
|
|
etype_t extract_type (expr_t *e);
|
2001-07-26 05:15:34 +00:00
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
expr_t *new_expr (void);
|
2002-09-11 16:21:26 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
const char *new_label_name (void);
|
2002-09-11 16:21:26 +00:00
|
|
|
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *new_label_expr (void);
|
2004-02-11 01:43:33 +00:00
|
|
|
expr_t *new_state_expr (expr_t *frame, expr_t *think, expr_t *step);
|
2003-10-22 08:05:17 +00:00
|
|
|
expr_t *new_bool_expr (ex_list_t *true_list, ex_list_t *false_list, expr_t *e);
|
2001-06-26 03:33:01 +00:00
|
|
|
expr_t *new_block_expr (void);
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *new_binary_expr (int op, expr_t *e1, expr_t *e2);
|
|
|
|
expr_t *new_unary_expr (int op, expr_t *e1);
|
2002-09-11 16:21:26 +00:00
|
|
|
expr_t *new_def_expr (struct def_s *def);
|
2002-06-04 18:44:03 +00:00
|
|
|
expr_t *new_temp_def_expr (struct type_s *type);
|
2002-09-11 16:21:26 +00:00
|
|
|
expr_t *new_nil_expr (void);
|
2002-01-21 19:03:29 +00:00
|
|
|
expr_t *new_name_expr (const char *name);
|
2002-09-11 16:21:26 +00:00
|
|
|
|
|
|
|
expr_t *new_string_expr (const char *string_val);
|
|
|
|
expr_t *new_float_expr (float float_val);
|
|
|
|
expr_t *new_vector_expr (float *vector_val);
|
|
|
|
expr_t *new_entity_expr (int entity_val);
|
2004-11-12 10:49:00 +00:00
|
|
|
expr_t *new_field_expr (int field_val, struct type_s *type, struct def_s *def);
|
2002-09-11 16:21:26 +00:00
|
|
|
expr_t *new_func_expr (int func_val);
|
2004-04-09 04:12:44 +00:00
|
|
|
expr_t *new_pointer_expr (int val, struct type_s *type, struct def_s *def);
|
2002-09-11 16:21:26 +00:00
|
|
|
expr_t *new_quaternion_expr (float *quaternion_val);
|
|
|
|
expr_t *new_integer_expr (int integer_val);
|
|
|
|
expr_t *new_uinteger_expr (unsigned int uinteger_val);
|
|
|
|
expr_t *new_short_expr (short short_val);
|
|
|
|
|
2004-01-25 08:55:03 +00:00
|
|
|
int is_constant (expr_t *e);
|
|
|
|
int is_compare (int op);
|
2010-01-13 06:26:18 +00:00
|
|
|
int is_math (int op);
|
2004-01-25 08:55:03 +00:00
|
|
|
int is_logic (int op);
|
2003-02-28 04:54:07 +00:00
|
|
|
expr_t *constant_expr (expr_t *var);
|
|
|
|
|
2002-09-11 16:21:26 +00:00
|
|
|
expr_t *new_bind_expr (expr_t *e1, expr_t *e2);
|
2002-05-18 00:30:14 +00:00
|
|
|
expr_t *new_self_expr (void);
|
2002-05-31 16:58:42 +00:00
|
|
|
expr_t *new_this_expr (void);
|
2003-04-22 15:29:32 +00:00
|
|
|
expr_t *new_ret_expr (struct type_s *type);
|
|
|
|
expr_t *new_param_expr (struct type_s *type, int num);
|
2002-10-20 02:35:12 +00:00
|
|
|
expr_t *new_move_expr (expr_t *e1, expr_t *e2, struct type_s *type);
|
2001-06-26 03:33:01 +00:00
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
void inc_users (expr_t *e);
|
2010-01-13 06:25:06 +00:00
|
|
|
void dec_users (expr_t *e);
|
2002-01-21 19:18:41 +00:00
|
|
|
void convert_name (expr_t *e);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
expr_t *append_expr (expr_t *block, expr_t *e);
|
|
|
|
|
2001-06-25 17:15:56 +00:00
|
|
|
void print_expr (expr_t *e);
|
2001-07-24 22:30:31 +00:00
|
|
|
|
2001-07-24 23:53:35 +00:00
|
|
|
void convert_int (expr_t *e);
|
2003-08-01 21:20:04 +00:00
|
|
|
void convert_uint (expr_t *e);
|
2004-01-25 08:55:03 +00:00
|
|
|
void convert_short (expr_t *e);
|
2003-08-01 21:20:04 +00:00
|
|
|
void convert_uint_int (expr_t *e);
|
|
|
|
void convert_int_uint (expr_t *e);
|
2003-09-02 17:41:16 +00:00
|
|
|
void convert_short_int (expr_t *e);
|
|
|
|
void convert_short_uint (expr_t *e);
|
2010-11-17 09:49:39 +00:00
|
|
|
void convert_nil (expr_t *e, struct type_s *t);
|
2001-07-24 23:53:35 +00:00
|
|
|
|
2001-07-24 22:30:31 +00:00
|
|
|
expr_t *test_expr (expr_t *e, int test);
|
2003-10-22 08:05:17 +00:00
|
|
|
void backpatch (ex_list_t *list, expr_t *label);
|
|
|
|
expr_t *convert_bool (expr_t *e, int block);
|
|
|
|
expr_t *bool_expr (int op, expr_t *label, expr_t *e1, expr_t *e2);
|
2001-06-20 07:02:36 +00:00
|
|
|
expr_t *binary_expr (int op, expr_t *e1, expr_t *e2);
|
2001-08-10 16:17:00 +00:00
|
|
|
expr_t *asx_expr (int op, expr_t *e1, expr_t *e2);
|
2001-06-20 07:02:36 +00:00
|
|
|
expr_t *unary_expr (int op, expr_t *e);
|
2004-11-13 11:50:00 +00:00
|
|
|
expr_t *build_function_call (expr_t *fexpr, struct type_s *ftype,
|
|
|
|
expr_t *params);
|
2001-06-20 21:18:04 +00:00
|
|
|
expr_t *function_expr (expr_t *e1, expr_t *e2);
|
2002-06-04 18:44:03 +00:00
|
|
|
struct function_s;
|
|
|
|
expr_t *return_expr (struct function_s *f, expr_t *e);
|
2001-08-11 21:15:24 +00:00
|
|
|
expr_t *conditional_expr (expr_t *cond, expr_t *e1, expr_t *e2);
|
2001-08-20 06:22:28 +00:00
|
|
|
expr_t *incop_expr (int op, expr_t *e, int postop);
|
2001-11-15 00:46:36 +00:00
|
|
|
expr_t *array_expr (expr_t *array, expr_t *index);
|
2010-01-13 06:31:41 +00:00
|
|
|
expr_t *pointer_expr (expr_t *pointer);
|
2002-06-04 18:44:03 +00:00
|
|
|
expr_t *address_expr (expr_t *e1, expr_t *e2, struct type_s *t);
|
2001-12-12 08:39:47 +00:00
|
|
|
expr_t *assign_expr (expr_t *e1, expr_t *e2);
|
2002-06-04 18:44:03 +00:00
|
|
|
expr_t *cast_expr (struct type_s *t, expr_t *e);
|
2001-06-26 07:21:20 +00:00
|
|
|
|
2002-06-04 18:44:03 +00:00
|
|
|
void init_elements (struct def_s *def, expr_t *eles);
|
2002-01-18 08:26:37 +00:00
|
|
|
|
2001-07-03 20:53:49 +00:00
|
|
|
expr_t *error (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
2007-03-31 15:27:36 +00:00
|
|
|
expr_t *warning (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
|
|
|
expr_t * notice (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
2001-07-14 01:15:40 +00:00
|
|
|
|
2001-10-25 17:48:35 +00:00
|
|
|
const char *get_op_string (int op);
|
|
|
|
|
2001-07-14 01:15:40 +00:00
|
|
|
extern int lineno_base;
|
2001-12-08 20:40:50 +00:00
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
struct keywordarg_s;
|
2003-05-15 05:58:31 +00:00
|
|
|
struct class_type_s;
|
2002-05-08 23:12:49 +00:00
|
|
|
expr_t *selector_expr (struct keywordarg_s *selector);
|
|
|
|
expr_t *protocol_expr (const char *protocol);
|
2002-06-04 18:44:03 +00:00
|
|
|
expr_t *encode_expr (struct type_s *type);
|
2003-05-15 05:58:31 +00:00
|
|
|
expr_t *super_expr (struct class_type_s *class_type);
|
2002-05-08 23:12:49 +00:00
|
|
|
expr_t *message_expr (expr_t *receiver, struct keywordarg_s *message);
|
2002-08-18 04:08:02 +00:00
|
|
|
expr_t *sizeof_expr (expr_t *expr, struct type_s *type);
|
2002-05-08 23:12:49 +00:00
|
|
|
|
2004-01-25 08:55:03 +00:00
|
|
|
expr_t *fold_constants (expr_t *e);
|
|
|
|
|
2001-12-08 20:40:50 +00:00
|
|
|
#endif//__expr_h
|