From eb81a7e5a65d73ef29e2263169261fab475536a1 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 26 May 2019 09:01:21 +0200 Subject: [PATCH] GSI binding of LVS objects. --- src/db/db/gsiDeclDbNetlist.cc | 72 +---- src/db/db/gsiDeclDbNetlistCrossReference.cc | 6 +- src/gsi/gsi/gsiEnums.h | 74 ++++- src/gsi/gsi/gsiMethodsVar.h | 330 ++++++++++++++------ src/gsi/gsi/gsiTypes.h | 7 + src/gsi/gsi_test/gsiTest.cc | 16 +- testdata/ruby/dbNetlistCrossReference.rb | 15 +- 7 files changed, 320 insertions(+), 200 deletions(-) diff --git a/src/db/db/gsiDeclDbNetlist.cc b/src/db/db/gsiDeclDbNetlist.cc index 76c6ff81a..837937563 100644 --- a/src/db/db/gsiDeclDbNetlist.cc +++ b/src/db/db/gsiDeclDbNetlist.cc @@ -33,66 +33,6 @@ namespace gsi { -// ------------------------------------------------------------ -// @@@@ - -template -class ConstMethodBiIterWithTransfer - : public MethodSpecificBase -{ -public: - typedef IterAdaptorAbstractBase iter_adaptor_base_type; - typedef IterAdaptor iter_adaptor_type; - - ConstMethodBiIterWithTransfer (const std::string &name, I (X::*b) () const, I (X::*e) () const, const std::string &doc) - : MethodSpecificBase (name, doc, true, false, 0), m_b (b), m_e (e) - { - } - - ConstMethodBiIterWithTransfer *add_args () - { - return this; - } - - void initialize () - { - this->clear (); - this->template set_return (); - } - - virtual MethodBase *clone () const - { - return new ConstMethodBiIterWithTransfer (*this); - } - - virtual void call (void *cls, SerialArgs &, SerialArgs &ret) const - { - this->mark_called (); - ret.write (static_cast (new iter_adaptor_type ((((const X *)cls)->*m_b) (), (((const X *)cls)->*m_e) ()))); - } - -private: - I (X::*m_b) () const; - I (X::*m_e) () const; -}; - -template -ConstMethodBiIterWithTransfer * -_iterator_with_transfer (const std::string &name, I (X::*b) () const, I (X::*e) () const, const std::string &doc) -{ - return new ConstMethodBiIterWithTransfer (name, b, e, doc); -} - -template -Methods -iterator_with_transfer (const std::string &name, I (X::*b) () const, I (X::*e) () const, const std::string &doc = std::string ()) -{ - return Methods (_iterator_with_transfer (name, b, e, doc)); -} - -// @@@@ -// ------------------------------------------------------------ - Class decl_dbPin ("db", "Pin", gsi::method ("id", &db::Pin::id, "@brief Gets the ID of the pin.\n" @@ -600,27 +540,21 @@ Class decl_dbNet ("db", "Net", "@brief Gets the cluster ID of the net.\n" "See \\cluster_id= for details about the cluster ID." ) + - // @@@ - gsi::iterator_with_transfer ("each_pin", (db::Net::const_pin_iterator (db::Net::*) () const) &db::Net::begin_pins, (db::Net::const_pin_iterator (db::Net::*) () const) &db::Net::end_pins, + gsi::iterator ("each_pin", gsi::return_reference (), (db::Net::const_pin_iterator (db::Net::*) () const) &db::Net::begin_pins, (db::Net::const_pin_iterator (db::Net::*) () const) &db::Net::end_pins, "@brief Iterates over all outgoing pins the net connects.\n" "Pin connections are described by \\NetPinRef objects. Pin connections " "are connections to outgoing pins of the circuit the net lives in." ) + - // @@@ - // @@@ - gsi::iterator_with_transfer ("each_subcircuit_pin", (db::Net::const_subcircuit_pin_iterator (db::Net::*) () const) &db::Net::begin_subcircuit_pins, (db::Net::const_subcircuit_pin_iterator (db::Net::*) () const) &db::Net::end_subcircuit_pins, + gsi::iterator ("each_subcircuit_pin", gsi::return_reference (), (db::Net::const_subcircuit_pin_iterator (db::Net::*) () const) &db::Net::begin_subcircuit_pins, (db::Net::const_subcircuit_pin_iterator (db::Net::*) () const) &db::Net::end_subcircuit_pins, "@brief Iterates over all subcircuit pins the net connects.\n" "Subcircuit pin connections are described by \\NetSubcircuitPinRef objects. These are " "connections to specific pins of subcircuits." ) + - // @@@ - // @@@ - gsi::iterator_with_transfer ("each_terminal", (db::Net::const_terminal_iterator (db::Net::*) () const) &db::Net::begin_terminals, (db::Net::const_terminal_iterator (db::Net::*) () const) &db::Net::end_terminals, + gsi::iterator ("each_terminal", gsi::return_reference (), (db::Net::const_terminal_iterator (db::Net::*) () const) &db::Net::begin_terminals, (db::Net::const_terminal_iterator (db::Net::*) () const) &db::Net::end_terminals, "@brief Iterates over all terminals the net connects.\n" "Terminals connect devices. Terminal connections are described by \\NetTerminalRef " "objects." ) + - // @@@ gsi::method ("is_floating?", &db::Net::is_floating, "@brief Returns true, if the net is floating.\n" "Floating nets are those who don't have any or only a single connection (pin_count + terminal_count < 2)." diff --git a/src/db/db/gsiDeclDbNetlistCrossReference.cc b/src/db/db/gsiDeclDbNetlistCrossReference.cc index c31f31b47..ec18e35cc 100644 --- a/src/db/db/gsiDeclDbNetlistCrossReference.cc +++ b/src/db/db/gsiDeclDbNetlistCrossReference.cc @@ -440,8 +440,7 @@ Class decl_dbNetlistCrossReference (decl_dbNetlistCom "This class has been introduced in version 0.26." ); -// TODO: there is no "enum as child class" currently, so we have to define that on top level too -gsi::Enum decl_dbNetlistCrossReference_Status ("db", "NetlistCrossReference_Status", +gsi::EnumIn decl_dbNetlistCrossReference_Status ("db", "Status", gsi::enum_const ("None", db::NetlistCrossReference::None, "@brief Enum constant NetlistCrossReference::None\n" "No specific status is implied if this code is present." @@ -478,9 +477,6 @@ gsi::Enum decl_dbNetlistCrossReference_Status ); // Inject the NetlistCrossReference::Status declarations into NetlistCrossReference: -// Inject constants: gsi::ClassExt inject_NetlistCrossReference_Status_in_parent (decl_dbNetlistCrossReference_Status.defs ()); -// Inject class: -gsi::ClassExt decl_NetlistCrossReference_Status_as_child (decl_dbNetlistCrossReference_Status, "Status"); } diff --git a/src/gsi/gsi/gsiEnums.h b/src/gsi/gsi/gsiEnums.h index e7f7a2c8d..56e799693 100644 --- a/src/gsi/gsi/gsiEnums.h +++ b/src/gsi/gsi/gsiEnums.h @@ -280,25 +280,14 @@ EnumSpecs enum_const (const std::string &estr, E evalue, const std::string &d } /** - * @brief The basic declaration class - * This is a gsi::Class specialization which implements an enum declaration. - * The use is this: - * - * @code - * gsi::Enum e_enum ("A description", - * gsi::enum_const ("a", E::a, "description of a") + - * gsi::enum_const ("b", E::b) + - * ... - * ); - * @endcode + * @brief A helper class for the enum implementation */ template -class Enum - : public Class, E> +class EnumImpl { public: - Enum (const std::string &module, const std::string &name, const EnumSpecs &specs, const std::string &doc = std::string ()) - : Class, E> (module, name, specs.methods (), doc), m_specs (specs) + EnumImpl (const EnumSpecs &specs) + : m_specs (specs) { } @@ -331,6 +320,61 @@ private: EnumSpecs m_specs; }; +/** + * @brief The basic declaration class + * This is a gsi::Class specialization which implements an enum declaration. + * The use is this: + * + * @code + * gsi::Enum e_enum ("A description", + * gsi::enum_const ("a", E::a, "description of a") + + * gsi::enum_const ("b", E::b) + + * ... + * ); + * @endcode + */ +template +class Enum + : public Class, E>, public EnumImpl +{ +public: + Enum (const std::string &module, const std::string &name, const EnumSpecs &specs, const std::string &doc = std::string ()) + : Class, E> (module, name, specs.methods (), doc), EnumImpl (specs) + { + } +}; + +/** + * @brief An enum declaration as a child class + * + * @code + * gsi::EnumIn e_enum ("A description", + * gsi::enum_const ("a", E::a, "description of a") + + * gsi::enum_const ("b", E::b) + + * ... + * ); + * @endcode + */ +template +class EnumIn + : public Enum +{ +public: + EnumIn (const std::string &module, const std::string &name, const EnumSpecs &specs, const std::string &doc = std::string ()) + : Enum (module, name, specs, doc) + { + } + + virtual bool consolidate () const + { + // TODO: ugly const cast + ClassBase *non_const_pcls = const_cast (cls_decl

()); + non_const_pcls->add_child_class (this); + + return Enum::consolidate (); + } +}; + #if defined(HAVE_QT) template diff --git a/src/gsi/gsi/gsiMethodsVar.h b/src/gsi/gsi/gsiMethodsVar.h index c0511038f..0792f5063 100644 --- a/src/gsi/gsi/gsiMethodsVar.h +++ b/src/gsi/gsi/gsiMethodsVar.h @@ -398,7 +398,7 @@ private: // pointer iterator method descriptors -template +template class _NAME(MethodPtrIter) : public MethodSpecificBase { @@ -422,7 +422,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -447,7 +447,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(MethodPtrConstIter) : public MethodSpecificBase { @@ -471,7 +471,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -496,7 +496,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ConstMethodPtrIter) : public MethodSpecificBase { @@ -520,7 +520,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -545,7 +545,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ConstMethodPtrConstIter) : public MethodSpecificBase { @@ -569,7 +569,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -594,7 +594,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ExtMethodPtrIter) : public MethodSpecificBase { @@ -618,7 +618,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -643,7 +643,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ExtMethodPtrConstIter) : public MethodSpecificBase { @@ -667,7 +667,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -692,7 +692,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(StaticMethodPtrIter) : public StaticMethodBase { @@ -716,7 +716,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -741,7 +741,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(StaticMethodPtrConstIter) : public StaticMethodBase { @@ -765,7 +765,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -792,7 +792,7 @@ private: // pair iterator method descriptors -template +template class _NAME(MethodBiIter) : public MethodSpecificBase { @@ -815,7 +815,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -840,7 +840,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ConstMethodBiIter) : public MethodSpecificBase { @@ -863,7 +863,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -888,7 +888,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ExtMethodBiIter) : public MethodSpecificBase { @@ -911,7 +911,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -938,7 +938,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(StaticMethodBiIter) : public StaticMethodBase { @@ -961,7 +961,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -988,7 +988,7 @@ private: // free iterator method descriptors -template +template class _NAME(MethodFreeIter) : public MethodSpecificBase { @@ -1011,7 +1011,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -1035,7 +1035,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ConstMethodFreeIter) : public MethodSpecificBase { @@ -1058,7 +1058,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -1082,7 +1082,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(ExtMethodFreeIter) : public MethodSpecificBase { @@ -1105,7 +1105,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -1129,7 +1129,7 @@ private: _ARGSPECMEM }; -template +template class _NAME(StaticMethodFreeIter) : public StaticMethodBase { @@ -1152,7 +1152,7 @@ public: { this->clear (); _ADDARGS - this->template set_return (); + this->template set_return (); } virtual MethodBase *clone () const @@ -1289,7 +1289,7 @@ method (const std::string &name, R (X::*m) (_FUNCARGLIST), const std::string &do template Methods -method (const std::string &name, R (X::*m) (_FUNCARGLIST), const std::string &doc = std::string ()) +method (const std::string &name, Transfer, R (X::*m) (_FUNCARGLIST), const std::string &doc = std::string ()) { return Methods (new _NAME(Method) (name, m, doc)); } @@ -1304,7 +1304,7 @@ method (const std::string &name, R (X::*m) (_FUNCARGLIST) _COMMA _ARGSPECS, cons template Methods -method (const std::string &name, R (X::*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +method (const std::string &name, Transfer, R (X::*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { return Methods ((new _NAME(Method) (name, m, doc))->add_args (_ARGSPECARGS)); } @@ -1314,7 +1314,7 @@ template Methods factory (const std::string &name, R *(X::*m) (_FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (new _NAME(Method) (name, m, doc)); + return Methods (new _NAME(Method) (name, m, doc)); } #if _COUNT != 0 @@ -1322,7 +1322,7 @@ template Methods factory (const std::string &name, R *(X::*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods ((new _NAME(Method) (name, m, doc))->add_args (_ARGSPECARGS)); + return Methods ((new _NAME(Method) (name, m, doc))->add_args (_ARGSPECARGS)); } #endif @@ -1335,7 +1335,7 @@ method_ext (const std::string &name, R (*xm) (X * _COMMA _FUNCARGLIST), const st template Methods -method_ext (const std::string &name, R (*xm) (X * _COMMA _FUNCARGLIST), const std::string &doc = std::string ()) +method_ext (const std::string &name, Transfer, R (*xm) (X * _COMMA _FUNCARGLIST), const std::string &doc = std::string ()) { return Methods (new _NAME(ExtMethod) (name, xm, doc)); } @@ -1350,7 +1350,7 @@ method_ext (const std::string &name, R (*xm) (X * _COMMA _FUNCARGLIST) _COMMA _A template Methods -method_ext (const std::string &name, R (*xm) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +method_ext (const std::string &name, Transfer, R (*xm) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { return Methods ((new _NAME(ExtMethod) (name, xm, doc))->add_args (_ARGSPECARGS)); } @@ -1360,7 +1360,7 @@ template Methods factory_ext (const std::string &name, R *(*xm) (X * _COMMA _FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (new _NAME(ExtMethod) (name, xm, doc)); + return Methods (new _NAME(ExtMethod) (name, xm, doc)); } #if _COUNT != 0 @@ -1368,7 +1368,7 @@ template Methods factory_ext (const std::string &name, R *(*xm) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods ((new _NAME(ExtMethod) (name, xm, doc))->add_args (_ARGSPECARGS)); + return Methods ((new _NAME(ExtMethod) (name, xm, doc))->add_args (_ARGSPECARGS)); } #endif @@ -1376,7 +1376,7 @@ template Methods constructor (const std::string &name, X *(*m) (_FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (new _NAME(StaticMethod) (name, m, doc)); + return Methods (new _NAME(StaticMethod) (name, m, doc)); } #if _COUNT != 0 @@ -1384,7 +1384,7 @@ template Methods constructor (const std::string &name, X *(*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods ((new _NAME(StaticMethod) (name, m, doc))->add_args (_ARGSPECARGS)); + return Methods ((new _NAME(StaticMethod) (name, m, doc))->add_args (_ARGSPECARGS)); } #endif @@ -1397,7 +1397,7 @@ method (const std::string &name, R (*m) (_FUNCARGLIST), const std::string &doc = template Methods -method (const std::string &name, R (*m) (_FUNCARGLIST), const std::string &doc = std::string ()) +method (const std::string &name, Transfer, R (*m) (_FUNCARGLIST), const std::string &doc = std::string ()) { return Methods (new _NAME(StaticMethod) (name, m, doc)); } @@ -1412,7 +1412,7 @@ method (const std::string &name, R (*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const s template Methods -method (const std::string &name, R (*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +method (const std::string &name, Transfer, R (*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { return Methods ((new _NAME(StaticMethod) (name, m, doc))->add_args (_ARGSPECARGS)); } @@ -1422,7 +1422,7 @@ template Methods factory (const std::string &name, R *(*m) (_FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (new _NAME(StaticMethod) (name, m, doc)); + return Methods (new _NAME(StaticMethod) (name, m, doc)); } #if _COUNT != 0 @@ -1430,7 +1430,7 @@ template Methods factory (const std::string &name, R *(*m) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods ((new _NAME(StaticMethod) (name, m, doc))->add_args (_ARGSPECARGS)); + return Methods ((new _NAME(StaticMethod) (name, m, doc))->add_args (_ARGSPECARGS)); } #endif @@ -1450,11 +1450,18 @@ callback (const std::string &name, R (X::*m) (_FUNCARGLIST), Callback X::*cb _CO } #endif +template +Methods +callback (const std::string &name, Transfer, R (X::*m) (_FUNCARGLIST), Callback X::*cb _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(Method) (name, m, doc, cb))->add_args (_ARGSPECARGS)); +} + template Methods factory_callback (const std::string &name, R (X::*m) (_FUNCARGLIST), Callback X::*cb, const std::string &doc = std::string ()) { - return Methods (new _NAME(Method) (name, m, doc, cb)); + return Methods (new _NAME(Method) (name, m, doc, cb)); } #if _COUNT != 0 @@ -1462,7 +1469,7 @@ template Methods factory_callback (const std::string &name, R (X::*m) (_FUNCARGLIST), Callback X::*cb _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods ((new _NAME(Method) (name, m, doc, cb))->add_args (_ARGSPECARGS)); + return Methods ((new _NAME(Method) (name, m, doc, cb))->add_args (_ARGSPECARGS)); } #endif @@ -1475,7 +1482,7 @@ method (const std::string &name, R (X::*m) (_FUNCARGLIST) const, const std::stri template Methods -method (const std::string &name, R (X::*m) (_FUNCARGLIST) const, const std::string &doc = std::string ()) +method (const std::string &name, Transfer, R (X::*m) (_FUNCARGLIST) const, const std::string &doc = std::string ()) { return Methods (new _NAME(ConstMethod) (name, m, doc)); } @@ -1490,7 +1497,7 @@ method (const std::string &name, R (X::*m) (_FUNCARGLIST) const _COMMA _ARGSPECS template Methods -method (const std::string &name, R (X::*m) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) +method (const std::string &name, Transfer, R (X::*m) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) { return Methods ((new _NAME(ConstMethod) (name, m, doc))->add_args (_ARGSPECARGS)); } @@ -1500,7 +1507,7 @@ template Methods factory (const std::string &name, R *(X::*m) (_FUNCARGLIST) const, const std::string &doc = std::string ()) { - return Methods (new _NAME(ConstMethod) (name, m, doc)); + return Methods (new _NAME(ConstMethod) (name, m, doc)); } #if _COUNT != 0 @@ -1508,7 +1515,7 @@ template Methods factory (const std::string &name, R *(X::*m) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods ((new _NAME(ConstMethod) (name, m, doc))->add_args (_ARGSPECARGS)); + return Methods ((new _NAME(ConstMethod) (name, m, doc))->add_args (_ARGSPECARGS)); } #endif @@ -1528,11 +1535,18 @@ callback (const std::string &name, R (X::*m) (_FUNCARGLIST) const, Callback X::* } #endif +template +Methods +callback (const std::string &name, Transfer, R (X::*m) (_FUNCARGLIST) const, Callback X::*cb _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(ConstMethod) (name, m, doc, cb))->add_args (_ARGSPECARGS)); +} + template Methods factory_callback (const std::string &name, R (X::*m) (_FUNCARGLIST) const, Callback X::*cb, const std::string &doc = std::string ()) { - return Methods (new _NAME(ConstMethod) (name, m, doc, cb)); + return Methods (new _NAME(ConstMethod) (name, m, doc, cb)); } #if _COUNT != 0 @@ -1540,7 +1554,7 @@ template Methods factory_callback (const std::string &name, R (X::*m) (_FUNCARGLIST) const, Callback X::*cb _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods ((new _NAME(ConstMethod) (name, m, doc, cb))->add_args (_ARGSPECARGS)); + return Methods ((new _NAME(ConstMethod) (name, m, doc, cb))->add_args (_ARGSPECARGS)); } #endif @@ -1562,6 +1576,13 @@ iterator (const std::string &name, R *(*b) (_FUNCARGLIST), R *(*e) (_FUNCARGLIST } #endif +template +Methods +iterator (const std::string &name, Transfer, R *(*b) (_FUNCARGLIST), R *(*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(StaticMethodPtrIter) (name, b, e, doc))->add_args (_ARGSPECARGS)); +} + template Methods iterator (const std::string &name, R const *(*b) (_FUNCARGLIST), R const *(*e) (_FUNCARGLIST), const std::string &doc = std::string ()) @@ -1578,6 +1599,13 @@ iterator (const std::string &name, R const *(*b) (_FUNCARGLIST), R const *(*e) ( } #endif +template +Methods +iterator (const std::string &name, Transfer, R const *(*b) (_FUNCARGLIST), R const *(*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(StaticMethodPtrConstIter) (name, b, e, doc))->add_args (_ARGSPECARGS)); +} + template Methods iterator (const std::string &name, R *(X::*b) (_FUNCARGLIST), R *(X::*e) (_FUNCARGLIST), const std::string &doc = std::string ()) @@ -1594,6 +1622,13 @@ iterator (const std::string &name, R *(X::*b) (_FUNCARGLIST), R *(X::*e) (_FUNCA } #endif +template +Methods +iterator (const std::string &name, Transfer, R *(X::*b) (_FUNCARGLIST), R *(X::*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(MethodPtrIter) (name, b, e, doc))->add_args (_ARGSPECARGS)); +} + template Methods iterator (const std::string &name, R const *(X::*b) (_FUNCARGLIST), R const *(X::*e) (_FUNCARGLIST), const std::string &doc = std::string ()) @@ -1610,6 +1645,13 @@ iterator (const std::string &name, R const *(X::*b) (_FUNCARGLIST), R const *(X: } #endif +template +Methods +iterator (const std::string &name, Transfer, R const *(X::*b) (_FUNCARGLIST), R const *(X::*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(MethodPtrConstIter) (name, b, e, doc))->add_args (_ARGSPECARGS)); +} + template Methods iterator_ext (const std::string &name, R *(*xb) (X * _COMMA _FUNCARGLIST), R *(*xe) (X * _COMMA _FUNCARGLIST), const std::string &doc = std::string ()) @@ -1626,6 +1668,13 @@ iterator_ext (const std::string &name, R *(*xb) (X * _COMMA _FUNCARGLIST), R *(* } #endif +template +Methods +iterator_ext (const std::string &name, Transfer, R *(*xb) (X * _COMMA _FUNCARGLIST), R *(*xe) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(ExtMethodPtrIter) (name, xb, xe, doc))->add_args (_ARGSPECARGS)); +} + template Methods iterator_ext (const std::string &name, R const *(*xb) (X * _COMMA _FUNCARGLIST), R const *(*xe) (X * _COMMA _FUNCARGLIST), const std::string &doc = std::string ()) @@ -1642,6 +1691,13 @@ iterator_ext (const std::string &name, R const *(*xb) (X * _COMMA _FUNCARGLIST), } #endif +template +Methods +iterator_ext (const std::string &name, Transfer, R const *(*xb) (X * _COMMA _FUNCARGLIST), R const *(*xe) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(ExtMethodPtrConstIter) (name, xb, xe, doc))->add_args (_ARGSPECARGS)); +} + template Methods iterator (const std::string &name, R *(X::*b) (_FUNCARGLIST) const, R *(X::*e) (_FUNCARGLIST) const, const std::string &doc = std::string ()) @@ -1658,6 +1714,13 @@ iterator (const std::string &name, R *(X::*b) (_FUNCARGLIST) const, R *(X::*e) ( } #endif +template +Methods +iterator (const std::string &name, Transfer, R *(X::*b) (_FUNCARGLIST) const, R *(X::*e) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(ConstMethodPtrIter) (name, b, e, doc))->add_args (_ARGSPECARGS)); +} + template Methods iterator (const std::string &name, R const *(X::*b) (_FUNCARGLIST) const, R const *(X::*e) (_FUNCARGLIST) const, const std::string &doc = std::string ()) @@ -1674,34 +1737,41 @@ iterator (const std::string &name, R const *(X::*b) (_FUNCARGLIST) const, R cons } #endif +template +Methods +iterator (const std::string &name, Transfer, R const *(X::*b) (_FUNCARGLIST) const, R const *(X::*e) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods ((new _NAME(ConstMethodPtrConstIter) (name, b, e, doc))->add_args (_ARGSPECARGS)); +} + // pair iterators -template -_NAME(MethodBiIter) * -_iterator (const std::string &name, I (X::*b) (_FUNCARGLIST), I (X::*e) (_FUNCARGLIST), const std::string &doc) +template +_NAME(MethodBiIter) * +_iterator (const std::string &name, I (X::*b) (_FUNCARGLIST), I (X::*e) (_FUNCARGLIST), Transfer, const std::string &doc) { - return new _NAME(MethodBiIter) (name, b, e, doc); + return new _NAME(MethodBiIter) (name, b, e, doc); } -template -_NAME(ExtMethodBiIter) * -_iterator_ext (const std::string &name, I (*xb) (X * _COMMA _FUNCARGLIST), I (*xe) (X * _COMMA _FUNCARGLIST), const std::string &doc) +template +_NAME(ExtMethodBiIter) * +_iterator_ext (const std::string &name, I (*xb) (X * _COMMA _FUNCARGLIST), I (*xe) (X * _COMMA _FUNCARGLIST), Transfer, const std::string &doc) { - return new _NAME(ExtMethodBiIter) (name, xb, xe, doc); + return new _NAME(ExtMethodBiIter) (name, xb, xe, doc); } -template -_NAME(StaticMethodBiIter) * -_iterator (const std::string &name, I (*b) (_FUNCARGLIST), I (*e) (_FUNCARGLIST), const std::string &doc) +template +_NAME(StaticMethodBiIter) * +_iterator (const std::string &name, I (*b) (_FUNCARGLIST), I (*e) (_FUNCARGLIST), Transfer, const std::string &doc) { - return new _NAME(StaticMethodBiIter) (name, b, e, doc); + return new _NAME(StaticMethodBiIter) (name, b, e, doc); } template Methods iterator (const std::string &name, I (*b) (_FUNCARGLIST), I (*e) (_FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (_iterator (name, b, e, doc)); + return Methods (_iterator (name, b, e, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1709,15 +1779,22 @@ template Methods iterator (const std::string &name, I (*b) (_FUNCARGLIST), I (*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator (name, b, e, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator (name, b, e, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif +template +Methods +iterator (const std::string &name, Transfer transfer, I (*b) (_FUNCARGLIST), I (*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods (_iterator (name, b, e, transfer, doc)->add_args (_ARGSPECARGS)); +} + template Methods iterator (const std::string &name, I (X::*b) (_FUNCARGLIST), I (X::*e) (_FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (_iterator (name, b, e, doc)); + return Methods (_iterator (name, b, e, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1725,15 +1802,22 @@ template Methods iterator (const std::string &name, I (X::*b) (_FUNCARGLIST), I (X::*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator (name, b, e, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator (name, b, e, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif +template +Methods +iterator (const std::string &name, Transfer transfer, I (X::*b) (_FUNCARGLIST), I (X::*e) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods (_iterator (name, b, e, transfer, doc)->add_args (_ARGSPECARGS)); +} + template Methods iterator_ext (const std::string &name, I (*xb) (X * _COMMA _FUNCARGLIST), I (*xe) (X * _COMMA _FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (_iterator_ext (name, xb, xe, doc)); + return Methods (_iterator_ext (name, xb, xe, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1741,22 +1825,29 @@ template Methods iterator_ext (const std::string &name, I (*xb) (X * _COMMA _FUNCARGLIST), I (*xe) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator_ext (name, xb, xe, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator_ext (name, xb, xe, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif -template -_NAME(ConstMethodBiIter) * -_iterator (const std::string &name, I (X::*b) (_FUNCARGLIST) const, I (X::*e) (_FUNCARGLIST) const, const std::string &doc) +template +Methods +iterator_ext (const std::string &name, Transfer transfer, I (*xb) (X * _COMMA _FUNCARGLIST), I (*xe) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return new _NAME(ConstMethodBiIter) (name, b, e, doc); + return Methods (_iterator_ext (name, xb, xe, transfer, doc)->add_args (_ARGSPECARGS)); +} + +template +_NAME(ConstMethodBiIter) * +_iterator (const std::string &name, I (X::*b) (_FUNCARGLIST) const, I (X::*e) (_FUNCARGLIST) const, Transfer, const std::string &doc) +{ + return new _NAME(ConstMethodBiIter) (name, b, e, doc); } template Methods iterator (const std::string &name, I (X::*b) (_FUNCARGLIST) const, I (X::*e) (_FUNCARGLIST) const, const std::string &doc = std::string ()) { - return Methods (_iterator (name, b, e, doc)); + return Methods (_iterator (name, b, e, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1764,38 +1855,45 @@ template Methods iterator (const std::string &name, I (X::*b) (_FUNCARGLIST) const, I (X::*e) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator (name, b, e, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator (name, b, e, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif +template +Methods +iterator (const std::string &name, Transfer transfer, I (X::*b) (_FUNCARGLIST) const, I (X::*e) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods (_iterator (name, b, e, transfer, doc)->add_args (_ARGSPECARGS)); +} + // free iterators -template -_NAME(MethodFreeIter) * -_iterator (const std::string &name, I (X::*i) (_FUNCARGLIST), const std::string &doc) +template +_NAME(MethodFreeIter) * +_iterator (const std::string &name, I (X::*i) (_FUNCARGLIST), Transfer, const std::string &doc) { - return new _NAME(MethodFreeIter) (name, i, doc); + return new _NAME(MethodFreeIter) (name, i, doc); } -template -_NAME(ExtMethodFreeIter) * -_iterator_ext (const std::string &name, I (*xi) (X * _COMMA _FUNCARGLIST), const std::string &doc) +template +_NAME(ExtMethodFreeIter) * +_iterator_ext (const std::string &name, I (*xi) (X * _COMMA _FUNCARGLIST), Transfer, const std::string &doc) { - return new _NAME(ExtMethodFreeIter) (name, xi, doc); + return new _NAME(ExtMethodFreeIter) (name, xi, doc); } -template -_NAME(StaticMethodFreeIter) * -_iterator (const std::string &name, I (*i) (_FUNCARGLIST), const std::string &doc) +template +_NAME(StaticMethodFreeIter) * +_iterator (const std::string &name, I (*i) (_FUNCARGLIST), Transfer, const std::string &doc) { - return new _NAME(StaticMethodFreeIter) (name, i, doc); + return new _NAME(StaticMethodFreeIter) (name, i, doc); } template Methods iterator (const std::string &name, I (*i) (_FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (_iterator (name, i, doc)); + return Methods (_iterator (name, i, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1803,15 +1901,22 @@ template Methods iterator (const std::string &name, I (*i) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator (name, i, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator (name, i, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif +template +Methods +iterator (const std::string &name, Transfer transfer, I (*i) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods (_iterator (name, i, transfer, doc)->add_args (_ARGSPECARGS)); +} + template Methods iterator (const std::string &name, I (X::*i) (_FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (_iterator (name, i, doc)); + return Methods (_iterator (name, i, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1819,15 +1924,22 @@ template Methods iterator (const std::string &name, I (X::*i) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator (name, i, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator (name, i, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif +template +Methods +iterator (const std::string &name, Transfer transfer, I (X::*i) (_FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods (_iterator (name, i, transfer, doc)->add_args (_ARGSPECARGS)); +} + template Methods iterator_ext (const std::string &name, I (*xi) (X * _COMMA _FUNCARGLIST), const std::string &doc = std::string ()) { - return Methods (_iterator_ext (name, xi, doc)); + return Methods (_iterator_ext (name, xi, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1835,22 +1947,29 @@ template Methods iterator_ext (const std::string &name, I (*xi) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator_ext (name, xi, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator_ext (name, xi, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif -template -_NAME(ConstMethodFreeIter) * -_iterator (const std::string &name, I (X::*i) (_FUNCARGLIST) const, const std::string &doc) +template +Methods +iterator_ext (const std::string &name, Transfer transfer, I (*xi) (X * _COMMA _FUNCARGLIST) _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return new _NAME(ConstMethodFreeIter) (name, i, doc); + return Methods (_iterator_ext (name, xi, transfer, doc)->add_args (_ARGSPECARGS)); +} + +template +_NAME(ConstMethodFreeIter) * +_iterator (const std::string &name, I (X::*i) (_FUNCARGLIST) const, Transfer, const std::string &doc) +{ + return new _NAME(ConstMethodFreeIter) (name, i, doc); } template Methods iterator (const std::string &name, I (X::*i) (_FUNCARGLIST) const, const std::string &doc = std::string ()) { - return Methods (_iterator (name, i, doc)); + return Methods (_iterator (name, i, arg_default_return_value_preference (), doc)); } #if _COUNT != 0 @@ -1858,9 +1977,16 @@ template Methods iterator (const std::string &name, I (X::*i) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) { - return Methods (_iterator (name, i, doc)->add_args (_ARGSPECARGS)); + return Methods (_iterator (name, i, arg_default_return_value_preference (), doc)->add_args (_ARGSPECARGS)); } #endif +template +Methods +iterator (const std::string &name, Transfer transfer, I (X::*i) (_FUNCARGLIST) const _COMMA _ARGSPECS, const std::string &doc = std::string ()) +{ + return Methods (_iterator (name, i, transfer, doc)->add_args (_ARGSPECARGS)); +} + #undef _COMMA diff --git a/src/gsi/gsi/gsiTypes.h b/src/gsi/gsi/gsiTypes.h index 22a941d09..664a5aa24 100644 --- a/src/gsi/gsi/gsiTypes.h +++ b/src/gsi/gsi/gsiTypes.h @@ -1410,6 +1410,13 @@ struct arg_make_reference { }; */ struct arg_default_return_value_preference { }; +// All of these modes can be used for arguments (in callbacks) or for +// return values. So we provide aliases to make their names clearer. + +typedef arg_pass_ownership return_new_object; +typedef arg_make_copy return_copy; +typedef arg_make_reference return_reference; + /** * @brief A function computing the "prefer_copy" value */ diff --git a/src/gsi/gsi_test/gsiTest.cc b/src/gsi/gsi_test/gsiTest.cc index d115a54a7..c99eeab2c 100644 --- a/src/gsi/gsi_test/gsiTest.cc +++ b/src/gsi/gsi_test/gsiTest.cc @@ -1074,17 +1074,17 @@ static gsi::Class decl_c ("", "C", gsi::method ("call_vfunc", &C_P::call_vfunc) + gsi::method ("pass_cd_direct", &C_P::pass_cd_direct) + gsi::method ("pass_cd_cref", &C_P::pass_cd_cref) + - gsi::method ("pass_cd_cref_as_copy", &C_P::pass_cd_cref) + - gsi::method ("pass_cd_cref_as_ref", &C_P::pass_cd_cref) + + gsi::method ("pass_cd_cref_as_copy", gsi::return_copy (), &C_P::pass_cd_cref) + + gsi::method ("pass_cd_cref_as_ref", gsi::return_reference (), &C_P::pass_cd_cref) + gsi::method ("pass_cd_cptr", &C_P::pass_cd_cptr) + - gsi::method ("pass_cd_cptr_as_copy", &C_P::pass_cd_cptr) + - gsi::method ("pass_cd_cptr_as_ref", &C_P::pass_cd_cptr) + + gsi::method ("pass_cd_cptr_as_copy", gsi::return_copy (), &C_P::pass_cd_cptr) + + gsi::method ("pass_cd_cptr_as_ref", gsi::return_reference (), &C_P::pass_cd_cptr) + gsi::method ("pass_cd_ref", &C_P::pass_cd_ref) + - gsi::method ("pass_cd_ref_as_copy", &C_P::pass_cd_ref) + - gsi::method ("pass_cd_ref_as_ref", &C_P::pass_cd_ref) + + gsi::method ("pass_cd_ref_as_copy", gsi::return_copy (), &C_P::pass_cd_ref) + + gsi::method ("pass_cd_ref_as_ref", gsi::return_reference (), &C_P::pass_cd_ref) + gsi::method ("pass_cd_ptr", &C_P::pass_cd_ptr) + - gsi::method ("pass_cd_ptr_as_copy", &C_P::pass_cd_ptr) + - gsi::method ("pass_cd_ptr_as_ref", &C_P::pass_cd_ptr) + + gsi::method ("pass_cd_ptr_as_copy", gsi::return_copy (), &C_P::pass_cd_ptr) + + gsi::method ("pass_cd_ptr_as_ref", gsi::return_reference (), &C_P::pass_cd_ptr) + gsi::method ("g", &C_P::g) + gsi::method ("s1", &C::s1) + gsi::method ("s2", &C::s2) + diff --git a/testdata/ruby/dbNetlistCrossReference.rb b/testdata/ruby/dbNetlistCrossReference.rb index 7bd7c9ec9..45fab3146 100644 --- a/testdata/ruby/dbNetlistCrossReference.rb +++ b/testdata/ruby/dbNetlistCrossReference.rb @@ -156,7 +156,20 @@ class DBNetlistCrossReference_TestClass < TestBase info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s end assert_equal(info.join(","), "(nil)/$2:Mismatch,/(nil):Mismatch,/(nil):Mismatch") - + + end + + def test_3_StatusEnums + + st = RBA::NetlistCrossReference::Status::new + assert_equal(st.to_i, 0) + assert_equal(st.to_s, "None") + + st = RBA::NetlistCrossReference::Status::Match + assert_equal(st.to_s, "Match") + + st = RBA::NetlistCrossReference::Skipped + assert_equal(st.to_s, "Skipped") end