From 0c01c5965e52303421021ce9acf8148db8135920 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Tue, 5 Mar 2024 14:07:05 +0800 Subject: [PATCH] refactor(cxx): formatted according to IDF astyle rules --- components/cxx/cxx_exception_stubs.cpp | 96 +++++++++---------- components/cxx/cxx_guards.cpp | 4 +- components/cxx/cxx_init.cpp | 2 +- .../exception/main/test_exception.cpp | 16 +--- .../general/main/test_cxx_general.cpp | 42 ++++---- .../cxx/test_apps/rtti/main/test_rtti.cpp | 2 +- .../main/exception_example_main.cpp | 5 +- examples/cxx/pthread/main/cpp_pthread.cpp | 3 +- examples/cxx/rtti/main/rtti_example_main.cpp | 21 ++-- tools/ci/astyle-rules.yml | 2 - 10 files changed, 90 insertions(+), 103 deletions(-) diff --git a/components/cxx/cxx_exception_stubs.cpp b/components/cxx/cxx_exception_stubs.cpp index a652ace2e3..168d9dae2c 100644 --- a/components/cxx/cxx_exception_stubs.cpp +++ b/components/cxx/cxx_exception_stubs.cpp @@ -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 */ @@ -40,45 +40,44 @@ extern "C" void __wrap__Unwind_SetEnableExceptionFdeSorting(unsigned char enable 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(); } -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(); } -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(); } -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(); } +extern "C" void __wrap___register_frame(void *begin) +__attribute__((alias("abort_expect_void"))); -extern "C" void __wrap___register_frame (void *begin) - __attribute__((alias("abort_expect_void"))); +extern "C" void __wrap___register_frame_table(void *begin) +__attribute__((alias("abort_expect_void"))); -extern "C" void __wrap___register_frame_table (void *begin) - __attribute__((alias("abort_expect_void"))); +extern "C" void *__wrap___deregister_frame_info_bases(const void *begin) +__attribute__((alias("abort_expect_void_and_return"))); -extern "C" void *__wrap___deregister_frame_info_bases (const void *begin) - __attribute__((alias("abort_expect_void_and_return"))); +extern "C" void *__wrap___deregister_frame_info(const void *begin) +__attribute__((alias("abort_expect_void_and_return"))); -extern "C" void *__wrap___deregister_frame_info (const void *begin) - __attribute__((alias("abort_expect_void_and_return"))); - -extern "C" void __wrap___deregister_frame (void *begin) - __attribute__((alias("abort_expect_void"))); +extern "C" void __wrap___deregister_frame(void *begin) +__attribute__((alias("abort_expect_void"))); 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(); } @@ -87,50 +86,50 @@ extern "C" const fde * __wrap__Unwind_Find_FDE (void *pc, struct dwarf_eh_bases typedef void* _Unwind_Ptr; 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>(); } -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>(); } -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(); } -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(); } -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>(); } -extern "C" _Unwind_Ptr __wrap__Unwind_GetIP (struct _Unwind_Context *context) - __attribute__((alias("forward_abort_uw_ctx"))); +extern "C" _Unwind_Ptr __wrap__Unwind_GetIP(struct _Unwind_Context *context) +__attribute__((alias("forward_abort_uw_ctx"))); -extern "C" _Unwind_Ptr __wrap__Unwind_GetRegionStart (struct _Unwind_Context *context) - __attribute__((alias("forward_abort_uw_ctx"))); +extern "C" _Unwind_Ptr __wrap__Unwind_GetRegionStart(struct _Unwind_Context *context) +__attribute__((alias("forward_abort_uw_ctx"))); -extern "C" _Unwind_Ptr __wrap__Unwind_GetDataRelBase (struct _Unwind_Context *context) - __attribute__((alias("forward_abort_uw_ctx"))); +extern "C" _Unwind_Ptr __wrap__Unwind_GetDataRelBase(struct _Unwind_Context *context) +__attribute__((alias("forward_abort_uw_ctx"))); -extern "C" _Unwind_Ptr __wrap__Unwind_GetTextRelBase (struct _Unwind_Context *context) - __attribute__((alias("forward_abort_uw_ctx"))); +extern "C" _Unwind_Ptr __wrap__Unwind_GetTextRelBase(struct _Unwind_Context *context) +__attribute__((alias("forward_abort_uw_ctx"))); -extern "C" void *__wrap__Unwind_GetLanguageSpecificData (struct _Unwind_Context *context) - __attribute__((alias("forward_abort_uw_ctx"))); +extern "C" void *__wrap__Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) +__attribute__((alias("forward_abort_uw_ctx"))); -extern "C" void *__wrap__Unwind_FindEnclosingFunction (void *pc) - __attribute__((alias("abort_expect_void_and_return"))); +extern "C" void *__wrap__Unwind_FindEnclosingFunction(void *pc) +__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(); } @@ -142,27 +141,26 @@ typedef int _Unwind_Exception_Class; typedef int* _Unwind_Trace_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(); } -extern "C" void __wrap__Unwind_DeleteException (struct _Unwind_Exception *exc) +extern "C" void __wrap__Unwind_DeleteException(struct _Unwind_Exception *exc) { abort(); } - extern "C" _Unwind_Reason_Code __wrap__Unwind_RaiseException(struct _Unwind_Exception *exc) { return abort_return<_Unwind_Reason_Code>(); } -extern "C" _Unwind_Reason_Code __wrap__Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc) - __attribute__((alias("__wrap__Unwind_RaiseException"))); +extern "C" _Unwind_Reason_Code __wrap__Unwind_Resume_or_Rethrow(struct _Unwind_Exception *exc) +__attribute__((alias("__wrap__Unwind_RaiseException"))); -extern "C" _Unwind_Reason_Code __wrap__Unwind_ForcedUnwind (struct _Unwind_Exception *exc, - _Unwind_Stop_Fn stop, void * stop_argument) +extern "C" _Unwind_Reason_Code __wrap__Unwind_ForcedUnwind(struct _Unwind_Exception *exc, + _Unwind_Stop_Fn stop, void * stop_argument) { 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 -extern "C" void __wrap___cxa_call_unexpected (void *exc_obj_in) - __attribute__((alias("abort_expect_void"))); +extern "C" void __wrap___cxa_call_unexpected(void *exc_obj_in) +__attribute__((alias("abort_expect_void"))); -extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0 (int version, - _Unwind_Action actions, - _Unwind_Exception_Class exception_class, - struct _Unwind_Exception *ue_header, - struct _Unwind_Context *context) +extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0(int version, + _Unwind_Action actions, + _Unwind_Exception_Class exception_class, + struct _Unwind_Exception *ue_header, + struct _Unwind_Context *context) { return abort_return<_Unwind_Reason_Code>(); } diff --git a/components/cxx/cxx_guards.cpp b/components/cxx/cxx_guards.cpp index e74ea9a7f0..0a76173769 100644 --- a/components/cxx/cxx_guards.cpp +++ b/components/cxx/cxx_guards.cpp @@ -68,7 +68,7 @@ static void wait_for_guard_obj(guard_t* g) s_static_init_waiting_count++; #ifndef _NDEBUG 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 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. * 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--; } diff --git a/components/cxx/cxx_init.cpp b/components/cxx/cxx_init.cpp index 7ade550d76..1819e5b7b2 100644 --- a/components/cxx/cxx_init.cpp +++ b/components/cxx/cxx_init.cpp @@ -9,7 +9,7 @@ #include "esp_private/startup_internal.h" namespace { - const char *TAG = "C++ init"; +const char *TAG = "C++ init"; } #ifdef CONFIG_COMPILER_CXX_EXCEPTIONS diff --git a/components/cxx/test_apps/exception/main/test_exception.cpp b/components/cxx/test_apps/exception/main/test_exception.cpp index ee77e0afcb..d0ef7166c7 100644 --- a/components/cxx/test_apps/exception/main/test_exception.cpp +++ b/components/cxx/test_apps/exception/main/test_exception.cpp @@ -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 */ @@ -171,12 +171,9 @@ TEST_CASE("c++ exceptions emergency pool", "[cxx] [exceptions]") void **p, **pprev = NULL; int thrown_value = 0; // throw first exception to ensure that all initial allocations are made - try - { + try { throw 33; - } - catch (int e) - { + } catch (int e) { thrown_value = e; } TEST_ASSERT_EQUAL(33, thrown_value); @@ -189,12 +186,9 @@ TEST_CASE("c++ exceptions emergency pool", "[cxx] [exceptions]") } pprev = p; } - try - { + try { throw 20; - } - catch (int e) - { + } catch (int e) { thrown_value = e; } #if CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE > 0 diff --git a/components/cxx/test_apps/general/main/test_cxx_general.cpp b/components/cxx/test_apps/general/main/test_cxx_general.cpp index 07e3fcc3bb..0e483ab655 100644 --- a/components/cxx/test_apps/general/main/test_cxx_general.cpp +++ b/components/cxx/test_apps/general/main/test_cxx_general.cpp @@ -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 */ @@ -28,8 +28,7 @@ extern "C" void tearDown() static const char* TAG = "cxx"; -class NonPOD -{ +class NonPOD { public: NonPOD(int a_) : a(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; template -class SlowInit -{ +class SlowInit { public: - SlowInit(int arg) { + SlowInit(int 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(0, mInitCount); mInitBy = arg; @@ -73,7 +72,8 @@ public: ESP_LOGD(TAG, "init obj=%d done", obj); } - static void task(void* arg) { + static void task(void* arg) + { int taskId = reinterpret_cast(arg); ESP_LOGD(TAG, "obj=%d before static init, task=%d", obj, taskId); static SlowInit slowinit(taskId); @@ -95,7 +95,7 @@ template static int start_slow_init_task(int id, int affinity) { return xTaskCreatePinnedToCore(&SlowInit::task, "slow_init", 2048, - reinterpret_cast(id), 3, NULL, affinity) ? 1 : 0; + reinterpret_cast(id), 3, NULL, affinity) ? 1 : 0; } 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 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); vTaskDelay(10); // Allow tasks to clean up, avoids race with leak detector } -struct GlobalInitTest -{ - GlobalInitTest() : index(order++) { +struct GlobalInitTest { + GlobalInitTest() : index(order++) + { } int index; 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); } -struct StaticInitTestBeforeScheduler -{ +struct StaticInitTestBeforeScheduler { StaticInitTestBeforeScheduler() { 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); } -struct PriorityInitTest -{ +struct PriorityInitTest { PriorityInitTest() { index = getOrder(); @@ -220,15 +218,13 @@ TEST_CASE("can use new and delete", "[misc]") delete[] int_array; } -class Base -{ +class Base { public: virtual ~Base() = default; virtual void foo() = 0; }; -class Derived : public Base -{ +class Derived : public Base { public: virtual void foo() { } }; @@ -236,7 +232,7 @@ public: TEST_CASE("can call virtual functions", "[misc]") { Derived d; - Base& b = static_cast(d); + Base &b = static_cast(d); b.foo(); } @@ -278,7 +274,7 @@ static void recur_and_smash_cxx() { static int cnt; volatile uint8_t buf[50]; - volatile int num = sizeof(buf)+10; + volatile int num = sizeof(buf) + 10; if (cnt++ < 1) { recur_and_smash_cxx(); diff --git a/components/cxx/test_apps/rtti/main/test_rtti.cpp b/components/cxx/test_apps/rtti/main/test_rtti.cpp index 06ae473376..71d0c3b949 100644 --- a/components/cxx/test_apps/rtti/main/test_rtti.cpp +++ b/components/cxx/test_apps/rtti/main/test_rtti.cpp @@ -101,7 +101,7 @@ TEST_CASE("unsuccessful dynamic cast on reference throws exception", "[cxx]") DerivedA derived_a; Base &base = derived_a; try { - DerivedB &derived_b = dynamic_cast(base); + DerivedB &derived_b = dynamic_cast(base); derived_b.name(); // suppress warning } catch (bad_cast &e) { thrown = true; diff --git a/examples/cxx/exceptions/main/exception_example_main.cpp b/examples/cxx/exceptions/main/exception_example_main.cpp index 29045beb4c..3c7e422b9a 100644 --- a/examples/cxx/exceptions/main/exception_example_main.cpp +++ b/examples/cxx/exceptions/main/exception_example_main.cpp @@ -14,11 +14,10 @@ using std::endl; using std::runtime_error; /* A simple class which may throw an exception from constructor */ -class Throwing -{ +class Throwing { public: Throwing(int arg) - : m_arg(arg) + : m_arg(arg) { cout << "In constructor, arg=" << arg << endl; if (arg == 0) { diff --git a/examples/cxx/pthread/main/cpp_pthread.cpp b/examples/cxx/pthread/main/cpp_pthread.cpp index 232e7f3431..8bcf57cb4b 100644 --- a/examples/cxx/pthread/main/cpp_pthread.cpp +++ b/examples/cxx/pthread/main/cpp_pthread.cpp @@ -20,8 +20,7 @@ using namespace std::chrono; -const auto sleep_time = seconds -{ +const auto sleep_time = seconds { 5 }; diff --git a/examples/cxx/rtti/main/rtti_example_main.cpp b/examples/cxx/rtti/main/rtti_example_main.cpp index e2a4a5efd3..d053f5e047 100644 --- a/examples/cxx/rtti/main/rtti_example_main.cpp +++ b/examples/cxx/rtti/main/rtti_example_main.cpp @@ -25,24 +25,27 @@ class DerivedB; static string demangle(const char* name); -class Base -{ +class Base { public: virtual ~Base() {} ; virtual string name() = 0; static shared_ptr make_random_derived(); }; -class DerivedA : public Base -{ +class DerivedA : public Base { public: - string name() override { return "DerivedA"; } + string name() override + { + return "DerivedA"; + } }; -class DerivedB : public Base -{ +class DerivedB : public Base { public: - string name() override { return "DerivedB"; } + string name() override + { + return "DerivedB"; + } }; /* Creates either DerivedA or DerivedB, depending on a random number */ @@ -70,7 +73,7 @@ extern "C" void app_main() std::vector> objects(5); cout << "Generating " << objects.size() << " random objects and printing their types:" << endl; 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 << "typeid(*obj).name() is: " << demangle(typeid(*obj).name()) << endl << '\t'; diff --git a/tools/ci/astyle-rules.yml b/tools/ci/astyle-rules.yml index fbff07ba69..c636bbf1cb 100644 --- a/tools/ci/astyle-rules.yml +++ b/tools/ci/astyle-rules.yml @@ -50,7 +50,6 @@ components_not_formatted_temporary: - "/components/bt/" - "/components/cmock/" - "/components/console/" - - "/components/cxx/" - "/components/efuse/" - "/components/esp_coex/" - "/components/esp_eth/" @@ -102,7 +101,6 @@ components_not_formatted_temporary: - "/examples/build_system/" - "/examples/common_components/" - "/examples/custom_bootloader/" - - "/examples/cxx/" - "/examples/ethernet/" - "/examples/get-started/" - "/examples/mesh/"