2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbc_class.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2022-09-12 15:13:13 +02:00
|
|
|
(c) 2000-2017 Benoît Minisini <benoit.minisini@gambas-basic.org>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01: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, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __GBC_CLASS_H
|
|
|
|
#define __GBC_CLASS_H
|
|
|
|
|
|
|
|
#include "gbc_type.h"
|
|
|
|
#include "gb_table.h"
|
|
|
|
#include "gbc_trans.h"
|
|
|
|
|
|
|
|
#define FUNC_INIT_STATIC 0
|
|
|
|
#define FUNC_INIT_DYNAMIC 1
|
2021-06-02 00:04:15 +02:00
|
|
|
#define FUNC_INIT_MAX 1
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int value;
|
2012-09-04 09:29:39 +02:00
|
|
|
int line;
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
CLASS_SYMBOL_INFO;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
|
|
|
SYMBOL symbol;
|
|
|
|
CLASS_SYMBOL_INFO global;
|
|
|
|
CLASS_SYMBOL_INFO local;
|
|
|
|
int class;
|
|
|
|
int unknown;
|
2012-09-04 09:29:39 +02:00
|
|
|
unsigned global_used : 1;
|
2018-02-14 17:03:14 +01:00
|
|
|
unsigned global_assigned : 1;
|
2019-12-22 20:48:58 +01:00
|
|
|
unsigned global_no_warning : 1;
|
2012-09-04 09:29:39 +02:00
|
|
|
unsigned local_used : 1;
|
2018-02-14 17:03:14 +01:00
|
|
|
unsigned local_assigned : 1;
|
2019-12-22 20:48:58 +01:00
|
|
|
unsigned _reserved : 27;
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
CLASS_SYMBOL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
TRANS_PARAM PARAM;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int index;
|
|
|
|
}
|
|
|
|
VARIABLE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
|
|
|
int num;
|
|
|
|
int param;
|
|
|
|
}
|
|
|
|
VARIABLE_INIT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int index;
|
|
|
|
int value;
|
|
|
|
int line;
|
|
|
|
int64_t lvalue;
|
2021-10-14 03:01:14 +02:00
|
|
|
unsigned is_integer : 1;
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
CONSTANT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
2010-05-21 01:23:39 +02:00
|
|
|
TYPE type; // Return value datatype
|
|
|
|
int name; // Function name index in class symbol table
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
char nparam; // Maximum number of arguments
|
|
|
|
char npmin; // Minimum number of arguments
|
2012-05-24 14:05:21 +02:00
|
|
|
unsigned vararg : 1; // If this function accepts extra arguments
|
|
|
|
unsigned fast : 1; // If this function is jit compiled
|
2018-06-29 00:10:31 +02:00
|
|
|
unsigned unsafe : 1; // If this function is unsafe
|
2014-05-18 15:18:32 +02:00
|
|
|
unsigned use_is_missing : 1; // If this function uses IsMissing()
|
2019-09-12 03:23:38 +02:00
|
|
|
unsigned no_debug : 1; // Do not output deubgging information
|
|
|
|
unsigned _reserved : 11;
|
2010-05-21 01:23:39 +02:00
|
|
|
short nlocal; // Local variable count
|
|
|
|
short nctrl; // Control structure variable count
|
2012-05-24 14:05:21 +02:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
uint64_t byref; // Byref mask
|
|
|
|
PARAM *local; // Datatypes of local variables
|
|
|
|
PARAM *param; // Datatypes of arguments
|
2021-06-01 23:12:55 +02:00
|
|
|
PARAM *stat; // Datatypes of static local variables
|
2010-05-21 01:23:39 +02:00
|
|
|
|
|
|
|
PATTERN *start; // Starts compilation from there
|
2012-05-24 14:05:21 +02:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
int line; // ...which is this line
|
2012-05-24 14:05:21 +02:00
|
|
|
short stack; // Needed stack
|
|
|
|
short _reserved2;
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
ushort *code; // Compile bytecode
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
short *pos_line; // Bytecode position of each code line
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
ushort ncode; // Number of instructions
|
|
|
|
ushort ncode_max; // Size of the bytecode allocation
|
|
|
|
|
2013-04-29 23:27:11 +02:00
|
|
|
ushort last_code; // Last compiled bytecode position
|
|
|
|
ushort last_code2; // Last last compiled bytecode position
|
|
|
|
ushort finally; // FINALLY position
|
|
|
|
ushort catch; // CATCH position
|
2021-06-01 23:12:55 +02:00
|
|
|
|
|
|
|
short code_stack_usage; // save state of code generation
|
|
|
|
short code_stack;
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
FUNCTION;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
2010-05-21 01:23:39 +02:00
|
|
|
TYPE type; // Return value datatype
|
|
|
|
int name; // Function name index in class symbol table
|
|
|
|
PARAM *param; // Argument list
|
|
|
|
short nparam; // Number of arguments
|
2010-05-19 14:43:57 +02:00
|
|
|
short _reserved;
|
|
|
|
}
|
|
|
|
EVENT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
2010-05-21 01:23:39 +02:00
|
|
|
TYPE type; // Return value datatype
|
|
|
|
int name; // Function name index in class symbol table
|
|
|
|
PARAM *param; // Argument list
|
|
|
|
short nparam; // Number of arguments
|
2012-06-01 02:18:38 +02:00
|
|
|
unsigned vararg : 1; // Variable number of arguments
|
|
|
|
unsigned _reserved : 15;
|
2010-05-21 01:23:39 +02:00
|
|
|
int library; // Library name index
|
|
|
|
int alias; // Real function name index
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
EXTFUNC;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
2010-05-21 01:23:39 +02:00
|
|
|
TYPE type; // Property datatype
|
|
|
|
int name; // Property name index
|
|
|
|
int line; // The line where the property is declared
|
|
|
|
int comment; // Property string description, added to datatype
|
2012-02-25 02:35:55 +01:00
|
|
|
int synonymous; // Synonymous property index (-1 if not a synonymous)
|
2019-08-22 03:13:58 +02:00
|
|
|
int use; // Associated global private variable
|
2010-05-21 01:23:39 +02:00
|
|
|
short read; // Read function
|
|
|
|
short write; // Write function
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
PROPERTY;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
2010-05-21 01:23:39 +02:00
|
|
|
TYPE type; // Array datatype
|
|
|
|
int ndim; // Number of dimensions
|
|
|
|
int dim[MAX_ARRAY_DIM]; // Dimensions bounds
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
CLASS_ARRAY;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
2010-05-21 01:23:39 +02:00
|
|
|
int index; // Structure name
|
|
|
|
int nfield; // Number of structure fields
|
|
|
|
VARIABLE *field; // Structure fields
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
CLASS_STRUCT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
|
|
|
struct {
|
2018-06-01 03:50:42 +02:00
|
|
|
int index; // class name
|
2010-05-28 08:24:14 +02:00
|
|
|
unsigned used : 1;
|
|
|
|
unsigned exported : 1;
|
|
|
|
unsigned structure : 1;
|
2015-01-16 01:31:59 +01:00
|
|
|
unsigned has_static : 1;
|
2018-06-01 03:50:42 +02:00
|
|
|
unsigned is_collection : 1; // if the class is Collection (for JIT)
|
|
|
|
unsigned _reserved : 20;
|
|
|
|
TYPE type; // if the class is an array, the type of the array contents (for JIT)
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
CLASS_REF;
|
|
|
|
|
|
|
|
typedef
|
2010-05-19 14:43:57 +02:00
|
|
|
struct {
|
2010-05-21 01:23:39 +02:00
|
|
|
TABLE *table; // symbol table
|
|
|
|
TABLE *string; // strings table
|
|
|
|
char *name; // class name
|
|
|
|
short parent; // parent class
|
|
|
|
unsigned exported : 1; // class is exported
|
|
|
|
unsigned autocreate : 1; // class is auto-creatable
|
|
|
|
unsigned optional : 1; // class is optional
|
2011-03-13 14:41:57 +01:00
|
|
|
unsigned nocreate : 1; // class cannot be instantiated
|
2012-05-23 21:26:15 +02:00
|
|
|
unsigned all_fast : 1; // all methods have the Fast option (JIT)
|
2018-06-29 00:10:31 +02:00
|
|
|
unsigned all_unsafe : 1; // all methods are unsafe
|
2015-01-16 01:31:59 +01:00
|
|
|
unsigned has_static : 1; // has static methods, properties or variables
|
2018-05-17 01:13:56 +02:00
|
|
|
unsigned has_fast : 1; // has at least one fast method
|
2018-06-29 00:10:31 +02:00
|
|
|
unsigned _reserved : 8;
|
2010-05-21 01:23:39 +02:00
|
|
|
VARIABLE *stat; // static variables
|
|
|
|
VARIABLE *dyn; // dynamic variables
|
|
|
|
CONSTANT *constant; // constants
|
|
|
|
CLASS_REF *class; // classes
|
|
|
|
int *unknown; // unknown symbols
|
|
|
|
FUNCTION *function; // functions
|
|
|
|
int size_stat; // static variables total size
|
|
|
|
int size_dyn; // dynamic variables total size
|
|
|
|
EVENT *event; // events
|
|
|
|
PROPERTY *prop; // properties
|
|
|
|
EXTFUNC *ext_func; // extern functions
|
|
|
|
CLASS_ARRAY *array; // array definitions
|
|
|
|
CLASS_STRUCT *structure; // structs definitions
|
|
|
|
char **names; // when some symbols must be created like object arrays
|
2021-05-18 02:12:33 +02:00
|
|
|
char *export_name; // export name of the class
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
CLASS;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
#define CLASS_get_symbol(class, ind) ((CLASS_SYMBOL *)TABLE_get_symbol((class)->table, ind))
|
|
|
|
|
|
|
|
#define FUNCTION_is_procedure(func) (TYPE_get_id((func)->type) == T_VOID)
|
|
|
|
#define FUNCTION_is_static(func) (TYPE_is_static((func)->type))
|
|
|
|
|
2013-04-29 23:27:11 +02:00
|
|
|
|
2008-05-13 14:52:06 +02:00
|
|
|
void CLASS_create(CLASS **result);
|
|
|
|
void CLASS_delete(CLASS **class);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-01-16 01:31:59 +01:00
|
|
|
CLASS_SYMBOL *CLASS_declare(CLASS *class, int index, int type, bool global);
|
2012-09-04 09:29:39 +02:00
|
|
|
void CLASS_check_unused_global(CLASS *class);
|
2021-06-02 00:04:15 +02:00
|
|
|
|
|
|
|
FUNCTION *CLASS_set_current_function(FUNCTION *func);
|
|
|
|
#define CLASS_set_current_init_function(_class, _type) CLASS_set_current_function(&(_class)->function[_type])
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-09-11 19:38:04 +02:00
|
|
|
int CLASS_add_function(CLASS *class, TRANS_FUNC *decl);
|
2008-05-13 14:52:06 +02:00
|
|
|
void CLASS_add_event(CLASS *class, TRANS_EVENT *decl);
|
|
|
|
void CLASS_add_property(CLASS *class, TRANS_PROPERTY *prop);
|
|
|
|
void CLASS_add_extern(CLASS *class, TRANS_EXTERN *decl);
|
2021-06-01 23:12:55 +02:00
|
|
|
|
2008-05-13 14:52:06 +02:00
|
|
|
void CLASS_add_declaration(CLASS *class, TRANS_DECL *decl);
|
2021-06-01 23:12:55 +02:00
|
|
|
void CLASS_add_static_declaration(CLASS *class, int index, TYPE type, CLASS_SYMBOL *sym, bool local);
|
|
|
|
void CLASS_init_global_declaration(CLASS *class, TRANS_DECL *decl, CLASS_SYMBOL *sym, bool local);
|
|
|
|
|
2008-05-13 14:52:06 +02:00
|
|
|
int CLASS_add_constant(CLASS *class, TRANS_DECL *decl);
|
|
|
|
int CLASS_add_class(CLASS *class, int index);
|
|
|
|
int CLASS_add_class_unused(CLASS *class, int index);
|
|
|
|
int CLASS_add_class_exported(CLASS *class, int index);
|
2008-09-01 01:45:47 +02:00
|
|
|
int CLASS_add_class_exported_unused(CLASS *class, int index);
|
2008-05-13 14:52:06 +02:00
|
|
|
bool CLASS_exist_class(CLASS *class, int index);
|
|
|
|
int CLASS_add_unknown(CLASS *class, int index);
|
|
|
|
int CLASS_add_array(CLASS *class, TRANS_ARRAY *array);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
int CLASS_get_array_class(CLASS *class, int type, int value);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-12-19 22:55:16 +01:00
|
|
|
void FUNCTION_add_last_pos_line(void);
|
|
|
|
void FUNCTION_add_all_pos_line(void);
|
2008-05-13 14:52:06 +02:00
|
|
|
char *FUNCTION_get_fake_name(int func);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-05-13 14:52:06 +02:00
|
|
|
int CLASS_add_symbol(CLASS *class, const char *name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-05-13 14:52:06 +02:00
|
|
|
void CLASS_sort_declaration(CLASS *class);
|
|
|
|
void CLASS_check_properties(CLASS *class);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2021-05-07 19:20:30 +02:00
|
|
|
void CLASS_check_variable_prefix(CLASS_SYMBOL *sym, bool local);
|
2018-02-14 17:03:14 +01:00
|
|
|
|
2021-05-18 02:12:33 +02:00
|
|
|
char *CLASS_get_export_name(CLASS *class);
|
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
// gbc_dump.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void CLASS_dump(void);
|
|
|
|
void CLASS_export(void);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#endif
|