Skip to content

Commit

Permalink
Merge pull request #106 from ultraleap/libelement/feature/warning-cle…
Browse files Browse the repository at this point in the history
…anup

libelement: Fix some warnings
  • Loading branch information
Zephilinox authored Jun 3, 2021
2 parents 74cc9a9 + 515bda8 commit b492252
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion libelement/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ if (ELEMENT_BUILD_TESTING)
target_link_libraries(element_tests PRIVATE fmt::fmt-header-only)
endif ()
target_link_libraries(element_tests PUBLIC element_coverage_config)
target_include_directories(element_tests PRIVATE "${element_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/_deps/fmt-src/include")
target_include_directories(element_tests PRIVATE "${element_SOURCE_DIR}/src")
add_test(NAME libelement_test
COMMAND element_tests -r junit -o ${CMAKE_BINARY_DIR}/libemelement_test_app_details.xml)

Expand Down
10 changes: 7 additions & 3 deletions libelement/src/instruction_tree/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ namespace element

explicit instruction_constant(element_value val);

[[nodiscard]] virtual object_const_shared_ptr call(const compilation_context& context,
[[nodiscard]] object_const_shared_ptr call(const compilation_context& context,
std::vector<object_const_shared_ptr> compiled_args,
const source_information& source_info) const;
const source_information& source_info) const override;
[[nodiscard]] element_value value() const { return m_value; }
[[nodiscard]] size_t get_size() const override { return 1; }
[[nodiscard]] std::string to_string() const override
Expand Down Expand Up @@ -354,7 +354,11 @@ namespace element
break;
}

//todo: optimise other operators
default:
{
//todo: optimise other operators
break;
}
}

return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions libelement/src/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ element_result element_interpreter_evaluate_call_expression(

int serialised_size = 0;
for (const auto& arg : serialised_arguments)
serialised_size += arg.size();
serialised_size += static_cast<int>(arg.size());

if (serialised_size > outputs->count)
return ELEMENT_ERROR_API_INSUFFICIENT_BUFFER;
Expand All @@ -667,7 +667,7 @@ element_result element_interpreter_evaluate_call_expression(
for (const auto& arg : serialised_arguments)
{
std::copy_n(arg.data(), arg.size(), outputs->values + outputs->count);
outputs->count += arg.size();
outputs->count += static_cast<int>(arg.size());
}

return ELEMENT_OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ bool user_function_constraint::matches_constraint(const compilation_context& con
if (!other)
return false;

unsigned int our_input_length = declarer->inputs.size();
unsigned int offset = 0;
std::size_t our_input_length = declarer->inputs.size();
std::size_t offset = 0;

if (applied)
{
Expand All @@ -62,7 +62,7 @@ bool user_function_constraint::matches_constraint(const compilation_context& con
if (our_input_length != other->get_inputs().size())
return false;

for (unsigned int i = 0; i < our_input_length; ++i)
for (std::size_t i = 0; i < our_input_length; ++i)
if (!check_match(declarer->inputs[i + offset], other->inputs[i]))
return false;

Expand Down
5 changes: 4 additions & 1 deletion libelement/src/object_model/declarations/declaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ bool declaration::has_scope() const
return !our_scope->is_empty();
}

object_const_shared_ptr declaration::generate_placeholder(const compilation_context& context, int& placeholder_index, unsigned int boundary_scope) const
object_const_shared_ptr declaration::generate_placeholder(
const compilation_context& context,
std::size_t& placeholder_index,
const std::size_t boundary_scope) const
{
return std::make_shared<const error>(
fmt::format("Tried to generate a placeholder for an unexpected declaration"),
Expand Down
2 changes: 1 addition & 1 deletion libelement/src/object_model/declarations/declaration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace element

[[nodiscard]] virtual bool serializable(const compilation_context& context) const { return false; }
[[nodiscard]] virtual bool deserializable(const compilation_context& context) const { return false; }
[[nodiscard]] virtual object_const_shared_ptr generate_placeholder(const compilation_context& context, int& placeholder_index, unsigned int boundary_scope) const;
[[nodiscard]] virtual object_const_shared_ptr generate_placeholder(const compilation_context& context, std::size_t& placeholder_index, std::size_t boundary_scope) const;

[[nodiscard]] virtual std::string location() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ bool struct_declaration::deserializable(const compilation_context& context) cons
return true;
}

object_const_shared_ptr struct_declaration::generate_placeholder(const compilation_context& context, int& placeholder_index, unsigned int boundary_scope) const
object_const_shared_ptr struct_declaration::generate_placeholder(
const compilation_context& context,
std::size_t& placeholder_index,
const std::size_t boundary_scope) const
{
if (inputs.empty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace element

[[nodiscard]] bool serializable(const compilation_context& context) const override;
[[nodiscard]] bool deserializable(const compilation_context& context) const override;
[[nodiscard]] object_const_shared_ptr generate_placeholder(const compilation_context& context, int& placeholder_index, unsigned int boundary_scope) const override;
[[nodiscard]] object_const_shared_ptr generate_placeholder(const compilation_context& context, std::size_t& placeholder_index, std::size_t boundary_scope) const override;

[[nodiscard]] bool is_intrinsic() const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace element
[[nodiscard]] bool matches_constraint(const compilation_context& context, const constraint* constraint) const override;
[[nodiscard]] const constraint* get_constraint() const override;

[[nodiscard]] virtual object_const_shared_ptr index(const compilation_context& context,
[[nodiscard]] object_const_shared_ptr index(const compilation_context& context,
const identifier& name,
const source_information& source_info) const;
const source_information& source_info) const override;

[[nodiscard]] object_const_shared_ptr compile(const compilation_context& context,
const source_information& source_info) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ namespace element
[[nodiscard]] const port& get_output() const override { return declarer->get_output(); }
[[nodiscard]] bool serializable(const compilation_context& context) const { return declarer->serializable(context); }
[[nodiscard]] bool deserializable(const compilation_context& context) const { return declarer->deserializable(context); }
[[nodiscard]] object_const_shared_ptr generate_placeholder(const compilation_context& context, int& placeholder_index, unsigned int boundary_scope) const { return declarer->generate_placeholder(context, placeholder_index, boundary_scope); }
[[nodiscard]] object_const_shared_ptr generate_placeholder(const compilation_context& context, std::size_t& placeholder_index, std::size_t boundary_scope) const { return declarer->generate_placeholder(context, placeholder_index, boundary_scope); }
//[[nodiscard]] std::string location() const { return declarer->location(); }

[[nodiscard]] object_const_shared_ptr index(const compilation_context& context,
const identifier& name,
const source_information& source_info) const
const source_information& source_info) const override
{
return declarer->index(context, name, source_info);
}

[[nodiscard]] object_const_shared_ptr call(const compilation_context& context,
std::vector<object_const_shared_ptr> compiled_args,
const source_information& source_info) const
const source_information& source_info) const override
{
return declarer->call(context, std::move(compiled_args), source_info);
}

[[nodiscard]] object_const_shared_ptr compile(const compilation_context& context,
const source_information& source_info) const
const source_information& source_info) const override
{
return declarer->compile(context, source_info);
}
Expand Down
9 changes: 4 additions & 5 deletions libelement/src/object_model/intrinsics/intrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,18 @@ intrinsic::intrinsic(const element_type_id id)
std::pair<std::vector<object_const_shared_ptr>, size_t> element::generate_placeholder_inputs(
const compilation_context& compilation_context,
const std::vector<port>& inputs,
const int index_offset,
const unsigned int boundary_scope)
std::size_t index_offset,
const std::size_t boundary_scope)
{
std::pair<std::vector<object_const_shared_ptr>, size_t> placeholder_inputs;
auto placeholder_index = index_offset;

for (const auto& input : inputs)
{
auto placeholder = input.generate_placeholder(compilation_context, placeholder_index, boundary_scope);
auto placeholder = input.generate_placeholder(compilation_context, index_offset, boundary_scope);
placeholder_inputs.first.push_back(std::move(placeholder));
}

placeholder_inputs.second = placeholder_index;
placeholder_inputs.second = index_offset;
return placeholder_inputs;
}

Expand Down
4 changes: 2 additions & 2 deletions libelement/src/object_model/intrinsics/intrinsic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ namespace element
std::pair<std::vector<object_const_shared_ptr>, size_t> generate_placeholder_inputs(
const compilation_context& compilation_context,
const std::vector<port>& inputs,
int index_offset,
unsigned int boundary_scope);
std::size_t index_offset,
std::size_t boundary_scope);

std::shared_ptr<const instruction> evaluate(const compilation_context& context, instruction_const_shared_ptr expr);
} // namespace element
6 changes: 3 additions & 3 deletions libelement/src/object_model/object_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ namespace element
const object& object,
const std::vector<port>& inputs,
const source_information& source_info,
const int placeholder_offset,
int boundary_scope)
const std::size_t placeholder_offset,
const int boundary_scope)
{
assert(!context.boundaries.empty());
const unsigned int boundary = boundary_scope < 0 ? context.boundaries.size() - 1 : boundary_scope;
const std::size_t boundary = boundary_scope < 0 ? context.boundaries.size() - 1 : boundary_scope;
auto [placeholders, size] = generate_placeholder_inputs(context, inputs, placeholder_offset, boundary);
context.boundaries[boundary].size = size;

Expand Down
13 changes: 7 additions & 6 deletions libelement/src/object_model/object_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ namespace element
const identifier& name,
const source_information& source_info);

