Mercurial > hg > octave-lyh
changeset 3356:d2e12e998a78
[project @ 1999-11-18 06:17:06 by jwe]
author | jwe |
---|---|
date | Thu, 18 Nov 1999 06:17:08 +0000 |
parents | c4983fc7318f |
children | 34d512262892 |
files | src/ChangeLog src/help.cc src/symtab.cc src/symtab.h |
diffstat | 4 files changed, 66 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,6 @@ 1999-11-17 John W. Eaton <jwe@bevo.che.wisc.edu> - * symtab.cc (symbol_record::symbol_def::type_as_string): New function. + * symtab.cc (symbol_record::type_as_string): New function. * symtab.cc (symbol_record::which): New functions. * help.cc (do_which): New functions. @@ -10,6 +10,7 @@ (builtin_help): Use them. * help.cc (do_type): New function. + (symbol_record::type): New function. (Ftype): Use them. * help.cc (print_symbol_type): Delete.
--- a/src/help.cc +++ b/src/help.cc @@ -60,7 +60,6 @@ #include "parse.h" #include "pathsearch.h" #include "procstream.h" -#include "pt-pr-code.h" #include "sighandlers.h" #include "symtab.h" #include "syswait.h" @@ -802,89 +801,7 @@ symbol_record *sym_rec = lookup_by_name (name, 0); if (sym_rec && sym_rec->is_defined ()) - { - if (sym_rec->is_user_function ()) - { - octave_value tmp = sym_rec->def (); - - octave_function *defn = tmp.function_value (); - - string fn = defn ? defn->fcn_file_name () : string (); - - if (pr_orig_txt && ! fn.empty ()) - { - ifstream fs (fn.c_str (), ios::in); - - if (fs) - { - if (pr_type_info && ! quiet) - os << name << " is the function defined from: " - << fn << "\n\n"; - - char ch; - - while (fs.get (ch)) - os << ch; - } - else - os << "unable to open `" << fn << "' for reading!\n"; - } - else - { - if (pr_type_info && ! quiet) - os << name << " is a user-defined function:\n\n"; - - tree_print_code tpc (os, "", pr_orig_txt); - - defn->accept (tpc); - } - } - - // XXX FIXME XXX -- this code should be shared with - // Fwhich. - - else if (sym_rec->is_text_function ()) - os << name << " is a built-in text-function\n"; - else if (sym_rec->is_builtin_function ()) - os << name << " is a built-in function\n"; - else if (sym_rec->is_user_variable () - || sym_rec->is_builtin_variable () - || sym_rec->is_builtin_constant ()) - { - octave_value defn = sym_rec->def (); - - int var_ok = 1; - - if (! error_state) - { - if (pr_type_info && ! quiet) - { - if (var_ok) - { - os << name; - - if (sym_rec->is_user_variable ()) - os << " is a user-defined variable\n"; - else if (sym_rec->is_builtin_variable ()) - os << " is a built-in variable\n"; - else if (sym_rec->is_builtin_constant ()) - os << " is a built-in constant\n"; - else - panic_impossible (); - } - else - os << "type: `" << name << "' has unknown type!\n"; - } - - defn.print_raw (os, true); - - if (pr_type_info) - os << "\n"; - } - } - else - error ("type: `%s' has unknown type!", name.c_str ()); - } + sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); else { string ff = fcn_file_in_path (name);
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -33,6 +33,7 @@ #include <climits> #include <iomanip.h> +#include <fstream.h> #include "glob-match.h" #include "str-vec.h" @@ -42,6 +43,7 @@ #include "oct-lvalue.h" #include "ov.h" #include "pager.h" +#include "pt-pr-code.h" #include "symtab.h" #include "utils.h" #include "variables.h" @@ -81,6 +83,60 @@ return retval; } +void +SYMBOL_DEF::type (ostream& os, const string& name, bool pr_type_info, + bool quiet, bool pr_orig_txt) +{ + if (is_user_function ()) + { + octave_function *defn = definition.function_value (); + + string fn = defn ? defn->fcn_file_name () : string (); + + if (pr_orig_txt && ! fn.empty ()) + { + ifstream fs (fn.c_str (), ios::in); + + if (fs) + { + if (pr_type_info && ! quiet) + os << name << " is the " << type_as_string () + << " defined from: " << fn << "\n\n"; + + char ch; + + while (fs.get (ch)) + os << ch; + } + else + os << "unable to open `" << fn << "' for reading!\n"; + } + else + { + if (pr_type_info && ! quiet) + os << name << " is a " << type_as_string () << ":\n\n"; + + tree_print_code tpc (os, "", pr_orig_txt); + + defn->accept (tpc); + } + } + else if (is_user_variable () + || is_builtin_variable () + || is_builtin_constant ()) + { + if (pr_type_info && ! quiet) + os << name << " is a " << type_as_string () << "\n"; + + definition.print_raw (os, true); + + if (pr_type_info) + os << "\n"; + } + else + os << name << " is a " << type_as_string () << "\n"; +} + string SYMBOL_DEF::which (const string& name) { @@ -508,7 +564,7 @@ return sr; } else if (warn) - warning ("lookup: symbol`%s' not found", nm.c_str ()); + warning ("lookup: symbol `%s' not found", nm.c_str ()); return 0; }
--- a/src/symtab.h +++ b/src/symtab.h @@ -143,6 +143,9 @@ string type_as_string (void) const; + void type (ostream& os, const string& name, bool pr_type_info, + bool quiet, bool pr_orig_txt); + string which (const string& name); void which (ostream& os, const string& name); @@ -317,6 +320,9 @@ string type_as_string (void) const { return definition->type_as_string (); } + void type (ostream& os, bool pr_type_info, bool quiet, bool pr_orig_txt) + { definition->type (os, name (), pr_type_info, quiet, pr_orig_txt); } + string which (void) { return definition->which (name ()); } void which (ostream& os) { definition->which (os, name ()); }