Skip to content

Commit

Permalink
build with -Wall -Wextra -Werror
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Dec 21, 2024
1 parent 8563d5b commit d0eb2db
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ jobs:
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get install -y ninja-build
run: |
# Install ninja
sudo apt-get install -y ninja-build
# Update clang to version 18
sudo apt-get install -y clang-18
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-18 100
- name: Configure CMake project
run: |
mkdir build
cd build
cmake .. -DRIFT_BUILD_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang \
-G Ninja -DCMAKE_C_FLAGS="-Wall -Wextra -Werror" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -std=c++20" \
cmake .. -DRIFT_BUILD_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -G Ninja -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror"
- name: Build project
run: cmake --build build
Expand Down
1 change: 0 additions & 1 deletion include/rift/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ namespace rift {

Value operator-() const noexcept;
Value at(const Value& key) const noexcept;
Value operator->*(const Value& key) const noexcept;

// Object/Array access operators

Expand Down
10 changes: 5 additions & 5 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace rift {
// Cast functions
int64_t intCast(int64_t value) noexcept { return value; }
double floatCast(double value) noexcept { return value; }
std::string strCast(std::string value) noexcept { return std::move(value); }
std::string strCast(std::string value) noexcept { return value; }

// String functions
RuntimeFuncResult length(std::span<const Value> args) noexcept {
Expand Down Expand Up @@ -66,14 +66,14 @@ namespace rift {
// Make sure the start index is within bounds
if (start < 0) {
start = 0;
} else if (start >= str.size()) {
} else if (start >= static_cast<int64_t>(str.size())) {
return "";
}

// Make sure the count is within bounds
if (count < 0) {
count = 0;
} else if (count > str.size() - start) {
} else if (count > static_cast<int64_t>(str.size()) - start) {
count = str.size() - start;
}

Expand Down Expand Up @@ -232,7 +232,7 @@ namespace rift {
return geode::Err("Expected at least one argument");
}

auto min = std::move(args[0]);
auto min = args[0];
for (size_t i = 1; i < args.size(); ++i) {
if (args[i] < min) {
min = std::move(args[i]);
Expand All @@ -247,7 +247,7 @@ namespace rift {
return geode::Err("Expected at least one argument");
}

auto max = std::move(args[0]);
auto max = args[0];
for (size_t i = 1; i < args.size(); ++i) {
if (args[i] > max) {
max = std::move(args[i]);
Expand Down
3 changes: 2 additions & 1 deletion src/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace rift {
if (peek() == '{') {
if (m_index == start) {
m_expressionDepth++;
return geode::Ok(Token { TokenType::LEFT_BRACE, m_index, ++m_index });
m_index++;
return geode::Ok(Token { TokenType::LEFT_BRACE, m_index - 1, m_index });
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ namespace rift {
// iterator
auto expression = parseExpression();
if (expression.isErr()) {
return std::move(expression);
return expression;
}

// check for 'do' keyword
Expand All @@ -252,7 +252,7 @@ namespace rift {
// body
auto body = parseExpression();
if (body.isErr()) {
return std::move(body);
return body;
}

// check for 'end' keyword
Expand Down
2 changes: 1 addition & 1 deletion src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace rift {
if (result.isErr()) {
return geode::Err(std::move(result.unwrapErr()));
}
return geode::Ok(std::move(result.unwrap().toString()));
return geode::Ok(result.unwrap().toString());
}

EvalResult Script::eval(Object const &variables) const noexcept {
Expand Down
4 changes: 0 additions & 4 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,6 @@ namespace rift {
}
}

Value Value::operator->*(const Value& key) const noexcept {
return {};
}

Value Value::operator[](size_t index) const noexcept {
if (!isArray()) return {};
auto const& array = getArray();
Expand Down
10 changes: 5 additions & 5 deletions src/visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ namespace rift {
auto& var = node.getVarName();
auto iter = visit(node.getIterator());
if (iter.isErr()) {
return std::move(iter);
return iter;
}

size_t maxIters = Config::get().maxLoopIterations();
int64_t maxIters = Config::get().maxLoopIterations();
auto& iterValue = iter.unwrap();

std::string result;
Expand All @@ -249,7 +249,7 @@ namespace rift {
} break;
case Value::Type::Array: {
auto const& arr = iterValue.getArray();
if (arr.size() > maxIters) {
if (static_cast<int64_t>(arr.size()) > maxIters) {
return node.error(fmt::format("For loop: {} -> {} : {} exceeds max iterations", var, iter.unwrap().toString(), maxIters));
}
for (auto const& val : arr) {
Expand All @@ -263,7 +263,7 @@ namespace rift {
} break;
case Value::Type::Object: {
auto const& obj = iterValue.getObject();
if (obj.size() > maxIters) {
if (static_cast<int64_t>(obj.size()) > maxIters) {
return node.error(fmt::format("For loop: {} -> {} : {} exceeds max iterations", var, iter.unwrap().toString(), maxIters));
}
for (auto const& [key, val] : obj) {
Expand Down Expand Up @@ -316,7 +316,7 @@ namespace rift {
VisitorResult Visitor::visit(AssignNode const& node) noexcept {
auto value = visit(*node.getValue());
if (value.isErr()) {
return std::move(value);
return value;
}

m_localVariables[node.getName()] = value.unwrap();
Expand Down

0 comments on commit d0eb2db

Please sign in to comment.