forked from OctaForge/libcubescript
StackedValue improvements
This commit is contained in:
parent
0df0f41507
commit
cd68185f40
|
@ -446,40 +446,54 @@ enum {
|
||||||
OSTD_EXPORT void init_libs(CsState &cs, int libs = CS_LIB_ALL);
|
OSTD_EXPORT void init_libs(CsState &cs, int libs = CS_LIB_ALL);
|
||||||
|
|
||||||
struct OSTD_EXPORT StackedValue: TaggedValue {
|
struct OSTD_EXPORT StackedValue: TaggedValue {
|
||||||
Ident *id;
|
StackedValue() = delete;
|
||||||
|
|
||||||
StackedValue(Ident *idv = nullptr):
|
StackedValue(CsState &cs, Ident *id = nullptr):
|
||||||
TaggedValue(), id(idv), p_stack(), p_pushed(false)
|
TaggedValue(), p_cs(cs), p_id(id), p_stack(), p_pushed(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~StackedValue() {
|
~StackedValue() {
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool alias(CsState &cs, ostd::ConstCharRange name) {
|
bool alias(Ident *id) {
|
||||||
id = cs.new_ident(name);
|
p_id = id;
|
||||||
return id && id->is_alias();
|
return p_id && p_id->is_alias();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool alias(ostd::ConstCharRange name) {
|
||||||
|
return alias(p_cs.new_ident(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool push() {
|
bool push() {
|
||||||
if (p_pushed || !id) {
|
if (p_pushed || !p_id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
id->push_arg(*this, p_stack);
|
p_id->push_arg(*this, p_stack);
|
||||||
p_pushed = true;
|
p_pushed = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pop() {
|
bool pop() {
|
||||||
if (!p_pushed || !id) {
|
if (!p_pushed || !p_id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
id->pop_arg();
|
p_id->pop_arg();
|
||||||
p_pushed = false;
|
p_pushed = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ident *get_id() const {
|
||||||
|
return p_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has_id() const {
|
||||||
|
return p_id != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CsState &p_cs;
|
||||||
|
Ident *p_id;
|
||||||
IdentStack p_stack;
|
IdentStack p_stack;
|
||||||
bool p_pushed;
|
bool p_pushed;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue