Skip to content

Commit b5af1db

Browse files
committed
chore: following cppcheck recommandations
1 parent 3a91c5a commit b5af1db

File tree

23 files changed

+198
-158
lines changed

23 files changed

+198
-158
lines changed

include/Ark/Compiler/AST/Node.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @brief AST node used by the parser, optimizer and compiler
55
* @date 2020-10-27
66
*
7-
* @copyright Copyright (c) 2020-2024
7+
* @copyright Copyright (c) 2020-2025
88
*
99
*/
1010

@@ -39,7 +39,7 @@ namespace Ark::internal
3939
explicit Node(double value);
4040
explicit Node(long value);
4141
explicit Node(Keyword value);
42-
explicit Node(Namespace namespace_);
42+
explicit Node(const Namespace& namespace_);
4343

4444
/**
4545
* @brief Return the string held by the value (if the node type allows it)
@@ -218,7 +218,7 @@ namespace Ark::internal
218218
friend bool operator<(const Node& A, const Node& B);
219219

220220
private:
221-
NodeType m_type;
221+
NodeType m_type { NodeType::Unused };
222222
Value m_value;
223223
// position of the node in the original code, useful when it comes to parser errors
224224
std::size_t m_line = 0, m_col = 0;

include/Ark/Compiler/NameResolution/StaticScope.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @brief Static scopes (for functions, loops) and namespace scopes (for packages) definitions, used at compile time
55
* @date 2024-11-30
66
*
7-
* @copyright Copyright (c) 2024
7+
* @copyright Copyright (c) 2024-2025
88
*
99
*/
1010

