Mercurial > hg > octave-lyh
diff src/pt-id.cc @ 7336:745a8299c2b5
[project @ 2007-12-28 20:56:55 by jwe]
author | jwe |
---|---|
date | Fri, 28 Dec 2007 20:56:58 +0000 |
parents | a1dbe9d80eee |
children | 40c428ea3408 |
line wrap: on
line diff
--- a/src/pt-id.cc +++ b/src/pt-id.cc @@ -39,41 +39,6 @@ // Symbols from the symbol table. -std::string -tree_identifier::name (void) const -{ - std::string retval; - if (sym) - retval = sym->name (); - return retval; -} - -tree_identifier * -tree_identifier::define (octave_function *f, unsigned int sym_type) -{ - int status = sym->define (f, sym_type); - return status ? this : 0; -} - -void -tree_identifier::document (const std::string& s) -{ - if (sym) - sym->document (s); -} - -bool -tree_identifier::is_defined (void) -{ - return (sym && sym->is_defined ()); -} - -bool -tree_identifier::is_function (void) -{ - return (sym && sym->is_function ()); -} - void tree_identifier::eval_undefined_error (void) { @@ -87,65 +52,6 @@ name ().c_str (), l, c); } -// Try to find a definition for an identifier. Here's how: -// -// * If the identifier is already defined and is a function defined -// in an function file that has been modified since the last time -// we parsed it, parse it again. -// -// * If the identifier is not defined, try to find a builtin -// variable or an already compiled function with the same name. -// -// * If the identifier is still undefined, try looking for an -// function file to parse. -// -// * On systems that support dynamic linking, we prefer .oct files, -// then .mex files, then .m files. - -octave_value -tree_identifier::do_lookup (bool& script_file_executed, bool exec_script) -{ - static octave_value foo; - - script_file_executed = lookup (sym, exec_script); - - return script_file_executed ? foo : sym->def (); -} - -void -tree_identifier::link_to_global (void) -{ - if (sym) - { - if (! sym->is_linked_to_global ()) - { - if (sym->is_defined () && sym->is_variable ()) - { - std::string nm = sym->name (); - - warning ("value of local variable `%s' may have changed to match global", - nm.c_str ()); - } - - link_to_global_variable (sym); - } - } -} - -void -tree_identifier::mark_as_static (void) -{ - if (sym) - sym->mark_as_static (); -} - -void -tree_identifier::mark_as_formal_parameter (void) -{ - if (sym) - sym->mark_as_formal_parameter (); -} - octave_value_list tree_identifier::rvalue (int nargout) { @@ -156,42 +62,41 @@ if (error_state) return retval; - bool script_file_executed = false; + octave_value_list evaluated_args; + bool args_evaluated; - octave_value val = do_lookup (script_file_executed); + octave_value val = sym.find (0, string_vector (), evaluated_args, + args_evaluated); - if (! script_file_executed) + if (val.is_defined ()) { - if (val.is_defined ()) + // GAGME -- this would be cleaner if we required + // parens to indicate function calls. + // + // If this identifier refers to a function, we need to know + // whether it is indexed so that we can do the same thing + // for `f' and `f()'. If the index is present, return the + // function object and let tree_index_expression::rvalue + // handle indexing. Otherwise, arrange to call the function + // here, so that we don't return the function definition as + // a value. + + if (val.is_function () && ! is_postfix_indexed ()) { - // GAGME -- this would be cleaner if we required - // parens to indicate function calls. - // - // If this identifier refers to a function, we need to know - // whether it is indexed so that we can do the same thing - // for `f' and `f()'. If the index is present, return the - // function object and let tree_index_expression::rvalue - // handle indexing. Otherwise, arrange to call the function - // here, so that we don't return the function definition as - // a value. + octave_value_list tmp_args; - if (val.is_function () && ! is_postfix_indexed ()) - { - octave_value_list tmp_args; - - retval = val.do_multi_index_op (nargout, tmp_args); - } - else - { - if (print_result () && nargout == 0) - val.print_with_name (octave_stdout, name ()); - - retval = val; - } + retval = val.do_multi_index_op (nargout, tmp_args); } else - eval_undefined_error (); + { + if (print_result () && nargout == 0) + val.print_with_name (octave_stdout, name ()); + + retval = val; + } } + else + eval_undefined_error (); return retval; } @@ -214,15 +119,21 @@ { MAYBE_DO_BREAKPOINT; - return sym->variable_reference (); + return octave_lvalue (&(sym.varref ())); } tree_identifier * -tree_identifier::dup (symbol_table *sym_tab) +tree_identifier::dup (symbol_table::scope_id scope) { - symbol_record *sr = (sym_tab && sym) ? sym_tab->lookup (sym->name ()) : 0; + // The new tree_identifier object contains a symbol_record + // entry from the duplicated scope. - tree_identifier *new_id = new tree_identifier (sr, line (), column ()); + // FIXME -- is this the best way? + symbol_table::symbol_record new_sym + = symbol_table::find_symbol (sym.name (), scope); + + tree_identifier *new_id + = new tree_identifier (new_sym, line (), column ()); new_id->copy_base (*this);