Skip to content
Open
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
11 changes: 11 additions & 0 deletions documentation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``<cstdef>`` and ``<cstdint>`` (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.
Expand Down
11 changes: 11 additions & 0 deletions source/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion source/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Config

string root_module;

std::vector<string> 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<string> 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<string> buffer_protocols, module_local_namespaces_to_add, module_local_namespaces_to_skip;

std::map<string, string> const &binders() const { return binders_; }
Expand Down
63 changes: 43 additions & 20 deletions source/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> standard_names {"std::size_t"};
static std::set<string> standard_names;

if (standard_names.empty())
{
standard_names =
{
// <cstddef>
"std::size_t", "std::ptrdiff_t",

// <stddef.h>
"size_t", "ptrdiff_t",

// <cstdint> (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",

// <stdint.h> (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",
Comment on lines +473 to +486
Copy link
Member

Choose a reason for hiding this comment

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

Optional, if you feel up to this: would be great if small test using some (or maybe all?) of this types added into https://github.com/RosettaCommons/binder/tree/master/test . 🤔 I think something like function taking very long argument list containing all these types will do .

Plus class member function with similar list of arguments as well as public data members. That way we should cover all instances where type conversion is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll try it; if days pass by and have no feedback, feel free of merging and doing it yourself or stacking in the TO-DO ;-)

};

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());
Expand All @@ -479,26 +499,29 @@ std::string standard_name(clang::QualType const &qt)
string standard_name_raw(string const &type)
{
static vector< std::pair<string, string> > 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<char>", "std::string"), make_pair("std::basic_string<char, std::char_traits<char>, std::allocator<char> >", "std::string"),
make_pair("class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >", "std::string"),
// {"class std::", "std::"},
// {"struct std::", "std::"},

make_pair("std::basic_ostream<char>", "std::ostream"), make_pair("std::basic_istream<char>", "std::istream"),
{"std::basic_string<char>", "std::string"},
{"std::basic_string<char, std::char_traits<char>, std::allocator<char> >", "std::string"},
{"class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >", "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<char>", "std::ostream"},
{"std::basic_istream<char>", "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);
Expand Down