2020-12-21 05:06:21 +00:00
|
|
|
/*
|
|
|
|
cexpr.h
|
|
|
|
|
|
|
|
Config expression parser. Or concurrent.
|
|
|
|
|
|
|
|
Copyright (C) 2020 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
2021-03-03 07:34:44 +00:00
|
|
|
#ifndef __QF_expr_h
|
|
|
|
#define __QF_expr_h
|
2020-12-21 05:06:21 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct exprval_s;
|
|
|
|
struct exprctx_s;
|
2022-04-24 06:04:08 +00:00
|
|
|
struct va_ctx_s;
|
2020-12-21 05:06:21 +00:00
|
|
|
|
|
|
|
typedef struct binop_s {
|
|
|
|
int op;
|
|
|
|
struct exprtype_s *other;
|
|
|
|
struct exprtype_s *result;
|
|
|
|
void (*func) (const struct exprval_s *val1,
|
|
|
|
const struct exprval_s *val2,
|
|
|
|
struct exprval_s *result,
|
|
|
|
struct exprctx_s *context);
|
|
|
|
} binop_t;
|
|
|
|
|
|
|
|
typedef struct unop_s {
|
|
|
|
int op;
|
|
|
|
struct exprtype_s *result;
|
|
|
|
void (*func) (const struct exprval_s *val, struct exprval_s *result,
|
|
|
|
struct exprctx_s *context);
|
|
|
|
} unop_t;
|
|
|
|
|
|
|
|
typedef struct exprtype_s {
|
|
|
|
const char *name;
|
|
|
|
size_t size;
|
2022-04-24 06:04:08 +00:00
|
|
|
const char *(*get_string) (const struct exprval_s *val, struct va_ctx_s *va_ctx);
|
2020-12-21 05:06:21 +00:00
|
|
|
binop_t *binops;
|
|
|
|
unop_t *unops;
|
|
|
|
void *data;
|
2022-10-16 09:02:25 +00:00
|
|
|
} __attribute__((designated_init)) exprtype_t;
|
2020-12-21 05:06:21 +00:00
|
|
|
|
|
|
|
typedef struct exprval_s {
|
|
|
|
exprtype_t *type;
|
|
|
|
void *value;
|
|
|
|
} exprval_t;
|
|
|
|
|
2021-01-03 15:11:52 +00:00
|
|
|
typedef struct exprlist_s {
|
|
|
|
struct exprlist_s *next;
|
|
|
|
exprval_t *value;
|
|
|
|
} exprlist_t;
|
|
|
|
|
2020-12-21 05:06:21 +00:00
|
|
|
typedef struct exprsym_s {
|
|
|
|
const char *name;
|
|
|
|
exprtype_t *type;
|
|
|
|
void *value;
|
|
|
|
struct exprsym_s *next;
|
|
|
|
} exprsym_t;
|
|
|
|
|
2021-01-03 15:11:52 +00:00
|
|
|
typedef struct exprfunc_s {
|
|
|
|
exprtype_t *result;
|
|
|
|
int num_params;
|
|
|
|
exprtype_t **param_types;
|
|
|
|
void (*func) (const exprval_t **params, exprval_t *result,
|
|
|
|
struct exprctx_s *context);
|
|
|
|
} exprfunc_t;
|
|
|
|
|
2020-12-21 05:06:21 +00:00
|
|
|
typedef struct exprtab_s {
|
|
|
|
exprsym_t *symbols;
|
|
|
|
struct hashtab_s *tab;
|
|
|
|
} exprtab_t;
|
|
|
|
|
2021-12-04 01:04:58 +00:00
|
|
|
typedef struct exprarray_s {
|
|
|
|
exprtype_t *type;
|
|
|
|
unsigned size;
|
|
|
|
} exprarray_t;
|
|
|
|
|
2020-12-21 05:06:21 +00:00
|
|
|
typedef struct exprctx_s {
|
2021-12-04 03:28:46 +00:00
|
|
|
struct exprctx_s *parent; // for nested symol scopes
|
2020-12-21 05:06:21 +00:00
|
|
|
exprval_t *result;
|
|
|
|
exprtab_t *symtab; // directly accessible symbols
|
|
|
|
exprtab_t *external_variables; // accessible via $id
|
2022-04-24 06:16:15 +00:00
|
|
|
const char *msg_prefix; // optional prefix for error messages
|
2020-12-21 05:06:21 +00:00
|
|
|
struct memsuper_s *memsuper;
|
|
|
|
const struct plitem_s *item;
|
|
|
|
struct plitem_s *messages;
|
2022-05-12 08:54:23 +00:00
|
|
|
struct hashctx_s **hashctx;
|
2020-12-21 11:15:43 +00:00
|
|
|
int errors;
|
2020-12-21 05:06:21 +00:00
|
|
|
} exprctx_t;
|
|
|
|
|
|
|
|
typedef struct exprenum_s {
|
|
|
|
exprtype_t *type;
|
|
|
|
exprtab_t *symtab;
|
|
|
|
} exprenum_t;
|
|
|
|
|
2022-04-24 06:18:09 +00:00
|
|
|
exprval_t *cexpr_assign_value (exprval_t *dst, const exprval_t *src,
|
|
|
|
exprctx_t *context);
|
2020-12-21 05:06:21 +00:00
|
|
|
int cexpr_parse_enum (exprenum_t *enm, const char *str,
|
|
|
|
const exprctx_t *context, void *data);
|
|
|
|
binop_t *cexpr_find_cast (exprtype_t *dst_type, exprtype_t *src_type) __attribute__((pure));
|
|
|
|
exprval_t *cexpr_value (exprtype_t *type, exprctx_t *ctx);
|
|
|
|
exprval_t *cexpr_value_reference (exprtype_t *type, void *data, exprctx_t *ctx);
|
2022-04-24 06:04:08 +00:00
|
|
|
const char *cexpr_enum_get_string (const exprval_t *val, struct va_ctx_s *va_ctx) __attribute__((pure));
|
2022-04-24 06:12:56 +00:00
|
|
|
const char *cexpr_flags_get_string (const exprval_t *val, struct va_ctx_s *va_ctx) __attribute__((pure));
|
2020-12-21 05:06:21 +00:00
|
|
|
int cexpr_eval_string (const char *str, exprctx_t *context);
|
2021-03-27 10:52:59 +00:00
|
|
|
void cexpr_error(exprctx_t *ctx, const char *fmt, ...) __attribute__((format(PRINTF,2,3)));
|
2020-12-21 05:06:21 +00:00
|
|
|
|
2021-12-04 01:04:58 +00:00
|
|
|
void cexpr_array_getelement (const exprval_t *a, const exprval_t *b,
|
|
|
|
exprval_t *c, exprctx_t *ctx);
|
2020-12-21 05:06:21 +00:00
|
|
|
void cexpr_struct_getfield (const exprval_t *a, const exprval_t *b,
|
|
|
|
exprval_t *c, exprctx_t *ctx);
|
2021-01-09 16:35:39 +00:00
|
|
|
void cexpr_struct_pointer_getfield (const exprval_t *a, const exprval_t *b,
|
|
|
|
exprval_t *c, exprctx_t *ctx);
|
2020-12-21 05:06:21 +00:00
|
|
|
exprval_t *cexpr_cvar (const char *name, exprctx_t *ctx);
|
|
|
|
exprval_t *cexpr_cvar_struct (exprctx_t *ctx);
|
|
|
|
|
2021-02-04 13:37:20 +00:00
|
|
|
void cexpr_cast_plitem (const exprval_t *val1, const exprval_t *src,
|
|
|
|
exprval_t *result, exprctx_t *ctx);
|
|
|
|
|
2020-12-21 05:06:21 +00:00
|
|
|
void cexpr_init_symtab (exprtab_t *symtab, exprctx_t *ctx);
|
|
|
|
|
|
|
|
char *cexpr_yyget_text (void *scanner);
|
|
|
|
|
|
|
|
extern exprtype_t cexpr_int;
|
|
|
|
extern exprtype_t cexpr_uint;
|
2020-12-23 05:06:20 +00:00
|
|
|
extern exprtype_t cexpr_size_t;
|
2020-12-21 05:06:21 +00:00
|
|
|
extern exprtype_t cexpr_float;
|
|
|
|
extern exprtype_t cexpr_double;
|
2020-12-28 05:56:59 +00:00
|
|
|
extern exprtype_t cexpr_vector;
|
|
|
|
extern exprtype_t cexpr_quaternion;
|
2020-12-21 05:06:21 +00:00
|
|
|
extern exprtype_t cexpr_exprval;
|
|
|
|
extern exprtype_t cexpr_field;
|
2021-01-03 15:11:52 +00:00
|
|
|
extern exprtype_t cexpr_function;
|
2021-02-04 07:58:13 +00:00
|
|
|
extern exprtype_t cexpr_plitem;
|
2020-12-21 05:06:21 +00:00
|
|
|
|
2021-12-04 01:04:58 +00:00
|
|
|
extern binop_t cexpr_array_binops[];
|
2020-12-21 05:06:21 +00:00
|
|
|
extern binop_t cexpr_struct_binops[];
|
2021-01-09 16:35:39 +00:00
|
|
|
extern binop_t cexpr_struct_pointer_binops[];
|
2022-04-24 06:12:56 +00:00
|
|
|
extern binop_t cexpr_flag_binops[];
|
|
|
|
extern unop_t cexpr_flag_unops[];
|
2020-12-21 05:06:21 +00:00
|
|
|
|
2021-12-04 05:04:45 +00:00
|
|
|
extern exprsym_t cexpr_lib_symbols[];
|
|
|
|
|
2021-03-03 07:34:44 +00:00
|
|
|
#endif//__QF_expr_h
|