# HG changeset patch # User John W. Eaton # Date 1550850015 0 # Node ID a95887edd55e1ff2a1597b37357b9649043c679b # Parent d1419ac095647fa3181eaf7fcd126a9f8eb5003d style fixes for classdef classes * cdef-class.cc, cdef-class.h, cdef-method.h, cdef-package.cc, cdef-package.h, cdef-property.h: Style fixes. diff -r d1419ac09564 -r a95887edd55e libinterp/octave-value/cdef-class.cc --- a/libinterp/octave-value/cdef-class.cc Fri Feb 22 15:28:42 2019 +0000 +++ b/libinterp/octave-value/cdef-class.cc Fri Feb 22 15:40:15 2019 +0000 @@ -111,6 +111,7 @@ class ctor_analyzer : public octave::tree_walker { public: + ctor_analyzer (void) = delete; ctor_analyzer (const std::string& ctor, const std::string& obj) @@ -153,6 +154,7 @@ { return ctor_list; } // NO-OP + void visit_anon_fcn_handle (octave::tree_anon_fcn_handle&) { } void visit_argument_list (octave::tree_argument_list&) { } void visit_binary_expression (octave::tree_binary_expression&) { } @@ -203,6 +205,7 @@ } private: + // The name of the constructor being analyzed. std::string who; diff -r d1419ac09564 -r a95887edd55e libinterp/octave-value/cdef-class.h --- a/libinterp/octave-value/cdef-class.h Fri Feb 22 15:28:42 2019 +0000 +++ b/libinterp/octave-value/cdef-class.h Fri Feb 22 15:40:15 2019 +0000 @@ -108,7 +108,9 @@ void meta_release (void); bool meta_accepts_postfix_index (char type) const - { return (type == '(' || type == '.'); } + { + return (type == '(' || type == '.'); + } octave_value construct (const octave_value_list& args); @@ -167,33 +169,42 @@ // The @-directory were this class is loaded from. // (not used yet) + std::string directory; // The methods defined by this class. + std::map method_map; // The properties defined by this class. + std::map property_map; // The number of members in this class (methods, properties...) + octave_idx_type member_count; // TRUE if this class is a handle class. A class is a handle // class when the abstract "handle" class is one of its superclasses. + bool handle_class; // The list of super-class constructors that are called implicitly by the // the classdef engine when creating an object. These constructors are not // called explicitly by the class constructor. + std::list implicit_ctor_list; // The number of objects of this class. + octave::refcount object_count; // TRUE if this class is a built-in meta class. + bool meta; - // Utility iterator typedef's. + // Utility iterator typedefs. + typedef std::map::iterator method_iterator; typedef std::map::const_iterator method_const_iterator; typedef std::map::iterator property_iterator; @@ -208,16 +219,18 @@ }; public: - // Create and invalid class object - cdef_class (void) - : cdef_meta_object () { } + + // Create an invalid class object. + + cdef_class (void) : cdef_meta_object () { } cdef_class (const std::string& nm, const std::list& superclasses) : cdef_meta_object (new cdef_class_rep (superclasses)) - { get_rep ()->set_name (nm); } + { + get_rep ()->set_name (nm); + } - cdef_class (const cdef_class& cls) - : cdef_meta_object (cls) { } + cdef_class (const cdef_class& cls) : cdef_meta_object (cls) { } cdef_class (const cdef_object& obj) : cdef_meta_object (obj) @@ -240,25 +253,35 @@ cdef_method find_method (const std::string& nm, bool local = false); void install_method (const cdef_method& meth) - { get_rep ()->install_method (meth); } + { + get_rep ()->install_method (meth); + } Cell get_methods (void) { return get_rep ()->get_methods (); } std::map get_method_map (bool only_inherited = false) - { return get_rep ()->get_method_map (only_inherited); } + { + return get_rep ()->get_method_map (only_inherited); + } cdef_property find_property (const std::string& nm); void install_property (const cdef_property& prop) - { get_rep ()->install_property (prop); } + { + get_rep ()->install_property (prop); + } Cell get_properties (int mode = property_normal) - { return get_rep ()->get_properties (mode); } + { + return get_rep ()->get_properties (mode); + } std::map get_property_map (int mode = property_normal) - { return get_rep ()->get_property_map (mode); } + { + return get_rep ()->get_property_map (mode); + } string_vector get_names (void) { return get_rep ()->get_names (); } @@ -267,19 +290,23 @@ bool is_sealed (void) const { return get_rep ()->is_sealed (); } void set_directory (const std::string& dir) - { get_rep ()->set_directory (dir); } + { + get_rep ()->set_directory (dir); + } std::string get_directory (void) const - { return get_rep ()->get_directory (); } + { + return get_rep ()->get_directory (); + } - std::string get_name (void) const - { return get_rep ()->get_name (); } + std::string get_name (void) const { return get_rep ()->get_name (); } - bool is_builtin (void) const - { return get_directory ().empty (); } + bool is_builtin (void) const { return get_directory ().empty (); } void delete_object (const cdef_object& obj) - { get_rep ()->delete_object (obj); } + { + get_rep ()->delete_object (obj); + } //! Analyze the tree_classdef tree and transform it to a cdef_class //! @@ -308,25 +335,39 @@ octave_function * get_method_function (const std::string& nm); octave_function * get_constructor_function (void) - { return get_method_function (get_name ()); } + { + return get_method_function (get_name ()); + } octave_value construct (const octave_value_list& args) - { return get_rep ()->construct (args); } + { + return get_rep ()->construct (args); + } cdef_object construct_object (const octave_value_list& args) - { return get_rep ()->construct_object (args); } + { + return get_rep ()->construct_object (args); + } void initialize_object (cdef_object& obj) - { get_rep ()->initialize_object (obj); } + { + get_rep ()->initialize_object (obj); + } void run_constructor (cdef_object& obj, const octave_value_list& args) - { get_rep ()->run_constructor (obj, args); } + { + get_rep ()->run_constructor (obj, args); + } void mark_as_handle_class (void) - { get_rep ()->mark_as_handle_class (); } + { + get_rep ()->mark_as_handle_class (); + } bool is_handle_class (void) const - { return get_rep ()->is_handle_class (); } + { + return get_rep ()->is_handle_class (); + } void mark_as_meta_class (void) { get_rep ()->mark_as_meta_class (); } @@ -337,6 +378,7 @@ void unregister_object (void) { get_rep ()->unregister_object (); } public: + enum { property_normal, @@ -345,11 +387,16 @@ }; private: + cdef_class_rep * get_rep (void) - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } const cdef_class_rep * get_rep (void) const - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } friend bool operator == (const cdef_class&, const cdef_class&); friend bool operator != (const cdef_class&, const cdef_class&); @@ -360,24 +407,36 @@ inline bool operator == (const cdef_class& clsa, const cdef_class& clsb) -// FIXME: is this really the right way to check class equality? -{ return (clsa.get_rep () == clsb.get_rep ()); } +{ + // FIXME: is this really the right way to check class equality? + + return (clsa.get_rep () == clsb.get_rep ()); +} inline bool operator != (const cdef_class& clsa, const cdef_class& clsb) -{ return ! (clsa == clsb); } +{ + return ! (clsa == clsb); +} // This is only to be able to use cdef_class as map keys. + inline bool operator < (const cdef_class& clsa, const cdef_class& clsb) -{ return clsa.get_rep () < clsb.get_rep (); } +{ + return clsa.get_rep () < clsb.get_rep (); +} inline cdef_method cdef_class::find_method (const std::string& nm, bool local) -{ return get_rep ()->find_method (nm, local); } +{ + return get_rep ()->find_method (nm, local); +} inline cdef_property cdef_class::find_property (const std::string& nm) -{ return get_rep ()->find_property (nm); } +{ + return get_rep ()->find_property (nm); +} #endif diff -r d1419ac09564 -r a95887edd55e libinterp/octave-value/cdef-method.h --- a/libinterp/octave-value/cdef-method.h Fri Feb 22 15:28:42 2019 +0000 +++ b/libinterp/octave-value/cdef-method.h Fri Feb 22 15:40:15 2019 +0000 @@ -45,6 +45,7 @@ cdef_method_rep : public cdef_meta_object_rep { public: + cdef_method_rep (void) : cdef_meta_object_rep (), function (), dispatch_type () { } @@ -72,7 +73,9 @@ bool is_external (void) const { return ! dispatch_type.empty (); } void mark_as_external (const std::string& dtype) - { dispatch_type = dtype; } + { + dispatch_type = dtype; + } octave_value_list execute (const octave_value_list& args, int nargout, bool do_check_access = true, @@ -90,9 +93,12 @@ const std::list& idx, int nargout); bool meta_accepts_postfix_index (char type) const - { return (type == '(' || type == '.'); } + { + return (type == '(' || type == '.'); + } private: + cdef_method_rep (const cdef_method_rep& m) : cdef_meta_object_rep (m), function (m.function), dispatch_type (m.dispatch_type) @@ -110,18 +116,21 @@ // When non-empty, the method is externally defined and this member // is used to cache the dispatch type to look for the method. + std::string dispatch_type; }; public: + cdef_method (void) : cdef_meta_object () { } cdef_method (const std::string& nm) : cdef_meta_object (new cdef_method_rep ()) - { get_rep ()->set_name (nm); } + { + get_rep ()->set_name (nm); + } - cdef_method (const cdef_method& meth) - : cdef_meta_object (meth) { } + cdef_method (const cdef_method& meth) : cdef_meta_object (meth) { } cdef_method (const cdef_object& obj) : cdef_meta_object (obj) @@ -145,14 +154,18 @@ octave_value_list execute (const octave_value_list& args, int nargout, bool do_check_access = true, const std::string& who = "") - { return get_rep ()->execute (args, nargout, do_check_access, who); } + { + return get_rep ()->execute (args, nargout, do_check_access, who); + } // dot-invocation: object is pushed as 1st argument octave_value_list execute (const cdef_object& obj, const octave_value_list& args, int nargout, bool do_check_access = true, const std::string& who = "") - { return get_rep ()->execute (obj, args, nargout, do_check_access, who); } + { + return get_rep ()->execute (obj, args, nargout, do_check_access, who); + } bool check_access (void) const { return get_rep ()->check_access (); } @@ -161,25 +174,38 @@ bool is_static (void) const { return get_rep ()->is_static (); } void set_function (const octave_value& fcn) - { get_rep ()->set_function (fcn); } + { + get_rep ()->set_function (fcn); + } octave_value get_function (void) const - { return get_rep ()->get_function (); } + { + return get_rep ()->get_function (); + } bool is_constructor (void) const - { return get_rep ()->is_constructor (); } + { + return get_rep ()->is_constructor (); + } bool is_external (void) const { return get_rep ()->is_external (); } void mark_as_external (const std::string& dtype) - { get_rep ()->mark_as_external (dtype); } + { + get_rep ()->mark_as_external (dtype); + } private: + cdef_method_rep * get_rep (void) - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } const cdef_method_rep * get_rep (void) const - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } }; #endif diff -r d1419ac09564 -r a95887edd55e libinterp/octave-value/cdef-package.cc --- a/libinterp/octave-value/cdef-package.cc Fri Feb 22 15:28:42 2019 +0000 +++ b/libinterp/octave-value/cdef-package.cc Fri Feb 22 15:40:15 2019 +0000 @@ -90,15 +90,21 @@ Cell cdef_package::cdef_package_rep::get_classes (void) const -{ return map2Cell (class_map); } +{ + return map2Cell (class_map); +} Cell cdef_package::cdef_package_rep::get_functions (void) const -{ return map2Cell (function_map); } +{ + return map2Cell (function_map); +} Cell cdef_package::cdef_package_rep::get_packages (void) const -{ return map2Cell (package_map); } +{ + return map2Cell (package_map); +} octave_value cdef_package::cdef_package_rep::find (const std::string& nm) diff -r d1419ac09564 -r a95887edd55e libinterp/octave-value/cdef-package.h --- a/libinterp/octave-value/cdef-package.h Fri Feb 22 15:28:42 2019 +0000 +++ b/libinterp/octave-value/cdef-package.h Fri Feb 22 15:40:15 2019 +0000 @@ -50,8 +50,8 @@ cdef_package_rep : public cdef_meta_object_rep { public: - cdef_package_rep (void) - : cdef_meta_object_rep (), member_count (0) { } + + cdef_package_rep (void) : cdef_meta_object_rep (), member_count (0) { } cdef_package_rep& operator = (const cdef_package_rep&) = delete; @@ -101,11 +101,14 @@ void meta_release (void); bool meta_accepts_postfix_index (char type) const - { return (type == '.'); } + { + return (type == '.'); + } octave_value find (const std::string& nm); private: + std::string full_name; std::map class_map; std::map function_map; @@ -136,14 +139,16 @@ }; public: + cdef_package (void) : cdef_meta_object () { } cdef_package (const std::string& nm) : cdef_meta_object (new cdef_package_rep ()) - { get_rep ()->set_name (nm); } + { + get_rep ()->set_name (nm); + } - cdef_package (const cdef_package& pack) - : cdef_meta_object (pack) { } + cdef_package (const cdef_package& pack) : cdef_meta_object (pack) { } cdef_package (const cdef_object& obj) : cdef_meta_object (obj) @@ -164,33 +169,53 @@ ~cdef_package (void) = default; void install_class (const cdef_class& cls, const std::string& nm) - { get_rep ()->install_class (cls, nm); } + { + get_rep ()->install_class (cls, nm); + } void install_function (const octave_value& fcn, const std::string& nm) - { get_rep ()->install_function (fcn, nm); } + { + get_rep ()->install_function (fcn, nm); + } void install_package (const cdef_package& pack, const std::string& nm) - { get_rep ()->install_package (pack, nm); } + { + get_rep ()->install_package (pack, nm); + } Cell get_classes (void) const - { return get_rep ()->get_classes (); } + { + return get_rep ()->get_classes (); + } Cell get_functions (void) const - { return get_rep ()->get_functions (); } + { + return get_rep ()->get_functions (); + } Cell get_packages (void) const - { return get_rep ()->get_packages (); } + { + return get_rep ()->get_packages (); + } std::string get_name (void) const { return get_rep ()->get_name (); } - octave_value find (const std::string& nm) { return get_rep ()->find (nm); } + octave_value find (const std::string& nm) + { + return get_rep ()->find (nm); + } private: + cdef_package_rep * get_rep (void) - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } const cdef_package_rep * get_rep (void) const - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } friend void install_classdef (octave::interpreter& interp); }; diff -r d1419ac09564 -r a95887edd55e libinterp/octave-value/cdef-property.h --- a/libinterp/octave-value/cdef-property.h Fri Feb 22 15:28:42 2019 +0000 +++ b/libinterp/octave-value/cdef-property.h Fri Feb 22 15:40:15 2019 +0000 @@ -45,14 +45,17 @@ cdef_property_rep : public cdef_meta_object_rep { public: - cdef_property_rep (void) - : cdef_meta_object_rep () { } + + cdef_property_rep (void) : cdef_meta_object_rep () { } cdef_property_rep& operator = (const cdef_property_rep& p) = delete; ~cdef_property_rep (void) = default; - cdef_object_rep * copy (void) const { return new cdef_property_rep (*this); } + cdef_object_rep * copy (void) const + { + return new cdef_property_rep (*this); + } bool is_property (void) const { return true; } @@ -79,7 +82,8 @@ private: cdef_property_rep (const cdef_property_rep& p) - : cdef_meta_object_rep (p) { } + : cdef_meta_object_rep (p) + { } bool is_recursive_set (const cdef_object& obj) const; @@ -91,14 +95,16 @@ }; public: + cdef_property (void) : cdef_meta_object () { } cdef_property (const std::string& nm) : cdef_meta_object (new cdef_property_rep ()) - { get_rep ()->set_name (nm); } + { + get_rep ()->set_name (nm); + } - cdef_property (const cdef_property& prop) - : cdef_meta_object (prop) { } + cdef_property (const cdef_property& prop) : cdef_meta_object (prop) { } cdef_property (const cdef_object& obj) : cdef_meta_object (obj) @@ -120,33 +126,48 @@ octave_value get_value (const cdef_object& obj, bool do_check_access = true, const std::string& who = "") - { return get_rep ()->get_value (obj, do_check_access, who); } + { + return get_rep ()->get_value (obj, do_check_access, who); + } octave_value get_value (bool do_check_access = true, const std::string& who = "") - { return get_rep ()->get_value (do_check_access, who); } + { + return get_rep ()->get_value (do_check_access, who); + } void set_value (cdef_object& obj, const octave_value& val, bool do_check_access = true, const std::string& who = "") - { get_rep ()->set_value (obj, val, do_check_access, who); } + { + get_rep ()->set_value (obj, val, do_check_access, who); + } bool check_get_access (void) const - { return get_rep ()->check_get_access (); } + { + return get_rep ()->check_get_access (); + } bool check_set_access (void) const - { return get_rep ()->check_set_access (); } + { + return get_rep ()->check_set_access (); + } std::string get_name (void) const { return get_rep ()->get_name (); } bool is_constant (void) const { return get_rep ()->is_constant (); } private: + cdef_property_rep * get_rep (void) - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } const cdef_property_rep * get_rep (void) const - { return dynamic_cast (cdef_object::get_rep ()); } + { + return dynamic_cast (cdef_object::get_rep ()); + } }; #endif