diff libinterp/octave-value/ov-usr-fcn.h @ 26794:287eba9ed14b

refactor predicates for classdef methods/constructors * ov-fcn.h (octave_function::is_classdef_method, octave_function::is_legacy_method, octave_function::is_legacy_constructor): New virtual functions. (octave_function::is_class_method): No longer virtual. Return true if either is_classdef_method or is_legacy_method is true. (octave_function::is_class_constructor): Likewise, for constructors. * ov-usr-fcn.h, ov-usr-fcn.cc: Define separate functions for marking and checking for legacy and classdef functions. (octave_user_function::mark_as_legacy_constructor, ): (octave_user_function::class_method_type): Rename from class_ctor_type. (octave_user_function)::method_type_str): New function. * oct-parse.yy (base_parser::start_function): Distinguish between legacy and classdef methods and constructors when marking function types. * cdef-untils.cc (make_function_of_class): Mark function as classdef constructor or method.
author John W. Eaton <jwe@octave.org>
date Mon, 25 Feb 2019 20:10:06 +0000
parents cf9e10ce3351
children 6e9034836239
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.h	Mon Feb 25 14:32:35 2019 +0000
+++ b/libinterp/octave-value/ov-usr-fcn.h	Mon Feb 25 20:10:06 2019 +0000
@@ -323,32 +323,40 @@
     return is_inline_function () || is_anonymous_function ();
   }
 
+  void mark_as_nested_function (void) { nested_function = true; }
+
   bool is_nested_function (void) const { return nested_function; }
 
-  void mark_as_nested_function (void) { nested_function = true; }
+  void mark_as_legacy_constructor (void) { class_constructor = legacy; }
 
-  void mark_as_class_constructor (void) { class_constructor = legacy; }
+  bool is_legacy_constructor (const std::string& cname = "") const
+  {
+    return (class_constructor == legacy
+            ? (cname.empty () ? true : cname == dispatch_class ()) : false);
+  }
 
   void mark_as_classdef_constructor (void) { class_constructor = classdef; }
 
-  bool is_class_constructor (const std::string& cname = "") const
-  {
-    return class_constructor == legacy
-      ? (cname.empty () ? true : cname == dispatch_class ()) : false;
-  }
-
   bool is_classdef_constructor (const std::string& cname = "") const
   {
-    return class_constructor == classdef
-      ? (cname.empty () ? true : cname == dispatch_class ()) : false;
+    return (class_constructor == classdef
+            ? (cname.empty () ? true : cname == dispatch_class ()) : false);
   }
 
-  void mark_as_class_method (void) { class_method = true; }
+  void mark_as_legacy_method (void) { class_method = legacy; }
 
-  bool is_class_method (const std::string& cname = "") const
+  bool is_legacy_method (const std::string& cname = "") const
   {
-    return class_method
-           ? (cname.empty () ? true : cname == dispatch_class ()) : false;
+    return (class_method == legacy
+            ? (cname.empty () ? true : cname == dispatch_class ()) : false);
+  }
+
+  void mark_as_classdef_method (void) { class_method = classdef; }
+
+  bool is_classdef_method (const std::string& cname = "") const
+  {
+    return (class_method == classdef
+            ? (cname.empty () ? true : cname == dispatch_class ()) : false);
   }
 
   octave_value_list
@@ -386,7 +394,7 @@
 
 private:
 
-  enum class_ctor_type
+  enum class_method_type
   {
     none,
     legacy,
@@ -394,6 +402,7 @@
   };
 
   std::string ctor_type_str (void) const;
+  std::string method_type_str (void) const;
 
   // List of arguments for this function.  These are local variables.
   octave::tree_parameter_list *param_list;
@@ -441,10 +450,10 @@
   bool nested_function;
 
   // Enum describing whether this function is the constructor for class object.
-  class_ctor_type class_constructor;
+  class_method_type class_constructor;
 
-  // TRUE means this function is a method for a class.
-  bool class_method;
+  // Enum describing whether this function is a method for a class.
+  class_method_type class_method;
 
 #if defined (HAVE_LLVM)
   octave::jit_function_info *jit_info;