Skip to content

Replace PPC_FUNC_NAME with ppc::util::FuncName() implementation #460

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

Merged
merged 7 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 17 additions & 1 deletion .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ on:

jobs:
macos-clang-build:
runs-on: macOS-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 'latest'
- name: Setup environment
run: |
brew update-reset
Expand Down Expand Up @@ -49,6 +53,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 'latest'
- name: Setup environment
run: |
brew update-reset
Expand Down Expand Up @@ -90,6 +98,10 @@ jobs:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v4
- name: Install Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 'latest'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using latest-stable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aobolensk done

- name: Setup environment
run: |
brew update-reset
Expand Down Expand Up @@ -152,6 +164,10 @@ jobs:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v4
- name: Install Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 'latest'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move to the separate PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aobolensk done

- name: Setup environment
run: |
brew update-reset
Expand Down
12 changes: 6 additions & 6 deletions modules/core/task/include/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,33 @@ class Task {
/// @brief Validates input data and task attributes before execution.
/// @return True if validation is successful.
virtual bool Validation() final {
InternalOrderTest(PPC_FUNC_NAME);
InternalOrderTest(ppc::util::FuncName());
return ValidationImpl();
}

/// @brief Performs preprocessing on the input data.
/// @return True if preprocessing is successful.
virtual bool PreProcessing() final {
InternalOrderTest(PPC_FUNC_NAME);
InternalOrderTest(ppc::util::FuncName());
if (state_of_testing_ == StateOfTesting::kFunc) {
InternalTimeTest(PPC_FUNC_NAME);
InternalTimeTest(ppc::util::FuncName());
}
return PreProcessingImpl();
}

/// @brief Executes the main logic of the task.
/// @return True if execution is successful.
virtual bool Run() final {
InternalOrderTest(PPC_FUNC_NAME);
InternalOrderTest(ppc::util::FuncName());
return RunImpl();
}

/// @brief Performs postprocessing on the output data.
/// @return True if postprocessing is successful.
virtual bool PostProcessing() final {
InternalOrderTest(PPC_FUNC_NAME);
InternalOrderTest(ppc::util::FuncName());
if (state_of_testing_ == StateOfTesting::kFunc) {
InternalTimeTest(PPC_FUNC_NAME);
InternalTimeTest(ppc::util::FuncName());
}
return PostProcessingImpl();
}
Expand Down
43 changes: 41 additions & 2 deletions modules/core/util/include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <source_location>
#include <string>
#include <string_view>

#include "nlohmann/json_fwd.hpp"

#define PPC_FUNC_NAME __func__

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4459)
Expand All @@ -27,6 +26,46 @@ using NlohmannJsonTypeError = nlohmann::json::type_error;

namespace ppc::util {

/**
* @brief Extract the bare function name (e.g. "PreProcessing" or "foo")
* from a full signature provided by std::source_location,
* working both on GCC/Clang and MSVC.
*
* @param loc Source location (file, line, pretty-signature).
* Defaults to the call site via std::source_location::current().
* @return A std::string containing only the function name.
*
* @note On GCC/Clang, loc.function_name() yields a “pretty” signature
* including namespaces, templates and parameter list.
* On MSVC, it also includes return type and calling convention.
* This function strips off everything before the last `::` (if any),
* and any parameter list or qualifiers after the name.
*/
inline std::string FuncName(const std::source_location& loc = std::source_location::current()) {
std::string_view full = loc.function_name();
// 1) find end of name (just before '(' or end of string)
size_t paren = full.find('(');
size_t name_end = (paren == std::string_view::npos ? full.size() : paren);

// 2) try to strip namespaces/classes via '::'
size_t colons = full.rfind("::", name_end);
size_t start = (colons == std::string_view::npos ? 0 : colons + 2);

// 3) on MSVC there's often a return-type + "__cdecl " prefix before the name
#ifdef _MSC_VER
if (colons == std::string_view::npos) {
// if no '::', drop everything up to last space before name_end
size_t last_space = full.rfind(' ', name_end);
if (last_space != std::string_view::npos) {
start = last_space + 1;
}
}
#endif

// 4) construct owning string of just the name
return std::string{full.substr(start, name_end - start)};
}

enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };

std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);
Expand Down
Loading