Skip to content

Commit

Permalink
Merge pull request #165 from RosettaCommons/devel
Browse files Browse the repository at this point in the history
Adding proper errors handling when compiling with LLVM-13 and improving `std::` names calculation.
  • Loading branch information
lyskov authored Dec 6, 2021
2 parents 9f5292f + 59623c4 commit 90cf5b3
Show file tree
Hide file tree
Showing 18 changed files with 866 additions and 189 deletions.
12 changes: 9 additions & 3 deletions source/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,15 @@ int main(int argc, const char **argv)

#else
//CommonOptionsParser op(argc, argv, BinderToolCategory);
llvm::Expected< CommonOptionsParser > eop = CommonOptionsParser::create(argc, argv, BinderToolCategory);
ClangTool tool(eop->getCompilations(), eop->getSourcePathList());
return tool.run(newFrontendActionFactory<BinderFrontendAction>().get());
if( llvm::Expected< CommonOptionsParser > eop = CommonOptionsParser::create(argc, argv, BinderToolCategory) ) {
ClangTool tool(eop->getCompilations(), eop->getSourcePathList());
return tool.run(newFrontendActionFactory<BinderFrontendAction>().get());
}
else {
auto errs = eop.takeError();
llvm::logAllUnhandledErrors(std::move(errs), outs(), "\nErrors:\n");
return 1;
}
#endif

}
5 changes: 4 additions & 1 deletion source/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ bool is_binding_requested(clang::CXXRecordDecl const *C, Config const &config)
// check if user requested skipping for the given declaration
bool is_skipping_requested(clang::CXXRecordDecl const *C, Config const &config)
{
bool skip = config.is_class_skipping_requested( standard_name( C->getQualifiedNameAsString() ) ) or config.is_class_skipping_requested( class_qualified_name(C) ) or config.is_namespace_skipping_requested( namespace_from_named_decl(C) );
bool skip = \
config.is_class_skipping_requested( standard_name( C->getQualifiedNameAsString() ) ) or
config.is_class_skipping_requested( class_qualified_name(C) ) or
config.is_namespace_skipping_requested( namespace_from_named_decl(C) );

for(auto & t : get_type_dependencies(C) ) skip |= is_skipping_requested(t, config);

Expand Down
2 changes: 1 addition & 1 deletion source/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ struct ostream_params {
};
} // namespace detail

static constexpr detail::buffer_size buffer_size;
static constexpr detail::buffer_size buffer_size();

