pt-id.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "error.h"
00028 #include "oct-obj.h"
00029 #include "oct-lvalue.h"
00030 #include "pager.h"
00031 #include "pt-bp.h"
00032 #include "pt-const.h"
00033 #include "pt-id.h"
00034 #include "pt-walk.h"
00035 #include "symtab.h"
00036 #include "utils.h"
00037 #include "variables.h"
00038 
00039 // Symbols from the symbol table.
00040 
00041 void
00042 tree_identifier::eval_undefined_error (void)
00043 {
00044   int l = line ();
00045   int c = column ();
00046 
00047   maybe_missing_function_hook (name ());
00048   if (error_state)
00049     return;
00050 
00051   if (l == -1 && c == -1)
00052     ::error ("'%s' undefined", name ().c_str ());
00053   else
00054     ::error ("'%s' undefined near line %d column %d",
00055              name ().c_str (), l, c);
00056 }
00057 
00058 octave_value_list
00059 tree_identifier::rvalue (int nargout)
00060 {
00061   octave_value_list retval;
00062 
00063   if (error_state)
00064     return retval;
00065 
00066   octave_value val = xsym ().find ();
00067 
00068   if (val.is_defined ())
00069     {
00070       // GAGME -- this would be cleaner if we required
00071       // parens to indicate function calls.
00072       //
00073       // If this identifier refers to a function, we need to know
00074       // whether it is indexed so that we can do the same thing
00075       // for 'f' and 'f()'.  If the index is present, return the
00076       // function object and let tree_index_expression::rvalue
00077       // handle indexing.  Otherwise, arrange to call the function
00078       // here, so that we don't return the function definition as
00079       // a value.
00080 
00081       if (val.is_function () && ! is_postfix_indexed ())
00082         {
00083           octave_value_list tmp_args;
00084 
00085           retval = val.do_multi_index_op (nargout, tmp_args);
00086         }
00087       else
00088         {
00089           if (print_result () && nargout == 0)
00090             val.print_with_name (octave_stdout, name ());
00091 
00092           retval = val;
00093         }
00094     }
00095   else
00096     eval_undefined_error ();
00097 
00098   return retval;
00099 }
00100 
00101 octave_value
00102 tree_identifier::rvalue1 (int nargout)
00103 {
00104   octave_value retval;
00105 
00106   octave_value_list tmp = rvalue (nargout);
00107 
00108   if (! tmp.empty ())
00109     retval = tmp(0);
00110 
00111   return retval;
00112 }
00113 
00114 octave_lvalue
00115 tree_identifier::lvalue (void)
00116 {
00117   return octave_lvalue (&(xsym().varref ()));
00118 }
00119 
00120 tree_identifier *
00121 tree_identifier::dup (symbol_table::scope_id sc,
00122                       symbol_table::context_id) const
00123 {
00124   // The new tree_identifier object contains a symbol_record
00125   // entry from the duplicated scope.
00126 
00127   // FIXME -- is this the best way?
00128   symbol_table::symbol_record new_sym
00129     = symbol_table::find_symbol (name (), sc);
00130 
00131   tree_identifier *new_id
00132     = new tree_identifier (new_sym, line (), column ());
00133 
00134   new_id->copy_base (*this);
00135 
00136   return new_id;
00137 }
00138 
00139 void
00140 tree_identifier::accept (tree_walker& tw)
00141 {
00142   tw.visit_identifier (*this);
00143 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines