From 14091b0b56059afdf0edabd822f2d2199dc03acd Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Tue, 16 May 2023 23:37:52 +0200 Subject: [PATCH 1/4] clean leftover --- source/type.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/type.cpp b/source/type.cpp index 2adf346d..d82adb0c 100644 --- a/source/type.cpp +++ b/source/type.cpp @@ -461,11 +461,6 @@ std::string standard_name(clang::QualType const &qt) //qt.dump(); string r = qt.getAsString(); - // if( r == "std::array::size_type" ) { - // //if( begins_with(r, "std::array<" ) ) { - // outs() << "--> " << r << '\n'; - // qt.dump(); - // } // if( begins_with(r, "std::") ) return r; //standard_name(r); static std::set standard_names {"std::size_t"}; From 61fbc5a4061523681a1f02160fce71881d14e372 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Wed, 17 May 2023 00:02:46 +0200 Subject: [PATCH 2/4] Prefer braced init to explicit make_pair() --- source/type.cpp | 55 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/source/type.cpp b/source/type.cpp index d82adb0c..a3b4dd71 100644 --- a/source/type.cpp +++ b/source/type.cpp @@ -463,7 +463,29 @@ std::string standard_name(clang::QualType const &qt) // if( begins_with(r, "std::") ) return r; //standard_name(r); - static std::set standard_names {"std::size_t"}; + static std::set standard_names; + + if (standard_names.empty()) + { + standard_names = + { + // + "std::size_t", "std::ptrdiff_t", + + // + "size_t", "ptrdiff_t", + + // (most common ones only) + "std::int8_t", "std::int16_t", "std::int32_t", "std::int64_t", + "std::uint8_t", "std::uint16_t", "std::uint32_t", "std::uint64_t", + "std::intmax_t", "std::uintmax_t", "std::intptr_t", "std::uintptr_t", + + // (most common ones only) + "int8_t", "int16_t", "int32_t", "int64_t", + "uint8_t", "uint16_t", "uint32_t", "uint64_t", + "intmax_t", "uintmax_t", "intptr_t", "uintptr_t", + }; + } if( standard_names.count(r) ) return r; else return standard_name(qt.getCanonicalType().getAsString()); @@ -474,26 +496,29 @@ std::string standard_name(clang::QualType const &qt) string standard_name_raw(string const &type) { static vector< std::pair > const name_map = { - make_pair("std::__1::", - "std::"), // Mac libc++ put all STD objects into std::__1:: // WARNING: order is important here: we want to first replace std::__1:: so later we can change basic_string into string - make_pair("std::__cxx11::", "std::"), // GCC libstdc++ 5.0+ puts all STD objects into std::__cxx11:: - - // make_pair("class std::", "std::"), - // make_pair("struct std::", "std::"), + {"std::__1::", "std::"}, // Mac libc++ put all STD objects into std::__1:: // WARNING: order is important here: we want to first replace std::__1:: so later we can change basic_string into string + {"std::__cxx11::", "std::"}, // GCC libstdc++ 5.0+ puts all STD objects into std::__cxx11:: - make_pair("std::basic_string", "std::string"), make_pair("std::basic_string, std::allocator >", "std::string"), - make_pair("class std::basic_string, class std::allocator >", "std::string"), + // {"class std::", "std::"}, + // {"struct std::", "std::"}, - make_pair("std::basic_ostream", "std::ostream"), make_pair("std::basic_istream", "std::istream"), + {"std::basic_string", "std::string"}, + {"std::basic_string, std::allocator >", "std::string"}, + {"class std::basic_string, class std::allocator >", "std::string"}, - make_pair("class std::string", "std::string"), make_pair("class std::ostream", "std::ostream"), make_pair("class std::istream", "std::istream"), + {"std::basic_ostream", "std::ostream"}, + {"std::basic_istream", "std::istream"}, + {"class std::string", "std::string"}, + {"class std::ostream", "std::ostream"}, + {"class std::istream", "std::istream"}, - make_pair("class std::__thread_id", "std::thread::id"), make_pair("std::__thread_id", "std::thread::id"), + {"class std::__thread_id", "std::thread::id"}, + {"std::__thread_id", "std::thread::id"}, - make_pair("nullptr_t", "std::nullptr_t"), + {"nullptr_t", "std::nullptr_t"}, - // make_pair("const class ", "const "), - // make_pair("const struct ", "const "), + // {"const class ", "const "}, + // {"const struct ", "const "}, }; string r(type); From 74c76689d1fad5df0de91f2964f681782ff62741 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Wed, 17 May 2023 00:18:09 +0200 Subject: [PATCH 3/4] Add new config option "+standard_type" --- documentation/config.rst | 11 +++++++++++ source/config.cpp | 11 +++++++++++ source/config.hpp | 2 +- source/type.cpp | 5 ++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/documentation/config.rst b/documentation/config.rst index ac86350e..b3a124a7 100644 --- a/documentation/config.rst +++ b/documentation/config.rst @@ -128,6 +128,17 @@ Config file directives: +* ``standard_type``, directive to declare C++ types which are to be retained as is without further resolution into underlying + native types. By default, most types in the standard headers ```` and ```` (e.g. ``uint8_t``, ``std::size_t``, etc.) + are already accounted for as "standard types" to prevent them to be mapped into elemental types (e.g. ``unsigned char``, ``long int``, etc.). + With this option, you can add more custom types to this list. + +.. code-block:: bash + + +standard_type int_fast8_t + + + * ``include_for_class``, directive to control C++ include directives on a per-class basis. Force Binder to add particular include into generated source files when a given target class is present. This allows the inclusion of custom binding code, which may then be referenced with either ``+binder`` or ``+add_on_binder`` directives. diff --git a/source/config.cpp b/source/config.cpp index 86e525a1..cc7e706d 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -60,6 +60,8 @@ void Config::read(string const &file_name) string const _field_{"field"}; string const _enum_{"enum"}; + string const _standard_type_{"standard_type"}; + string const _python_builtin_{"python_builtin"}; string const _include_{"include"}; @@ -213,6 +215,15 @@ void Config::read(string const &file_name) if (!bind) { fields_to_skip.push_back(name_without_spaces); } + } else if ( token == _standard_type_ ) { + + if (bind) { + standard_types.push_back(name_without_spaces); + } + else { + throw std::runtime_error("standard_type must be '+' configuration."); + } + } else if( token == _custom_shared_ ) holder_type_ = name_without_spaces; diff --git a/source/config.hpp b/source/config.hpp index 46418d7f..25545b2c 100644 --- a/source/config.hpp +++ b/source/config.hpp @@ -64,7 +64,7 @@ class Config string root_module; - std::vector namespaces_to_bind, classes_to_bind, functions_to_bind, namespaces_to_skip, classes_to_skip, functions_to_skip, includes_to_add, includes_to_skip, fields_to_skip; + std::vector namespaces_to_bind, classes_to_bind, functions_to_bind, namespaces_to_skip, classes_to_skip, functions_to_skip, includes_to_add, includes_to_skip, fields_to_skip, standard_types; std::vector buffer_protocols, module_local_namespaces_to_add, module_local_namespaces_to_skip; std::map const &binders() const { return binders_; } diff --git a/source/type.cpp b/source/type.cpp index a3b4dd71..d1fec8af 100644 --- a/source/type.cpp +++ b/source/type.cpp @@ -464,7 +464,7 @@ std::string standard_name(clang::QualType const &qt) // if( begins_with(r, "std::") ) return r; //standard_name(r); static std::set standard_names; - + if (standard_names.empty()) { standard_names = @@ -485,6 +485,9 @@ std::string standard_name(clang::QualType const &qt) "uint8_t", "uint16_t", "uint32_t", "uint64_t", "intmax_t", "uintmax_t", "intptr_t", "uintptr_t", }; + + for (const auto &t : Config::get().standard_types) + standard_names.insert(t); } if( standard_names.count(r) ) return r; From 86780dbffc9cf7bf4f905662bf094e4ef7af0203 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Wed, 17 May 2023 23:26:45 +0200 Subject: [PATCH 4/4] consistent const placement --- source/type.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/type.cpp b/source/type.cpp index d1fec8af..6d91f36d 100644 --- a/source/type.cpp +++ b/source/type.cpp @@ -486,7 +486,7 @@ std::string standard_name(clang::QualType const &qt) "intmax_t", "uintmax_t", "intptr_t", "uintptr_t", }; - for (const auto &t : Config::get().standard_types) + for (auto const &t : Config::get().standard_types) standard_names.insert(t); }