// A fast output stream which is not thread-safe.
class ostream final : private detail::buffer<char> {
Expand Down
38 changes: 23 additions & 15 deletions source/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,32 +523,40 @@ string simplify_std_class_name(string const &type)

if( regex_map.empty() ) {
vector< std::pair<string, string> > regex_arg_map = {
make_pair("^list<(.*),std::allocator<\\1>>$", "list<\\1>"),
make_pair("^deque<(.*),std::allocator<\\1>>$", "deque<\\1>"),
make_pair("^vector<(.*),std::allocator<\\1>>$", "vector<\\1>"),
make_pair("^set<(.*),std::less<\\1>,std::allocator<\\1>>$", "set<\\1>"),
make_pair("^forward_list<(.*),std::allocator<\\1>>$", "forward_list<\\1>"),
make_pair("^map<(.*),(.*),std::less<\\1>,std::allocator<std::pair<const \\1, \\2> >>$", "map<\\1,\\2>"),
make_pair("list<(.*), *std::allocator<\\1 *> *>", "list<\\1>"),
make_pair("deque<(.*), *std::allocator<\\1 *> *>", "deque<\\1>"),

make_pair("^multiset<(.*),std::less<(.*)>,std::allocator<(.*)>>$", "multiset<\\1>"),
make_pair("^multimap<(.*),(.*),std::less<\\1>,std::allocator<std::pair<const \\1, \\2> >>$", "multimap<\\1,\\2>"),
make_pair("vector<(.*), *std::allocator<\\1 *> *>", "vector<\\1>"),

make_pair("set<(.*), *std::less<\\1 *>, *std::allocator<\\1 *> *>", "set<\\1>"),
make_pair("forward_list<(.*), *std::allocator<\\1 *> *>", "forward_list<\\1>"),
make_pair("map<(.*),(.*), *std::less<\\1 *>, *std::allocator<std::pair<const \\1, \\2 *> *> *>", "map<\\1,\\2>"),

make_pair("multiset<(.*), *std::less<(.*)>, *std::allocator<(.*)>>", "multiset<\\1 *>"),
make_pair("multimap<(.*),(.*), *std::less<\\1>, *std::allocator<std::pair<const \\1, \\2 *> *> *>", "multimap<\\1,\\2>"),

// LLVM-3.7
//make_pair("^std::multimap<(.*),(.*),std::less<\\1>,std::allocator<std::pair<const \\1, \\2> >>", "multimap<\\1,\\2>"),

make_pair("^unordered_set<(.*),std::hash<\\1>,std::equal_to<\\1>,std::allocator<\\1>>$", "unordered_set<\\1>"),
make_pair("^unordered_map<(.*),(.*),std::hash<\\1>,std::equal_to<\\1>,std::allocator<std::pair<const \\1, \\2> >>$", "unordered_map<\\1,\\2>"),
make_pair("unordered_set<(.*), *std::hash<\\1>,std::equal_to<\\1>,std::allocator<\\1>>", "unordered_set<\\1>"),
make_pair("unordered_map<(.*), *(.*),std::hash<\\1>,std::equal_to<\\1>,std::allocator<std::pair<const \\1, \\2 *> *> *>", "unordered_map<\\1,\\2>"),

make_pair("^unordered_multiset<(.*),std::hash<\\1>,std::equal_to<\\1>,std::allocator<\\1>>$", "unordered_multiset<\\1>"),
make_pair("^unordered_multimap<(.*),(.*),std::hash<\\1>,std::equal_to<\\1>,std::allocator<std::pair<const \\1, \\2> >>$", "unordered_multimap<\\1,\\2>"),
make_pair("unordered_multiset<(.*), *std::hash<\\1>, *std::equal_to<\\1>, *std::allocator<\\1 *> *>", "unordered_multiset<\\1>"),
make_pair("unordered_multimap<(.*), *(.*),std::hash<\\1 *>, *std::equal_to<\\1 *>, *std::allocator<std::pair<const \\1, \\2 *> *> *>", "unordered_multimap<\\1,\\2>"),
};

for(auto & p : regex_arg_map) regex_map.emplace_back(llvm::Regex(p.first), p.second);
}

for(auto & p : regex_map) {
//llvm::Regex R(p.first);
res = p.first.sub(p.second, res);
int len = res.size(), previous_len = 0;

while( len != previous_len ) {
for(auto & p : regex_map) {
//llvm::Regex R(p.first);
res = p.first.sub(p.second, res);
}
previous_len = len;
len = res.size();
}

return res;
Expand Down
14 changes: 7 additions & 7 deletions test/T15.inner_class.fwd.ref
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@

void bind_T15_inner_class_fwd(std::function< pybind11::module &(std::string const &namespace_) > &M)
{
{ // outer file:T15.inner_class.fwd.hpp line:11
pybind11::class_<outer, std::shared_ptr<outer>> cl(M(""), "outer", "binder/test/T15.inner_class.fwd.hpp\n \n\n Binder self-test file. Tests for bindings of forward declared inner functions.\n \n\n Thomas Feierl");
{ // outer file:T15.inner_class.fwd.hpp line:10
pybind11::class_<outer, std::shared_ptr<outer>> cl(M(""), "outer", "binder/test/T15.inner_class.fwd.hpp\n \n\n Binder self-test file. Tests for bindings of forward declared inner functions.");
cl.def( pybind11::init( [](){ return new outer(); } ) );
cl.def("f", (void (outer::*)(struct outer::inner *, struct outer::inner2 *, struct outer::inner3 *)) &outer::f, "C++: outer::f(struct outer::inner *, struct outer::inner2 *, struct outer::inner3 *) --> void", pybind11::arg("i"), pybind11::arg("i2"), pybind11::arg("i3"));

{ // outer::inner file:T15.inner_class.fwd.hpp line:13
{ // outer::inner file:T15.inner_class.fwd.hpp line:12
auto & enclosing_class = cl;
pybind11::class_<outer::inner, std::shared_ptr<outer::inner>> cl(enclosing_class, "inner", "");
cl.def( pybind11::init( [](){ return new outer::inner(); } ) );
cl.def_readwrite("a", &outer::inner::a);
}

{ // outer::inner2 file:T15.inner_class.fwd.hpp line:23
{ // outer::inner2 file:T15.inner_class.fwd.hpp line:22
auto & enclosing_class = cl;
pybind11::class_<outer::inner2, std::shared_ptr<outer::inner2>> cl(enclosing_class, "inner2", "");
cl.def( pybind11::init( [](){ return new outer::inner2(); } ) );
cl.def_readwrite("b", &outer::inner2::b);
}

{ // outer::inner3 file:T15.inner_class.fwd.hpp line:28
{ // outer::inner3 file:T15.inner_class.fwd.hpp line:27
auto & enclosing_class = cl;
pybind11::class_<outer::inner3, std::shared_ptr<outer::inner3>> cl(enclosing_class, "inner3", "");
cl.def( pybind11::init( [](){ return new outer::inner3(); } ) );
Expand Down Expand Up @@ -82,9 +82,9 @@ PYBIND11_MODULE(T15_inner_class_fwd, root_module) {

}

// Source list file: /home/thomas/Projects/thfe/binder/build/test//T15_inner_class_fwd.sources
// Source list file: TEST/T15_inner_class_fwd.sources
// T15_inner_class_fwd.cpp
// T15_inner_class_fwd.cpp

// Modules list file: /home/thomas/Projects/thfe/binder/build/test//T15_inner_class_fwd.modules
// Modules list file: TEST/T15_inner_class_fwd.modules
//
12 changes: 7 additions & 5 deletions test/T17.anonymous.ref
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// File: T17_anonymous.cpp
#include <T17.anonymous.hpp> // Anonymous
#include <T17.anonymous.hpp> // Anonymous::(anonymous)
#include <T17.anonymous.hpp> // S
#include <T17.anonymous.hpp> // S::_D
#include <T17.anonymous.hpp> // _S2
Expand Down Expand Up @@ -42,14 +44,14 @@ void bind_T17_anonymous(std::function< pybind11::module &(std::string const &nam
pybind11::class_<_S2, std::shared_ptr<_S2>> cl(M(""), "_S2", "");
cl.def( pybind11::init( [](){ return new _S2(); } ) );
cl.def_readwrite("a", &_S2::a);
}
}
{ // Anonymous file:T17.anonymous.hpp line:56
pybind11::class_<Anonymous, std::shared_ptr<Anonymous>> cl(M(""), "Anonymous", "");
cl.def( pybind11::init( [](){ return new Anonymous(); } ) );
{ // Anonymous::(anonymous) file: line:58
cl.def( pybind11::init( [](){ return new Anonymous(); } ) );

{ // Anonymous::(anonymous) file:T17.anonymous.hpp line:58

{ // Anonymous::(anonymous union)::(anonymous) file: line:60
{ // Anonymous::(anonymous union)::(anonymous) file:T17.anonymous.hpp line:60
cl.def_readwrite("x", &Anonymous::x);
cl.def_readwrite("y", &Anonymous::y);
}
Expand Down
7 changes: 5 additions & 2 deletions test/T42.stl.names.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// @author Sergey Lyskov

/// The multimap/multiset classes are tested in the binder/test/T43.stl.names.multi.hpp to avoid
/// problems with different ordering of multiset/set and multimap/map bindings
/// problems with different ordering of multiset/set and multimap/map bindings
/// in the generated files on different platforms.
#ifndef _INCLUDED_T42_stl_names_hpp_
#define _INCLUDED_T42_stl_names_hpp_
Expand All @@ -22,12 +22,15 @@
#include <vector>
#include <forward_list>


void foo(std::list<double> ) {}
void foo(std::forward_list<float> ) {}
void foo(std::vector<double> ) {}
void foo(std::deque<int> ) {}

void foo(std::vector< std::vector<double> >) {}
void foo(std::vector< std::vector< std::vector<double> > >) {}

void foo(std::vector< std::list< std::forward_list< std::deque<double> > > >) {}


#endif // _INCLUDED_T42_stl_names_hpp_
11 changes: 10 additions & 1 deletion test/T42.stl.names.map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// @author Sergey Lyskov

/// The multimap/multiset classes are tested in the binder/test/T43.stl.names.multi.hpp to avoid
/// problems with different ordering of multiset/set and multimap/map bindings
/// problems with different ordering of multiset/set and multimap/map bindings
/// in the generated files on different platforms.
#ifndef _INCLUDED_T42_stl_names_map_hpp_
#define _INCLUDED_T42_stl_names_map_hpp_
Expand All @@ -20,9 +20,18 @@
#include <map>
#include <unordered_map>

#include <string>
#include <list>
#include <vector>
#include <deque>
#include <vector>
#include <forward_list>

void foo(std::map<float,int> ) {}

void foo(std::unordered_map<float,int> ) {}

void foo(std::map<std::string, std::list< std::forward_list< std::deque< std::vector<double> > > > >) {}
void foo(std::unordered_map<std::string, std::list< std::forward_list< std::deque< std::vector<double> > > > >) {}

#endif // _INCLUDED_T42_stl_names_map_hpp_
192 changes: 186 additions & 6 deletions test/T42.stl.names.map.ref

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion test/T42.stl.names.multi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// @author Sergey Lyskov/Andrii Verbytskyi

/// This test is separated from the binder/test/T42.stl.names.hpp to avoid
/// problems with different ordering of multiset/set and multimap/map bindings
/// problems with different ordering of multiset/set and multimap/map bindings
/// in the generated files on different platforms.
#ifndef _INCLUDED_T42_stl_names_multi_hpp_
#define _INCLUDED_T42_stl_names_multi_hpp_
Expand All @@ -23,11 +23,18 @@
#include <unordered_set>
#include <unordered_map>

#include <list>
#include <deque>
#include <vector>
#include <forward_list>

void foo(std::multimap<float, int> ) {}
void foo(std::multiset<float> ) {}

void foo(std::unordered_multiset<float> ) {}
void foo(std::unordered_multimap<float, int> ) {}

void foo(std::multimap<std::string, std::list< std::forward_list< std::deque< std::vector<double> > > > >) {}
void foo(std::unordered_multimap<std::string, std::list< std::forward_list< std::deque< std::vector<double> > > > >) {}

#endif // _INCLUDED_T42_stl_names_multi_hpp_
Loading

0 comments on commit 90cf5b3

Please sign in to comment.