@@ -141,20 +141,7 @@ namespace Ark::internal
141141
[[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
142142
[[nodiscard]] inline std::string prefix() const override { return m_namespace; }
143143
[[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
144-
[[nodiscard]] inline bool recursiveHasSymbol(const std::string& symbol) override
145-
{
146-
if (hasSymbol(symbol))
147-
return true;
148-
if (isGlob() && std::ranges::find(m_vars, fullyQualifiedName(symbol), &Declaration::name) != m_vars.end())
149-
return true;
150-
151-
for (const auto& saved_scope : m_additional_namespaces)
152-
{
153-
if (saved_scope->recursiveHasSymbol(symbol))
154-
return true;
155-
}
156-
return false;
157-
}
144+
[[nodiscard]] bool recursiveHasSymbol(const std::string& symbol) override;
158145

159146
private:
160147
std::string m_namespace;

include/Ark/VM/VM.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ inline void VM::call(internal::ExecutionContext& context, const uint16_t argc)
300300
// is it a user defined closure?
301301
case ValueType::Closure:
302302
{
303-
Closure& c = function.refClosure();
303+
const Closure& c = function.closure();
304304
const PageAddr_t new_page_pointer = c.pageAddr();
305305

306306
// create dedicated scope

src/arkreactor/Builtins/IO.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ namespace Ark::internal::Builtins::IO
2121
* =end
2222
* @author https://github.com/SuperFola
2323
*/
24+
// cppcheck-suppress constParameterReference
2425
Value print(std::vector<Value>& n, VM* vm)
2526
{
26-
for (auto& value : n)
27+
for (const auto& value : n)
2728
fmt::print("{}", value.toString(*vm));
2829
fmt::println("");
2930

@@ -40,9 +41,10 @@ namespace Ark::internal::Builtins::IO
4041
* =end
4142
* @author https://github.com/SuperFola
4243
*/
44+
// cppcheck-suppress constParameterReference
4345
Value puts_(std::vector<Value>& n, VM* vm)
4446
{
45-
for (auto& value : n)
47+
for (const auto& value : n)
4648
fmt::print("{}", value.toString(*vm));
4749

4850
return nil;
@@ -58,6 +60,7 @@ namespace Ark::internal::Builtins::IO
5860
* =end
5961
* @author https://github.com/SuperFola
6062
*/
63+
// cppcheck-suppress constParameterReference
6164
Value input(std::vector<Value>& n, VM* vm [[maybe_unused]])
6265
{
6366
if (types::check(n, ValueType::String))
@@ -144,6 +147,7 @@ namespace Ark::internal::Builtins::IO
144147
* =end
145148
* @author https://github.com/SuperFola
146149
*/
150+
// cppcheck-suppress constParameterReference
147151
Value readFile(std::vector<Value>& n, VM* vm [[maybe_unused]])
148152
{
149153
if (!types::check(n, ValueType::String))
@@ -169,6 +173,7 @@ namespace Ark::internal::Builtins::IO
169173
* =end
170174
* @author https://github.com/SuperFola
171175
*/
176+
// cppcheck-suppress constParameterReference
172177
Value fileExists(std::vector<Value>& n, VM* vm [[maybe_unused]])
173178
{
174179
if (!types::check(n, ValueType::String))
@@ -189,6 +194,7 @@ namespace Ark::internal::Builtins::IO
189194
* =end
190195
* @author https://github.com/SuperFola
191196
*/
197+
// cppcheck-suppress constParameterReference
192198
Value listFiles(std::vector<Value>& n, VM* vm [[maybe_unused]])
193199
{
194200
if (!types::check(n, ValueType::String))
@@ -215,6 +221,7 @@ namespace Ark::internal::Builtins::IO
215221
* =end
216222
* @author https://github.com/SuperFola
217223
*/
224+
// cppcheck-suppress constParameterReference
218225
Value isDirectory(std::vector<Value>& n, VM* vm [[maybe_unused]])
219226
{
220227
if (!types::check(n, ValueType::String))
@@ -235,6 +242,7 @@ namespace Ark::internal::Builtins::IO
235242
* =end
236243
* @author https://github.com/SuperFola
237244
*/
245+
// cppcheck-suppress constParameterReference
238246
Value makeDir(std::vector<Value>& n, VM* vm [[maybe_unused]])
239247
{
240248
if (!types::check(n, ValueType::String))
@@ -257,6 +265,7 @@ namespace Ark::internal::Builtins::IO
257265
* =end
258266
* @author https://github.com/SuperFola
259267
*/
268+
// cppcheck-suppress constParameterReference
260269
Value removeFiles(std::vector<Value>& n, VM* vm [[maybe_unused]])
261270
{
262271
if (n.empty() || n[0].valueType() != ValueType::String)

src/arkreactor/Builtins/Mathematics.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Ark::internal::Builtins::Mathematics
1919
* =end
2020
* @author https://github.com/SuperFola
2121
*/
22+
// cppcheck-suppress constParameterReference
2223
Value exponential(std::vector<Value>& n, VM* vm [[maybe_unused]])
2324
{
2425
if (!types::check(n, ValueType::Number))
@@ -39,6 +40,7 @@ namespace Ark::internal::Builtins::Mathematics
3940
* =end
4041
* @author https://github.com/SuperFola
4142
*/
43+
// cppcheck-suppress constParameterReference
4244
Value logarithm(std::vector<Value>& n, VM* vm [[maybe_unused]])
4345
{
4446
if (!types::check(n, ValueType::Number))
@@ -62,6 +64,7 @@ namespace Ark::internal::Builtins::Mathematics
6264
* =end
6365
* @author https://github.com/SuperFola
6466
*/
67+
// cppcheck-suppress constParameterReference
6568
Value ceil_(std::vector<Value>& n, VM* vm [[maybe_unused]])
6669
{
6770
if (!types::check(n, ValueType::Number))
@@ -82,6 +85,7 @@ namespace Ark::internal::Builtins::Mathematics
8285
* =end
8386
* @author https://github.com/SuperFola
8487
*/
88+
// cppcheck-suppress constParameterReference
8589
Value floor_(std::vector<Value>& n, VM* vm [[maybe_unused]])
8690
{
8791
if (!types::check(n, ValueType::Number))
@@ -103,6 +107,7 @@ namespace Ark::internal::Builtins::Mathematics
103107
* =end
104108
* @author https://github.com/SuperFola
105109
*/
110+
// cppcheck-suppress constParameterReference
106111
Value round_(std::vector<Value>& n, VM* vm [[maybe_unused]])
107112
{
108113
if (!types::check(n, ValueType::Number))
@@ -124,6 +129,7 @@ namespace Ark::internal::Builtins::Mathematics
124129
* =end
125130
* @author https://github.com/SuperFola
126131
*/
132+
// cppcheck-suppress constParameterReference
127133
Value isnan_(std::vector<Value>& n, VM* vm [[maybe_unused]])
128134
{
129135
if (n[0].valueType() != ValueType::Number)
@@ -142,6 +148,7 @@ namespace Ark::internal::Builtins::Mathematics
142148
* =end
143149
* @author https://github.com/SuperFola
144150
*/
151+
// cppcheck-suppress constParameterReference
145152
Value isinf_(std::vector<Value>& n, VM* vm [[maybe_unused]])
146153
{
147154
if (n[0].valueType() != ValueType::Number)
@@ -160,6 +167,7 @@ namespace Ark::internal::Builtins::Mathematics
160167
* =end
161168
* @author https://github.com/SuperFola
162169
*/
170+
// cppcheck-suppress constParameterReference
163171
Value cos_(std::vector<Value>& n, VM* vm [[maybe_unused]])
164172
{
165173
if (!types::check(n, ValueType::Number))
@@ -181,6 +189,7 @@ namespace Ark::internal::Builtins::Mathematics
181189
* =end
182190
* @author https://github.com/SuperFola
183191
*/
192+
// cppcheck-suppress constParameterReference
184193
Value sin_(std::vector<Value>& n, VM* vm [[maybe_unused]])
185194
{
186195
if (!types::check(n, ValueType::Number))
@@ -202,6 +211,7 @@ namespace Ark::internal::Builtins::Mathematics
202211
* =end
203212
* @author https://github.com/SuperFola
204213
*/
214+
// cppcheck-suppress constParameterReference
205215
Value tan_(std::vector<Value>& n, VM* vm [[maybe_unused]])
206216
{
207217
if (!types::check(n, ValueType::Number))
@@ -222,6 +232,7 @@ namespace Ark::internal::Builtins::Mathematics
222232
* =end
223233
* @author https://github.com/SuperFola
224234
*/
235+
// cppcheck-suppress constParameterReference
225236
Value acos_(std::vector<Value>& n, VM* vm [[maybe_unused]])
226237
{
227238
if (!types::check(n, ValueType::Number))
@@ -242,6 +253,7 @@ namespace Ark::internal::Builtins::Mathematics
242253
* =end
243254
* @author https://github.com/SuperFola
244255
*/
256+
// cppcheck-suppress constParameterReference
245257
Value asin_(std::vector<Value>& n, VM* vm [[maybe_unused]])
246258
{
247259
if (!types::check(n, ValueType::Number))
@@ -262,6 +274,7 @@ namespace Ark::internal::Builtins::Mathematics
262274
* =end
263275
* @author https://github.com/SuperFola
264276
*/
277+
// cppcheck-suppress constParameterReference
265278
Value atan_(std::vector<Value>& n, VM* vm [[maybe_unused]])
266279
{
267280
if (!types::check(n, ValueType::Number))
@@ -279,6 +292,7 @@ namespace Ark::internal::Builtins::Mathematics
279292
* @param value the Number
280293
* @author https://github.com/Gryfenfer97
281294
*/
295+
// cppcheck-suppress constParameterReference
282296
Value cosh_(std::vector<Value>& n, VM* vm [[maybe_unused]])
283297
{
284298
if (!types::check(n, ValueType::Number))
@@ -296,6 +310,7 @@ namespace Ark::internal::Builtins::Mathematics
296310
* @param value the Number
297311
* @author https://github.com/Gryfenfer97
298312
*/
313+
// cppcheck-suppress constParameterReference
299314
Value sinh_(std::vector<Value>& n, VM* vm [[maybe_unused]])
300315
{
301316
if (!types::check(n, ValueType::Number))
@@ -313,6 +328,7 @@ namespace Ark::internal::Builtins::Mathematics
313328
* @param value the Number
314329
* @author https://github.com/Gryfenfer97
315330
*/
331+
// cppcheck-suppress constParameterReference
316332
Value tanh_(std::vector<Value>& n, VM* vm [[maybe_unused]])
317333
{
318334
if (!types::check(n, ValueType::Number))
@@ -330,6 +346,7 @@ namespace Ark::internal::Builtins::Mathematics
330346
* @param value the Number
331347
* @author https://github.com/Gryfenfer97
332348
*/
349+
// cppcheck-suppress constParameterReference
333350
Value acosh_(std::vector<Value>& n, VM* vm [[maybe_unused]])
334351
{
335352
if (!types::check(n, ValueType::Number))
@@ -347,6 +364,7 @@ namespace Ark::internal::Builtins::Mathematics
347364
* @param value the Number
348365
* @author https://github.com/Gryfenfer97
349366
*/
367+
// cppcheck-suppress constParameterReference
350368
Value asinh_(std::vector<Value>& n, VM* vm [[maybe_unused]])
351369
{
352370
if (!types::check(n, ValueType::Number))
@@ -364,6 +382,7 @@ namespace Ark::internal::Builtins::Mathematics
364382
* @param value the Number
365383
* @author https://github.com/Gryfenfer97
366384
*/
385+
// cppcheck-suppress constParameterReference
367386
Value atanh_(std::vector<Value>& n, VM* vm [[maybe_unused]])
368387
{
369388
if (!types::check(n, ValueType::Number))
@@ -386,6 +405,7 @@ namespace Ark::internal::Builtins::Mathematics
386405
* =end
387406
* @author https://github.com/SuperFola
388407
*/
408+
// cppcheck-suppress constParameterReference
389409
Value random(std::vector<Value>& n, VM* vm [[maybe_unused]])
390410
{
391411
static std::mt19937 gen { std::random_device()() };

src/arkreactor/Builtins/String.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ namespace Ark::internal::Builtins::String
163163
* =end
164164
* @author https://github.com/SuperFola
165165
*/
166+
// cppcheck-suppress constParameterReference
166167
Value chr(std::vector<Value>& n, VM* vm [[maybe_unused]])
167168
{
168169
if (!types::check(n, ValueType::Number))

src/arkreactor/Builtins/System.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace Ark::internal::Builtins::System
4040
* =end
4141
* @author https://github.com/SuperFola
4242
*/
43+
// cppcheck-suppress constParameterReference
4344
Value system_(std::vector<Value>& n, VM* vm [[maybe_unused]])
4445
{
4546
if (!types::check(n, ValueType::String))
@@ -72,6 +73,7 @@ namespace Ark::internal::Builtins::System
7273
* =end
7374
* @author https://github.com/SuperFola
7475
*/
76+
// cppcheck-suppress constParameterReference
7577
Value sleep(std::vector<Value>& n, VM* vm [[maybe_unused]])
7678
{
7779
if (!types::check(n, ValueType::Number))
@@ -96,6 +98,7 @@ namespace Ark::internal::Builtins::System
9698
* =end
9799
* @author https://github.com/SuperFola
98100
*/
101+
// cppcheck-suppress constParameterReference
99102
Value exit_(std::vector<Value>& n, VM* vm)
100103
{
101104
if (!types::check(n, ValueType::Number))

src/arkreactor/Compiler/AST/BaseParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ namespace Ark::internal
2525

2626
for (std::size_t i = 0, end = m_it_to_row.size(); i < end; ++i)
2727
{
28-
auto current = m_it_to_row[i].first;
29-
auto next = i + 1 < end ? m_it_to_row[i + 1].first : m_str.end();
30-
if (current < it && it < next)
28+
auto current_it = m_it_to_row[i].first;
29+
auto next_it = i + 1 < end ? m_it_to_row[i + 1].first : m_str.end();
30+
if (current_it < it && it < next_it)
3131
{
3232
m_it_to_row.insert(
3333
m_it_to_row.begin() + static_cast<decltype(m_it_to_row)::difference_type>(i) + 1,

src/arkreactor/Compiler/AST/Node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace Ark::internal
3030
m_type(NodeType::Keyword), m_value(value)
3131
{}
3232

33-
Node::Node(Namespace namespace_) :
33+
Node::Node(const Namespace& namespace_) :
3434
m_type(NodeType::Namespace), m_value(namespace_)
3535
{}
3636

src/arkreactor/Compiler/AST/Optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace Ark::internal
4646
else if (node.nodeType() == NodeType::List)
4747
{
4848
// FIXME: very primitive removal of (if true/false ...) and (while false ...)
49-
if (node.constList().size() > 1 && node.constList().front().nodeType() == NodeType::Keyword &&
49+
if (node.constList().size() >= 2 && node.constList().front().nodeType() == NodeType::Keyword &&
5050
(node.constList().front().keyword() == Keyword::If || node.constList().front().keyword() == Keyword::While))
5151
{
5252
const auto keyword = node.constList().front().keyword();

0 commit comments

Comments
 (0)