From 357ccabd0c19bff8cc09c0937556c6e65040c4e4 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Fri, 20 Nov 2026 03:42:41 +0100 Subject: [PATCH] refactor: rename the import methods and the module variables (Sonar S1669) (#363) import and module are contextual keywords of C++20 modules. The text loaders of the scene nodes (shape_node, lines_node, road_node, junction_node, roadpoint_node, sweep_node) become import_from(), the WASM module of the screen host's cache entry and of load() becomes wasm_module, and the path of the written test module becomes module_path. Renames only. --- scene/scenenode.cpp | 4 ++-- scene/scenenode.h | 4 ++-- scene/sceneterrain.cpp | 4 ++-- scripting/wasmprogram.cpp | 20 ++++++++++---------- simulation/simulationstateserializer.cpp | 12 ++++++------ tests/unit/test_script_screen_host.cpp | 18 +++++++++--------- world/Road.cpp | 4 ++-- world/Road.h | 4 ++-- world/RoadPoint.cpp | 2 +- world/RoadPoint.h | 2 +- world/Sweep.cpp | 2 +- world/Sweep.h | 2 +- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/scene/scenenode.cpp b/scene/scenenode.cpp index 426f0e077..18b1905a4 100644 --- a/scene/scenenode.cpp +++ b/scene/scenenode.cpp @@ -143,7 +143,7 @@ shape_node::deserialize( std::istream &Input ) { // restores content of the node from provided input stream shape_node & -shape_node::import( cParser &Input, scene::node_data const &Nodedata ) { +shape_node::import_from( cParser &Input, scene::node_data const &Nodedata ) { // import common data m_name = Nodedata.name; @@ -561,7 +561,7 @@ lines_node::deserialize( std::istream &Input ) { // restores content of the node from provded input stream lines_node & -lines_node::import( cParser &Input, scene::node_data const &Nodedata ) { +lines_node::import_from( cParser &Input, scene::node_data const &Nodedata ) { // import common data m_name = Nodedata.name; diff --git a/scene/scenenode.h b/scene/scenenode.h index 237056669..a534f0631 100644 --- a/scene/scenenode.h +++ b/scene/scenenode.h @@ -122,7 +122,7 @@ public: deserialize( std::istream &Input ); // restores content of the node from provided input stream shape_node & - import( cParser &Input, scene::node_data const &Nodedata ); + import_from( cParser &Input, scene::node_data const &Nodedata ); // imports data from provided submodel shape_node & convert( TSubModel const *Submodel ); @@ -254,7 +254,7 @@ public: deserialize( std::istream &Input ); // restores content of the node from provided input stream lines_node & - import( cParser &Input, scene::node_data const &Nodedata ); + import_from( cParser &Input, scene::node_data const &Nodedata ); // adds content of provided node to already enclosed geometry. returns: true if merge could be performed bool merge( lines_node &Lines ); diff --git a/scene/sceneterrain.cpp b/scene/sceneterrain.cpp index d0453f2b3..585912a2b 100644 --- a/scene/sceneterrain.cpp +++ b/scene/sceneterrain.cpp @@ -455,7 +455,7 @@ bool terrain_file::write(std::string const &Text, std::string const &Binaryfile, Message = "node of type \"" + nodedata.type + "\" (line " + std::to_string(input.Line()) + ") can't be a part of binary terrain"; return false; } - auto shape{shape_node().import(input, nodedata)}; + auto shape{shape_node().import_from(input, nodedata)}; // the shapes are all sent to the section cells, which groups them the way it'd be done for translucent geometry. // whether they can be merged into section-wide pieces instead is decided when the file is loaded, see the layout notes shape.m_data.translucent = true; @@ -799,7 +799,7 @@ bool read_text_triangles(std::string const &Text, terrain_reference const &Refer input >> nodedata.range_max >> nodedata.range_min >> nodedata.name >> nodedata.type; if (nodedata.type == "triangles" || nodedata.type == "triangle_strip" || nodedata.type == "triangle_fan") { - auto const shape{shape_node().import(input, nodedata)}; + auto const shape{shape_node().import_from(input, nodedata)}; auto const &data{shape.data()}; auto const *material{GfxRenderer->Material(data.material)}; auto const name{material != nullptr ? material->GetName() : std::string{}}; diff --git a/scripting/wasmprogram.cpp b/scripting/wasmprogram.cpp index 422ce70dc..1a1751732 100644 --- a/scripting/wasmprogram.cpp +++ b/scripting/wasmprogram.cpp @@ -523,9 +523,9 @@ class wasm_runtime_host final : public runtime { for (auto const &[script, entry] : m_modules) { - if (entry.module != nullptr) + if (entry.wasm_module != nullptr) { - wasm_runtime_unload(entry.module); + wasm_runtime_unload(entry.wasm_module); } } if (m_started) @@ -551,7 +551,7 @@ class wasm_runtime_host final : public runtime struct module_entry { std::vector bytes; // the runtime reads the module from here as long as it is loaded - wasm_module_t module{nullptr}; + wasm_module_t wasm_module{nullptr}; }; wasm_module_t load_module(std::string const &Script); @@ -584,7 +584,7 @@ wasm_module_t wasm_runtime_host::load_module(std::string const &Script) { if (auto const lookup{m_modules.find(Script)}; lookup != m_modules.end()) { - return lookup->second.module; + return lookup->second.wasm_module; } // a failure is kept as well, so the module isn't tried again for every screen using it auto &entry{m_modules[Script]}; @@ -601,23 +601,23 @@ wasm_module_t wasm_runtime_host::load_module(std::string const &Script) return nullptr; } std::array error{}; - entry.module = wasm_runtime_load(entry.bytes.data(), static_cast(entry.bytes.size()), error.data(), static_cast(error.size())); - if (entry.module == nullptr) + entry.wasm_module = wasm_runtime_load(entry.bytes.data(), static_cast(entry.bytes.size()), error.data(), static_cast(error.size())); + if (entry.wasm_module == nullptr) { ErrorLog(std::format("WASM screen \"{}\": failed to load the module: {}", Script, error.data())); } - return entry.module; + return entry.wasm_module; } std::unique_ptr wasm_runtime_host::load(std::string const &Script, script_screen_kind const Kind) { - auto *module{load_module(Script)}; - if (module == nullptr) + auto *wasm_module{load_module(Script)}; + if (wasm_module == nullptr) { return nullptr; } auto loaded{std::make_unique(Script, Kind)}; - if (false == loaded->instantiate(module)) + if (false == loaded->instantiate(wasm_module)) { return nullptr; } diff --git a/simulation/simulationstateserializer.cpp b/simulation/simulationstateserializer.cpp index 60854482c..da3e075ef 100644 --- a/simulation/simulationstateserializer.cpp +++ b/simulation/simulationstateserializer.cpp @@ -576,7 +576,7 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch else if( nodedata.type == "road" ) { auto *road { new road_node( nodedata ) }; - road->import( + road->import_from( Input, ( Scratchpad.location.offset.empty() ? glm::dvec3 { 0.0 } : @@ -592,7 +592,7 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch else if( nodedata.type == "sweep" ) { auto *sweep { new sweep_node( nodedata ) }; - sweep->import( + sweep->import_from( Input, ( Scratchpad.location.offset.empty() ? glm::dvec3 { 0.0 } : @@ -606,7 +606,7 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch else if( nodedata.type == "junction" ) { auto *junction { new junction_node( nodedata ) }; - junction->import( + junction->import_from( Input, ( Scratchpad.location.offset.empty() ? glm::dvec3 { 0.0 } : @@ -638,7 +638,7 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch else if( roadpoint_node::is_keyword( nodedata.type ) ) { // level crossing, or a point where road vehicles appear or are taken away auto *point { new roadpoint_node( nodedata ) }; - point->import( + point->import_from( Input, ( Scratchpad.location.offset.empty() ? glm::dvec3 { 0.0 } : @@ -739,7 +739,7 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch if( false == skip ) { ++Scratchpad.binary.geometry_imported; - auto shape { scene::shape_node().import( Input, nodedata ) }; + auto shape { scene::shape_node().import_from( Input, nodedata ) }; material = shape.data().material; if( true == Global.editor_session ) { shape.source_file( scene::terrain_file::reference_of( Input.Name() ) ); @@ -777,7 +777,7 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch ++Scratchpad.binary.geometry_imported; simulation::Region->insert( - scene::lines_node().import( + scene::lines_node().import_from( Input, nodedata ), Scratchpad ); } diff --git a/tests/unit/test_script_screen_host.cpp b/tests/unit/test_script_screen_host.cpp index c4226da40..6add4f008 100644 --- a/tests/unit/test_script_screen_host.cpp +++ b/tests/unit/test_script_screen_host.cpp @@ -285,16 +285,16 @@ constexpr std::array flood_module{ TEST_CASE("wasm screens: a cab screen draws from its input and sends commands to its vehicle") { sent_commands().clear(); script_folder const folder{"wasm_paint"}; - auto const module{folder.write("paint.wasm", paint_module)}; + auto const module_path{folder.write("paint.wasm", paint_module)}; script_screen_queue queue; REQUIRE(queue.init()); REQUIRE(queue.runs(script_language::wasm)); recording_texture texture; - auto const screen{queue.acquire(request(script_language::wasm, module, "cab", &texture))}; + auto const screen{queue.acquire(request(script_language::wasm, module_path, "cab", &texture))}; REQUIRE(screen != nullptr); // the same key, the same screen - CHECK(queue.acquire(request(script_language::wasm, module, "cab", &texture)) == screen); + CHECK(queue.acquire(request(script_language::wasm, module_path, "cab", &texture)) == screen); refresh(queue, screen, speed(5.0), 42); REQUIRE(run_until(queue, [&texture] { return texture.uploads > 0 && false == sent_commands().empty(); })); @@ -321,13 +321,13 @@ TEST_CASE("wasm screens: a cab screen draws from its input and sends commands to TEST_CASE("wasm screens: the image goes up again when the texture is made anew, and waits while it isn't there") { sent_commands().clear(); script_folder const folder{"wasm_reupload"}; - auto const module{folder.write("paint.wasm", paint_module)}; + auto const module_path{folder.write("paint.wasm", paint_module)}; script_screen_queue queue; REQUIRE(queue.init()); recording_texture texture; texture.ready = false; - auto const screen{queue.acquire(request(script_language::wasm, module, "cab", &texture))}; + auto const screen{queue.acquire(request(script_language::wasm, module_path, "cab", &texture))}; refresh(queue, screen, speed(9.0), 1); REQUIRE(run_until(queue, [] { return false == sent_commands().empty(); })); queue.update(); @@ -350,12 +350,12 @@ TEST_CASE("wasm screens: the image goes up again when the texture is made anew, TEST_CASE("wasm screens: a screen outside the cab draws, but its commands are dropped") { sent_commands().clear(); script_folder const folder{"wasm_sign"}; - auto const module{folder.write("paint.wasm", paint_module)}; + auto const module_path{folder.write("paint.wasm", paint_module)}; script_screen_queue queue; REQUIRE(queue.init()); recording_texture texture; - auto const screen{queue.acquire(request(script_language::wasm, module, "sign", &texture, script_screen_kind::external))}; + auto const screen{queue.acquire(request(script_language::wasm, module_path, "sign", &texture, script_screen_kind::external))}; refresh(queue, screen, speed(3.0), 0); REQUIRE(run_until(queue, [&texture] { return texture.uploads > 0; })); queue.update(); @@ -388,13 +388,13 @@ TEST_CASE("wasm screens: a screen stuck in a loop is stopped, and the others kee TEST_CASE("wasm screens: the screens outlive the queue without harm") { script_folder const folder{"wasm_outlive"}; - auto const module{folder.write("paint.wasm", paint_module)}; + auto const module_path{folder.write("paint.wasm", paint_module)}; std::shared_ptr screen; recording_texture texture; { script_screen_queue queue; REQUIRE(queue.init()); - screen = queue.acquire(request(script_language::wasm, module, "cab", &texture)); + screen = queue.acquire(request(script_language::wasm, module_path, "cab", &texture)); refresh(queue, screen, speed(4.0), 1); REQUIRE(run_until(queue, [&texture] { return texture.uploads > 0; })); } diff --git a/world/Road.cpp b/world/Road.cpp index 26b458c16..79fc54f84 100644 --- a/world/Road.cpp +++ b/world/Road.cpp @@ -875,7 +875,7 @@ glm::dvec3 road_node::state::tangent(double const T) const road_node::road_node(scene::node_data const &Nodedata) : basic_node(Nodedata) {} // restores content of the node from provided input stream; reads up to and including the closing 'endroad' -void road_node::import(cParser &Input, glm::dvec3 const &Offset) +void road_node::import_from(cParser &Input, glm::dvec3 const &Offset) { auto const label{m_name.empty() ? std::string{"unnamed road"} : "road \"" + m_name + "\""}; @@ -2307,7 +2307,7 @@ std::vector junction_node::state::outline(std::vector roadpoint_node::parse_vehicles(std::st } // restores content of the node from provided input stream; reads up to and including the closing statement -void roadpoint_node::import(cParser &Input, glm::dvec3 const &Offset) +void roadpoint_node::import_from(cParser &Input, glm::dvec3 const &Offset) { auto const type{keyword(m_state.kind)}; auto const label{type + " \"" + m_name + "\""}; diff --git a/world/RoadPoint.h b/world/RoadPoint.h index 3ad45b4c3..670eb0fb1 100644 --- a/world/RoadPoint.h +++ b/world/RoadPoint.h @@ -97,7 +97,7 @@ class roadpoint_node : public scene::basic_node explicit roadpoint_node(scene::node_data const &Nodedata); // methods // restores content of the node from provided input stream; reads up to and including the closing statement - void import(cParser &Input, glm::dvec3 const &Offset); + void import_from(cParser &Input, glm::dvec3 const &Offset); state const &definition() const { return m_state; diff --git a/world/Sweep.cpp b/world/Sweep.cpp index 31587fe7d..9c5638cf3 100644 --- a/world/Sweep.cpp +++ b/world/Sweep.cpp @@ -404,7 +404,7 @@ bool sweep_node::state::operator==(state const &Other) const sweep_node::sweep_node(scene::node_data const &Nodedata) : basic_node(Nodedata) {} -void sweep_node::import(cParser &Input, glm::dvec3 const &Offset) +void sweep_node::import_from(cParser &Input, glm::dvec3 const &Offset) { m_state = state{}; m_state.model = Input.getToken(); diff --git a/world/Sweep.h b/world/Sweep.h index 2e65f5fa9..b83b7fa12 100644 --- a/world/Sweep.h +++ b/world/Sweep.h @@ -91,7 +91,7 @@ class sweep_node : public scene::basic_node explicit sweep_node(scene::node_data const &Nodedata); - void import(cParser &Input, glm::dvec3 const &Offset); + void import_from(cParser &Input, glm::dvec3 const &Offset); void define(state const &State); state const &definition() const {