# HG changeset patch # User John W. Eaton # Date 1477072695 14400 # Node ID e7a9dfb8bf169a82628db0c1f5f945b732287b09 # Parent 65d84345abfca963405f1faa5cf155bc6ec09066 remove obsolete function __dispatch__ * __dispatch__.cc: Delete * libinterp/corefcn/module.mk: Update. * ov-fcn-handle.cc: Eliminte special case for legacy dispatch. * symtab.h, symtab.cc (symbol_table::fcn_info::dispatch_map_type, symbol_table::fcn_info::dispatch_map_const_iterator, symbol_table::fcn_info::dispatch_map_iterator): Delete typedefs. (symbol_table::fcn_info::fcn_info_rep::dispatch_map): Delete data member. (symbol_table::fcn_info::fcn_info_rep::add_dispatch, symbol_table::fcn_info::fcn_info_rep::clear_dispatch, symbol_table::fcn_info::fcn_info_rep::print_dispatch, symbol_table::fcn_info::fcn_info_rep::help_for_dispatch, symbol_table::fcn_info::fcn_info_rep::get_dispatch): Delete member functions. (symbol_table::fcn_info::add_dispatch, symbol_table::fcn_info::clear_dispatch, symbol_table::fcn_info::print_dispatch, symbol_table::fcn_info::help_for_dispatch, symbol_table::fcn_info::get_dispatch): Delete static member functions. diff -r 65d84345abfc -r e7a9dfb8bf16 libinterp/corefcn/__dispatch__.cc --- a/libinterp/corefcn/__dispatch__.cc Thu Oct 20 23:58:45 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - -Copyright (C) 2001-2016 John W. Eaton and Paul Kienzle - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -. - -*/ - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include -#include -#include - -#include "Cell.h" -#include "oct-map.h" -#include "defun.h" -#include "ov.h" -#include "ov-fcn.h" -#include "ov-typeinfo.h" -#include "pager.h" -#include "parse.h" -#include "symtab.h" -#include "variables.h" - -DEFUN (__dispatch__, args, nargout, - doc: /* -*- texinfo -*- -@deftypefn {} {} __dispatch__ () -Undocumented internal function. -@end deftypefn */) -{ - int nargin = args.length (); - - if (nargin < 1 || nargin > 3) - print_usage (); - - std::string f, r, t; - - f = args(0).xstring_value ("__dispatch__: first argument must be a function name"); - - if (nargin > 1) - r = args(1).xstring_value ("__dispatch__: second argument must be a function name"); - - if (nargin > 2) - t = args(2).xstring_value ("__dispatch__: third argument must be a type name"); - - octave_value retval; - - if (nargin == 1) - { - if (nargout > 0) - { - symbol_table::fcn_info::dispatch_map_type dm - = symbol_table::get_dispatch (f); - - size_t len = dm.size (); - - Cell type_field (len, 1); - Cell name_field (len, 1); - - symbol_table::fcn_info::dispatch_map_type::const_iterator p - = dm.begin (); - - for (size_t i = 0; i < len; i++) - { - type_field(i) = p->first; - name_field(i) = p->second; - - p++; - } - - octave_scalar_map m; - - m.assign ("type", type_field); - m.assign ("name", name_field); - - retval = m; - } - else - symbol_table::print_dispatch (octave_stdout, f); - } - else if (nargin == 2) - { - t = r; - symbol_table::clear_dispatch (f, t); - } - else - symbol_table::add_dispatch (f, t, r); - - return retval; -} - -/* -## No test needed for internal helper function. -%!assert (1) -*/ - diff -r 65d84345abfc -r e7a9dfb8bf16 libinterp/corefcn/module.mk --- a/libinterp/corefcn/module.mk Thu Oct 20 23:58:45 2016 +0200 +++ b/libinterp/corefcn/module.mk Fri Oct 21 13:58:15 2016 -0400 @@ -116,7 +116,6 @@ COREFCN_SRC = \ libinterp/corefcn/Cell.cc \ libinterp/corefcn/__contourc__.cc \ - libinterp/corefcn/__dispatch__.cc \ libinterp/corefcn/__dsearchn__.cc \ libinterp/corefcn/__ichol__.cc \ libinterp/corefcn/__ilu__.cc \ diff -r 65d84345abfc -r e7a9dfb8bf16 libinterp/corefcn/symtab.cc --- a/libinterp/corefcn/symtab.cc Thu Oct 20 23:58:45 2016 +0200 +++ b/libinterp/corefcn/symtab.cc Fri Oct 21 13:58:15 2016 -0400 @@ -550,41 +550,6 @@ } } -void -symbol_table::fcn_info::fcn_info_rep::print_dispatch (std::ostream& os) const -{ - if (dispatch_map.empty ()) - os << "dispatch: " << name << " is not overloaded" << std::endl; - else - { - os << "Overloaded function " << name << ":\n\n"; - - for (dispatch_map_const_iterator p = dispatch_map.begin (); - p != dispatch_map.end (); p++) - os << " " << name << " (" << p->first << ", ...) -> " - << p->second << " (" << p->first << ", ...)\n"; - - os << std::endl; - } -} - -std::string -symbol_table::fcn_info::fcn_info_rep::help_for_dispatch (void) const -{ - std::string retval; - - if (! dispatch_map.empty ()) - { - retval = "Overloaded function:\n\n"; - - for (dispatch_map_const_iterator p = dispatch_map.begin (); - p != dispatch_map.end (); p++) - retval += " " + p->second + " (" + p->first + ", ...)\n\n"; - } - - return retval; -} - // :-) JWE, can you parse this? Returns a 2D array with second dimension equal // to btyp_num_types (static constant). Only the leftmost dimension can be // variable in C/C++. Typedefs are boring. @@ -687,7 +652,6 @@ // private function // class method // class constructor -// legacy dispatch // command-line function // autoload function // function on the path @@ -824,31 +788,6 @@ } } - // Legacy dispatch. - - if (! args.empty () && ! dispatch_map.empty ()) - { - std::string dispatch_type = args(0).type_name (); - - std::string fname; - - dispatch_map_iterator p = dispatch_map.find (dispatch_type); - - if (p == dispatch_map.end ()) - p = dispatch_map.find ("any"); - - if (p != dispatch_map.end ()) - { - fname = p->second; - - octave_value fcn - = symbol_table::find_function (fname, args); - - if (fcn.is_defined ()) - return fcn; - } - } - // Command-line function. if (cmdline_function.is_defined ()) @@ -896,8 +835,7 @@ // But since the list of built-in functions is different in Octave and // Matlab, we also search up the precedence list until we find // something that matches. Note that we are only searching by name, -// so class methods, constructors, and legacy dispatch functions are -// skipped. +// so class methods and constructors are skipped. octave_value symbol_table::fcn_info::fcn_info_rep::builtin_find (void) @@ -1224,14 +1162,6 @@ os << tprefix << "method: " << fcn_file_name (p->second) << " [" << p->first << "]\n"; } - - if (! dispatch_map.empty ()) - { - for (dispatch_map_const_iterator p = dispatch_map.begin (); - p != dispatch_map.end (); p++) - os << tprefix << "dispatch: " << fcn_file_name (p->second) - << " [" << p->first << "]\n"; - } } void diff -r 65d84345abfc -r e7a9dfb8bf16 libinterp/corefcn/symtab.h --- a/libinterp/corefcn/symtab.h Thu Oct 20 23:58:45 2016 +0200 +++ b/libinterp/corefcn/symtab.h Fri Oct 21 13:58:15 2016 -0400 @@ -733,8 +733,6 @@ { public: - typedef std::map dispatch_map_type; - typedef std::map::const_iterator scope_val_const_iterator; typedef std::map::iterator scope_val_iterator; @@ -743,9 +741,6 @@ str_val_const_iterator; typedef std::map::iterator str_val_iterator; - typedef dispatch_map_type::const_iterator dispatch_map_const_iterator; - typedef dispatch_map_type::iterator dispatch_map_iterator; - private: class @@ -755,9 +750,9 @@ fcn_info_rep (const std::string& nm) : name (nm), package_name (), subfunctions (), private_functions (), - class_constructors (), class_methods (), dispatch_map (), - cmdline_function (), autoload_function (), function_on_path (), - built_in_function (), count (1) + class_constructors (), class_methods (), cmdline_function (), + autoload_function (), function_on_path (), built_in_function (), + count (1) { size_t pos = name.rfind ('.'); @@ -911,25 +906,6 @@ clear_package (); } - void add_dispatch (const std::string& type, const std::string& fname) - { - dispatch_map[type] = fname; - } - - void clear_dispatch (const std::string& type) - { - dispatch_map_iterator p = dispatch_map.find (type); - - if (p != dispatch_map.end ()) - dispatch_map.erase (p); - } - - void print_dispatch (std::ostream& os) const; - - std::string help_for_dispatch (void) const; - - dispatch_map_type get_dispatch (void) const { return dispatch_map; } - void dump (std::ostream& os, const std::string& prefix) const; std::string full_name (void) const @@ -956,9 +932,6 @@ // Dispatch type to function object. std::map class_methods; - // Legacy dispatch map (dispatch type name to function name). - dispatch_map_type dispatch_map; - octave_value cmdline_function; octave_value autoload_function; @@ -1123,29 +1096,6 @@ void clear_mex_function (void) { rep->clear_mex_function (); } - void add_dispatch (const std::string& type, const std::string& fname) - { - rep->add_dispatch (type, fname); - } - - void clear_dispatch (const std::string& type) - { - rep->clear_dispatch (type); - } - - void print_dispatch (std::ostream& os) const - { - rep->print_dispatch (os); - } - - std::string help_for_dispatch (void) const - { return rep->help_for_dispatch (); } - - dispatch_map_type get_dispatch (void) const - { - return rep->get_dispatch (); - } - void dump (std::ostream& os, const std::string& prefix = "") const { @@ -1845,83 +1795,6 @@ panic ("alias: '%s' is undefined", name.c_str ()); } - static void add_dispatch (const std::string& name, const std::string& type, - const std::string& fname) - { - fcn_table_iterator p = fcn_table.find (name); - - if (p != fcn_table.end ()) - { - fcn_info& finfo = p->second; - - finfo.add_dispatch (type, fname); - } - else - { - fcn_info finfo (name); - - finfo.add_dispatch (type, fname); - - fcn_table[name] = finfo; - } - } - - static void clear_dispatch (const std::string& name, const std::string& type) - { - fcn_table_iterator p = fcn_table.find (name); - - if (p != fcn_table.end ()) - { - fcn_info& finfo = p->second; - - finfo.clear_dispatch (type); - } - } - - static void print_dispatch (std::ostream& os, const std::string& name) - { - fcn_table_iterator p = fcn_table.find (name); - - if (p != fcn_table.end ()) - { - fcn_info& finfo = p->second; - - finfo.print_dispatch (os); - } - } - - static fcn_info::dispatch_map_type get_dispatch (const std::string& name) - { - fcn_info::dispatch_map_type retval; - - fcn_table_iterator p = fcn_table.find (name); - - if (p != fcn_table.end ()) - { - fcn_info& finfo = p->second; - - retval = finfo.get_dispatch (); - } - - return retval; - } - - static std::string help_for_dispatch (const std::string& name) - { - std::string retval; - - fcn_table_iterator p = fcn_table.find (name); - - if (p != fcn_table.end ()) - { - fcn_info& finfo = p->second; - - retval = finfo.help_for_dispatch (); - } - - return retval; - } - static void push_context (scope_id scope = xcurrent_scope) { if (scope == xglobal_scope || scope == xtop_scope) @@ -2953,6 +2826,7 @@ extern OCTINTERP_API std::string get_dispatch_type (const octave_value_list& args); + extern OCTINTERP_API std::string get_dispatch_type (const octave_value_list& args, builtin_type_t& builtin_type); diff -r 65d84345abfc -r e7a9dfb8bf16 libinterp/octave-value/ov-fcn-handle.cc --- a/libinterp/octave-value/ov-fcn-handle.cc Thu Oct 20 23:58:45 2016 +0200 +++ b/libinterp/octave-value/ov-fcn-handle.cc Fri Oct 21 13:58:15 2016 -0400 @@ -2039,28 +2039,19 @@ bad = true; else { - // Function handles can't handle legacy - // dispatch, so we make sure it's not - // defined. + // Simulate try/catch. + octave::unwind_protect frame; + interpreter_try (frame); - if (symbol_table::get_dispatch (head_name).size () > 0) - bad = true; - else + try { - // Simulate try/catch. - octave::unwind_protect frame; - interpreter_try (frame); + root_val = make_fcn_handle (head_name); + } + catch (const octave::execution_exception&) + { + recover_from_exception (); - try - { - root_val = make_fcn_handle (head_name); - } - catch (const octave::execution_exception&) - { - recover_from_exception (); - - bad = true; - } + bad = true; } } }