F´ Flight Software - C/C++ Documentation
devel
A framework for building embedded system applications to NASA flight quality standards.
Assert.hpp
Go to the documentation of this file.
1
#ifndef FW_ASSERT_HPP
2
#define FW_ASSERT_HPP
3
4
#include <
FpConfig.hpp
>
5
6
// Return only the first argument passed to the macro.
7
#define FW_ASSERT_FIRST_ARG(ARG_0, ...) ARG_0
8
// Return all the arguments of the macro, but the first one
9
#define FW_ASSERT_NO_FIRST_ARG(ARG_0, ...) __VA_ARGS__
10
11
#if FW_ASSERT_LEVEL == FW_NO_ASSERT
12
// Users may override the NO_ASSERT case should they choose
13
#ifndef FW_ASSERT
14
#define FW_ASSERT(...) ((void)(FW_ASSERT_FIRST_ARG(__VA_ARGS__)))
15
#endif
16
#define FILE_NAME_ARG const CHAR*
17
#else
// ASSERT is defined
18
19
// Passing the __LINE__ argument at the end of the function ensures that
20
// the FW_ASSERT_NO_FIRST_ARG macro will never have an empty variadic variable
21
#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
22
#define FILE_NAME_ARG U32
23
#define FW_ASSERT(...) \
24
((void)((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \
25
? (0) \
26
: (Fw::SwAssert(ASSERT_FILE_ID, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
27
#elif FW_ASSERT_LEVEL == FW_RELATIVE_PATH_ASSERT
28
#define FILE_NAME_ARG const CHAR*
29
#define FW_ASSERT(...) \
30
((void)((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \
31
? (0) \
32
: (Fw::SwAssert(ASSERT_RELATIVE_PATH, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
33
#else
34
#define FILE_NAME_ARG const CHAR*
35
#define FW_ASSERT(...) \
36
((void)((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \
37
? (0) \
38
: (Fw::SwAssert(__FILE__, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))))
39
#endif
40
#endif
// if ASSERT is defined
41
42
// F' Assertion functions can technically return even though the intention is for the assertion to terminate the
43
// program. This breaks static analysis depending on assertions, since the analyzer has to assume the assertion will
44
// return. When supported, annotate assertion functions as noreturn when statically analyzing.
45
#ifndef CLANG_ANALYZER_NORETURN
46
#ifndef __has_feature
47
#define __has_feature(x) 0
// Compatibility with non-clang compilers.
48
#endif
49
#if __has_feature(attribute_analyzer_noreturn)
50
#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
51
#else
52
#define CLANG_ANALYZER_NORETURN
53
#endif
54
#endif
55
56
namespace
Fw
{
58
NATIVE_INT_TYPE
SwAssert
(
FILE_NAME_ARG
file,
NATIVE_UINT_TYPE
lineNo)
CLANG_ANALYZER_NORETURN
;
59
61
NATIVE_INT_TYPE
SwAssert
(
FILE_NAME_ARG
file,
FwAssertArgType
arg1,
NATIVE_UINT_TYPE
lineNo)
CLANG_ANALYZER_NORETURN
;
62
64
NATIVE_INT_TYPE
SwAssert
(
FILE_NAME_ARG
file,
FwAssertArgType
arg1,
FwAssertArgType
arg2,
NATIVE_UINT_TYPE
lineNo)
65
CLANG_ANALYZER_NORETURN
;
66
68
NATIVE_INT_TYPE
SwAssert
(
FILE_NAME_ARG
file,
69
FwAssertArgType
arg1,
70
FwAssertArgType
arg2,
71
FwAssertArgType
arg3,
72
NATIVE_UINT_TYPE
lineNo)
CLANG_ANALYZER_NORETURN
;
73
75
NATIVE_INT_TYPE
SwAssert
(
FILE_NAME_ARG
file,
76
FwAssertArgType
arg1,
77
FwAssertArgType
arg2,
78
FwAssertArgType
arg3,
79
FwAssertArgType
arg4,
80
NATIVE_UINT_TYPE
lineNo)
CLANG_ANALYZER_NORETURN
;
81
83
NATIVE_INT_TYPE
SwAssert
(
FILE_NAME_ARG
file,
84
FwAssertArgType
arg1,
85
FwAssertArgType
arg2,
86
FwAssertArgType
arg3,
87
FwAssertArgType
arg4,
88
FwAssertArgType
arg5,
89
NATIVE_UINT_TYPE
lineNo)
CLANG_ANALYZER_NORETURN
;
90
92
NATIVE_INT_TYPE
SwAssert
(
FILE_NAME_ARG
file,
93
FwAssertArgType
arg1,
94
FwAssertArgType
arg2,
95
FwAssertArgType
arg3,
96
FwAssertArgType
arg4,
97
FwAssertArgType
arg5,
98
FwAssertArgType
arg6,
99
NATIVE_UINT_TYPE
lineNo)
CLANG_ANALYZER_NORETURN
;
100
}
// namespace Fw
101
102
// Base class for declaring an assert hook
103
// Each of the base class functions can be overridden
104
// or used by derived classes.
105
106
namespace
Fw
{
107
// Base class for declaring an assert hook
108
class
AssertHook
{
109
public
:
110
AssertHook
() : previousHook(nullptr){};
111
virtual
~AssertHook
(){};
112
// override this function to intercept asserts
113
virtual
void
reportAssert
(
FILE_NAME_ARG
file,
114
NATIVE_UINT_TYPE
lineNo,
115
NATIVE_UINT_TYPE
numArgs,
116
FwAssertArgType
arg1,
117
FwAssertArgType
arg2,
118
FwAssertArgType
arg3,
119
FwAssertArgType
arg4,
120
FwAssertArgType
arg5,
121
FwAssertArgType
arg6);
122
// default reportAssert() will call this when the message is built
123
// override it to do another kind of print. printf by default
124
virtual
void
printAssert
(
const
CHAR
* msg);
125
// do assert action. By default, calls assert.
126
// Called after reportAssert()
127
virtual
void
doAssert
();
128
// register the hook
129
void
registerHook
();
130
// deregister the hook
131
void
deregisterHook
();
132
133
protected
:
134
private
:
135
// the previous assert hook
136
AssertHook
* previousHook;
137
};
138
}
// namespace Fw
139
140
#endif
// FW_ASSERT_HPP
CLANG_ANALYZER_NORETURN
#define CLANG_ANALYZER_NORETURN
Definition:
Assert.hpp:52
FILE_NAME_ARG
#define FILE_NAME_ARG
Definition:
Assert.hpp:16
NATIVE_INT_TYPE
PlatformIntType NATIVE_INT_TYPE
Definition:
BasicTypes.h:55
CHAR
char CHAR
Definition:
BasicTypes.h:32
NATIVE_UINT_TYPE
PlatformUIntType NATIVE_UINT_TYPE
Definition:
BasicTypes.h:56
FwAssertArgType
PlatformAssertArgType FwAssertArgType
Definition:
FpConfig.h:39
FpConfig.hpp
C++-compatible configuration header for fprime configuration.
Fw::AssertHook
Definition:
Assert.hpp:108
Fw::AssertHook::reportAssert
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)
destructor
Definition:
Assert.cpp:75
Fw::AssertHook::deregisterHook
void deregisterHook()
Definition:
Assert.cpp:101
Fw::AssertHook::~AssertHook
virtual ~AssertHook()
constructor
Definition:
Assert.hpp:111
Fw::AssertHook::doAssert
virtual void doAssert()
Definition:
Assert.cpp:90
Fw::AssertHook::registerHook
void registerHook()
Definition:
Assert.cpp:96
Fw::AssertHook::AssertHook
AssertHook()
Definition:
Assert.hpp:110
Fw::AssertHook::printAssert
virtual void printAssert(const CHAR *msg)
Definition:
Assert.cpp:71
Fw
Definition:
FppConstantsAc.hpp:121
Fw::SwAssert
NATIVE_INT_TYPE SwAssert(FILE_NAME_ARG file, NATIVE_UINT_TYPE lineNo)
Assert with no arguments.
Definition:
Assert.cpp:127
Fw
Types
Assert.hpp
Generated by
1.9.1