Skip to content

Commit fa81b1d

Browse files
committed
fix: addressing cppcheck warnings
1 parent ebb9368 commit fa81b1d

File tree

12 files changed

+50
-53
lines changed

12 files changed

+50
-53
lines changed

include/Ark/Compiler/AST/Parser.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ namespace Ark::internal
174174

175175
std::optional<Node> field()
176176
{
177-
std::string symbol;
178-
if (!name(&symbol))
177+
std::string sym;
178+
if (!name(&sym))
179179
return std::nullopt;
180180

181181
std::optional<Node> leaf { Node(NodeType::Field) };
182182
setNodePosAndFilename(leaf.value());
183-
leaf->push_back(Node(NodeType::Symbol, symbol));
183+
leaf->push_back(Node(NodeType::Symbol, sym));
184184

185185
while (true)
186186
{

include/Ark/Compiler/AST/Predicates.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace Ark::internal
114114
explicit IsChar(const char c) :
115115
CharPred("'" + std::string(1, c) + "'"), m_k(c)
116116
{}
117-
explicit IsChar(const utf8_char_t c) :
117+
explicit IsChar(const utf8_char_t& c) :
118118
CharPred(std::string(c.c_str())), m_k(c.codepoint())
119119
{}
120120
bool operator()(const utf8_char_t::codepoint_t c) const override

include/Ark/Compiler/AST/utf8_char.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Ark::internal
2525
// https://github.com/sheredom/utf8.h/blob/4e4d828174c35e4564c31a9e35580c299c69a063/utf8.h#L1178
2626
static std::pair<std::string::iterator, utf8_char_t> at(std::string::iterator it, const std::string::iterator end)
2727
{
28-
codepoint_t codepoint;
28+
codepoint_t cp;
2929
length_t length;
3030
repr_t repr = {};
3131

@@ -34,7 +34,7 @@ namespace Ark::internal
3434
if (it + 3 == end || it + 2 == end || it + 1 == end)
3535
return std::make_pair(end, utf8_char_t {});
3636

37-
codepoint = (static_cast<codepoint_t>(0x07 & *it) << 18) |
37+
cp = (static_cast<codepoint_t>(0x07 & *it) << 18) |
3838
(static_cast<codepoint_t>(0x3f & *(it + 1)) << 12) |
3939
(static_cast<codepoint_t>(0x3f & *(it + 2)) << 6) |
4040
static_cast<codepoint_t>(0x3f & *(it + 3));
@@ -45,7 +45,7 @@ namespace Ark::internal
4545
if (it + 2 == end || it + 1 == end)
4646
return std::make_pair(end, utf8_char_t {});
4747

48-
codepoint = (static_cast<codepoint_t>(0x0f & *it) << 12) |
48+
cp = (static_cast<codepoint_t>(0x0f & *it) << 12) |
4949
(static_cast<codepoint_t>(0x3f & *(it + 1)) << 6) |
5050
static_cast<codepoint_t>(0x3f & *(it + 2));
5151
length = 3;
@@ -55,21 +55,21 @@ namespace Ark::internal
5555
if (it + 1 == end)
5656
return std::make_pair(end, utf8_char_t {});
5757

58-
codepoint = (static_cast<codepoint_t>(0x1f & *it) << 6) |
58+
cp = (static_cast<codepoint_t>(0x1f & *it) << 6) |
5959
static_cast<codepoint_t>(0x3f & *(it + 1));
6060
length = 2;
6161
}
6262
else // 1 byte utf8 codepoint otherwise
6363
{
64-
codepoint = static_cast<unsigned char>(*it);
64+
cp = static_cast<unsigned char>(*it);
6565
length = 1;
6666
}
6767

6868
for (length_t i = 0; i < length; ++i)
6969
repr[i] = static_cast<unsigned char>(*(it + static_cast<int>(i)));
7070

7171
return std::make_pair(it + static_cast<long>(length),
72-
utf8_char_t(codepoint, length, repr));
72+
utf8_char_t(cp, length, repr));
7373
}
7474

7575
[[nodiscard]] bool isPrintable() const

include/Ark/TypeChecker.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file TypeChecker.hpp
33
* @author Alexandre Plateau ([email protected])
44
* @brief
5-
* @version 0.4
5+
* @version 1.0
66
* @date 2022-01-16
77
*
88
* @copyright Copyright (c) 2022-2024
@@ -66,11 +66,11 @@ namespace Ark::types
6666
std::vector<ValueType> types;
6767
bool variadic;
6868

69-
Typedef(const std::string_view type_name, const ValueType type, const bool is_variadic = false) :
69+
Typedef(const std::string_view& type_name, const ValueType type, const bool is_variadic = false) :
7070
name(type_name), types { type }, variadic(is_variadic)
7171
{}
7272

