From ec7453ae859c409414ac310fa68fc807aa4891d0 Mon Sep 17 00:00:00 2001 From: Dmitry Orlov Date: Sun, 5 Sep 2021 15:23:36 +0300 Subject: [PATCH] Fix some warnings, Add headers to the solution --- scripting/erm/CMakeLists.txt | 9 ++++++++- scripting/erm/ERMInterpreter.cpp | 8 ++++---- scripting/erm/ERMParser.cpp | 3 ++- scripting/erm/ERMParser.h | 5 +++++ test/CMakeLists.txt | 2 ++ test/erm/interpretter/ERM_UN.cpp | 28 ++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 test/erm/interpretter/ERM_UN.cpp diff --git a/scripting/erm/CMakeLists.txt b/scripting/erm/CMakeLists.txt index 0d58877a2..1f8dd7515 100644 --- a/scripting/erm/CMakeLists.txt +++ b/scripting/erm/CMakeLists.txt @@ -7,7 +7,14 @@ set(lib_SRCS ERMScriptModule.cpp ) -add_library(vcmiERM SHARED ${lib_SRCS}) +set(lib_HDRS + StdInc.h + ERMParser.h + ERMInterpreter.h + ERMScriptModule.h +) + +add_library(vcmiERM SHARED ${lib_SRCS} ${lib_HDRS}) target_link_libraries(vcmiERM ${Boost_LIBRARIES} vcmi) vcmi_set_output_dir(vcmiERM "scripting") diff --git a/scripting/erm/ERMInterpreter.cpp b/scripting/erm/ERMInterpreter.cpp index d5068d8db..b553f9a2b 100644 --- a/scripting/erm/ERMInterpreter.cpp +++ b/scripting/erm/ERMInterpreter.cpp @@ -1282,7 +1282,7 @@ namespace ERMConverter ERM::Tidentifier tid = trig.identifier.get(); - if(tid.size() == 0) + if(tid.empty()) throw EInterpreterError("Function must have identifier"); Variable v = boost::apply_visitor(LVL1IexpToVar(), tid[0]); @@ -1432,7 +1432,7 @@ bool ERMInterpreter::isATrigger( const ERM::TLine & line ) case 0: //v-exp { TVExp vexp = boost::get(line); - if(vexp.children.size() == 0) + if(vexp.children.empty()) return false; switch (getExpType(vexp.children[0])) @@ -1614,7 +1614,7 @@ namespace VERMInterpreter if(asSymbol) { children.resize(children.size()+1); - for(int i=children.size()-1; i >0; i--) + for(auto i=children.size()-1; i >0; i--) { children[i] = children[i-1]; } @@ -1718,7 +1718,7 @@ namespace VERMInterpreter } VOption OptionConverterVisitor::operator()( ERM::TSymbol const& cmd ) const { - if(cmd.symModifier.size() == 0) + if(cmd.symModifier.empty()) return VSymbol(cmd.sym); else return VNode(cmd); diff --git a/scripting/erm/ERMParser.cpp b/scripting/erm/ERMParser.cpp index cfbd8a705..9e19aafd1 100644 --- a/scripting/erm/ERMParser.cpp +++ b/scripting/erm/ERMParser.cpp @@ -187,7 +187,8 @@ std::vector ERMParser::parseFile(CERMPreprocessor & preproc) } catch (ParseErrorException & e) { - logGlobal->error("Stopped parsing file."); + logGlobal->error("ERM Parser Error. File: '%s' Line: %d Exception: '%s'" + , preproc.getCurFileName(), preproc.getCurLineNo(), e.what()); throw; } return ret; diff --git a/scripting/erm/ERMParser.h b/scripting/erm/ERMParser.h index eb0b04c8a..9602819f9 100644 --- a/scripting/erm/ERMParser.h +++ b/scripting/erm/ERMParser.h @@ -37,6 +37,11 @@ public: { return lineNo; } + + const std::string& getCurFileName() const + { + return fname; + } }; //various classes that represent ERM/VERM AST diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c3d2cfce7..4cb697b60 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,9 +40,11 @@ set(test_SRCS erm/ERM_MF.cpp erm/ERM_TM_T.cpp erm/ERM_VR.cpp + erm/ERM_UN.cpp erm/ERMPersistenceTest.cpp erm/ExamplesTest.cpp erm/interpretter/ERM_VR.cpp + erm/interpretter/ERM_UN.cpp erm/interpretter/ErmRunner.cpp events/ApplyDamageTest.cpp diff --git a/test/erm/interpretter/ERM_UN.cpp b/test/erm/interpretter/ERM_UN.cpp new file mode 100644 index 000000000..bcde193ee --- /dev/null +++ b/test/erm/interpretter/ERM_UN.cpp @@ -0,0 +1,28 @@ +/* + * ERM_UN.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" +#include "ErmRunner.h" + +namespace test +{ + namespace scripting + { + using namespace ::testing; + + TEST(ERM_UN_B, AnyInteger_ShouldGenerateIntToStringConversionAndSetStatement) + { + LuaStrings lua = ErmRunner::convertErmToLua({ "!#UN:B;" }); + ASSERT_EQ(lua.lines.size(), 9) << lua.text; + EXPECT_EQ(lua.lines[ErmRunner::REGULAR_INSTRUCTION_FIRST_LINE], "ERM.UN():B(x)"); + } + } +} + +