2887
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
2887
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2887
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2887
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "error.h" |
|
29 #include "oct-obj.h" |
2979
|
30 #include "oct-lvalue.h" |
2900
|
31 #include "pager.h" |
3770
|
32 #include "pt-bp.h" |
2887
|
33 #include "pt-const.h" |
|
34 #include "pt-id.h" |
|
35 #include "pt-walk.h" |
2900
|
36 #include "symtab.h" |
2887
|
37 #include "utils.h" |
2956
|
38 #include "variables.h" |
2887
|
39 |
|
40 // Symbols from the symbol table. |
|
41 |
|
42 void |
|
43 tree_identifier::eval_undefined_error (void) |
|
44 { |
|
45 int l = line (); |
|
46 int c = column (); |
|
47 |
|
48 if (l == -1 && c == -1) |
|
49 ::error ("`%s' undefined", name ().c_str ()); |
|
50 else |
|
51 ::error ("`%s' undefined near line %d column %d", |
|
52 name ().c_str (), l, c); |
|
53 } |
|
54 |
|
55 octave_value_list |
2971
|
56 tree_identifier::rvalue (int nargout) |
2887
|
57 { |
|
58 octave_value_list retval; |
|
59 |
3770
|
60 MAYBE_DO_BREAKPOINT; |
|
61 |
2887
|
62 if (error_state) |
|
63 return retval; |
|
64 |
7336
|
65 octave_value_list evaluated_args; |
|
66 bool args_evaluated; |
2887
|
67 |
7336
|
68 octave_value val = sym.find (0, string_vector (), evaluated_args, |
|
69 args_evaluated); |
2887
|
70 |
7336
|
71 if (val.is_defined ()) |
2887
|
72 { |
7336
|
73 // GAGME -- this would be cleaner if we required |
|
74 // parens to indicate function calls. |
|
75 // |
|
76 // If this identifier refers to a function, we need to know |
|
77 // whether it is indexed so that we can do the same thing |
|
78 // for `f' and `f()'. If the index is present, return the |
|
79 // function object and let tree_index_expression::rvalue |
|
80 // handle indexing. Otherwise, arrange to call the function |
|
81 // here, so that we don't return the function definition as |
|
82 // a value. |
|
83 |
|
84 if (val.is_function () && ! is_postfix_indexed ()) |
2887
|
85 { |
7336
|
86 octave_value_list tmp_args; |
2887
|
87 |
7336
|
88 retval = val.do_multi_index_op (nargout, tmp_args); |
2887
|
89 } |
|
90 else |
7336
|
91 { |
|
92 if (print_result () && nargout == 0) |
|
93 val.print_with_name (octave_stdout, name ()); |
|
94 |
|
95 retval = val; |
|
96 } |
2887
|
97 } |
7336
|
98 else |
|
99 eval_undefined_error (); |
2887
|
100 |
|
101 return retval; |
|
102 } |
|
103 |
2971
|
104 octave_value |
|
105 tree_identifier::rvalue (void) |
|
106 { |
|
107 octave_value retval; |
|
108 |
|
109 octave_value_list tmp = rvalue (1); |
|
110 |
|
111 if (! tmp.empty ()) |
|
112 retval = tmp(0); |
|
113 |
|
114 return retval; |
|
115 } |
|
116 |
2979
|
117 octave_lvalue |
2971
|
118 tree_identifier::lvalue (void) |
|
119 { |
3770
|
120 MAYBE_DO_BREAKPOINT; |
|
121 |
7336
|
122 return octave_lvalue (&(sym.varref ())); |
2971
|
123 } |
|
124 |
5861
|
125 tree_identifier * |
7336
|
126 tree_identifier::dup (symbol_table::scope_id scope) |
5861
|
127 { |
7336
|
128 // The new tree_identifier object contains a symbol_record |
|
129 // entry from the duplicated scope. |
5861
|
130 |
7336
|
131 // FIXME -- is this the best way? |
|
132 symbol_table::symbol_record new_sym |
|
133 = symbol_table::find_symbol (sym.name (), scope); |
|
134 |
|
135 tree_identifier *new_id |
|
136 = new tree_identifier (new_sym, line (), column ()); |
5861
|
137 |
|
138 new_id->copy_base (*this); |
|
139 |
|
140 return new_id; |
|
141 } |
|
142 |
2887
|
143 void |
|
144 tree_identifier::accept (tree_walker& tw) |
|
145 { |
|
146 tw.visit_identifier (*this); |
|
147 } |
|
148 |
|
149 /* |
|
150 ;;; Local Variables: *** |
|
151 ;;; mode: C++ *** |
|
152 ;;; End: *** |
|
153 */ |