Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format cpp and hpp files in Fw/Types #2677

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
391 changes: 150 additions & 241 deletions Fw/Types/Assert.cpp

Large diffs are not rendered by default.

220 changes: 104 additions & 116 deletions Fw/Types/Assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,42 @@
#define FW_ASSERT_NO_FIRST_ARG(ARG_0, ...) __VA_ARGS__

#if FW_ASSERT_LEVEL == FW_NO_ASSERT
// Users may override the NO_ASSERT case should they choose
#ifndef FW_ASSERT
#define FW_ASSERT(...) ((void)(FW_ASSERT_FIRST_ARG(__VA_ARGS__)))
#endif
#define FILE_NAME_ARG const CHAR*
#else // ASSERT is defined

// Users may override the NO_ASSERT case should they choose
#ifndef FW_ASSERT
#define FW_ASSERT(...) ((void)(FW_ASSERT_FIRST_ARG(__VA_ARGS__)))
#endif
#define FILE_NAME_ARG const CHAR*
#else // ASSERT is defined

// Passing the __LINE__ argument at the end of the function ensures that
// the FW_ASSERT_NO_FIRST_ARG macro will never have an empty variadic variable
#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
#define FILE_NAME_ARG U32
#define FW_ASSERT(...) \
((void) ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) ? (0) : \
(Fw::SwAssert(ASSERT_FILE_ID, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
#define FILE_NAME_ARG U32
#define FW_ASSERT(...) \
((void)((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \
? (0) \
: (Fw::SwAssert(ASSERT_FILE_ID, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
#elif FW_ASSERT_LEVEL == FW_RELATIVE_PATH_ASSERT
#define FILE_NAME_ARG const CHAR*
#define FW_ASSERT(...) \
((void) ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) ? (0) : \
(Fw::SwAssert(ASSERT_RELATIVE_PATH, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
#define FILE_NAME_ARG const CHAR*
#define FW_ASSERT(...) \
((void)((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \
? (0) \
: (Fw::SwAssert(ASSERT_RELATIVE_PATH, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
#else
#define FILE_NAME_ARG const CHAR*
#define FW_ASSERT(...) \
((void) ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) ? (0) : \
(Fw::SwAssert(__FILE__, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
#define FILE_NAME_ARG const CHAR*
#define FW_ASSERT(...) \
((void)((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \
? (0) \
: (Fw::SwAssert(__FILE__, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
#endif
#endif // if ASSERT is defined
#endif // if ASSERT is defined

// F' Assertion functions can technically return even though the intention is for the assertion to terminate the program.
// This breaks static analysis depending on assertions, since the analyzer has to assume the assertion will return.
// When supported, annotate assertion functions as noreturn when statically analyzing.
// F' Assertion functions can technically return even though the intention is for the assertion to terminate the
// program. This breaks static analysis depending on assertions, since the analyzer has to assume the assertion will
// return. When supported, annotate assertion functions as noreturn when statically analyzing.
#ifndef CLANG_ANALYZER_NORETURN
#ifndef __has_feature
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
#if __has_feature(attribute_analyzer_noreturn)
#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
Expand All @@ -52,101 +54,87 @@
#endif

namespace Fw {
//! Assert with no arguments
NATIVE_INT_TYPE SwAssert(
FILE_NAME_ARG file,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with one argument
NATIVE_INT_TYPE SwAssert(
FILE_NAME_ARG file,
FwAssertArgType arg1,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with two arguments
NATIVE_INT_TYPE SwAssert(
FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with three arguments
NATIVE_INT_TYPE SwAssert(
FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with four arguments
NATIVE_INT_TYPE SwAssert(
FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with five arguments
NATIVE_INT_TYPE SwAssert(
FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with six arguments
NATIVE_INT_TYPE SwAssert(
FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;
}
//! Assert with no arguments
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file, NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with one argument
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with two arguments
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, NATIVE_UINT_TYPE lineNo)
CLANG_ANALYZER_NORETURN;

//! Assert with three arguments
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with four arguments
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with five arguments
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;

//! Assert with six arguments
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6,
NATIVE_UINT_TYPE lineNo) CLANG_ANALYZER_NORETURN;
} // namespace Fw

// Base class for declaring an assert hook
// Each of the base class functions can be overridden
// or used by derived classes.

namespace Fw {
// Base class for declaring an assert hook
class AssertHook {
public:
AssertHook() : previousHook(nullptr) {}; //!< constructor
virtual ~AssertHook() {}; //!< destructor
// override this function to intercept asserts
virtual void reportAssert(
FILE_NAME_ARG file,
NATIVE_UINT_TYPE lineNo,
NATIVE_UINT_TYPE numArgs,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6
);
// default reportAssert() will call this when the message is built
// override it to do another kind of print. printf by default
virtual void printAssert(const CHAR* msg);
// do assert action. By default, calls assert.
// Called after reportAssert()
virtual void doAssert();
// register the hook
void registerHook();
// deregister the hook
void deregisterHook();

protected:
private:
// the previous assert hook
AssertHook *previousHook;
};
}

#endif // FW_ASSERT_HPP
// Base class for declaring an assert hook
class AssertHook {
public:
AssertHook() : previousHook(nullptr){}; //!< constructor
virtual ~AssertHook(){}; //!< destructor
// override this function to intercept asserts
virtual void reportAssert(FILE_NAME_ARG file,
NATIVE_UINT_TYPE lineNo,
NATIVE_UINT_TYPE numArgs,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6);
// default reportAssert() will call this when the message is built
// override it to do another kind of print. printf by default
virtual void printAssert(const CHAR* msg);
// do assert action. By default, calls assert.
// Called after reportAssert()
virtual void doAssert();
// register the hook
void registerHook();
// deregister the hook
void deregisterHook();

protected:
private:
// the previous assert hook
AssertHook* previousHook;
};
} // namespace Fw

#endif // FW_ASSERT_HPP
67 changes: 30 additions & 37 deletions Fw/Types/ByteArray.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ======================================================================
// ======================================================================
// \title ByteArray.hpp
// \author bocchino
// \brief hpp file for ByteArray type
Expand All @@ -7,8 +7,8 @@
// Copyright (C) 2016 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
//
// ======================================================================

#ifndef Fw_ByteArray_HPP
#define Fw_ByteArray_HPP
Expand All @@ -17,39 +17,32 @@

namespace Fw {

//! \class ByteArray
//! \brief A variable-length byte array
//!
struct ByteArray {

// ----------------------------------------------------------------------
// Construction
// ----------------------------------------------------------------------

//! Construct a ByteArray
//!
ByteArray(
U8 *const bytes, //!< Pointer to the bytes
const U32 size //!< The array size
) :
bytes(bytes),
size(size)
{

}

// ----------------------------------------------------------------------
// Data
// ----------------------------------------------------------------------

//! The bytes
U8 *const bytes;

//! The size
const U32 size;

};

}
//! \class ByteArray
//! \brief A variable-length byte array
//!
struct ByteArray {
// ----------------------------------------------------------------------
// Construction
// ----------------------------------------------------------------------

//! Construct a ByteArray
//!
ByteArray(U8* const bytes, //!< Pointer to the bytes
const U32 size //!< The array size
)
: bytes(bytes), size(size) {}

// ----------------------------------------------------------------------
// Data
// ----------------------------------------------------------------------

//! The bytes
U8* const bytes;

//! The size
const U32 size;
};

} // namespace Fw

#endif
Loading
Loading