libcubescript/src/cs_ident.hh

120 lines
3.0 KiB
C++
Raw Normal View History

#ifndef LIBCUBESCRIPT_ALIAS_HH
#define LIBCUBESCRIPT_ALIAS_HH
#include <cubescript/cubescript.hh>
namespace cscript {
enum {
ID_UNKNOWN = -1, ID_IVAR, ID_FVAR, ID_SVAR, ID_COMMAND, ID_ALIAS,
ID_LOCAL, ID_DO, ID_DOARGS, ID_IF, ID_BREAK, ID_CONTINUE, ID_RESULT,
ID_NOT, ID_AND, ID_OR
};
2021-03-23 23:29:32 +01:00
struct ident_link {
ident *id;
ident_link *next;
int usedargs;
2021-03-23 23:29:32 +01:00
ident_stack *argstack;
};
2021-03-23 23:29:32 +01:00
struct ident_impl {
ident_impl() = delete;
ident_impl(ident_impl const &) = delete;
ident_impl(ident_impl &&) = delete;
/* trigger destructors for all inherited members properly */
2021-03-23 23:29:32 +01:00
virtual ~ident_impl() {};
2021-03-23 23:29:32 +01:00
ident_impl &operator=(ident_impl const &) = delete;
ident_impl &operator=(ident_impl &&) = delete;
2021-03-23 23:29:32 +01:00
ident_impl(ident_type tp, string_ref name, int flags = 0);
2021-03-23 23:29:32 +01:00
string_ref p_name;
/* represents the ident_type above, but internally it has a wider
* variety of values, so it's an int here (maps to an internal enum)
*/
int p_type, p_flags;
int p_index = -1;
};
2021-03-23 23:29:32 +01:00
struct var_impl: ident_impl {
var_impl(
ident_type tp, string_ref name, var_cb_func func, int flags = 0
);
2021-03-23 23:29:32 +01:00
var_cb_func cb_var;
2021-03-23 23:29:32 +01:00
void changed(state &cs);
};
2021-03-23 23:29:32 +01:00
struct ivar_impl: var_impl, integer_var {
ivar_impl(
string_ref n, integer_type m, integer_type x, integer_type v, var_cb_func f, int flags
);
2021-03-23 23:29:32 +01:00
integer_type p_storage, p_minval, p_maxval, p_overrideval;
};
2021-03-23 23:29:32 +01:00
struct fvar_impl: var_impl, float_var {
fvar_impl(
string_ref n, float_type m, float_type x, float_type v,
var_cb_func f, int flags
);
2021-03-23 23:29:32 +01:00
float_type p_storage, p_minval, p_maxval, p_overrideval;
};
2021-03-23 23:29:32 +01:00
struct svar_impl: var_impl, string_var {
svar_impl(
string_ref n, string_ref v, string_ref ov, var_cb_func f, int flags
);
2021-03-23 23:29:32 +01:00
string_ref p_storage, p_overrideval;
};
2021-03-23 23:29:32 +01:00
struct alias_impl: ident_impl, alias {
alias_impl(state &cs, string_ref n, string_ref a, int flags);
alias_impl(state &cs, string_ref n, std::string_view a, int flags);
alias_impl(state &cs, string_ref n, integer_type a, int flags);
alias_impl(state &cs, string_ref n, float_type a, int flags);
alias_impl(state &cs, string_ref n, int flags);
alias_impl(state &cs, string_ref n, any_value v, int flags);
2021-03-23 23:29:32 +01:00
void push_arg(any_value &v, ident_stack &st, bool um = true);
void pop_arg();
2021-03-23 23:29:32 +01:00
void undo_arg(ident_stack &st);
void redo_arg(ident_stack &st);
void set_arg(state &cs, any_value &v);
void set_alias(state &cs, any_value &v);
void clean_code();
2021-03-23 23:29:32 +01:00
bcode *compile_code(state &cs);
2021-03-23 23:29:32 +01:00
bcode *p_acode;
ident_stack *p_astack;
any_value p_val;
};
2021-03-23 23:29:32 +01:00
struct command_impl: ident_impl, command {
command_impl(
string_ref name, string_ref args, int numargs, command_func func
);
2021-03-23 23:29:32 +01:00
void call(state &cs, std::span<any_value> args, any_value &ret) {
p_cb_cftv(cs, args, ret);
}
2021-03-23 23:29:32 +01:00
string_ref p_cargs;
command_func p_cb_cftv;
int p_numargs;
};
2021-03-23 23:29:32 +01:00
bool ident_is_used_arg(ident *id, state &cs);
} /* namespace cscript */
#endif