remove is_ helpers for ident types (except is_var)
parent
bd1e7825d8
commit
344bba07f3
|
@ -67,24 +67,6 @@ struct LIBCUBESCRIPT_EXPORT ident {
|
||||||
/** @brief Check if the idents are not the same. */
|
/** @brief Check if the idents are not the same. */
|
||||||
bool operator!=(ident &other) const;
|
bool operator!=(ident &other) const;
|
||||||
|
|
||||||
/** @brief Check if the ident is a cubescript::alias.
|
|
||||||
*
|
|
||||||
* Effectively like `type() == ident_type::ALIAS`.
|
|
||||||
*/
|
|
||||||
bool is_alias() const;
|
|
||||||
|
|
||||||
/** @brief Check if the ident is a cubescript::command.
|
|
||||||
*
|
|
||||||
* Effectively like `type() == ident_type::COMMAND`.
|
|
||||||
*/
|
|
||||||
bool is_command() const;
|
|
||||||
|
|
||||||
/** @brief Check if the ident is a special ident.
|
|
||||||
*
|
|
||||||
* Effectively like `type() == ident_type::SPECIAL`.
|
|
||||||
*/
|
|
||||||
bool is_special() const;
|
|
||||||
|
|
||||||
/** @brief Check if the ident is a cubescript::global_var.
|
/** @brief Check if the ident is a cubescript::global_var.
|
||||||
*
|
*
|
||||||
* This will return `true` if ident::type() returns either
|
* This will return `true` if ident::type() returns either
|
||||||
|
@ -92,24 +74,6 @@ struct LIBCUBESCRIPT_EXPORT ident {
|
||||||
*/
|
*/
|
||||||
bool is_var() const;
|
bool is_var() const;
|
||||||
|
|
||||||
/** @brief Check if the ident is a cubescript::integer_var.
|
|
||||||
*
|
|
||||||
* Effectively like `type() == ident_type::IVAR`.
|
|
||||||
*/
|
|
||||||
bool is_ivar() const;
|
|
||||||
|
|
||||||
/** @brief Check if the ident is a cubescript::float_var.
|
|
||||||
*
|
|
||||||
* Effectively like `type() == ident_type::FVAR`.
|
|
||||||
*/
|
|
||||||
bool is_fvar() const;
|
|
||||||
|
|
||||||
/** @brief Check if the ident is a cubescript::string_var.
|
|
||||||
*
|
|
||||||
* Effectively like `type() == ident_type::SVAR`.
|
|
||||||
*/
|
|
||||||
bool is_svar() const;
|
|
||||||
|
|
||||||
/** @brief Get if the ident is overridden.
|
/** @brief Get if the ident is overridden.
|
||||||
*
|
*
|
||||||
* This can be true for aliases or builtins. When an alias or a builtin
|
* This can be true for aliases or builtins. When an alias or a builtin
|
||||||
|
|
|
@ -11,7 +11,8 @@ ident_impl::ident_impl(ident_type tp, string_ref nm, int fl):
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool ident_is_callable(ident const *id) {
|
bool ident_is_callable(ident const *id) {
|
||||||
if (!id->is_command() && !id->is_special()) {
|
auto tp = id->type();
|
||||||
|
if ((tp != ident_type::COMMAND) && (tp != ident_type::SPECIAL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !!static_cast<command_impl const *>(id)->p_cb_cftv;
|
return !!static_cast<command_impl const *>(id)->p_cb_cftv;
|
||||||
|
@ -197,18 +198,6 @@ LIBCUBESCRIPT_EXPORT bool ident::operator!=(ident &other) const {
|
||||||
return this != &other;
|
return this != &other;
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_alias() const {
|
|
||||||
return type() == ident_type::ALIAS;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_command() const {
|
|
||||||
return type() == ident_type::COMMAND;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_special() const {
|
|
||||||
return type() == ident_type::SPECIAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_var() const {
|
LIBCUBESCRIPT_EXPORT bool ident::is_var() const {
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
case ident_type::IVAR:
|
case ident_type::IVAR:
|
||||||
|
@ -221,18 +210,6 @@ LIBCUBESCRIPT_EXPORT bool ident::is_var() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_ivar() const {
|
|
||||||
return type() == ident_type::IVAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_fvar() const {
|
|
||||||
return type() == ident_type::FVAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_svar() const {
|
|
||||||
return type() == ident_type::SVAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool ident::is_overridden(state &cs) const {
|
LIBCUBESCRIPT_EXPORT bool ident::is_overridden(state &cs) const {
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
case ident_type::IVAR:
|
case ident_type::IVAR:
|
||||||
|
@ -502,7 +479,7 @@ LIBCUBESCRIPT_EXPORT any_value command::call(
|
||||||
/* external API for alias stack management */
|
/* external API for alias stack management */
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT alias_local::alias_local(state &cs, ident &a) {
|
LIBCUBESCRIPT_EXPORT alias_local::alias_local(state &cs, ident &a) {
|
||||||
if (!a.is_alias()) {
|
if (a.type() != ident_type::ALIAS) {
|
||||||
throw error{cs, "ident '%s' is not an alias", a.name().data()};
|
throw error{cs, "ident '%s' is not an alias", a.name().data()};
|
||||||
}
|
}
|
||||||
auto &ts = state_p{cs}.ts();
|
auto &ts = state_p{cs}.ts();
|
||||||
|
|
10
src/cs_vm.cc
10
src/cs_vm.cc
|
@ -10,7 +10,10 @@
|
||||||
namespace cubescript {
|
namespace cubescript {
|
||||||
|
|
||||||
static inline void push_alias(thread_state &ts, ident &id, ident_stack &st) {
|
static inline void push_alias(thread_state &ts, ident &id, ident_stack &st) {
|
||||||
if (id.is_alias() && !static_cast<alias &>(id).is_arg()) {
|
if (id.type() != ident_type::ALIAS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!static_cast<alias &>(id).is_arg()) {
|
||||||
auto *aimp = static_cast<alias_impl *>(&id);
|
auto *aimp = static_cast<alias_impl *>(&id);
|
||||||
auto ast = ts.get_astack(aimp);
|
auto ast = ts.get_astack(aimp);
|
||||||
ast.push(st);
|
ast.push(st);
|
||||||
|
@ -19,7 +22,10 @@ static inline void push_alias(thread_state &ts, ident &id, ident_stack &st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void pop_alias(thread_state &ts, ident &id) {
|
static inline void pop_alias(thread_state &ts, ident &id) {
|
||||||
if (id.is_alias() && !static_cast<alias &>(id).is_arg()) {
|
if (id.type() != ident_type::ALIAS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!static_cast<alias &>(id).is_arg()) {
|
||||||
ts.get_astack(static_cast<alias *>(&id)).pop();
|
ts.get_astack(static_cast<alias *>(&id)).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,10 +71,10 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
|
||||||
new_cmd_quiet(gcs, "pcall", "bvv", [](auto &cs, auto args, auto &ret) {
|
new_cmd_quiet(gcs, "pcall", "bvv", [](auto &cs, auto args, auto &ret) {
|
||||||
auto &cret = args[1].get_ident(cs);
|
auto &cret = args[1].get_ident(cs);
|
||||||
auto &css = args[2].get_ident(cs);
|
auto &css = args[2].get_ident(cs);
|
||||||
if (!cret.is_alias()) {
|
if (cret.type() != ident_type::ALIAS) {
|
||||||
throw error{cs, "'%s' is not an alias", cret.name().data()};
|
throw error{cs, "'%s' is not an alias", cret.name().data()};
|
||||||
}
|
}
|
||||||
if (!css.is_alias()) {
|
if (css.type() != ident_type::ALIAS) {
|
||||||
throw error{cs, "'%s' is not an alias", css.name().data()};
|
throw error{cs, "'%s' is not an alias", css.name().data()};
|
||||||
}
|
}
|
||||||
any_value result{}, tback{};
|
any_value result{}, tback{};
|
||||||
|
|
|
@ -16,7 +16,7 @@ static cs::state *ln_cs = nullptr;
|
||||||
inline void ln_complete(char const *buf, std::vector<std::string> &lc) {
|
inline void ln_complete(char const *buf, std::vector<std::string> &lc) {
|
||||||
std::string_view cmd = get_complete_cmd(buf);
|
std::string_view cmd = get_complete_cmd(buf);
|
||||||
for (auto id: ln_cs->get_idents()) {
|
for (auto id: ln_cs->get_idents()) {
|
||||||
if (!id->is_command()) {
|
if (id->type() != cs::ident_type::COMMAND) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::string_view idname = id->name();
|
std::string_view idname = id->name();
|
||||||
|
|
|
@ -147,7 +147,7 @@ inline cs::command *get_hint_cmd(cs::state &cs, std::string_view buf) {
|
||||||
}
|
}
|
||||||
if (!buf.empty()) {
|
if (!buf.empty()) {
|
||||||
auto cmd = cs.get_ident(buf);
|
auto cmd = cs.get_ident(buf);
|
||||||
if (cmd && cmd->get().is_command()) {
|
if (cmd && (cmd->get().type() == cs::ident_type::COMMAND)) {
|
||||||
return static_cast<cs::command *>(&cmd->get());
|
return static_cast<cs::command *>(&cmd->get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue