refactor(cxx): formatted according to IDF astyle rules

This commit is contained in:
Jakob Hasse 2024-03-05 14:07:05 +08:00
parent 5f85aefe0d
commit 0c01c5965e
10 changed files with 90 additions and 103 deletions

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -40,45 +40,44 @@ extern "C" void __wrap__Unwind_SetEnableExceptionFdeSorting(unsigned char enable
abort(); abort();
} }
extern "C" void __wrap___register_frame_info_bases (const void *begin, struct object *ob, void *tbase, void *dbase) extern "C" void __wrap___register_frame_info_bases(const void *begin, struct object *ob, void *tbase, void *dbase)
{ {
abort(); abort();
} }
extern "C" void __wrap___register_frame_info (const void *begin, struct object *ob) extern "C" void __wrap___register_frame_info(const void *begin, struct object *ob)
{ {
abort(); abort();
} }
extern "C" void __wrap___register_frame_info_table_bases (void *begin, struct object *ob, void *tbase, void *dbase) extern "C" void __wrap___register_frame_info_table_bases(void *begin, struct object *ob, void *tbase, void *dbase)
{ {
abort(); abort();
} }
extern "C" void __wrap___register_frame_info_table (void *begin, struct object *ob) extern "C" void __wrap___register_frame_info_table(void *begin, struct object *ob)
{ {
abort(); abort();
} }
extern "C" void __wrap___register_frame(void *begin)
__attribute__((alias("abort_expect_void")));
extern "C" void __wrap___register_frame (void *begin) extern "C" void __wrap___register_frame_table(void *begin)
__attribute__((alias("abort_expect_void"))); __attribute__((alias("abort_expect_void")));
extern "C" void __wrap___register_frame_table (void *begin) extern "C" void *__wrap___deregister_frame_info_bases(const void *begin)
__attribute__((alias("abort_expect_void"))); __attribute__((alias("abort_expect_void_and_return")));
extern "C" void *__wrap___deregister_frame_info_bases (const void *begin) extern "C" void *__wrap___deregister_frame_info(const void *begin)
__attribute__((alias("abort_expect_void_and_return"))); __attribute__((alias("abort_expect_void_and_return")));
extern "C" void *__wrap___deregister_frame_info (const void *begin) extern "C" void __wrap___deregister_frame(void *begin)
__attribute__((alias("abort_expect_void_and_return"))); __attribute__((alias("abort_expect_void")));
extern "C" void __wrap___deregister_frame (void *begin)
__attribute__((alias("abort_expect_void")));
typedef void* fde; typedef void* fde;
extern "C" const fde * __wrap__Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases) extern "C" const fde * __wrap__Unwind_Find_FDE(void *pc, struct dwarf_eh_bases *bases)
{ {
return abort_return<fde*>(); return abort_return<fde*>();
} }
@ -87,50 +86,50 @@ extern "C" const fde * __wrap__Unwind_Find_FDE (void *pc, struct dwarf_eh_bases
typedef void* _Unwind_Ptr; typedef void* _Unwind_Ptr;
typedef int _Unwind_Word; typedef int _Unwind_Word;
extern "C" _Unwind_Word __wrap__Unwind_GetGR (struct _Unwind_Context *context, int index) extern "C" _Unwind_Word __wrap__Unwind_GetGR(struct _Unwind_Context *context, int index)
{ {
return abort_return<_Unwind_Word>(); return abort_return<_Unwind_Word>();
} }
extern "C" _Unwind_Word __wrap__Unwind_GetCFA (struct _Unwind_Context *context) extern "C" _Unwind_Word __wrap__Unwind_GetCFA(struct _Unwind_Context *context)
{ {
return abort_return<_Unwind_Word>(); return abort_return<_Unwind_Word>();
} }
extern "C" void __wrap__Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val) extern "C" void __wrap__Unwind_SetIP(struct _Unwind_Context *context, _Unwind_Ptr val)
{ {
abort(); abort();
} }
extern "C" void __wrap__Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val) extern "C" void __wrap__Unwind_SetGR(struct _Unwind_Context *context, int index, _Unwind_Word val)
{ {
abort(); abort();
} }
extern "C" _Unwind_Ptr __wrap__Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn) extern "C" _Unwind_Ptr __wrap__Unwind_GetIPInfo(struct _Unwind_Context *context, int *ip_before_insn)
{ {
return abort_return<_Unwind_Ptr>(); return abort_return<_Unwind_Ptr>();
} }
extern "C" _Unwind_Ptr __wrap__Unwind_GetIP (struct _Unwind_Context *context) extern "C" _Unwind_Ptr __wrap__Unwind_GetIP(struct _Unwind_Context *context)
__attribute__((alias("forward_abort_uw_ctx"))); __attribute__((alias("forward_abort_uw_ctx")));
extern "C" _Unwind_Ptr __wrap__Unwind_GetRegionStart (struct _Unwind_Context *context) extern "C" _Unwind_Ptr __wrap__Unwind_GetRegionStart(struct _Unwind_Context *context)
__attribute__((alias("forward_abort_uw_ctx"))); __attribute__((alias("forward_abort_uw_ctx")));
extern "C" _Unwind_Ptr __wrap__Unwind_GetDataRelBase (struct _Unwind_Context *context) extern "C" _Unwind_Ptr __wrap__Unwind_GetDataRelBase(struct _Unwind_Context *context)
__attribute__((alias("forward_abort_uw_ctx"))); __attribute__((alias("forward_abort_uw_ctx")));
extern "C" _Unwind_Ptr __wrap__Unwind_GetTextRelBase (struct _Unwind_Context *context) extern "C" _Unwind_Ptr __wrap__Unwind_GetTextRelBase(struct _Unwind_Context *context)
__attribute__((alias("forward_abort_uw_ctx"))); __attribute__((alias("forward_abort_uw_ctx")));
extern "C" void *__wrap__Unwind_GetLanguageSpecificData (struct _Unwind_Context *context) extern "C" void *__wrap__Unwind_GetLanguageSpecificData(struct _Unwind_Context *context)
__attribute__((alias("forward_abort_uw_ctx"))); __attribute__((alias("forward_abort_uw_ctx")));
extern "C" void *__wrap__Unwind_FindEnclosingFunction (void *pc) extern "C" void *__wrap__Unwind_FindEnclosingFunction(void *pc)
__attribute__((alias("abort_expect_void_and_return"))); __attribute__((alias("abort_expect_void_and_return")));
struct frame_state *__frame_state_for (void *pc_target, struct frame_state *state_in) struct frame_state *__frame_state_for(void *pc_target, struct frame_state *state_in)
{ {
return abort_return<struct frame_state *>(); return abort_return<struct frame_state *>();
} }
@ -142,27 +141,26 @@ typedef int _Unwind_Exception_Class;
typedef int* _Unwind_Trace_Fn; typedef int* _Unwind_Trace_Fn;
typedef int* _Unwind_Stop_Fn; typedef int* _Unwind_Stop_Fn;
extern "C" void __wrap__Unwind_Resume (struct _Unwind_Exception *exc) extern "C" void __wrap__Unwind_Resume(struct _Unwind_Exception *exc)
{ {
abort(); abort();
} }
extern "C" void __wrap__Unwind_DeleteException (struct _Unwind_Exception *exc) extern "C" void __wrap__Unwind_DeleteException(struct _Unwind_Exception *exc)
{ {
abort(); abort();
} }
extern "C" _Unwind_Reason_Code __wrap__Unwind_RaiseException(struct _Unwind_Exception *exc) extern "C" _Unwind_Reason_Code __wrap__Unwind_RaiseException(struct _Unwind_Exception *exc)
{ {
return abort_return<_Unwind_Reason_Code>(); return abort_return<_Unwind_Reason_Code>();
} }
extern "C" _Unwind_Reason_Code __wrap__Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc) extern "C" _Unwind_Reason_Code __wrap__Unwind_Resume_or_Rethrow(struct _Unwind_Exception *exc)
__attribute__((alias("__wrap__Unwind_RaiseException"))); __attribute__((alias("__wrap__Unwind_RaiseException")));
extern "C" _Unwind_Reason_Code __wrap__Unwind_ForcedUnwind (struct _Unwind_Exception *exc, extern "C" _Unwind_Reason_Code __wrap__Unwind_ForcedUnwind(struct _Unwind_Exception *exc,
_Unwind_Stop_Fn stop, void * stop_argument) _Unwind_Stop_Fn stop, void * stop_argument)
{ {
return abort_return<_Unwind_Reason_Code>(); return abort_return<_Unwind_Reason_Code>();
} }
@ -173,14 +171,14 @@ extern "C" _Unwind_Reason_Code __wrap__Unwind_Backtrace(_Unwind_Trace_Fn trace,
} }
// eh_personality.o // eh_personality.o
extern "C" void __wrap___cxa_call_unexpected (void *exc_obj_in) extern "C" void __wrap___cxa_call_unexpected(void *exc_obj_in)
__attribute__((alias("abort_expect_void"))); __attribute__((alias("abort_expect_void")));
extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0 (int version, extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0(int version,
_Unwind_Action actions, _Unwind_Action actions,
_Unwind_Exception_Class exception_class, _Unwind_Exception_Class exception_class,
struct _Unwind_Exception *ue_header, struct _Unwind_Exception *ue_header,
struct _Unwind_Context *context) struct _Unwind_Context *context)
{ {
return abort_return<_Unwind_Reason_Code>(); return abort_return<_Unwind_Reason_Code>();
} }

View File

@ -68,7 +68,7 @@ static void wait_for_guard_obj(guard_t* g)
s_static_init_waiting_count++; s_static_init_waiting_count++;
#ifndef _NDEBUG #ifndef _NDEBUG
s_static_init_max_waiting_count = std::max(s_static_init_waiting_count, s_static_init_max_waiting_count = std::max(s_static_init_waiting_count,
s_static_init_max_waiting_count); s_static_init_max_waiting_count);
#endif #endif
do { do {
@ -91,7 +91,7 @@ static void wait_for_guard_obj(guard_t* g)
/* Semaphore may have been given because some other guard object became ready. /* Semaphore may have been given because some other guard object became ready.
* Check the guard object we need and wait again if it is still pending. * Check the guard object we need and wait again if it is still pending.
*/ */
} while(g->pending); } while (g->pending);
s_static_init_waiting_count--; s_static_init_waiting_count--;
} }

View File

@ -9,7 +9,7 @@
#include "esp_private/startup_internal.h" #include "esp_private/startup_internal.h"
namespace { namespace {
const char *TAG = "C++ init"; const char *TAG = "C++ init";
} }
#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS #ifdef CONFIG_COMPILER_CXX_EXCEPTIONS

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -171,12 +171,9 @@ TEST_CASE("c++ exceptions emergency pool", "[cxx] [exceptions]")
void **p, **pprev = NULL; void **p, **pprev = NULL;
int thrown_value = 0; int thrown_value = 0;
// throw first exception to ensure that all initial allocations are made // throw first exception to ensure that all initial allocations are made
try try {
{
throw 33; throw 33;
} } catch (int e) {
catch (int e)
{
thrown_value = e; thrown_value = e;
} }
TEST_ASSERT_EQUAL(33, thrown_value); TEST_ASSERT_EQUAL(33, thrown_value);
@ -189,12 +186,9 @@ TEST_CASE("c++ exceptions emergency pool", "[cxx] [exceptions]")
} }
pprev = p; pprev = p;
} }
try try {
{
throw 20; throw 20;
} } catch (int e) {
catch (int e)
{
thrown_value = e; thrown_value = e;
} }
#if CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE > 0 #if CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE > 0

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -28,8 +28,7 @@ extern "C" void tearDown()
static const char* TAG = "cxx"; static const char* TAG = "cxx";
class NonPOD class NonPOD {
{
public: public:
NonPOD(int a_) : a(a_) { } NonPOD(int a_) : a(a_) { }
int a; int a;
@ -60,12 +59,12 @@ TEST_CASE("can use static initializers for non-POD types", "[restart_init]")
static SemaphoreHandle_t s_slow_init_sem = NULL; static SemaphoreHandle_t s_slow_init_sem = NULL;
template<int obj> template<int obj>
class SlowInit class SlowInit {
{
public: public:
SlowInit(int arg) { SlowInit(int arg)
{
ESP_LOGD(TAG, "init obj=%d start, arg=%d", obj, arg); ESP_LOGD(TAG, "init obj=%d start, arg=%d", obj, arg);
vTaskDelay(300/portTICK_PERIOD_MS); vTaskDelay(300 / portTICK_PERIOD_MS);
TEST_ASSERT_EQUAL(-1, mInitBy); TEST_ASSERT_EQUAL(-1, mInitBy);
TEST_ASSERT_EQUAL(0, mInitCount); TEST_ASSERT_EQUAL(0, mInitCount);
mInitBy = arg; mInitBy = arg;
@ -73,7 +72,8 @@ public:
ESP_LOGD(TAG, "init obj=%d done", obj); ESP_LOGD(TAG, "init obj=%d done", obj);
} }
static void task(void* arg) { static void task(void* arg)
{
int taskId = reinterpret_cast<int>(arg); int taskId = reinterpret_cast<int>(arg);
ESP_LOGD(TAG, "obj=%d before static init, task=%d", obj, taskId); ESP_LOGD(TAG, "obj=%d before static init, task=%d", obj, taskId);
static SlowInit slowinit(taskId); static SlowInit slowinit(taskId);
@ -95,7 +95,7 @@ template<int obj>
static int start_slow_init_task(int id, int affinity) static int start_slow_init_task(int id, int affinity)
{ {
return xTaskCreatePinnedToCore(&SlowInit<obj>::task, "slow_init", 2048, return xTaskCreatePinnedToCore(&SlowInit<obj>::task, "slow_init", 2048,
reinterpret_cast<void*>(id), 3, NULL, affinity) ? 1 : 0; reinterpret_cast<void*>(id), 3, NULL, affinity) ? 1 : 0;
} }
TEST_CASE("static initialization guards work as expected", "[misc]") TEST_CASE("static initialization guards work as expected", "[misc]")
@ -122,16 +122,16 @@ TEST_CASE("static initialization guards work as expected", "[misc]")
// All tasks should // All tasks should
for (int i = 0; i < task_count; ++i) { for (int i = 0; i < task_count; ++i) {
TEST_ASSERT_TRUE(xSemaphoreTake(s_slow_init_sem, 500/portTICK_PERIOD_MS)); TEST_ASSERT_TRUE(xSemaphoreTake(s_slow_init_sem, 500 / portTICK_PERIOD_MS));
} }
vSemaphoreDelete(s_slow_init_sem); vSemaphoreDelete(s_slow_init_sem);
vTaskDelay(10); // Allow tasks to clean up, avoids race with leak detector vTaskDelay(10); // Allow tasks to clean up, avoids race with leak detector
} }
struct GlobalInitTest struct GlobalInitTest {
{ GlobalInitTest() : index(order++)
GlobalInitTest() : index(order++) { {
} }
int index; int index;
static int order; static int order;
@ -150,8 +150,7 @@ TEST_CASE("global initializers run in the correct order", "[misc]")
TEST_ASSERT_EQUAL(2, g_init_test3.index); TEST_ASSERT_EQUAL(2, g_init_test3.index);
} }
struct StaticInitTestBeforeScheduler struct StaticInitTestBeforeScheduler {
{
StaticInitTestBeforeScheduler() StaticInitTestBeforeScheduler()
{ {
static int first_init_order = getOrder(); static int first_init_order = getOrder();
@ -181,8 +180,7 @@ TEST_CASE("before scheduler has started, static initializers work correctly", "[
TEST_ASSERT_EQUAL(2, StaticInitTestBeforeScheduler::order); TEST_ASSERT_EQUAL(2, StaticInitTestBeforeScheduler::order);
} }
struct PriorityInitTest struct PriorityInitTest {
{
PriorityInitTest() PriorityInitTest()
{ {
index = getOrder(); index = getOrder();
@ -220,15 +218,13 @@ TEST_CASE("can use new and delete", "[misc]")
delete[] int_array; delete[] int_array;
} }
class Base class Base {
{
public: public:
virtual ~Base() = default; virtual ~Base() = default;
virtual void foo() = 0; virtual void foo() = 0;
}; };
class Derived : public Base class Derived : public Base {
{
public: public:
virtual void foo() { } virtual void foo() { }
}; };
@ -236,7 +232,7 @@ public:
TEST_CASE("can call virtual functions", "[misc]") TEST_CASE("can call virtual functions", "[misc]")
{ {
Derived d; Derived d;
Base& b = static_cast<Base&>(d); Base &b = static_cast<Base &>(d);
b.foo(); b.foo();
} }
@ -278,7 +274,7 @@ static void recur_and_smash_cxx()
{ {
static int cnt; static int cnt;
volatile uint8_t buf[50]; volatile uint8_t buf[50];
volatile int num = sizeof(buf)+10; volatile int num = sizeof(buf) + 10;
if (cnt++ < 1) { if (cnt++ < 1) {
recur_and_smash_cxx(); recur_and_smash_cxx();

View File

@ -101,7 +101,7 @@ TEST_CASE("unsuccessful dynamic cast on reference throws exception", "[cxx]")
DerivedA derived_a; DerivedA derived_a;
Base &base = derived_a; Base &base = derived_a;
try { try {
DerivedB &derived_b = dynamic_cast<DerivedB&>(base); DerivedB &derived_b = dynamic_cast<DerivedB &>(base);
derived_b.name(); // suppress warning derived_b.name(); // suppress warning
} catch (bad_cast &e) { } catch (bad_cast &e) {
thrown = true; thrown = true;

View File

@ -14,11 +14,10 @@ using std::endl;
using std::runtime_error; using std::runtime_error;
/* A simple class which may throw an exception from constructor */ /* A simple class which may throw an exception from constructor */
class Throwing class Throwing {
{
public: public:
Throwing(int arg) Throwing(int arg)
: m_arg(arg) : m_arg(arg)
{ {
cout << "In constructor, arg=" << arg << endl; cout << "In constructor, arg=" << arg << endl;
if (arg == 0) { if (arg == 0) {

View File

@ -20,8 +20,7 @@
using namespace std::chrono; using namespace std::chrono;
const auto sleep_time = seconds const auto sleep_time = seconds {
{
5 5
}; };

View File

@ -25,24 +25,27 @@ class DerivedB;
static string demangle(const char* name); static string demangle(const char* name);
class Base class Base {
{
public: public:
virtual ~Base() {} ; virtual ~Base() {} ;
virtual string name() = 0; virtual string name() = 0;
static shared_ptr<Base> make_random_derived(); static shared_ptr<Base> make_random_derived();
}; };
class DerivedA : public Base class DerivedA : public Base {
{
public: public:
string name() override { return "DerivedA"; } string name() override
{
return "DerivedA";
}
}; };
class DerivedB : public Base class DerivedB : public Base {
{
public: public:
string name() override { return "DerivedB"; } string name() override
{
return "DerivedB";
}
}; };
/* Creates either DerivedA or DerivedB, depending on a random number */ /* Creates either DerivedA or DerivedB, depending on a random number */
@ -70,7 +73,7 @@ extern "C" void app_main()
std::vector<shared_ptr<Base>> objects(5); std::vector<shared_ptr<Base>> objects(5);
cout << "Generating " << objects.size() << " random objects and printing their types:" << endl; cout << "Generating " << objects.size() << " random objects and printing their types:" << endl;
std::generate(objects.begin(), objects.end(), Base::make_random_derived); std::generate(objects.begin(), objects.end(), Base::make_random_derived);
for (auto &obj: objects) { for (auto &obj : objects) {
cout << "obj->name() is: " << obj->name() << endl << '\t'; cout << "obj->name() is: " << obj->name() << endl << '\t';
cout << "typeid(*obj).name() is: " << demangle(typeid(*obj).name()) << endl << '\t'; cout << "typeid(*obj).name() is: " << demangle(typeid(*obj).name()) << endl << '\t';

View File

@ -50,7 +50,6 @@ components_not_formatted_temporary:
- "/components/bt/" - "/components/bt/"
- "/components/cmock/" - "/components/cmock/"
- "/components/console/" - "/components/console/"
- "/components/cxx/"
- "/components/efuse/" - "/components/efuse/"
- "/components/esp_coex/" - "/components/esp_coex/"
- "/components/esp_eth/" - "/components/esp_eth/"
@ -102,7 +101,6 @@ components_not_formatted_temporary:
- "/examples/build_system/" - "/examples/build_system/"
- "/examples/common_components/" - "/examples/common_components/"
- "/examples/custom_bootloader/" - "/examples/custom_bootloader/"
- "/examples/cxx/"
- "/examples/ethernet/" - "/examples/ethernet/"
- "/examples/get-started/" - "/examples/get-started/"
- "/examples/mesh/" - "/examples/mesh/"