From 032ae6a08cdba3a162a52d480fd32df3bf68ec98 Mon Sep 17 00:00:00 2001 From: mekolat Date: Sun, 26 Apr 2015 09:40:36 -0400 Subject: make the script parser take warnings seriously --- src/map/script-parse.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/map') diff --git a/src/map/script-parse.cpp b/src/map/script-parse.cpp index fb306c5..2c7305b 100644 --- a/src/map/script-parse.cpp +++ b/src/map/script-parse.cpp @@ -451,7 +451,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) ZString::iterator tmpp = skip_space(p + 1); if (*tmpp == ';' || *tmpp == ',') { - --script_errors; disp_error_message("deprecated: implicit 'next statement' label"_s, p); + disp_error_message("error: implicit 'next statement' label"_s, p); add_scriptl(borrow(LABEL_NEXTLINE_)); p++; return p; @@ -752,7 +752,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) { if (can_step) { - --script_errors; disp_error_message("deprecated: implicit fallthrough"_s, p); + disp_error_message("error: implicit fallthrough"_s, p); } can_step = true; @@ -777,7 +777,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (!can_step) { - --script_errors; disp_error_message("deprecated: unreachable statement"_s, p); + disp_error_message("error: unreachable statement"_s, p); } // 他は全部一緒くた p = parse_line(p, &can_step); @@ -792,7 +792,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (can_step && !implicit_end) { - --script_errors; disp_error_message("deprecated: implicit end"_s, p); + disp_error_message("error: implicit end"_s, p); } add_scriptc(ByteCode::NOP); @@ -824,14 +824,14 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (key.startswith("On"_s)) continue; if (!(key.startswith("L_"_s) || key.startswith("S_"_s))) - PRINTF("Warning: ugly label: %s\n"_fmt, key); + disp_error_message(STRPRINTF("error: ugly label: %s\n"_fmt, key),p); else if (!probable_labels.count(key)) - PRINTF("Warning: unused label: %s\n"_fmt, key); + disp_error_message(STRPRINTF("error: unused label: %s\n"_fmt, key),p); } for (ScriptLabel used : probable_labels) { if (scriptlabel_db.search(used).is_none()) - PRINTF("Warning: no such label: %s\n"_fmt, used); + disp_error_message(STRPRINTF("error: no such label: %s\n"_fmt, used),p); } probable_labels.clear(); -- cgit v1.2.3-60-g2f50 From 307c60a8faf7d1e7cb98c9d89a7a737a0267d37a Mon Sep 17 00:00:00 2001 From: mekolat Date: Sun, 26 Apr 2015 09:59:54 -0400 Subject: make the script-fun die on errors --- src/map/script-fun.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/map') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 142debf..fe46685 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -108,8 +108,9 @@ void builtin_goto(ScriptState *st) { if (!AARG(0).is()) { - PRINTF("script: goto: that's not a label!\n"_fmt); + PRINTF("fatal: script: goto: not label !\n"_fmt); st->state = ScriptEndState::END; + runflag = 0; return; } @@ -149,8 +150,9 @@ void builtin_callfunc(ScriptState *st) } OMATCH_CASE_NONE () { - PRINTF("script: callfunc: function not found! [%s]\n"_fmt, str); + PRINTF("fatal: script: callfunc: function not found! [%s]\n"_fmt, str); st->state = ScriptEndState::END; + runflag = 0; } } OMATCH_END (); @@ -276,7 +278,9 @@ void builtin_menu(ScriptState *st) int arg_index = (sd->npc_menu - 1) * 2 + 1; if (!AARG(arg_index).is()) { + PRINTF("fatal: script:menu: not a label\n"_fmt); st->state = ScriptEndState::END; + runflag = 0; return; } st->scriptp.pos = AARG(arg_index).get_if()->numi; -- cgit v1.2.3-60-g2f50 From 1d40bf62ef1180039797d64f9c0aaf5cc639e17e Mon Sep 17 00:00:00 2001 From: mekolat Date: Mon, 27 Apr 2015 22:26:50 -0400 Subject: make script-call stricter --- src/map/script-call.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/map') diff --git a/src/map/script-call.cpp b/src/map/script-call.cpp index c3c6aa1..7092dbc 100644 --- a/src/map/script-call.cpp +++ b/src/map/script-call.cpp @@ -28,6 +28,8 @@ #include "../mmo/cxxstdio_enums.hpp" +#include "../high/core.hpp" + #include "battle.hpp" #include "battle_conf.hpp" #include "globals.hpp" @@ -584,6 +586,7 @@ void run_func(ScriptState *st) if (battle_config.error_log) PRINTF("function not found\n"_fmt); st->state = ScriptEndState::END; + runflag = 0; return; } } @@ -596,6 +599,7 @@ void run_func(ScriptState *st) { PRINTF("run_func: not function and command! \n"_fmt); st->state = ScriptEndState::END; + runflag = 0; return; } size_t func = st->stack->stack_datav[st->start].get_if()->numi; @@ -665,6 +669,7 @@ void run_func(ScriptState *st) { PRINTF("script:run_func (return) return without callfunc or callsub!\n"_fmt); st->state = ScriptEndState::END; + runflag = 0; return; } assert (olddefsp == st->defsp); // pretty sure it hasn't changed yet @@ -761,6 +766,7 @@ void run_script_main(ScriptState *st, Borrowed rootscript) { PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; + runflag = 0; } } break; @@ -804,12 +810,14 @@ void run_script_main(ScriptState *st, Borrowed rootscript) PRINTF("unknown command : %d @ %zu\n"_fmt, c, st->scriptp.pos); st->state = ScriptEndState::END; + runflag = 0; break; } if (st->freeloop != 1 && cmdcount > 0 && (--cmdcount) <= 0) { PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; + runflag = 0; } } switch (st->state) -- cgit v1.2.3-60-g2f50 From 278c2a8a88966a61a3c41a78c843cf9b6db4af2e Mon Sep 17 00:00:00 2001 From: mekolat Date: Tue, 5 May 2015 10:16:56 -0400 Subject: do not allow close/end in func or sub --- src/map/script-fun.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/map') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index fe46685..e619169 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -217,6 +217,14 @@ void builtin_next(ScriptState *st) static void builtin_close(ScriptState *st) { + if (st->stack->stack_datav[st->defsp - 1].is()) + { + dumb_ptr nd = map_id_is_npc(st->oid); + if(nd) + PRINTF("Deprecated: close in a callfunc or callsub! @ %s\n"_fmt, nd->name); + else + PRINTF("Deprecated: close in a callfunc or callsub! (no npc)\n"_fmt); + } st->state = ScriptEndState::END; clif_scriptclose(script_rid2sd(st), st->oid); } @@ -1258,6 +1266,14 @@ void builtin_getgmlevel(ScriptState *st) static void builtin_end(ScriptState *st) { + if (st->stack->stack_datav[st->defsp - 1].is()) + { + dumb_ptr nd = map_id_is_npc(st->oid); + if(nd) + PRINTF("Deprecated: close in a callfunc or callsub! @ %s\n"_fmt, nd->name); + else + PRINTF("Deprecated: close in a callfunc or callsub! (no npc)\n"_fmt); + } st->state = ScriptEndState::END; } -- cgit v1.2.3-60-g2f50 From 2ef763179ebf12ac8834e593f9c5668065e778f7 Mon Sep 17 00:00:00 2001 From: mekolat Date: Tue, 5 May 2015 23:52:44 -0400 Subject: do not allow return outside func or sub --- src/map/script-fun.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/map') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index e619169..6dc1510 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -190,6 +190,14 @@ void builtin_callsub(ScriptState *st) static void builtin_return(ScriptState *st) { + if (!(st->stack->stack_datav[st->defsp - 1].is())) + { + dumb_ptr nd = map_id_is_npc(st->oid); + if(nd) + PRINTF("Deprecated: return outside of callfunc or callsub! @ %s\n"_fmt, nd->name); + else + PRINTF("Deprecated: return outside of callfunc or callsub! (no npc)\n"_fmt); + } #if 0 if (HARG(0)) { // 戻り値有り -- cgit v1.2.3-60-g2f50