73-
Typedef(const std::string_view type_name, const std::vector<ValueType>& type_list, const bool is_variadic = false) :
73+
Typedef(const std::string_view& type_name, const std::vector<ValueType>& type_list, const bool is_variadic = false) :
7474
name(type_name), types(type_list), variadic(is_variadic)
7575
{}
7676
};
@@ -91,7 +91,7 @@ namespace Ark::types
9191
* @param contracts types contracts the function can follow
9292
* @param args provided argument list
9393
*/
94-
ARK_API void generateError [[noreturn]] (std::string_view funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args);
94+
ARK_API void generateError [[noreturn]] (const std::string_view& funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args);
9595
}
9696

9797
#endif

src/arkreactor/Compiler/AST/BaseParser.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,9 @@ namespace Ark::internal
314314

315315
bool BaseParser::sequence(const std::string& s)
316316
{
317-
for (const char i : s)
318-
{
319-
if (!accept(IsChar(i)))
320-
return false;
321-
}
322-
323-
return true;
317+
return std::ranges::all_of(s, [this](const char c) {
318+
return accept(IsChar(c));
319+
});
324320
}
325321

326322
bool BaseParser::packageName(std::string* s)
@@ -354,11 +350,8 @@ namespace Ark::internal
354350
if (s)
355351
*s = buffer;
356352

357-
for (const auto& word : words)
358-
{
359-
if (word == buffer)
360-
return true;
361-
}
362-
return false;
353+
return std::ranges::any_of(words, [&buffer](const std::string& word) {
354+
return word == buffer;
355+
});
363356
}
364357
}

src/arkreactor/Compiler/Compiler.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ namespace Ark
141141
{
142142
// push the string, null terminated
143143
std::string s = sym.string();
144-
for (const char i : s)
145-
m_bytecode.push_back(static_cast<uint8_t>(i));
144+
std::ranges::transform(s, std::back_inserter(m_bytecode), [](const char i) {
145+
return static_cast<uint8_t>(i);
146+
});
146147
m_bytecode.push_back(0_u8);
147148
}
148149

@@ -161,15 +162,17 @@ namespace Ark
161162
m_bytecode.push_back(NUMBER_TYPE);
162163
const auto n = std::get<double>(val.value);
163164
std::string t = std::to_string(n);
164-
for (const char i : t)
165-
m_bytecode.push_back(static_cast<uint8_t>(i));
165+
std::ranges::transform(t, std::back_inserter(m_bytecode), [](const char i) {
166+
return static_cast<uint8_t>(i);
167+
});
166168
}
167169
else if (val.type == ValTableElemType::String)
168170
{
169171
m_bytecode.push_back(STRING_TYPE);
170172
auto t = std::get<std::string>(val.value);
171-
for (const char i : t)
172-
m_bytecode.push_back(static_cast<uint8_t>(i));
173+
std::ranges::transform(t, std::back_inserter(m_bytecode), [](const char i) {
174+
return static_cast<uint8_t>(i);
175+
});
173176
}
174177
else if (val.type == ValTableElemType::PageAddr)
175178
{

src/arkreactor/Compiler/ImportSolver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ namespace Ark::internal
148148
module_node.push_back(Node(Keyword::Import));
149149

150150
auto package_node = Node(NodeType::List);
151-
for (const std::string& stem : import.package)
152-
package_node.push_back(Node(NodeType::String, stem));
151+
std::ranges::transform(import.package, std::back_inserter(package_node.list()), [](const std::string& stem) {
152+
return Node(NodeType::String, stem);
153+
});
153154
module_node.push_back(package_node);
154155
// empty symbols list
155156
module_node.push_back(Node(NodeType::List));

src/arkreactor/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace Ark::types
7777
}
7878
}
7979

80-
[[noreturn]] void generateError(std::string_view funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args)
80+
[[noreturn]] void generateError(const std::string_view& funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args)
8181
{
8282
std::cout << "Function " << termcolor::blue << funcname << termcolor::reset << " expected ";
8383

src/arkreactor/VM/Future.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
namespace Ark::internal
66
{
77
Future::Future(ExecutionContext* context, VM* vm, std::vector<Value>& args) :
8-
m_context(context), m_vm(vm)
9-
{
10-
m_value = std::async(std::launch::async, [vm, context, args]() mutable {
8+
m_context(context), m_vm(vm), m_value(std::async(std::launch::async, [vm, context, args]() mutable {
119
return vm->resolve(context, args);
12-
});
13-
}
10+
}))
11+
{}
1412

1513
Value Future::resolve()
1614
{

src/arkreactor/VM/State.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ namespace Ark
125125
void State::setArgs(const std::vector<std::string>& args) noexcept
126126
{
127127
Value val(ValueType::List);
128-
for (const std::string& arg : args)
129-
val.push_back(Value(arg));
128+
std::ranges::transform(args, std::back_inserter(val.list()), [](const std::string& arg) {
129+
return Value(arg);
130+
});
130131
m_binded["sys:args"] = val;
131132

132133
m_binded["sys:platform"] = Value(ARK_PLATFORM_NAME);

0 commit comments

Comments
 (0)