Commit de72b872 authored by twanvl's avatar twanvl

naming style (variable_to_string); nicer error messages for problems during dependency checking

parent 87f61e27
......@@ -171,6 +171,7 @@ IMPLEMENT_REFLECTION_ENUM(ChoiceRenderStyle) {
}
IMPLEMENT_REFLECTION(ChoiceStyle) {
tag.addAlias(300, _("card list colors"), _("colors card list"));
REFLECT_BASE(Style);
REFLECT(popup_style);
REFLECT(render_style);
......
......@@ -38,11 +38,11 @@ InputStreamP StyleSheet::openIconFile() {
}
IMPLEMENT_REFLECTION(StyleSheet) {
// < 0.3.0 didn't use card_ prefix
tag.addAlias(300, _("width"), _("card_width"));
tag.addAlias(300, _("height"), _("card_height"));
tag.addAlias(300, _("dpi"), _("card_dpi"));
tag.addAlias(300, _("background"), _("card_background"));
tag.addAlias(300, _("info_style"), _("set_info_style"));
tag.addAlias(300, _("width"), _("card width"));
tag.addAlias(300, _("height"), _("card height"));
tag.addAlias(300, _("dpi"), _("card dpi"));
tag.addAlias(300, _("background"), _("card background"));
tag.addAlias(300, _("info style"), _("set info style"));
tag.addAlias(300, _("align"), _("alignment"));
REFLECT(game);
......
......@@ -37,6 +37,7 @@ IMPLEMENT_APP(MSE)
bool MSE::OnInit() {
try {
SetAppName(_("Magic Set Editor"));
wxInitAllImageHandlers();
init_file_formats();
settings.read();
......
......@@ -72,7 +72,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
// Get a variable
case I_GET_VAR: {
ScriptValueP value = variables[i.data].value;
if (!value) throw ScriptError(_("Variable not set: ") + variableToString(i.data));
if (!value) throw ScriptError(_("Variable not set: ") + variable_to_string(i.data));
stack.push_back(value);
break;
}
......@@ -163,7 +163,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
}
void Context::setVariable(const String& name, const ScriptValueP& value) {
setVariable(stringToVariable(name), value);
setVariable(string_to_variable(name), value);
}
void Context::setVariable(int name, const ScriptValueP& value) {
......@@ -178,13 +178,13 @@ void Context::setVariable(int name, const ScriptValueP& value) {
}
ScriptValueP Context::getVariable(const String& name) {
ScriptValueP value = variables[stringToVariable(name)].value;
ScriptValueP value = variables[string_to_variable(name)].value;
if (!value) throw ScriptError(_("Variable not set: ") + name);
return value;
}
ScriptValueP Context::getVariableOpt(const String& name) {
return variables[stringToVariable(name)].value;
return variables[string_to_variable(name)].value;
}
......
......@@ -69,7 +69,7 @@ class Context {
Variable value; ///< Old value of that variable.
};
private:
/// Variables, indexed by integer naem (using stringToVariable)
/// Variables, indexed by integer naem (using string_to_variable)
VectorIntMap<unsigned int, Variable> variables;
/// Shadowed variable bindings
vector<Binding> shadowed;
......
......@@ -64,6 +64,20 @@ ScriptValueP unified(const ScriptValueP& a, const ScriptValueP& b) {
else return new_intrusive2<DependencyUnion>(a,b);
}
/// Behaves like script_nil, but with a name
class ScriptMissingVariable : public ScriptValue {
public:
ScriptMissingVariable(const String& name) : name(name) {}
virtual ScriptType type() const { return SCRIPT_NIL; }
virtual String typeName() const { return _("missing variable '") + name + _("'"); }
virtual operator String() const { return wxEmptyString; }
virtual operator double() const { return 0.0; }
virtual operator int() const { return 0; }
virtual ScriptValueP eval(Context&) const { return script_nil; } // nil() == nil
private:
String name; ///< Name of the variable
};
// ----------------------------------------------------------------------------- : Jump record
// Utility class: a jump that has been postponed
......@@ -245,7 +259,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
// Get a variable (almost as normal)
case I_GET_VAR: {
ScriptValueP value = variables[i.data].value;
if (!value) value = script_nil; // no errors here
if (!value) value = new_intrusive1<ScriptMissingVariable>(variable_to_string(i.data)); // no errors here
stack.push_back(value);
break;
}
......
......@@ -355,7 +355,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
script.addInstruction(I_LOOP, 0xFFFF); // loop
expectToken(input, _("do")); // do
script.addInstruction(I_SET_VAR,
stringToVariable(name.value)); // set name
string_to_variable(name.value));// set name
script.addInstruction(I_POP); // pop
parseOper(input, script, PREC_SET, I_BINARY, I_ADD);// CCC; add
script.addInstruction(I_JUMP, lblStart); // jump lbl_start
......@@ -373,7 +373,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
script.addInstruction(I_LOOP, 0xFFFF); // loop
expectToken(input, _("do")); // do
script.addInstruction(I_SET_VAR,
stringToVariable(name.value)); // set name
string_to_variable(name.value));// set name
script.addInstruction(I_POP); // pop
parseOper(input, script, PREC_SET, I_BINARY, I_ADD);// DDD; add
script.addInstruction(I_JUMP, lblStart); // jump lbl_start
......@@ -391,7 +391,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
script.addInstruction(I_TERNARY, I_RGB);
} else {
// variable
unsigned int var = stringToVariable(token.value);
unsigned int var = string_to_variable(token.value);
script.addInstruction(I_GET_VAR, var);
}
} else if (token == TOK_INT) {
......@@ -475,13 +475,13 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc
while (t != _(")")) {
if (input.peek(2) == _(":")) {
// name: ...
arguments.push_back(stringToVariable(t.value));
arguments.push_back(string_to_variable(t.value));
input.read(); // skip the name
input.read(); // and the :
parseOper(input, script, PREC_SEQ);
} else {
// implicit "input" argument
arguments.push_back(stringToVariable(_("input")));
arguments.push_back(string_to_variable(_("input")));
parseOper(input, script, PREC_SEQ);
}
t = input.peek();
......
......@@ -17,7 +17,7 @@ Variables variables;
DECLARE_TYPEOF(Variables);
/// Return a unique name for a variable to allow for faster loopups
unsigned int stringToVariable(const String& s) {
unsigned int string_to_variable(const String& s) {
map<String, unsigned int>::iterator it = variables.find(s);
if (it == variables.end()) {
unsigned int v = (unsigned int)variables.size();
......@@ -31,7 +31,7 @@ unsigned int stringToVariable(const String& s) {
/// Get the name of a vaiable
/** Warning: this function is slow, it should only be used for error messages and such.
*/
String variableToString(unsigned int v) {
String variable_to_string(unsigned int v) {
FOR_EACH(vi, variables) {
if (vi.second == v) return vi.first;
}
......@@ -159,7 +159,7 @@ String Script::dumpInstr(unsigned int pos, Instruction i) const {
ret += "\t" + lexical_cast<String>(i.data);
break;
case I_GET_VAR: case I_SET_VAR: case I_NOP: // variable
ret += "\t" + variableToString(i.data) + "\t$" + lexical_cast<String>(i.data);
ret += "\t" + variable_to_string(i.data) + "\t$" + lexical_cast<String>(i.data);
break;
}
return ret;
......
......@@ -93,12 +93,12 @@ struct Instruction {
// ----------------------------------------------------------------------------- : Variables
/// Return a unique name for a variable to allow for faster loopups
unsigned int stringToVariable(const String& s);
unsigned int string_to_variable(const String& s);
/// Get the name of a vaiable
/** Warning: this function is slow, it should only be used for error messages and such.
*/
String variableToString(unsigned int v);
String variable_to_string(unsigned int v);
// ----------------------------------------------------------------------------- : Script
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment