Skip to content

Commit

Permalink
Merge pull request #1125 from LLNL/feature/kweiss/fix-one-liners
Browse files Browse the repository at this point in the history
Uses clang-tidy to add braces around one line statements
  • Loading branch information
kennyweiss committed Jul 5, 2023
2 parents 2da4dd7 + 8458938 commit 878d8ce
Show file tree
Hide file tree
Showing 89 changed files with 1,354 additions and 250 deletions.
6 changes: 6 additions & 0 deletions src/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Checks: '-*,readability-braces-around-statements'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ if (“${PROJECT_SOURCE_DIR}” STREQUAL “${CMAKE_SOURCE_DIR}”)
# These are not used in Axom, turn them off
set(_unused_blt_tools
CLANGQUERY
CLANGTIDY
VALGRIND
ASTYLE
CMAKEFORMAT
Expand All @@ -65,6 +64,8 @@ if (“${PROJECT_SOURCE_DIR}” STREQUAL “${CMAKE_SOURCE_DIR}”)
# unless an explicit executable path is given
set(_used_blt_tools
CLANGFORMAT
CLANGTIDY
CLANGAPPLYREPLACEMENTS
CPPCHECK
DOXYGEN
SPHINX)
Expand All @@ -77,6 +78,9 @@ if (“${PROJECT_SOURCE_DIR}” STREQUAL “${CMAKE_SOURCE_DIR}”)
endforeach()

set(BLT_REQUIRED_CLANGFORMAT_VERSION "10" CACHE STRING "")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy
${CMAKE_CURRENT_BINARY_DIR}/.clang-tidy
COPYONLY)

# If Axom is the top project and AXOM_ENABLE_TESTS is off, force ENABLE_TESTS to off so
# gtest doesn't build when it's not needed
Expand Down
5 changes: 4 additions & 1 deletion src/axom/core/examples/core_numerics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ void display_eigs(double* eigvec, double* eigval, int nrows, int i)
<< " = [";
for(int j = 0; j < nrows; ++j)
{
if(j > 0) std::cout << ", ";
if(j > 0)
{
std::cout << ", ";
}
std::cout << eigvec[i * nrows + j];
}
std::cout << "]" << std::endl;
Expand Down
5 changes: 4 additions & 1 deletion src/axom/core/memory_management.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ inline T* allocate(std::size_t n, int allocID) noexcept
template <typename T>
inline void deallocate(T*& pointer) noexcept
{
if(pointer == nullptr) return;
if(pointer == nullptr)
{
return;
}

#ifdef AXOM_USE_UMPIRE

Expand Down
10 changes: 8 additions & 2 deletions src/axom/core/numerics/matvecops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,19 @@ void make_orthogonal(T* u, T* v, int dim, double tol)

double norm = static_cast<double>(dot_product(v, v, dim));

if(norm < tol) return;
if(norm < tol)
{
return;
}

T tnorm = static_cast<T>(norm);

T dot = dot_product(u, v, dim);

for(int l = 0; l < dim; ++l) u[l] -= ((dot * v[l]) / tnorm);
for(int l = 0; l < dim; ++l)
{
u[l] -= ((dot * v[l]) / tnorm);
}
}

//------------------------------------------------------------------------------
Expand Down
15 changes: 12 additions & 3 deletions src/axom/core/tests/core_bit_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ TEST(core_bit_utilities, trailingZeroes)
int bit = 0;
for(; bit < BITS; ++bit)
{
if(rand_val & shifted(bit)) break;
if(rand_val & shifted(bit))
{
break;
}
}
EXPECT_EQ(bit, axom::utilities::trailingZeros(rand_val));
}
Expand Down Expand Up @@ -127,7 +130,10 @@ TEST(core_bit_utilities, popCount)
int bits = 0;
for(int i = 0; i < BITS; ++i)
{
if(val & shifted(i)) ++bits;
if(val & shifted(i))
{
++bits;
}
}

