-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add useful config options for hydrogen/Qt bindings #160
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,11 +54,14 @@ void Config::read(string const &file_name) | |
string const _namespace_ {"namespace"}; | ||
string const _function_ {"function"}; | ||
string const _class_ {"class"}; | ||
string const _field_ {"field"}; | ||
|
||
string const _include_ {"include"}; | ||
string const _include_for_class_ {"include_for_class"}; | ||
string const _include_for_namespace_ {"include_for_namespace"}; | ||
string const _include_before_ {"include_before"}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate why this option is needed? Particularly how is it different from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All other include directives are written by the code generator after <pybind11/pybind11.h>, which includes <Python.h>. Since I'm creating bindings for a library that makes use of Qt I needed a way to cleanup the preprocessor namespace before the inclusion of <pybind11/pybind11.h> in the generated code (Qt defines That's the purpose of the +include_before <qtcleanup.hpp> // qtcleanup.hpp
#undef slots There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hm... this can't be right: all custom includes is always put on top of the file. For example please see test output here: All other include directives are written by the code generator after <pybind11/pybind11.h>, which includes <Python.h>. This is also explicitly tested here: https://github.com/RosettaCommons/binder/blob/master/test/T31.include_for_class.ref#L2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, please note that current implementation of |
||
|
||
string const _primitive_ {"primitive"}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all new config options: could you please add short short documentation? Good place to put it will be this file: https://github.com/RosettaCommons/binder/blob/master/documentation/config.rst Thanks, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added some docs, see 5d150fd |
||
string const _binder_ {"binder"}; | ||
string const _add_on_binder_ {"add_on_binder"}; | ||
|
||
|
@@ -120,7 +123,18 @@ void Config::read(string const &file_name) | |
|
||
if(bind) includes_to_add.push_back(name_without_spaces); | ||
else includes_to_skip.push_back(name_without_spaces); | ||
|
||
} else if ( token == _include_before_ ) { | ||
if (bind) { | ||
includes_to_add_before.push_back(name_without_spaces); | ||
} | ||
} else if ( token == _primitive_ ) { | ||
if (bind) { | ||
primitives.push_back(name_without_spaces); | ||
} | ||
} else if ( token == _field_ ) { | ||
if (!bind) { | ||
fields_to_skip.push_back(name_without_spaces); | ||
} | ||
} else if( token == _include_for_class_ ) { | ||
|
||
if(bind) { | ||
|
@@ -302,6 +316,23 @@ bool Config::is_class_skipping_requested(string const &class__) const | |
} | ||
|
||
|
||
bool Config::is_field_skipping_requested(string const &field_) const | ||
{ | ||
string field {field_}; | ||
field.erase(std::remove(field.begin(), field.end(), ' '), field.end()); | ||
|
||
auto bind = std::find(fields_to_skip.begin(), fields_to_skip.end(), field); | ||
|
||
if( bind != fields_to_skip.end() ) { | ||
//outs() << "Skipping: " << class_ << "\n"; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will look at this and try to write some tests. |
||
bool Config::is_include_skipping_requested(string const &include) const | ||
{ | ||
for(auto & i : includes_to_skip) | ||
|
@@ -318,4 +349,19 @@ string Config::includes_code() const | |
return c.size() ? c+'\n' : c; | ||
} | ||
|
||
|
||
string Config::includes_before_code() const | ||
{ | ||
string c; | ||
for(auto & i: includes_to_add_before) c += "#include " + i + "\n"; | ||
return c.size() ? c+'\n' : c; | ||
} | ||
|
||
bool Config::is_primitive(string const &name) const | ||
{ | ||
auto prim = std::find(primitives.begin(), primitives.end(), name); | ||
if ( prim != primitives.end() ) return true; | ||
return false; | ||
} | ||
|
||
} // namespace binder |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,8 +269,14 @@ bool is_binding_requested(FunctionDecl const *F, Config const &config) | |
{ | ||
bool bind = config.is_function_binding_requested( F->getQualifiedNameAsString() ) or config.is_function_binding_requested( function_qualified_name(F) ) or config.is_namespace_binding_requested( namespace_from_named_decl(F) ); | ||
|
||
for(auto & t : get_type_dependencies(F) ) bind |= binder::is_binding_requested(t, config); | ||
|
||
for(auto & t : get_type_dependencies(F) ) { | ||
bool requested = binder::is_binding_requested(t, config); | ||
bool primitive = binder::is_primitive(t, config); | ||
if ( primitive ) { | ||
requested = false; | ||
} | ||
bind |= requested; // binder::is_binding_requested(t, config); | ||
} | ||
Comment on lines
+272
to
+279
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please elaborate of what exactly the Also, if above assumption about what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's It, thanks for the pointer. I'm pretty new to your codebase and I missed it. I will redo this part after I have added some tests 😁 |
||
return bind; | ||
} | ||
|
||
|
@@ -296,8 +302,18 @@ bool is_skipping_requested(FunctionDecl const *F, Config const &config) | |
} | ||
//outs() << "OK\n"; | ||
|
||
for(auto & t : get_type_dependencies(F) ) skip |= is_skipping_requested(t, config); | ||
|
||
for(auto & t : get_type_dependencies(F) ) { | ||
bool dep_skip = is_skipping_requested(t, config); | ||
bool primitive = is_primitive(t, config); | ||
if ( primitive ) dep_skip = false; | ||
skip |= dep_skip; | ||
} | ||
Comment on lines
+305
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again: could you please elaborate why do we need to take There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hum, I was borrowing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess my previous comment might have been a bit cryptic, what i meant ask is this: why do we need to check if type |
||
// if (skip) { | ||
// // check if explicitly added | ||
// if (config.is_function_binding_requested(F->getQualifiedNameAsString())) { | ||
// skip = false; | ||
// } | ||
// } | ||
return skip; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 I like this idea!