store idents by pointer
parent
32335049fa
commit
03c3145956
|
@ -122,20 +122,21 @@ CsState::CsState() {
|
|||
new_ident(static_cast<char const *>(buf), IDF_ARG);
|
||||
}
|
||||
dummy = new_ident("//dummy");
|
||||
add_ident("numargs", MaxArguments, 0, &numargs);
|
||||
add_ident("dbgalias", 0, 1000, &dbgalias);
|
||||
add_ident(new Ident("numargs", MaxArguments, 0, &numargs));
|
||||
add_ident(new Ident("dbgalias", 0, 1000, &dbgalias));
|
||||
cs_init_lib_base(*this);
|
||||
}
|
||||
|
||||
CsState::~CsState() {
|
||||
for (Ident &i: idents.iter()) {
|
||||
if (i.type == ID_ALIAS) {
|
||||
i.force_null();
|
||||
delete[] reinterpret_cast<ostd::Uint32 *>(i.code);
|
||||
i.code = nullptr;
|
||||
} else if (i.type == ID_COMMAND || i.type >= ID_LOCAL) {
|
||||
delete[] i.cargs;
|
||||
for (auto &p: idents.iter()) {
|
||||
Ident *i = p.second;
|
||||
if (i->type == ID_ALIAS) {
|
||||
i->force_null();
|
||||
delete[] reinterpret_cast<ostd::Uint32 *>(i->code);
|
||||
} else if (i->type == ID_COMMAND || i->type >= ID_LOCAL) {
|
||||
delete[] i->cargs;
|
||||
}
|
||||
delete i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,8 +172,8 @@ void CsState::clear_override(Ident &id) {
|
|||
}
|
||||
|
||||
void CsState::clear_overrides() {
|
||||
for (Ident &id: idents.iter()) {
|
||||
clear_override(id);
|
||||
for (auto &p: idents.iter()) {
|
||||
clear_override(*(p.second));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +186,7 @@ Ident *CsState::new_ident(ostd::ConstCharRange name, int flags) {
|
|||
);
|
||||
return dummy;
|
||||
}
|
||||
id = add_ident(name, flags);
|
||||
id = add_ident(new Ident(name, flags));
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
@ -263,7 +264,7 @@ void CsState::set_alias(ostd::ConstCharRange name, TaggedValue &v) {
|
|||
cs_debug_code(*this, "cannot alias number %s", name);
|
||||
v.cleanup();
|
||||
} else {
|
||||
add_ident(name, v, identflags);
|
||||
add_ident(new Ident(name, v, identflags));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1026,7 +1027,7 @@ static bool cs_add_command(
|
|||
return false;
|
||||
}
|
||||
}
|
||||
cs.add_ident(type, name, args, argmask, nargs, ostd::move(func));
|
||||
cs.add_ident(new Ident(type, name, args, argmask, nargs, ostd::move(func)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <ostd/types.hh>
|
||||
#include <ostd/string.hh>
|
||||
#include <ostd/vector.hh>
|
||||
#include <ostd/keyset.hh>
|
||||
#include <ostd/map.hh>
|
||||
#include <ostd/range.hh>
|
||||
#include <ostd/utility.hh>
|
||||
#include <ostd/maybe.hh>
|
||||
|
@ -280,10 +280,6 @@ struct OSTD_EXPORT Ident {
|
|||
void get_cstr(TaggedValue &v) const;
|
||||
void get_cval(TaggedValue &v) const;
|
||||
|
||||
ostd::ConstCharRange get_key() const {
|
||||
return name.iter();
|
||||
}
|
||||
|
||||
void clean_code();
|
||||
|
||||
void push_arg(TaggedValue const &v, IdentStack &st, bool um = true);
|
||||
|
@ -337,7 +333,7 @@ struct IdentLink {
|
|||
};
|
||||
|
||||
struct OSTD_EXPORT CsState {
|
||||
ostd::Keyset<Ident> idents;
|
||||
ostd::Map<ostd::ConstCharRange, Ident *> idents;
|
||||
ostd::Vector<Ident *> identmap;
|
||||
|
||||
Ident *dummy = nullptr;
|
||||
|
@ -359,18 +355,24 @@ struct OSTD_EXPORT CsState {
|
|||
void clear_override(Ident &id);
|
||||
void clear_overrides();
|
||||
|
||||
template<typename ...A>
|
||||
Ident *add_ident(A &&...args) {
|
||||
Ident &def = idents.emplace(ostd::forward<A>(args)...).first.front();
|
||||
def.index = identmap.size();
|
||||
return identmap.push(&def);
|
||||
Ident *add_ident(Ident *id) {
|
||||
if (!id) {
|
||||
return nullptr;
|
||||
}
|
||||
idents[id->name] = id;
|
||||
id->index = identmap.size();
|
||||
return identmap.push(id);
|
||||
}
|
||||
|
||||
Ident *new_ident(ostd::ConstCharRange name, int flags = IDF_UNKNOWN);
|
||||
Ident *force_ident(TaggedValue &v);
|
||||
|
||||
Ident *get_ident(ostd::ConstCharRange name) {
|
||||
return idents.at(name);
|
||||
Ident **id = idents.at(name);
|
||||
if (!id) {
|
||||
return nullptr;
|
||||
}
|
||||
return *id;
|
||||
}
|
||||
|
||||
bool have_ident(ostd::ConstCharRange name) {
|
||||
|
|
Loading…
Reference in New Issue