EXPECT_EQ(bits, axom::utilities::popCount(val));
Expand Down Expand Up @@ -166,7 +172,10 @@ TEST(core_bit_utilities, leadingZeros)
int bit = 0;
for(; bit < BITS; ++bit)
{
if(rand_val & shifted(BITS - bit - 1)) break;
if(rand_val & shifted(BITS - bit - 1))
{
break;
}
}
EXPECT_EQ(bit, axom::utilities::leadingZeros(rand_val));
}
Expand Down
20 changes: 16 additions & 4 deletions src/axom/core/utilities/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class Timer
*/
Timer(bool startRunning = false) : m_running(startRunning)
{
if(m_running) start();
if(m_running)
{
start();
}
}

/*!
Expand Down Expand Up @@ -107,7 +110,10 @@ class Timer
*/
double elapsedTimeInSec()
{
if(m_running) stop();
if(m_running)
{
stop();
}
return clockDiff().count();
}

Expand All @@ -117,7 +123,10 @@ class Timer
*/
double elapsedTimeInMilliSec()
{
if(m_running) stop();
if(m_running)
{
stop();
}
return std::chrono::duration_cast<MilliTimeDiff>(clockDiff()).count();
}

Expand All @@ -127,7 +136,10 @@ class Timer
*/
double elapsedTimeInMicroSec()
{
if(m_running) stop();
if(m_running)
{
stop();
}
return std::chrono::duration_cast<MicroTimeDiff>(clockDiff()).count();
}

Expand Down
20 changes: 9 additions & 11 deletions src/axom/klee/tests/KleeMatchers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class AlmostEqMatrixMatcher
: m_mat(mat)
{ }

bool MatchAndExplain(const axom::numerics::Matrix<T>& other,
std::ostream* /* listener */) const
bool MatchAndExplain(const axom::numerics::Matrix<T>& other, std::ostream*) const
{
if(other.getNumRows() != m_mat.getNumRows() ||
other.getNumColumns() != m_mat.getNumColumns())
Expand All @@ -59,8 +58,8 @@ class AlmostEqMatrixMatcher
return true;
}

void DescribeTo(std::ostream* os) const { }
void DescribeNegationTo(std::ostream* os) const { }
void DescribeTo(std::ostream*) const { }
void DescribeNegationTo(std::ostream*) const { }

private:
const axom::numerics::Matrix<T> m_mat;
Expand All @@ -85,7 +84,7 @@ class AlmostEqArrMatcher

explicit AlmostEqArrMatcher(const T& arr) : m_arr(arr) { }

bool MatchAndExplain(const T& other, std::ostream* /* listener */) const
bool MatchAndExplain(const T& other, std::ostream*) const
{
for(int i = 0; i < m_arr.dimension(); ++i)
{
Expand All @@ -97,8 +96,8 @@ class AlmostEqArrMatcher
return true;
}

void DescribeTo(std::ostream* os) const { }
void DescribeNegationTo(std::ostream* os) const { }
void DescribeTo(std::ostream*) const { }
void DescribeNegationTo(std::ostream*) const { }

private:
const T m_arr;
Expand Down Expand Up @@ -130,8 +129,7 @@ class AlmostEqSliceMatcher
: m_slice(slice)
{ }

bool MatchAndExplain(const klee::SliceOperator& other,
std::ostream* /* listener */) const
bool MatchAndExplain(const klee::SliceOperator& other, std::ostream*) const
{
return ::testing::Matches(AlmostEqPoint(m_slice.getOrigin()))(
other.getOrigin()) &&
Expand All @@ -141,8 +139,8 @@ class AlmostEqSliceMatcher
other.getStartProperties());
}

void DescribeTo(std::ostream* os) const { }
void DescribeNegationTo(std::ostream* os) const { }
void DescribeTo(std::ostream*) const { }
void DescribeNegationTo(std::ostream*) const { }

private:
const klee::SliceOperator m_slice;
Expand Down

0 comments on commit 878d8ce

Please sign in to comment.