Skip to content

Commit

Permalink
update request_bindings / request_skipping mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
lyskov committed Mar 16, 2024
1 parent be50c7c commit 80273dd
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
10 changes: 9 additions & 1 deletion source/binder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ class IncludeSet
friend void add_relevant_includes_cached(clang::CXXRecordDecl const *C, IncludeSet &includes);
};


enum RequestFlags : int8_t {
none=0, skipping = 1, binding = 2,
};
inline RequestFlags operator|(RequestFlags a, RequestFlags b) { return static_cast<RequestFlags>(static_cast<int>(a) | static_cast<int>(b)); }
inline RequestFlags operator&(RequestFlags a, RequestFlags b) { return static_cast<RequestFlags>(static_cast<int>(a) & static_cast<int>(b)); }

/// Bindings Generator - represent object that can generate binding info for function, class, enum or data variable
class Binder
{
Expand All @@ -83,8 +90,9 @@ class Binder
/// request skipping for this generator
void request_skipping() { skipping_requested_ = true; }


/// check if user supplied config requested binding for the given declaration and if so request it
virtual void request_bindings_and_skipping(Config const &) = 0;
virtual void request_bindings_and_skipping(Config const &, RequestFlags flags = RequestFlags::skipping | RequestFlags::binding) = 0;

/// extract include needed for this generator and add it to includes vector
virtual void add_relevant_includes(IncludeSet &) const = 0;
Expand Down
6 changes: 3 additions & 3 deletions source/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ bool ClassBinder::bindable() const


/// check if user requested binding for the given declaration
void ClassBinder::request_bindings_and_skipping(Config const &config)
void ClassBinder::request_bindings_and_skipping(Config const & config, RequestFlags flags)
{
if( is_skipping_requested(C, config) ) Binder::request_skipping();
else if( is_binding_requested(C, config) ) Binder::request_bindings();
if( (flags&RequestFlags::skipping) and is_skipping_requested(C, config) ) Binder::request_skipping();
else if( (flags&RequestFlags::binding) and is_binding_requested(C, config) ) Binder::request_bindings();
}


Expand Down
2 changes: 1 addition & 1 deletion source/class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ClassBinder : public Binder
bool bindable() const override;

/// check if user requested binding for the given declaration
virtual void request_bindings_and_skipping(Config const &) override;
void request_bindings_and_skipping(Config const &, RequestFlags flags = RequestFlags::skipping | RequestFlags::binding) override;

/// extract include needed for this generator and add it to includes vector
void add_relevant_includes(IncludeSet &includes) const override;
Expand Down
5 changes: 4 additions & 1 deletion source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ void Context::bind(Config const &config)
{
for( auto &sp : binders ) {
Binder &b(*sp);
if( !b.is_in_system_header() and b.bindable() ) b.request_bindings_and_skipping(config);
if( b.bindable() ) {
if( b.is_in_system_header() ) b.request_bindings_and_skipping(config, RequestFlags::skipping);
else b.request_bindings_and_skipping(config);
}
}

bool flag = true;
Expand Down
6 changes: 3 additions & 3 deletions source/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ bool EnumBinder::bindable() const


/// check if user requested binding for the given declaration
void EnumBinder::request_bindings_and_skipping(Config const &config)
void EnumBinder::request_bindings_and_skipping(Config const &config, RequestFlags flags)
{
if( is_skipping_requested(E, config) ) Binder::request_skipping();
else if( is_binding_requested(E, config) ) Binder::request_bindings();
if( (flags&RequestFlags::skipping) and is_skipping_requested(E, config) ) Binder::request_skipping();
else if( (flags&RequestFlags::binding) and is_binding_requested(E, config) ) Binder::request_bindings();
}


Expand Down
2 changes: 1 addition & 1 deletion source/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class EnumBinder : public Binder
bool bindable() const override;

/// check if user requested binding for the given declaration
virtual void request_bindings_and_skipping(Config const &) override;
void request_bindings_and_skipping(Config const &, RequestFlags flags = RequestFlags::skipping | RequestFlags::binding) override;

/// extract include needed for this generator and add it to includes vector
void add_relevant_includes(IncludeSet &includes) const override;
Expand Down
6 changes: 3 additions & 3 deletions source/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,10 @@ bool FunctionBinder::bindable() const


/// check if user requested binding for the given declaration
void FunctionBinder::request_bindings_and_skipping(Config const &config)
void FunctionBinder::request_bindings_and_skipping(Config const &config, RequestFlags flags)
{
if( is_skipping_requested(F, config) ) Binder::request_skipping();
else if( is_binding_requested(F, config) ) Binder::request_bindings();
if( (flags&RequestFlags::skipping) and is_skipping_requested(F, config) ) Binder::request_skipping();
else if( (flags&RequestFlags::binding) and is_binding_requested(F, config) ) Binder::request_bindings();
}


Expand Down
2 changes: 1 addition & 1 deletion source/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FunctionBinder : public Binder
bool bindable() const override;

/// check if user requested binding for the given declaration
void request_bindings_and_skipping(Config const &) override;
void request_bindings_and_skipping(Config const &, RequestFlags flags = RequestFlags::skipping | RequestFlags::binding) override;

/// extract include needed for this generator and add it to includes vector
void add_relevant_includes(IncludeSet &includes) const override;
Expand Down

0 comments on commit 80273dd

Please sign in to comment.