2002-05-08 05:15:19 +00:00
|
|
|
/*
|
2002-10-22 14:53:18 +00:00
|
|
|
function.h
|
2002-05-08 05:15:19 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
QC function support code
|
2002-05-08 05:15:19 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Copyright (C) 2002 Bill Currie <bill@taniwha.org>
|
2002-05-08 05:15:19 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2002/05/08
|
2002-05-08 05:15:19 +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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __function_h
|
|
|
|
#define __function_h
|
|
|
|
|
2012-10-30 08:37:02 +00:00
|
|
|
/** \defgroup qfcc_function Internal function structures.
|
|
|
|
*/
|
|
|
|
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "QF/pr_comp.h"
|
2011-01-06 07:31:44 +00:00
|
|
|
#include "QF/pr_debug.h"
|
|
|
|
|
|
|
|
#include "def.h"
|
2002-06-04 18:44:03 +00:00
|
|
|
|
2012-10-30 08:37:02 +00:00
|
|
|
/** Represent an overloading of a function.
|
|
|
|
|
|
|
|
Every function, whether overloaded or not, has an entry in the overloaded
|
|
|
|
function database.
|
|
|
|
*/
|
2004-11-13 11:50:00 +00:00
|
|
|
typedef struct overloaded_function_s {
|
|
|
|
struct overloaded_function_s *next;
|
2011-01-17 13:33:33 +00:00
|
|
|
const char *name; ///< source level name of function
|
|
|
|
const char *full_name; ///< progs name of function, with type
|
|
|
|
///< encoding
|
|
|
|
struct type_s *type; ///< type of this function
|
|
|
|
int overloaded; ///< is this function overloaded
|
|
|
|
string_t file; ///< source file of the function
|
|
|
|
int line; ///< source line of this function
|
2004-11-13 11:50:00 +00:00
|
|
|
} overloaded_function_t;
|
|
|
|
|
2012-10-30 08:37:02 +00:00
|
|
|
/** Internal representation of a function.
|
|
|
|
*/
|
2002-06-04 18:44:03 +00:00
|
|
|
typedef struct function_s {
|
2002-06-21 20:46:56 +00:00
|
|
|
struct function_s *next;
|
2011-01-17 13:33:33 +00:00
|
|
|
int builtin; ///< if non 0, call an internal function
|
|
|
|
int code; ///< first statement
|
2002-06-21 20:46:56 +00:00
|
|
|
int function_num;
|
2011-03-07 04:33:02 +00:00
|
|
|
int line_info;
|
|
|
|
int local_defs;
|
2011-01-17 13:33:33 +00:00
|
|
|
string_t s_file; ///< source file with definition
|
2012-10-30 08:37:02 +00:00
|
|
|
string_t s_name; ///< name of function in output
|
2011-02-09 01:04:55 +00:00
|
|
|
int temp_num; ///< number for next temp var
|
2012-11-18 10:08:16 +00:00
|
|
|
struct def_s *temp_defs[4]; ///< freed temp vars (by size)
|
2012-10-30 08:37:02 +00:00
|
|
|
struct def_s *def; ///< output def holding function number
|
|
|
|
struct symbol_s *sym; ///< internal symbol for this function
|
|
|
|
/** Root scope symbol table of the function.
|
|
|
|
|
|
|
|
Sub-scope symbol tables are not directly accessible, but all defs
|
|
|
|
created in the function's local data space are recorded in the root
|
|
|
|
scope symbol table's defspace.
|
|
|
|
*/
|
2011-01-18 03:37:12 +00:00
|
|
|
struct symtab_s *symtab;
|
2012-10-30 08:37:02 +00:00
|
|
|
struct reloc_s *refs; ///< relocation targets for this function
|
2004-02-21 05:52:05 +00:00
|
|
|
struct expr_s *var_init;
|
2011-01-17 13:33:33 +00:00
|
|
|
const char *name; ///< nice name for __PRETTY_FUNCTION__
|
2012-11-02 08:30:29 +00:00
|
|
|
struct sblock_s *sblock; ///< initial node of function's code
|
|
|
|
struct flowgraph_s *graph; ///< the function's flow graph
|
2012-10-30 08:41:40 +00:00
|
|
|
/** Array of pointers to all variables referenced by the function's code.
|
|
|
|
|
|
|
|
This permits ready mapping of (function specific) variable number to
|
|
|
|
variable in the flow analyzer.
|
|
|
|
*/
|
2012-11-05 10:00:57 +00:00
|
|
|
struct flowvar_s **vars;
|
2012-10-30 08:41:40 +00:00
|
|
|
int num_vars; ///< total number of variables referenced
|
2012-11-19 08:21:35 +00:00
|
|
|
struct set_s *global_vars;///< set indicating which vars are global
|
2012-11-05 06:21:40 +00:00
|
|
|
struct statement_s **statements;
|
|
|
|
int num_statements;
|
2002-06-04 18:44:03 +00:00
|
|
|
} function_t;
|
|
|
|
|
|
|
|
extern function_t *current_func;
|
|
|
|
|
2012-10-30 08:37:02 +00:00
|
|
|
/** Representation of a function parameter.
|
|
|
|
\note The first two fields match the first two fields of keywordarg_t
|
|
|
|
in method.h
|
|
|
|
*/
|
2002-05-08 05:15:19 +00:00
|
|
|
typedef struct param_s {
|
|
|
|
struct param_s *next;
|
|
|
|
const char *selector;
|
2011-01-13 05:45:53 +00:00
|
|
|
struct type_s *type; //FIXME redundant
|
|
|
|
const char *name; //FIXME redundant
|
|
|
|
struct symbol_s *symbol;
|
2002-05-08 05:15:19 +00:00
|
|
|
} param_t;
|
|
|
|
|
2002-05-17 18:35:54 +00:00
|
|
|
struct expr_s;
|
2011-01-13 05:45:53 +00:00
|
|
|
struct symbol_s;
|
2011-01-18 03:37:12 +00:00
|
|
|
struct symtab_s;
|
2002-05-17 18:35:54 +00:00
|
|
|
|
2002-06-04 18:44:03 +00:00
|
|
|
param_t *new_param (const char *selector, struct type_s *type,
|
|
|
|
const char *name);
|
2011-01-13 05:45:53 +00:00
|
|
|
param_t *param_append_identifiers (param_t *params, struct symbol_s *idents,
|
|
|
|
struct type_s *type);
|
2002-05-08 21:24:24 +00:00
|
|
|
param_t *_reverse_params (param_t *params, param_t *next);
|
2002-05-08 17:33:28 +00:00
|
|
|
param_t *reverse_params (param_t *params);
|
2002-08-20 02:09:34 +00:00
|
|
|
param_t *copy_params (param_t *params);
|
2002-06-04 18:44:03 +00:00
|
|
|
struct type_s *parse_params (struct type_s *type, param_t *params);
|
2011-02-01 12:18:08 +00:00
|
|
|
param_t *check_params (param_t *params);
|
2011-01-26 05:48:22 +00:00
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
enum storage_class_e;
|
|
|
|
struct defspace_s;
|
2011-01-26 05:48:22 +00:00
|
|
|
void make_function (struct symbol_s *sym, const char *nice_name,
|
2011-02-15 03:38:29 +00:00
|
|
|
struct defspace_s *space, enum storage_class_e storage);
|
2011-01-18 03:37:12 +00:00
|
|
|
struct symbol_s *function_symbol (struct symbol_s *sym,
|
|
|
|
int overload, int create);
|
2004-11-13 11:50:00 +00:00
|
|
|
struct expr_s *find_function (struct expr_s *fexpr, struct expr_s *params);
|
2011-01-18 03:37:12 +00:00
|
|
|
function_t *new_function (const char *name, const char *nice_name);
|
2008-08-01 13:54:24 +00:00
|
|
|
void add_function (function_t *f);
|
2011-01-18 03:37:12 +00:00
|
|
|
function_t *begin_function (struct symbol_s *sym, const char *nicename,
|
2011-02-15 03:38:29 +00:00
|
|
|
struct symtab_s *parent, int far);
|
2011-01-18 23:38:09 +00:00
|
|
|
function_t *build_code_function (struct symbol_s *fsym,
|
|
|
|
struct expr_s *state_expr,
|
2004-02-11 00:36:34 +00:00
|
|
|
struct expr_s *statements);
|
2011-01-18 03:37:12 +00:00
|
|
|
function_t *build_builtin_function (struct symbol_s *sym,
|
2011-02-15 03:38:29 +00:00
|
|
|
struct expr_s *bi_val, int far);
|
2002-05-08 05:15:19 +00:00
|
|
|
void build_function (function_t *f);
|
|
|
|
void finish_function (function_t *f);
|
2002-06-21 20:46:56 +00:00
|
|
|
void emit_function (function_t *f, struct expr_s *e);
|
2002-06-27 22:48:28 +00:00
|
|
|
int function_parms (function_t *f, byte *parm_size);
|
2012-11-01 11:52:22 +00:00
|
|
|
void clear_functions (void);
|
2002-05-08 05:15:19 +00:00
|
|
|
|
|
|
|
#endif//__function_h
|