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

[global] Added gcc7 ioc implementation #19268

Merged
merged 1 commit into from
Sep 4, 2023
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
21 changes: 13 additions & 8 deletions src/framework/global/modularity/imoduleinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@
#include "moduleinfo.h"

namespace mu::modularity {
struct InterfaceInfo {
std::string_view id;
std::string_view module;
bool internal = false;
constexpr InterfaceInfo(std::string_view i, std::string_view m, bool intr)
: id(i), module(m), internal(intr) {}
};

class IModuleInterface
{
public:
Expand Down Expand Up @@ -77,6 +69,8 @@ struct IModuleInternalCreator : public IModuleCreator {
};
}

#ifndef IOC_NO_STRING_VIEW_CONSTEXPR_METHODS

#define INTERFACE_ID(id) \
public: \
static constexpr mu::modularity::InterfaceInfo interfaceInfo() { \
Expand All @@ -86,6 +80,17 @@ public: \
} \
private: \

#else
#define INTERFACE_ID(id) \
public: \
static const mu::modularity::InterfaceInfo& interfaceInfo() { \
static const std::string_view sig(IOC_FUNC_SIG); \
static const mu::modularity::InterfaceInfo info(#id, mu::modularity::moduleNameBySig(sig), isInternalInterface()); \
return info; \
} \
private: \

#endif

#define MODULE_EXPORT_INTERFACE public mu::modularity::IModuleExportInterface
#define MODULE_EXPORT_CREATOR public mu::modularity::IModuleExportCreator
Expand Down
44 changes: 44 additions & 0 deletions src/framework/global/modularity/moduleinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,23 @@
#endif
#endif

#if defined(__GNUC__) && !defined(__clang__)
#if (__GNUC__ < 11)
#define IOC_NO_STRING_VIEW_CONSTEXPR_METHODS
#endif
#endif

namespace mu::modularity {
struct InterfaceInfo {
std::string_view id;
std::string_view module;
bool internal = false;
constexpr InterfaceInfo(std::string_view i, std::string_view m, bool intr)
: id(i), module(m), internal(intr) {}
};

#ifndef IOC_NO_STRING_VIEW_CONSTEXPR_METHODS

constexpr std::string_view moduleNameBySig(const std::string_view& sig)
{
constexpr std::string_view ArgBegin("(");
Expand All @@ -58,6 +74,34 @@ constexpr std::string_view moduleNameBySig(const std::string_view& sig)
std::string_view module = sig.substr(beginModule, endModule - beginModule);
return module;
}

#else
inline std::string_view moduleNameBySig(const std::string_view& sig)
{
static const std::string_view ArgBegin("(");
static const std::string_view Space(" ");
static const std::string_view Colon("::");

//! NOTE Signature should be like
//! SomeType mu::modulename::maybe::ClassName::methodName()

std::size_t endMethod = sig.find_first_of(ArgBegin);
if (endMethod == std::string_view::npos) {
return sig;
}

std::size_t beginMethod = sig.find_last_of(Space, endMethod);
if (beginMethod == std::string_view::npos) {
return sig;
}

size_t beginModule = sig.find_first_of(Colon, beginMethod) + 2;
size_t endModule = sig.find_first_of(Colon, beginModule);
std::string_view module = sig.substr(beginModule, endModule - beginModule);
return module;
}

#endif
}

#endif // MU_MODULARITY_MODULEINFO_H