Unverified Commit d37a4df9 authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Enable cppcheck rule for 'not', 'or' keywords (#1361)

Using not and or improves readability. The cppcheck rule will help ensure we are doing it consistently.
parent 794a4335
......@@ -371,7 +371,7 @@ void tf_parser::parse_node(const std::string& name)
{
result = ops[node.op()](*this, {get_attributes(node), node.op(), mm}, args);
}
assert(!result.empty());
assert(not result.empty());
// First output has no ":" delimiter
instructions[name] = result.front();
for(size_t i = 1; i < result.size(); i++)
......@@ -458,7 +458,7 @@ literal tf_parser::parse_tensor(const tensorflow::TensorProto& t) const
{
std::vector<size_t> dims = parse_dims(t.tensor_shape());
size_t shape_size = std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<size_t>());
if(!t.tensor_content().empty()) // has raw data
if(not t.tensor_content().empty()) // has raw data
{
const std::string& s = t.tensor_content();
switch(t.dtype())
......
......@@ -78,7 +78,7 @@ void tmp_dir::execute(const std::string& exe, const std::string& args) const
tmp_dir::~tmp_dir()
{
if(!enabled(MIGRAPHX_DEBUG_SAVE_TEMP_DIR{}))
if(not enabled(MIGRAPHX_DEBUG_SAVE_TEMP_DIR{}))
{
fs::remove_all(this->path);
}
......
......@@ -400,7 +400,7 @@ std::pair<value*, bool> value::insert(const value& v)
{
if(v.key.empty())
{
if(!x)
if(not x)
x = std::make_shared<array_value_holder>();
get_array_impl(x).push_back(v);
assert(this->if_array());
......@@ -408,7 +408,7 @@ std::pair<value*, bool> value::insert(const value& v)
}
else
{
if(!x)
if(not x)
x = std::make_shared<object_value_holder>();
auto p = x->if_object()->emplace(v.key, get_array_impl(x).size());
if(p.second)
......@@ -420,7 +420,7 @@ std::pair<value*, bool> value::insert(const value& v)
value* value::insert(const value* pos, const value& v)
{
assert(v.key.empty());
if(!x)
if(not x)
x = std::make_shared<array_value_holder>();
auto&& a = get_array_impl(x);
auto it = a.insert(a.begin() + (pos - begin()), v);
......@@ -466,7 +466,7 @@ bool compare(const value& x, const value& y, F f)
value::type_t value::get_type() const
{
if(!x)
if(not x)
return null_type;
return x->get_type();
}
......
......@@ -55,7 +55,7 @@ struct simple_custom_op final : migraphx::experimental_custom_op_base
virtual migraphx::shape compute_shape(migraphx::shapes inputs) const override
{
if(!inputs[0].standard())
if(not inputs[0].standard())
{
throw std::runtime_error("first arg must be standard shaped");
}
......
......@@ -49,6 +49,6 @@ bool create_shapes(bool dynamic_allowed)
TEST_CASE(allow_dynamic_shape) { EXPECT(create_shapes(true)); }
TEST_CASE(fail_dynamic_shape) { EXPECT(!create_shapes(false)); }
TEST_CASE(fail_dynamic_shape) { EXPECT(not create_shapes(false)); }
int main(int argc, const char* argv[]) { test::run(argc, argv); }
......@@ -187,7 +187,7 @@ TEST_CASE(print_test)
std::stringstream ss;
ss << p;
std::string s = ss.str();
EXPECT(!s.empty());
EXPECT(not s.empty());
}
TEST_CASE(param_test)
......
......@@ -47,7 +47,7 @@ TEST_CASE(is_supported)
{
auto p = create_program();
auto targets = migraphx::get_targets();
EXPECT(!targets.empty());
EXPECT(not targets.empty());
auto t = migraphx::make_target("fpga");
const auto assignments = p.get_target_assignments({t});
......
......@@ -112,12 +112,12 @@ struct mod_pass_op
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs,
std::vector<migraphx::module_ref> mods) const
{
if(!mods.empty())
if(not mods.empty())
{
auto out_shapes = mods[0]->get_output_shapes();
return out_shapes[0];
}
if(!inputs.empty())
if(not inputs.empty())
{
return inputs.front();
}
......
......@@ -345,7 +345,7 @@ inline std::ostream& operator<<(std::ostream& os, const color& c)
template <class T, class F>
void failed(T x, const char* msg, const char* func, const char* file, int line, F f)
{
if(!bool(x.value()))
if(not bool(x.value()))
{
std::cout << func << std::endl;
std::cout << file << ":" << line << ":" << std::endl;
......
......@@ -39,8 +39,8 @@ TEST_CASE(literal_test)
migraphx::literal l2 = l1; // NOLINT
EXPECT(l1 == l2);
EXPECT(l1.at<int>(0) == 1);
EXPECT(!l1.empty());
EXPECT(!l2.empty());
EXPECT(not l1.empty());
EXPECT(not l2.empty());
migraphx::literal l3{};
migraphx::literal l4{};
......
......@@ -3988,7 +3988,8 @@ TEST_CASE(not_test)
std::vector<char> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<bool> gold(data.size());
std::transform(data.begin(), data.end(), gold.begin(), [](bool n) -> bool { return !n; });
std::transform(
data.begin(), data.end(), gold.begin(), [](bool n) -> bool { return not n; });
EXPECT(migraphx::verify_range(results_vector, gold));
}
}
......
......@@ -43,7 +43,7 @@ TEST_CASE(test_shape_assign)
migraphx::shape s1{migraphx::shape::float_type, {100, 32, 8, 8}};
migraphx::shape s2 = s1; // NOLINT
EXPECT(s1 == s2);
EXPECT(!(s1 != s2));
EXPECT(not(s1 != s2));
}
TEST_CASE(test_shape_packed_default)
......@@ -325,7 +325,7 @@ TEST_CASE(test_shape_default_copy)
migraphx::shape s1{};
migraphx::shape s2{};
EXPECT(s1 == s2);
EXPECT(!(s1 != s2));
EXPECT(not(s1 != s2));
}
TEST_CASE(test_shape_normalize_standard1)
......
......@@ -169,7 +169,7 @@ void run_verify::verify(const std::string& name, const migraphx::program& p) con
for(const auto& tname : migraphx::get_targets())
{
// TODO(varunsh): once verify tests can run, remove fpga
if(tname == "ref" || tname == "fpga")
if(tname == "ref" or tname == "fpga")
continue;
// if tests disabled, skip running it
......
......@@ -560,7 +560,7 @@ lifetime get_lifetime_op(const T&)
inline bool operator!=(const operation& x, const operation& y)
{
return !(x == y);
return not(x == y);
}
inline value
......
......@@ -136,7 +136,7 @@ private:
template <typename PrivateDetailTypeErasedU = PrivateDetailTypeErasedT>
private_detail_te_handle_type (PrivateDetailTypeErasedT value,
typename std::enable_if<
!std::is_reference<PrivateDetailTypeErasedU>::value,
not std::is_reference<PrivateDetailTypeErasedU>::value,
int
>::type * = nullptr) noexcept :
private_detail_te_value (std::move(value))
......@@ -178,7 +178,7 @@ private:
private_detail_te_handle_base_type & private_detail_te_get_handle ()
{
assert(private_detail_te_handle_mem_var != nullptr);
if (!private_detail_te_handle_mem_var.unique())
if (not private_detail_te_handle_mem_var.unique())
private_detail_te_handle_mem_var = private_detail_te_handle_mem_var->clone();
return *private_detail_te_handle_mem_var;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment