GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-id.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "error.h"
28 #include "oct-obj.h"
29 #include "oct-lvalue.h"
30 #include "pager.h"
31 #include "pt-bp.h"
32 #include "pt-const.h"
33 #include "pt-eval.h"
34 #include "pt-id.h"
35 #include "pt-walk.h"
36 #include "symtab.h"
37 #include "utils.h"
38 #include "variables.h"
39 
40 // Symbols from the symbol table.
41 
42 void
44 {
45  int l = line ();
46  int c = column ();
47 
49  if (error_state)
50  return;
51 
52  if (l == -1 && c == -1)
53  ::error_with_id ("Octave:undefined-function",
54  "'%s' undefined", name ().c_str ());
55  else
56  ::error_with_id ("Octave:undefined-function",
57  "'%s' undefined near line %d column %d",
58  name ().c_str (), l, c);
59 }
60 
63  const std::list<octave_lvalue> *lvalue_list)
64 {
65  octave_value_list retval;
66 
67  if (error_state)
68  return retval;
69 
70  octave_value val = sym->find ();
71 
72  if (val.is_defined ())
73  {
74  // GAGME -- this would be cleaner if we required
75  // parens to indicate function calls.
76  //
77  // If this identifier refers to a function, we need to know
78  // whether it is indexed so that we can do the same thing
79  // for 'f' and 'f()'. If the index is present, return the
80  // function object and let tree_index_expression::rvalue
81  // handle indexing. Otherwise, arrange to call the function
82  // here, so that we don't return the function definition as
83  // a value.
84 
85  if (val.is_function () && ! is_postfix_indexed ())
86  {
87  octave_value_list tmp_args;
88 
89  retval = (lvalue_list
90  ? val.do_multi_index_op (nargout, tmp_args, lvalue_list)
91  : val.do_multi_index_op (nargout, tmp_args));
92  }
93  else
94  {
95  if (print_result () && nargout == 0
98 
99  retval = val;
100  }
101  }
102  else if (sym->is_added_static ())
104  else
106 
107  return retval;
108 }
109 
112 {
113  octave_value retval;
114 
115  octave_value_list tmp = rvalue (nargout);
116 
117  if (! tmp.empty ())
118  retval = tmp(0);
119 
120  return retval;
121 }
122 
125 {
126  if (sym->is_added_static ())
128 
129  return octave_lvalue (sym);
130 }
131 
135 {
136  // The new tree_identifier object contains a symbol_record
137  // entry from the duplicated scope.
138 
139  // FIXME: is this the best way?
141  = symbol_table::find_symbol (name (), sc);
142 
143  tree_identifier *new_id
144  = new tree_identifier (new_sym, line (), column ());
145 
146  new_id->copy_base (*this);
147 
148  return new_id;
149 }
150 
151 void
153 {
154  tw.visit_identifier (*this);
155 }