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 2adf346d..6d91f36d 100644 --- a/source/type.cpp +++ b/source/type.cpp @@ -461,14 +461,34 @@ 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"}; + 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", + }; + + for (auto const &t : Config::get().standard_types) + standard_names.insert(t); + } if( standard_names.count(r) ) return r; else return standard_name(qt.getCanonicalType().getAsString()); @@ -479,26 +499,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);