rename identvalueptr fields

master
Daniel Kolesa 2015-08-13 21:08:57 +01:00
parent b7995d4ee9
commit 634c52b168
2 changed files with 60 additions and 61 deletions

View File

@ -80,7 +80,7 @@ Ident::Ident(int t, ostd::ConstCharRange n, int m, int x, int *s,
IdentFunc f, int flags) IdentFunc f, int flags)
: type(t), flags(flags | (m > x ? IDF_READONLY : 0)), name(n), : type(t), flags(flags | (m > x ? IDF_READONLY : 0)), name(n),
minval(m), maxval(x), fun(f) { minval(m), maxval(x), fun(f) {
storage.i = s; storage.ip = s;
} }
/* ID_FVAR */ /* ID_FVAR */
@ -88,13 +88,13 @@ Ident::Ident(int t, ostd::ConstCharRange n, float m, float x, float *s,
IdentFunc f, int flags) IdentFunc f, int flags)
: type(t), flags(flags | (m > x ? IDF_READONLY : 0)), name(n), : type(t), flags(flags | (m > x ? IDF_READONLY : 0)), name(n),
minvalf(m), maxvalf(x), fun(f) { minvalf(m), maxvalf(x), fun(f) {
storage.f = s; storage.fp = s;
} }
/* ID_SVAR */ /* ID_SVAR */
Ident::Ident(int t, ostd::ConstCharRange n, char **s, IdentFunc f, int flags) Ident::Ident(int t, ostd::ConstCharRange n, char **s, IdentFunc f, int flags)
: type(t), flags(flags), name(n), fun(f) { : type(t), flags(flags), name(n), fun(f) {
storage.s = s; storage.sp = s;
} }
/* ID_ALIAS */ /* ID_ALIAS */
@ -235,16 +235,16 @@ void CsState::clear_override(Ident &id) {
id.val.s = cs_dup_ostr(""); id.val.s = cs_dup_ostr("");
break; break;
case ID_VAR: case ID_VAR:
*id.storage.i = id.overrideval.i; *id.storage.ip = id.overrideval.i;
id.changed(*this); id.changed(*this);
break; break;
case ID_FVAR: case ID_FVAR:
*id.storage.f = id.overrideval.f; *id.storage.fp = id.overrideval.f;
id.changed(*this); id.changed(*this);
break; break;
case ID_SVAR: case ID_SVAR:
delete[] *id.storage.s; delete[] *id.storage.sp;
*id.storage.s = id.overrideval.s; *id.storage.sp = id.overrideval.s;
id.changed(*this); id.changed(*this);
break; break;
} }
@ -376,13 +376,13 @@ void CsState::print_var_str(Ident *id, ostd::ConstCharRange s) {
void CsState::print_var(Ident *id) { void CsState::print_var(Ident *id) {
switch (id->type) { switch (id->type) {
case ID_VAR: case ID_VAR:
print_var_int(id, *id->storage.i); print_var_int(id, *id->storage.ip);
break; break;
case ID_FVAR: case ID_FVAR:
print_var_float(id, *id->storage.f); print_var_float(id, *id->storage.fp);
break; break;
case ID_SVAR: case ID_SVAR:
print_var_str(id, *id->storage.s); print_var_str(id, *id->storage.sp);
break; break;
} }
} }
@ -738,14 +738,14 @@ void CsState::set_var_int(ostd::ConstCharRange name, int v,
if (!id || id->type != ID_VAR) if (!id || id->type != ID_VAR)
return; return;
bool success = cs_override_var(*this, id, bool success = cs_override_var(*this, id,
[&id]() { id->overrideval.i = *id->storage.i; }, [&id]() { id->overrideval.i = *id->storage.ip; },
[]() {}, []() {}); []() {}, []() {});
if (!success) if (!success)
return; return;
if (doclamp) if (doclamp)
*id->storage.i = ostd::clamp(v, id->minval, id->maxval); *id->storage.ip = ostd::clamp(v, id->minval, id->maxval);
else else
*id->storage.i = v; *id->storage.ip = v;
if (dofunc) if (dofunc)
id->changed(*this); id->changed(*this);
} }
@ -756,14 +756,14 @@ void CsState::set_var_float(ostd::ConstCharRange name, float v,
if (!id || id->type != ID_FVAR) if (!id || id->type != ID_FVAR)
return; return;
bool success = cs_override_var(*this, id, bool success = cs_override_var(*this, id,
[&id]() { id->overrideval.f = *id->storage.f; }, [&id]() { id->overrideval.f = *id->storage.fp; },
[]() {}, []() {}); []() {}, []() {});
if (!success) if (!success)
return; return;
if (doclamp) if (doclamp)
*id->storage.f = ostd::clamp(v, id->minvalf, id->maxvalf); *id->storage.fp = ostd::clamp(v, id->minvalf, id->maxvalf);
else else
*id->storage.f = v; *id->storage.fp = v;
if (dofunc) if (dofunc)
id->changed(*this); id->changed(*this);
} }
@ -774,12 +774,12 @@ void CsState::set_var_str(ostd::ConstCharRange name, ostd::ConstCharRange v,
if (!id || id->type != ID_SVAR) if (!id || id->type != ID_SVAR)
return; return;
bool success = cs_override_var(*this, id, bool success = cs_override_var(*this, id,
[&id]() { id->overrideval.s = *id->storage.s; }, [&id]() { id->overrideval.s = *id->storage.sp; },
[&id]() { delete[] id->overrideval.s; }, [&id]() { delete[] id->overrideval.s; },
[&id]() { delete[] *id->storage.s; }); [&id]() { delete[] *id->storage.sp; });
if (!success) if (!success)
return; return;
*id->storage.s = cs_dup_ostr(v); *id->storage.sp = cs_dup_ostr(v);
if (dofunc) if (dofunc)
id->changed(*this); id->changed(*this);
} }
@ -788,21 +788,21 @@ ostd::Maybe<int> CsState::get_var_int(ostd::ConstCharRange name) {
Ident *id = idents.at(name); Ident *id = idents.at(name);
if (!id || id->type != ID_VAR) if (!id || id->type != ID_VAR)
return ostd::nothing; return ostd::nothing;
return *id->storage.i; return *id->storage.ip;
} }
ostd::Maybe<float> CsState::get_var_float(ostd::ConstCharRange name) { ostd::Maybe<float> CsState::get_var_float(ostd::ConstCharRange name) {
Ident *id = idents.at(name); Ident *id = idents.at(name);
if (!id || id->type != ID_FVAR) if (!id || id->type != ID_FVAR)
return ostd::nothing; return ostd::nothing;
return *id->storage.f; return *id->storage.fp;
} }
ostd::Maybe<ostd::String> CsState::get_var_str(ostd::ConstCharRange name) { ostd::Maybe<ostd::String> CsState::get_var_str(ostd::ConstCharRange name) {
Ident *id = idents.at(name); Ident *id = idents.at(name);
if (!id || id->type != ID_SVAR) if (!id || id->type != ID_SVAR)
return ostd::nothing; return ostd::nothing;
return ostd::String(*id->storage.s); return ostd::String(*id->storage.sp);
} }
ostd::Maybe<int> CsState::get_var_min_int(ostd::ConstCharRange name) { ostd::Maybe<int> CsState::get_var_min_int(ostd::ConstCharRange name) {
@ -865,13 +865,13 @@ void CsState::set_var_int_checked(Ident *id, int v) {
return; return;
} }
bool success = cs_override_var(*this, id, bool success = cs_override_var(*this, id,
[&id]() { id->overrideval.i = *id->storage.i; }, [&id]() { id->overrideval.i = *id->storage.ip; },
[]() {}, []() {}); []() {}, []() {});
if (!success) if (!success)
return; return;
if (v < id->minval || v > id->maxval) if (v < id->minval || v > id->maxval)
v = cs_clamp_var(*this, id, v); v = cs_clamp_var(*this, id, v);
*id->storage.i = v; *id->storage.ip = v;
id->changed(*this); id->changed(*this);
} }
@ -904,13 +904,13 @@ void CsState::set_var_float_checked(Ident *id, float v) {
return; return;
} }
bool success = cs_override_var(*this, id, bool success = cs_override_var(*this, id,
[&id]() { id->overrideval.f = *id->storage.f; }, [&id]() { id->overrideval.f = *id->storage.fp; },
[]() {}, []() {}); []() {}, []() {});
if (!success) if (!success)
return; return;
if (v < id->minvalf || v > id->maxvalf) if (v < id->minvalf || v > id->maxvalf)
v = cs_clamp_fvar(*this, id, v); v = cs_clamp_fvar(*this, id, v);
*id->storage.f = v; *id->storage.fp = v;
id->changed(*this); id->changed(*this);
} }
@ -920,11 +920,11 @@ void CsState::set_var_str_checked(Ident *id, ostd::ConstCharRange v) {
return; return;
} }
bool success = cs_override_var(*this, id, bool success = cs_override_var(*this, id,
[&id]() { id->overrideval.s = *id->storage.s; }, [&id]() { id->overrideval.s = *id->storage.sp; },
[&id]() { delete[] id->overrideval.s; }, [&id]() { delete[] id->overrideval.s; },
[&id]() { delete[] *id->storage.s; }); [&id]() { delete[] *id->storage.sp; });
if (!success) return; if (!success) return;
*id->storage.s = cs_dup_ostr(v); *id->storage.sp = cs_dup_ostr(v);
id->changed(*this); id->changed(*this);
} }
@ -2977,9 +2977,9 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
continue; \ continue; \
} }
LOOKUPU(arg.set_str(cs_dup_ostr(id->get_str())), LOOKUPU(arg.set_str(cs_dup_ostr(id->get_str())),
arg.set_str(cs_dup_ostr(*id->storage.s)), arg.set_str(cs_dup_ostr(*id->storage.sp)),
arg.set_str(cs_dup_ostr(intstr(*id->storage.i))), arg.set_str(cs_dup_ostr(intstr(*id->storage.ip))),
arg.set_str(cs_dup_ostr(floatstr(*id->storage.f))), arg.set_str(cs_dup_ostr(floatstr(*id->storage.fp))),
arg.set_str(cs_dup_ostr(""))); arg.set_str(cs_dup_ostr("")));
case CODE_LOOKUP|RET_STR: case CODE_LOOKUP|RET_STR:
#define LOOKUP(aval) { \ #define LOOKUP(aval) { \
@ -2999,9 +2999,9 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
LOOKUPARG(args[numargs++].set_str(cs_dup_ostr(id->get_str())), args[numargs++].set_str(cs_dup_ostr(""))); LOOKUPARG(args[numargs++].set_str(cs_dup_ostr(id->get_str())), args[numargs++].set_str(cs_dup_ostr("")));
case CODE_LOOKUPU|RET_INT: case CODE_LOOKUPU|RET_INT:
LOOKUPU(arg.set_int(id->get_int()), LOOKUPU(arg.set_int(id->get_int()),
arg.set_int(parseint(*id->storage.s)), arg.set_int(parseint(*id->storage.sp)),
arg.set_int(*id->storage.i), arg.set_int(*id->storage.ip),
arg.set_int(int(*id->storage.f)), arg.set_int(int(*id->storage.fp)),
arg.set_int(0)); arg.set_int(0));
case CODE_LOOKUP|RET_INT: case CODE_LOOKUP|RET_INT:
LOOKUP(args[numargs++].set_int(id->get_int())); LOOKUP(args[numargs++].set_int(id->get_int()));
@ -3009,9 +3009,9 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
LOOKUPARG(args[numargs++].set_int(id->get_int()), args[numargs++].set_int(0)); LOOKUPARG(args[numargs++].set_int(id->get_int()), args[numargs++].set_int(0));
case CODE_LOOKUPU|RET_FLOAT: case CODE_LOOKUPU|RET_FLOAT:
LOOKUPU(arg.set_float(id->get_float()), LOOKUPU(arg.set_float(id->get_float()),
arg.set_float(parsefloat(*id->storage.s)), arg.set_float(parsefloat(*id->storage.sp)),
arg.set_float(float(*id->storage.i)), arg.set_float(float(*id->storage.ip)),
arg.set_float(*id->storage.f), arg.set_float(*id->storage.fp),
arg.set_float(0.0f)); arg.set_float(0.0f));
case CODE_LOOKUP|RET_FLOAT: case CODE_LOOKUP|RET_FLOAT:
LOOKUP(args[numargs++].set_float(id->get_float())); LOOKUP(args[numargs++].set_float(id->get_float()));
@ -3019,9 +3019,9 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
LOOKUPARG(args[numargs++].set_float(id->get_float()), args[numargs++].set_float(0.0f)); LOOKUPARG(args[numargs++].set_float(id->get_float()), args[numargs++].set_float(0.0f));
case CODE_LOOKUPU|RET_NULL: case CODE_LOOKUPU|RET_NULL:
LOOKUPU(id->get_val(arg), LOOKUPU(id->get_val(arg),
arg.set_str(cs_dup_ostr(*id->storage.s)), arg.set_str(cs_dup_ostr(*id->storage.sp)),
arg.set_int(*id->storage.i), arg.set_int(*id->storage.ip),
arg.set_float(*id->storage.f), arg.set_float(*id->storage.fp),
arg.set_null()); arg.set_null());
case CODE_LOOKUP|RET_NULL: case CODE_LOOKUP|RET_NULL:
LOOKUP(id->get_val(args[numargs++])); LOOKUP(id->get_val(args[numargs++]));
@ -3030,9 +3030,9 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
case CODE_LOOKUPMU|RET_STR: case CODE_LOOKUPMU|RET_STR:
LOOKUPU(id->get_cstr(arg), LOOKUPU(id->get_cstr(arg),
arg.set_cstr(*id->storage.s), arg.set_cstr(*id->storage.sp),
arg.set_str(cs_dup_ostr(intstr(*id->storage.i))), arg.set_str(cs_dup_ostr(intstr(*id->storage.ip))),
arg.set_str(cs_dup_ostr(floatstr(*id->storage.f))), arg.set_str(cs_dup_ostr(floatstr(*id->storage.fp))),
arg.set_cstr("")); arg.set_cstr(""));
case CODE_LOOKUPM|RET_STR: case CODE_LOOKUPM|RET_STR:
LOOKUP(id->get_cstr(args[numargs++])); LOOKUP(id->get_cstr(args[numargs++]));
@ -3040,9 +3040,9 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
LOOKUPARG(id->get_cstr(args[numargs++]), args[numargs++].set_cstr("")); LOOKUPARG(id->get_cstr(args[numargs++]), args[numargs++].set_cstr(""));
case CODE_LOOKUPMU|RET_NULL: case CODE_LOOKUPMU|RET_NULL:
LOOKUPU(id->get_cval(arg), LOOKUPU(id->get_cval(arg),
arg.set_cstr(*id->storage.s), arg.set_cstr(*id->storage.sp),
arg.set_int(*id->storage.i), arg.set_int(*id->storage.ip),
arg.set_float(*id->storage.f), arg.set_float(*id->storage.fp),
arg.set_null()); arg.set_null());
case CODE_LOOKUPM|RET_NULL: case CODE_LOOKUPM|RET_NULL:
LOOKUP(id->get_cval(args[numargs++])); LOOKUP(id->get_cval(args[numargs++]));
@ -3051,16 +3051,16 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
case CODE_SVAR|RET_STR: case CODE_SVAR|RET_STR:
case CODE_SVAR|RET_NULL: case CODE_SVAR|RET_NULL:
args[numargs++].set_str(cs_dup_ostr(*cs.identmap[op >> 8]->storage.s)); args[numargs++].set_str(cs_dup_ostr(*cs.identmap[op >> 8]->storage.sp));
continue; continue;
case CODE_SVAR|RET_INT: case CODE_SVAR|RET_INT:
args[numargs++].set_int(parseint(*cs.identmap[op >> 8]->storage.s)); args[numargs++].set_int(parseint(*cs.identmap[op >> 8]->storage.sp));
continue; continue;
case CODE_SVAR|RET_FLOAT: case CODE_SVAR|RET_FLOAT:
args[numargs++].set_float(parsefloat(*cs.identmap[op >> 8]->storage.s)); args[numargs++].set_float(parsefloat(*cs.identmap[op >> 8]->storage.sp));
continue; continue;
case CODE_SVARM: case CODE_SVARM:
args[numargs++].set_cstr(*cs.identmap[op >> 8]->storage.s); args[numargs++].set_cstr(*cs.identmap[op >> 8]->storage.sp);
continue; continue;
case CODE_SVAR1: case CODE_SVAR1:
cs.set_var_str_checked(cs.identmap[op >> 8], args[--numargs].s); cs.set_var_str_checked(cs.identmap[op >> 8], args[--numargs].s);
@ -3069,13 +3069,13 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
case CODE_IVAR|RET_INT: case CODE_IVAR|RET_INT:
case CODE_IVAR|RET_NULL: case CODE_IVAR|RET_NULL:
args[numargs++].set_int(*cs.identmap[op >> 8]->storage.i); args[numargs++].set_int(*cs.identmap[op >> 8]->storage.ip);
continue; continue;
case CODE_IVAR|RET_STR: case CODE_IVAR|RET_STR:
args[numargs++].set_str(cs_dup_ostr(intstr(*cs.identmap[op >> 8]->storage.i))); args[numargs++].set_str(cs_dup_ostr(intstr(*cs.identmap[op >> 8]->storage.ip)));
continue; continue;
case CODE_IVAR|RET_FLOAT: case CODE_IVAR|RET_FLOAT:
args[numargs++].set_float(float(*cs.identmap[op >> 8]->storage.i)); args[numargs++].set_float(float(*cs.identmap[op >> 8]->storage.ip));
continue; continue;
case CODE_IVAR1: case CODE_IVAR1:
cs.set_var_int_checked(cs.identmap[op >> 8], args[--numargs].i); cs.set_var_int_checked(cs.identmap[op >> 8], args[--numargs].i);
@ -3091,13 +3091,13 @@ static const ostd::Uint32 *runcode(CsState &cs, const ostd::Uint32 *code, Tagged
case CODE_FVAR|RET_FLOAT: case CODE_FVAR|RET_FLOAT:
case CODE_FVAR|RET_NULL: case CODE_FVAR|RET_NULL:
args[numargs++].set_float(*cs.identmap[op >> 8]->storage.f); args[numargs++].set_float(*cs.identmap[op >> 8]->storage.fp);
continue; continue;
case CODE_FVAR|RET_STR: case CODE_FVAR|RET_STR:
args[numargs++].set_str(cs_dup_ostr(floatstr(*cs.identmap[op >> 8]->storage.f))); args[numargs++].set_str(cs_dup_ostr(floatstr(*cs.identmap[op >> 8]->storage.fp)));
continue; continue;
case CODE_FVAR|RET_INT: case CODE_FVAR|RET_INT:
args[numargs++].set_int(int(*cs.identmap[op >> 8]->storage.f)); args[numargs++].set_int(int(*cs.identmap[op >> 8]->storage.fp));
continue; continue;
case CODE_FVAR1: case CODE_FVAR1:
cs.set_var_float_checked(cs.identmap[op >> 8], args[--numargs].f); cs.set_var_float_checked(cs.identmap[op >> 8], args[--numargs].f);

View File

@ -155,10 +155,9 @@ struct IdentStack {
}; };
union IdentValuePtr { union IdentValuePtr {
void *p; int *ip; /* ID_VAR */
int *i; /* ID_VAR */ float *fp; /* ID_FVAR */
float *f; /* ID_FVAR */ char **sp; /* ID_SVAR */
char **s; /* ID_SVAR */
}; };
struct CsState; struct CsState;