Skip to content

Commit 0a0c00e

Browse files
committed
Show variable names on errors in the cross-compiler.
This also makes the error position match between the IDE and the cross compiler when a variable not defined or the wrong type is found.
1 parent f20c133 commit 0a0c00e

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/compiler/parser-actions.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,22 @@ static bool SMB_E_VAR_SET_TYPE(parse &s)
467467
return var_type_is_array(type);
468468
}
469469

470-
static bool var_check(parse &s, int type)
470+
static bool var_check(parse &s, enum VarType type)
471471
{
472472
auto &v = s.vars;
473473
std::string name;
474474
if(!s.get_ident(name))
475475
return false;
476476
if(v.find(name) == v.end())
477+
{
478+
s.error("variable name but got '" + name + "'");
477479
return false;
480+
}
478481
if((v[name] & 0xFF) != type)
482+
{
483+
s.error(get_vt_name(type) + " and got '" + name + "'");
479484
return false;
485+
}
480486
s.add_text(name);
481487
s.emit_varn(name);
482488
return true;

src/compiler/vartype.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ std::string get_vt_name(enum VarType t)
4747
switch(t)
4848
{
4949
case VT_ARRAY_WORD:
50-
return "Word Array";
50+
return "word array";
5151
case VT_ARRAY_BYTE:
52-
return "Byte Array";
52+
return "byte array";
5353
case VT_ARRAY_STRING:
54-
return "String Array";
54+
return "string array";
5555
case VT_ARRAY_FLOAT:
56-
return "Float Array";
56+
return "float array";
5757
case VT_WORD:
58-
return "Word";
58+
return "word";
5959
case VT_STRING:
60-
return "String";
60+
return "string";
6161
case VT_FLOAT:
62-
return "Float";
62+
return "float";
6363
case VT_UNDEF:
6464
break;
6565
}

testsuite/tests/err-bad-pos.chk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Name: Check error reporting in cross-compiler.
22
Test: compile-error
33
Error: parse error at line 2 column 6
4-
Error-pos: 2:5
4+
Error-pos: 2:6

testsuite/tests/err-parse-bug.chk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Name: Check infinite loop bug in parser
22
Test: compile-error
33
Error: parse error at line 1 column 15
4-
Error-pos: 1:13
4+
Error-pos: 1:15

0 commit comments

Comments
 (0)