From 6494870a541189aade6fcd4563c5c7d2ee039eff Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 31 Aug 2016 19:18:53 +0100 Subject: [PATCH] value getter for CsAlias --- cs_vm.cc | 32 +++++++++++++----------- cubescript.cc | 68 +++++++++++++++++++++++++-------------------------- cubescript.hh | 10 +++++++- 3 files changed, 61 insertions(+), 49 deletions(-) diff --git a/cs_vm.cc b/cs_vm.cc index 6bda1bc..90d53f2 100644 --- a/cs_vm.cc +++ b/cs_vm.cc @@ -982,7 +982,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { switch (cs_get_lookupu_type(cs, arg, id, op)) { case ID_ALIAS: arg.set_str(ostd::move( - static_cast(id)->val_v.get_str() + static_cast(id)->get_value().get_str() )); continue; case ID_SVAR: @@ -1007,7 +1007,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { } case CODE_LOOKUP | RET_STR: args[numargs++].set_str( - ostd::move(cs_get_lookup_id(cs, op)->val_v.get_str()) + ostd::move(cs_get_lookup_id(cs, op)->get_value().get_str()) ); continue; case CODE_LOOKUPARG | RET_STR: { @@ -1015,7 +1015,9 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { if (!a) { args[numargs++].set_str(""); } else { - args[numargs++].set_str(ostd::move(a->val_v.get_str())); + args[numargs++].set_str( + ostd::move(a->get_value().get_str()) + ); } continue; } @@ -1024,7 +1026,9 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { CsValue &arg = args[numargs - 1]; switch (cs_get_lookupu_type(cs, arg, id, op)) { case ID_ALIAS: - arg.set_int(static_cast(id)->val_v.get_int()); + arg.set_int( + static_cast(id)->get_value().get_int() + ); continue; case ID_SVAR: arg.set_int(cs_parse_int( @@ -1048,7 +1052,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { } case CODE_LOOKUP | RET_INT: args[numargs++].set_int( - cs_get_lookup_id(cs, op)->val_v.get_int() + cs_get_lookup_id(cs, op)->get_value().get_int() ); continue; case CODE_LOOKUPARG | RET_INT: { @@ -1056,7 +1060,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { if (!a) { args[numargs++].set_int(0); } else { - args[numargs++].set_int(a->val_v.get_int()); + args[numargs++].set_int(a->get_value().get_int()); } continue; } @@ -1066,7 +1070,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { switch (cs_get_lookupu_type(cs, arg, id, op)) { case ID_ALIAS: arg.set_float( - static_cast(id)->val_v.get_float() + static_cast(id)->get_value().get_float() ); continue; case ID_SVAR: @@ -1093,7 +1097,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { } case CODE_LOOKUP | RET_FLOAT: args[numargs++].set_float( - cs_get_lookup_id(cs, op)->val_v.get_float() + cs_get_lookup_id(cs, op)->get_value().get_float() ); continue; case CODE_LOOKUPARG | RET_FLOAT: { @@ -1101,7 +1105,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { if (!a) { args[numargs++].set_float(CsFloat(0)); } else { - args[numargs++].set_float(a->val_v.get_float()); + args[numargs++].set_float(a->get_value().get_float()); } continue; } @@ -1110,7 +1114,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { CsValue &arg = args[numargs - 1]; switch (cs_get_lookupu_type(cs, arg, id, op)) { case ID_ALIAS: - static_cast(id)->val_v.get_val(arg); + static_cast(id)->get_value().get_val(arg); continue; case ID_SVAR: arg.set_str(static_cast(id)->get_value()); @@ -1131,14 +1135,14 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { } } case CODE_LOOKUP | RET_NULL: - cs_get_lookup_id(cs, op)->val_v.get_val(args[numargs++]); + cs_get_lookup_id(cs, op)->get_value().get_val(args[numargs++]); continue; case CODE_LOOKUPARG | RET_NULL: { CsAlias *a = cs_get_lookuparg_id(cs, op); if (!a) { args[numargs++].set_null(); } else { - a->val_v.get_val(args[numargs++]); + a->get_value().get_val(args[numargs++]); } continue; } @@ -1557,7 +1561,7 @@ noid: force_arg(result, op & CODE_RET_MASK); continue; } - if (a->val_v.get_type() == CsValueType::null) { + if (a->get_value().get_type() == CsValueType::null) { goto noid; } idarg.cleanup(); @@ -1652,7 +1656,7 @@ void CsState::run_ret(CsIdent *id, CsValueRange args, CsValue &ret) { break; } } - if (a->val_v.get_type() == CsValueType::null) { + if (a->get_value().get_type() == CsValueType::null) { break; } cs_call_alias( diff --git a/cubescript.cc b/cubescript.cc index 17c80b8..033ad76 100644 --- a/cubescript.cc +++ b/cubescript.cc @@ -73,29 +73,29 @@ CsAlias::CsAlias(ostd::ConstCharRange name, char *a, int fl): CsIdent(CsIdentType::alias, name, fl), p_acode(nullptr), p_astack(nullptr) { - val_v.set_mstr(a); + p_val.set_mstr(a); } CsAlias::CsAlias(ostd::ConstCharRange name, CsInt a, int fl): CsIdent(CsIdentType::alias, name, fl), p_acode(nullptr), p_astack(nullptr) { - val_v.set_int(a); + p_val.set_int(a); } CsAlias::CsAlias(ostd::ConstCharRange name, CsFloat a, int fl): CsIdent(CsIdentType::alias, name, fl), p_acode(nullptr), p_astack(nullptr) { - val_v.set_float(a); + p_val.set_float(a); } CsAlias::CsAlias(ostd::ConstCharRange name, int fl): CsIdent(CsIdentType::alias, name, fl), p_acode(nullptr), p_astack(nullptr) { - val_v.set_null(); + p_val.set_null(); } CsAlias::CsAlias(ostd::ConstCharRange name, CsValue const &v, int fl): CsIdent(CsIdentType::alias, name, fl), - val_v(v), p_acode(nullptr), p_astack(nullptr) + p_acode(nullptr), p_astack(nullptr), p_val(v) {} Command::Command( @@ -275,7 +275,7 @@ CsState::~CsState() { CsIdent *i = p.second; CsAlias *a = i->get_alias(); if (a) { - a->val_v.force_null(); + a->get_value().force_null(); a->clean_code(); } else if (i->is_command() || i->is_special()) { delete[] static_cast(i)->cargs; @@ -291,9 +291,9 @@ void CsState::clear_override(CsIdent &id) { switch (id.get_type()) { case CsIdentType::alias: { CsAlias &a = static_cast(id); - a.val_v.cleanup(); + a.get_value().cleanup(); a.clean_code(); - a.val_v.set_str(""); + a.get_value().set_str(""); break; } case CsIdentType::ivar: { @@ -778,19 +778,19 @@ bool CsValue::get_bool() const { } void CsAlias::get_cstr(CsValue &v) const { - switch (val_v.get_type()) { + switch (p_val.get_type()) { case CsValueType::macro: - v.set_macro(val_v.get_strr()); + v.set_macro(p_val.get_strr()); break; case CsValueType::string: case CsValueType::cstring: - v.set_cstr(val_v.get_strr()); + v.set_cstr(p_val.get_strr()); break; case CsValueType::integer: - v.set_str(ostd::move(intstr(val_v.get_int()))); + v.set_str(ostd::move(intstr(p_val.get_int()))); break; case CsValueType::number: - v.set_str(ostd::move(floatstr(val_v.get_float()))); + v.set_str(ostd::move(floatstr(p_val.get_float()))); break; default: v.set_cstr(""); @@ -799,19 +799,19 @@ void CsAlias::get_cstr(CsValue &v) const { } void CsAlias::get_cval(CsValue &v) const { - switch (val_v.get_type()) { + switch (p_val.get_type()) { case CsValueType::macro: - v.set_macro(val_v.get_strr()); + v.set_macro(p_val.get_strr()); break; case CsValueType::string: case CsValueType::cstring: - v.set_cstr(val_v.get_strr()); + v.set_cstr(p_val.get_strr()); break; case CsValueType::integer: - v.set_int(val_v.get_int()); + v.set_int(p_val.get_int()); break; case CsValueType::number: - v.set_float(val_v.get_float()); + v.set_float(p_val.get_float()); break; default: v.set_null(); @@ -829,7 +829,7 @@ void CsAlias::clean_code() { CsBytecode *CsAlias::compile_code(CsState &cs) { if (!p_acode) { - p_acode = reinterpret_cast(compilecode(cs, val_v.get_str())); + p_acode = reinterpret_cast(compilecode(cs, p_val.get_str())); } return p_acode; } @@ -837,15 +837,15 @@ CsBytecode *CsAlias::compile_code(CsState &cs) { void CsAlias::push_arg(CsValue const &v, CsIdentStack &st, bool um) { if (p_astack == &st) { /* prevent cycles and unnecessary code elsewhere */ - val_v.cleanup(); - val_v = v; + p_val.cleanup(); + p_val = v; clean_code(); return; } - st.val_s = val_v; + st.val_s = p_val; st.next = p_astack; p_astack = &st; - val_v = v; + p_val = v; clean_code(); if (um) { p_flags &= ~IDF_UNKNOWN; @@ -857,33 +857,33 @@ void CsAlias::pop_arg() { return; } CsIdentStack *st = p_astack; - val_v.cleanup(); - val_v = p_astack->val_s; + p_val.cleanup(); + p_val = p_astack->val_s; clean_code(); p_astack = st->next; } void CsAlias::undo_arg(CsIdentStack &st) { CsIdentStack *prev = p_astack; - st.val_s = val_v; + st.val_s = p_val; st.next = prev; p_astack = prev->next; - val_v = prev->val_s; + p_val = prev->val_s; clean_code(); } void CsAlias::redo_arg(CsIdentStack const &st) { CsIdentStack *prev = st.next; - prev->val_s = val_v; + prev->val_s = p_val; p_astack = prev; - val_v = st.val_s; + p_val = st.val_s; clean_code(); } void CsAlias::set_arg(CsState &cs, CsValue &v) { if (cs.p_stack->usedargs & (1 << get_index())) { - val_v.cleanup(); - val_v = v; + p_val.cleanup(); + p_val = v; clean_code(); } else { push_arg(v, cs.p_stack->argstack[get_index()], false); @@ -892,8 +892,8 @@ void CsAlias::set_arg(CsState &cs, CsValue &v) { } void CsAlias::set_alias(CsState &cs, CsValue &v) { - val_v.cleanup(); - val_v = v; + p_val.cleanup(); + p_val = v; clean_code(); p_flags = (p_flags & cs.identflags) | cs.identflags; } @@ -1077,7 +1077,7 @@ CsState::get_alias_val(ostd::ConstCharRange name) { ) { return ostd::nothing; } - return ostd::move(a->val_v.get_str()); + return ostd::move(a->get_value().get_str()); } CsInt cs_clamp_var(CsState &cs, CsIvar *iv, CsInt v) { diff --git a/cubescript.hh b/cubescript.hh index 87c569e..fe88bc5 100644 --- a/cubescript.hh +++ b/cubescript.hh @@ -262,7 +262,14 @@ private: struct OSTD_EXPORT CsAlias: CsIdent { friend struct CsState; - CsValue val_v; + + CsValue const &get_value() const { + return p_val; + } + + CsValue &get_value() { + return p_val; + } void get_cstr(CsValue &v) const; void get_cval(CsValue &v) const; @@ -286,6 +293,7 @@ private: CsBytecode *p_acode; CsIdentStack *p_astack; + CsValue p_val; }; struct CsIdentLink {