forked from OctaForge/libcubescript
safe typecasting accessors for Ident
parent
066c6b045f
commit
479c245190
109
cubescript.cc
109
cubescript.cc
|
@ -124,6 +124,115 @@ Command::Command(
|
||||||
name = n;
|
name = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Ident::is_alias() const {
|
||||||
|
return get_type() == IdentType::alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alias *Ident::get_alias() {
|
||||||
|
if (!is_alias()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Alias *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Alias const *Ident::get_alias() const {
|
||||||
|
if (!is_alias()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Alias const *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ident::is_command() const {
|
||||||
|
return get_type() == IdentType::command;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command *Ident::get_command() {
|
||||||
|
if (!is_command()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Command *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Command const *Ident::get_command() const {
|
||||||
|
if (!is_command()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Command const *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ident::is_var() const {
|
||||||
|
IdentType tp = get_type();
|
||||||
|
return (tp >= IdentType::ivar) && (tp <= IdentType::svar);
|
||||||
|
}
|
||||||
|
|
||||||
|
Var *Ident::get_var() {
|
||||||
|
if (!is_var()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Var *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Var const *Ident::get_var() const {
|
||||||
|
if (!is_var()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Var const *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ident::is_ivar() const {
|
||||||
|
return get_type() == IdentType::ivar;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ivar *Ident::get_ivar() {
|
||||||
|
if (!is_ivar()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Ivar *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ivar const *Ident::get_ivar() const {
|
||||||
|
if (!is_ivar()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Ivar const *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ident::is_fvar() const {
|
||||||
|
return get_type() == IdentType::fvar;
|
||||||
|
}
|
||||||
|
|
||||||
|
Fvar *Ident::get_fvar() {
|
||||||
|
if (!is_fvar()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Fvar *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Fvar const *Ident::get_fvar() const {
|
||||||
|
if (!is_fvar()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Fvar const *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ident::is_svar() const {
|
||||||
|
return get_type() == IdentType::svar;
|
||||||
|
}
|
||||||
|
|
||||||
|
Svar *Ident::get_svar() {
|
||||||
|
if (!is_svar()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Svar *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Svar const *Ident::get_svar() const {
|
||||||
|
if (!is_svar()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<Svar const *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
void cs_init_lib_base(CsState &cs);
|
void cs_init_lib_base(CsState &cs);
|
||||||
|
|
||||||
CsState::CsState() {
|
CsState::CsState() {
|
||||||
|
|
|
@ -171,6 +171,12 @@ enum class IdentType {
|
||||||
ivar, fvar, svar, command, alias
|
ivar, fvar, svar, command, alias
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Command;
|
||||||
|
struct Var;
|
||||||
|
struct Ivar;
|
||||||
|
struct Fvar;
|
||||||
|
struct Svar;
|
||||||
|
|
||||||
struct OSTD_EXPORT Ident {
|
struct OSTD_EXPORT Ident {
|
||||||
ostd::byte type; /* ID_something */
|
ostd::byte type; /* ID_something */
|
||||||
ostd::ushort flags;
|
ostd::ushort flags;
|
||||||
|
@ -179,30 +185,29 @@ struct OSTD_EXPORT Ident {
|
||||||
|
|
||||||
IdentType get_type() const;
|
IdentType get_type() const;
|
||||||
|
|
||||||
bool is_alias() const {
|
bool is_alias() const;
|
||||||
return get_type() == IdentType::alias;
|
Alias *get_alias();
|
||||||
}
|
Alias const *get_alias() const;
|
||||||
|
|
||||||
bool is_command() const {
|
bool is_command() const;
|
||||||
return get_type() == IdentType::command;
|
Command *get_command();
|
||||||
}
|
Command const *get_command() const;
|
||||||
|
|
||||||
bool is_var() const {
|
bool is_var() const;
|
||||||
IdentType tp = get_type();
|
Var *get_var();
|
||||||
return (tp >= IdentType::ivar) && (tp <= IdentType::svar);
|
Var const *get_var() const;
|
||||||
}
|
|
||||||
|
|
||||||
bool is_ivar() const {
|
bool is_ivar() const;
|
||||||
return get_type() == IdentType::ivar;
|
Ivar *get_ivar();
|
||||||
}
|
Ivar const *get_ivar() const;
|
||||||
|
|
||||||
bool is_fvar() const {
|
bool is_fvar() const;
|
||||||
return get_type() == IdentType::fvar;
|
Fvar *get_fvar();
|
||||||
}
|
Fvar const *get_fvar() const;
|
||||||
|
|
||||||
bool is_svar() const {
|
bool is_svar() const;
|
||||||
return get_type() == IdentType::svar;
|
Svar *get_svar();
|
||||||
}
|
Svar const *get_svar() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Ident();
|
Ident();
|
||||||
|
|
Loading…
Reference in New Issue