object_const_shared_ptr compile_placeholder_expression(const compilation_context& context,
const object& object,
const std::vector<port>& inputs,
const source_information& source_info,
int placeholder_offset = 0,
int boundary_scope = -1);
object_const_shared_ptr compile_placeholder_expression(
const compilation_context& context,
const object& object,
const std::vector<port>& inputs,
const source_information& source_info,
std::size_t placeholder_offset = 0,
int boundary_scope = -1);
} // namespace element
5 changes: 4 additions & 1 deletion libelement/src/object_model/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const declaration* port::resolve_annotation(const compilation_context& context)
return declarer->get_scope()->find(annotation->to_string(), context.interpreter->caches, true);
}

object_const_shared_ptr port::generate_placeholder(const compilation_context& context, int& placeholder_index, unsigned int boundary_scope) const
object_const_shared_ptr port::generate_placeholder(
const compilation_context& context,
std::size_t& placeholder_index,
const std::size_t boundary_scope) const
{
const auto* type = resolve_annotation(context);
if (!type)
Expand Down
2 changes: 1 addition & 1 deletion libelement/src/object_model/port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace element
[[nodiscard]] const type_annotation* get_annotation() const { return annotation.get(); }

[[nodiscard]] const declaration* resolve_annotation(const compilation_context& context) const;
[[nodiscard]] object_const_shared_ptr generate_placeholder(const compilation_context& context, int& placeholder_index, unsigned int boundary_scope) const;
[[nodiscard]] object_const_shared_ptr generate_placeholder(const compilation_context& context, std::size_t& placeholder_index, std::size_t boundary_scope) const;

[[nodiscard]] bool has_default() const { return get_default(); }
[[nodiscard]] expression_chain* get_default() const { return expr_chain.get(); }
Expand Down

0 comments on commit b492252

Please sign in to comment.