Skip to content

Commit 5e848d2

Browse files
committed
chore: enhancing code with cppcheck suggestions
1 parent c5673fd commit 5e848d2

File tree

7 files changed

+37
-28
lines changed

7 files changed

+37
-28
lines changed

include/Ark/Compiler/Lowerer/ASTLowerer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ namespace Ark::internal
180180
*/
181181
void compileExpression(Node& x, Page p, bool is_result_unused, bool is_terminal);
182182

183-
void compileSymbol(Node& x, Page p, bool is_result_unused);
183+
void compileSymbol(const Node& x, Page p, bool is_result_unused);
184184
void compileListInstruction(Node& x, Page p, bool is_result_unused);
185185
void compileIf(Node& x, Page p, bool is_result_unused, bool is_terminal);
186186
void compileFunction(Node& x, Page p, bool is_result_unused);
187187
void compileLetMutSet(Keyword n, Node& x, Page p);
188188
void compileWhile(Node& x, Page p);
189-
void compilePluginImport(Node& x, Page p);
189+
void compilePluginImport(const Node& x, Page p);
190190
void pushFunctionCallArguments(Node& call, Page p, bool is_tail_call);
191191
void handleCalls(Node& x, Page p, bool is_result_unused, bool is_terminal);
192192

src/arkreactor/Builtins/Dict.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Ark::internal::Builtins::Dict
1717
* =end
1818
* @author https://github.com/SuperFola
1919
*/
20+
// cppcheck-suppress constParameterReference
2021
Value dict(std::vector<Value>& n, VM* vm [[maybe_unused]])
2122
{
2223
if (n.size() % 2 != 0)

src/arkreactor/Builtins/IO.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ namespace Ark::internal::Builtins::IO
7878
return Value(line);
7979
}
8080

81+
// cppcheck-suppress constParameterReference
8182
Value writeFile(std::vector<Value>& n, VM* vm [[maybe_unused]])
8283
{
8384
if (types::check(n, ValueType::String, ValueType::Any))
@@ -102,6 +103,7 @@ namespace Ark::internal::Builtins::IO
102103
return nil;
103104
}
104105

106+
// cppcheck-suppress constParameterReference
105107
Value appendToFile(std::vector<Value>& n, VM* vm [[maybe_unused]])
106108
{
107109
if (types::check(n, ValueType::String, ValueType::Any))

src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ namespace Ark::internal
241241
x);
242242
}
243243

244-
void ASTLowerer::compileSymbol(Node& x, const Page p, const bool is_result_unused)
244+
void ASTLowerer::compileSymbol(const Node& x, const Page p, const bool is_result_unused)
245245
{
246246
const std::string& name = x.string();
247247

@@ -504,7 +504,7 @@ namespace Ark::internal
504504
m_locals_locator.deleteScope();
505505
}
506506

507-
void ASTLowerer::compilePluginImport(Node& x, const Page p)
507+
void ASTLowerer::compilePluginImport(const Node& x, const Page p)
508508
{
509509
std::string path;
510510
const Node package_node = x.constList()[1];

src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,20 @@ namespace Ark::internal
144144
// if we had specific symbols to import, check that those exist
145145
if (!namespace_.symbols.empty())
146146
{
147-
for (const auto& sym : namespace_.symbols)
148-
{
149-
if (!scope->get(sym, true).has_value())
150-
throw CodeError(
151-
fmt::format("ImportError: Can not import symbol {} from {}, as it isn't in the package", sym, namespace_.name),
152-
CodeErrorContext(
153-
namespace_.ast->filename(),
154-
namespace_.ast->line(),
155-
namespace_.ast->col(),
156-
"import"));
157-
}
147+
const auto it = std::ranges::find_if(
148+
namespace_.symbols,
149+
[&scope](const std::string& sym) -> bool {
150+
return !scope->get(sym, true).has_value();
151+
});
152+
153+
if (it != namespace_.symbols.end())
154+
throw CodeError(
155+
fmt::format("ImportError: Can not import symbol {} from {}, as it isn't in the package", *it, namespace_.name),
156+
CodeErrorContext(
157+
namespace_.ast->filename(),
158+
namespace_.ast->line(),
159+
namespace_.ast->col(),
160+
"import"));
158161
}
159162

160163
m_scope_resolver.saveNamespaceAndRemove();
@@ -266,7 +269,7 @@ namespace Ark::internal
266269
// update the declared variable name to use the fully qualified name
267270
// this will prevent name conflicts, and handle scope resolution
268271
std::string old_name = child.string();
269-
std::string fqn = updateSymbolWithFullyQualifiedName(child);
272+
updateSymbolWithFullyQualifiedName(child);
270273
// FIXME: addDefinedSymbol(fqn, true); ?
271274
addDefinedSymbol(old_name, true);
272275
}

src/arkreactor/VM/Future.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Ark::internal
66
{
7+
// cppcheck-suppress constParameterReference
78
Future::Future(ExecutionContext* context, VM* vm, std::vector<Value>& args)
89
{
910
m_value = std::async(

src/arkreactor/VM/VM.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,21 @@ namespace Ark
353353

354354
if (m_execution_contexts.size() > 1)
355355
{
356-
for (std::size_t i = 0; i < m_execution_contexts.size(); ++i)
356+
const auto it = std::ranges::find_if(
357+
m_execution_contexts,
358+
[](const std::unique_ptr<ExecutionContext>& context) -> bool {
359+
return !context->primary && context->isFree();
360+
});
361+
362+
if (it != m_execution_contexts.end())
357363
{
358-
if (!m_execution_contexts[i]->primary && m_execution_contexts[i]->isFree())
359-
{
360-
ctx = m_execution_contexts[i].get();
361-
ctx->setActive(true);
362-
// reset the context before using it
363-
ctx->sp = 0;
364-
ctx->saved_scope.reset();
365-
ctx->stacked_closure_scopes.clear();
366-
ctx->locals.clear();
367-
break;
368-
}
364+
ctx = it->get();
365+
ctx->setActive(true);
366+
// reset the context before using it
367+
ctx->sp = 0;
368+
ctx->saved_scope.reset();
369+
ctx->stacked_closure_scopes.clear();
370+
ctx->locals.clear();
369371
}
370372
}
371373

0 commit comments

Comments
 (0)