aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/include/pybind11/detail/typeid.h
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2020-07-27 13:50:42 +0100
committerGitHub <noreply@github.com>2020-07-27 13:50:42 +0100
commitb39a2a502065ec1407417ffacdac2154385bf80f (patch)
tree3349c93ac87f5758009c53b3e2eb5b9a130cd0d6 /3rdparty/pybind11/include/pybind11/detail/typeid.h
parente6991ad5dc79f6118838f091cc05f10d3377eb4a (diff)
parentfe398ab983aee9283f61c288dc98d94542c30332 (diff)
downloadnextpnr-b39a2a502065ec1407417ffacdac2154385bf80f.tar.gz
nextpnr-b39a2a502065ec1407417ffacdac2154385bf80f.tar.bz2
nextpnr-b39a2a502065ec1407417ffacdac2154385bf80f.zip
Merge pull request #477 from YosysHQ/pybind11
Move to pybind11
Diffstat (limited to '3rdparty/pybind11/include/pybind11/detail/typeid.h')
-rw-r--r--3rdparty/pybind11/include/pybind11/detail/typeid.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/3rdparty/pybind11/include/pybind11/detail/typeid.h b/3rdparty/pybind11/include/pybind11/detail/typeid.h
new file mode 100644
index 00000000..9c8a4fc6
--- /dev/null
+++ b/3rdparty/pybind11/include/pybind11/detail/typeid.h
@@ -0,0 +1,55 @@
+/*
+ pybind11/detail/typeid.h: Compiler-independent access to type identifiers
+
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
+
+ All rights reserved. Use of this source code is governed by a
+ BSD-style license that can be found in the LICENSE file.
+*/
+
+#pragma once
+
+#include <cstdio>
+#include <cstdlib>
+
+#if defined(__GNUG__)
+#include <cxxabi.h>
+#endif
+
+#include "common.h"
+
+NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
+NAMESPACE_BEGIN(detail)
+/// Erase all occurrences of a substring
+inline void erase_all(std::string &string, const std::string &search) {
+ for (size_t pos = 0;;) {
+ pos = string.find(search, pos);
+ if (pos == std::string::npos) break;
+ string.erase(pos, search.length());
+ }
+}
+
+PYBIND11_NOINLINE inline void clean_type_id(std::string &name) {
+#if defined(__GNUG__)
+ int status = 0;
+ std::unique_ptr<char, void (*)(void *)> res {
+ abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free };
+ if (status == 0)
+ name = res.get();
+#else
+ detail::erase_all(name, "class ");
+ detail::erase_all(name, "struct ");
+ detail::erase_all(name, "enum ");
+#endif
+ detail::erase_all(name, "pybind11::");
+}
+NAMESPACE_END(detail)
+
+/// Return a string representation of a C++ type
+template <typename T> static std::string type_id() {
+ std::string name(typeid(T).name());
+ detail::clean_type_id(name);
+ return name;
+}
+
+NAMESPACE_END(PYBIND11_NAMESPACE)