Mercurial > hg > octave-nkf
annotate src/pt-id.cc @ 9644:080e11f1b0c1
don't return undefined output values from user functions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 15 Sep 2009 17:17:13 +0200 |
parents | c5f03874ea2a |
children | cd96d29c5efa |
rev | line source |
---|---|
2887 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2004, 2005, 2006, 2007, |
4 2008, 2009 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 | |
60 if (error_state) | |
61 return retval; | |
62 | |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
63 octave_value val = xsym ().find (); |
2887 | 64 |
7336 | 65 if (val.is_defined ()) |
2887 | 66 { |
7336 | 67 // GAGME -- this would be cleaner if we required |
68 // parens to indicate function calls. | |
69 // | |
70 // If this identifier refers to a function, we need to know | |
71 // whether it is indexed so that we can do the same thing | |
72 // for `f' and `f()'. If the index is present, return the | |
73 // function object and let tree_index_expression::rvalue | |
74 // handle indexing. Otherwise, arrange to call the function | |
75 // here, so that we don't return the function definition as | |
76 // a value. | |
77 | |
78 if (val.is_function () && ! is_postfix_indexed ()) | |
2887 | 79 { |
7336 | 80 octave_value_list tmp_args; |
2887 | 81 |
7336 | 82 retval = val.do_multi_index_op (nargout, tmp_args); |
2887 | 83 } |
84 else | |
7336 | 85 { |
86 if (print_result () && nargout == 0) | |
87 val.print_with_name (octave_stdout, name ()); | |
88 | |
89 retval = val; | |
90 } | |
2887 | 91 } |
7336 | 92 else |
93 eval_undefined_error (); | |
2887 | 94 |
95 return retval; | |
96 } | |
97 | |
2971 | 98 octave_value |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7924
diff
changeset
|
99 tree_identifier::rvalue1 (int nargout) |
2971 | 100 { |
101 octave_value retval; | |
102 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7924
diff
changeset
|
103 octave_value_list tmp = rvalue (nargout); |
2971 | 104 |
105 if (! tmp.empty ()) | |
106 retval = tmp(0); | |
107 | |
108 return retval; | |
109 } | |
110 | |
2979 | 111 octave_lvalue |
2971 | 112 tree_identifier::lvalue (void) |
113 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
114 return octave_lvalue (&(xsym().varref ())); |
2971 | 115 } |
116 | |
5861 | 117 tree_identifier * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
118 tree_identifier::dup (symbol_table::scope_id sc, |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
119 symbol_table::context_id) const |
5861 | 120 { |
7336 | 121 // The new tree_identifier object contains a symbol_record |
122 // entry from the duplicated scope. | |
5861 | 123 |
7336 | 124 // FIXME -- is this the best way? |
125 symbol_table::symbol_record new_sym | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
126 = symbol_table::find_symbol (name (), sc); |
7336 | 127 |
128 tree_identifier *new_id | |
129 = new tree_identifier (new_sym, line (), column ()); | |
5861 | 130 |
131 new_id->copy_base (*this); | |
132 | |
133 return new_id; | |
134 } | |
135 | |
2887 | 136 void |
137 tree_identifier::accept (tree_walker& tw) | |
138 { | |
139 tw.visit_identifier (*this); | |
140 } | |
141 | |
142 /* | |
143 ;;; Local Variables: *** | |
144 ;;; mode: C++ *** | |
145 ;;; End: *** | |
146 */ |