Mercurial > hg > octave-nkf
annotate src/pt-id.cc @ 12121:87237a866c71 release-3-2-x
this branch is no longer maintained and is closed for further development
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 22 Jan 2011 01:00:54 -0500 |
parents | eb63fbe60fab |
children | c5f03874ea2a |
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 | |
7336 | 63 octave_value_list evaluated_args; |
7753
e76a4a6e3c47
initialize args_evaluated; delete useless statement
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
64 bool args_evaluated = false; |
2887 | 65 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
66 octave_value val = xsym().find (0, string_vector (), evaluated_args, |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
67 args_evaluated); |
2887 | 68 |
7336 | 69 if (val.is_defined ()) |
2887 | 70 { |
7336 | 71 // GAGME -- this would be cleaner if we required |
72 // parens to indicate function calls. | |
73 // | |
74 // If this identifier refers to a function, we need to know | |
75 // whether it is indexed so that we can do the same thing | |
76 // for `f' and `f()'. If the index is present, return the | |
77 // function object and let tree_index_expression::rvalue | |
78 // handle indexing. Otherwise, arrange to call the function | |
79 // here, so that we don't return the function definition as | |
80 // a value. | |
81 | |
82 if (val.is_function () && ! is_postfix_indexed ()) | |
2887 | 83 { |
7336 | 84 octave_value_list tmp_args; |
2887 | 85 |
7336 | 86 retval = val.do_multi_index_op (nargout, tmp_args); |
2887 | 87 } |
88 else | |
7336 | 89 { |
90 if (print_result () && nargout == 0) | |
91 val.print_with_name (octave_stdout, name ()); | |
92 | |
93 retval = val; | |
94 } | |
2887 | 95 } |
7336 | 96 else |
97 eval_undefined_error (); | |
2887 | 98 |
99 return retval; | |
100 } | |
101 | |
2971 | 102 octave_value |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7924
diff
changeset
|
103 tree_identifier::rvalue1 (int nargout) |
2971 | 104 { |
105 octave_value retval; | |
106 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7924
diff
changeset
|
107 octave_value_list tmp = rvalue (nargout); |
2971 | 108 |
109 if (! tmp.empty ()) | |
110 retval = tmp(0); | |
111 | |
112 return retval; | |
113 } | |
114 | |
2979 | 115 octave_lvalue |
2971 | 116 tree_identifier::lvalue (void) |
117 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
118 return octave_lvalue (&(xsym().varref ())); |
2971 | 119 } |
120 | |
5861 | 121 tree_identifier * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
122 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
|
123 symbol_table::context_id) const |
5861 | 124 { |
7336 | 125 // The new tree_identifier object contains a symbol_record |
126 // entry from the duplicated scope. | |
5861 | 127 |
7336 | 128 // FIXME -- is this the best way? |
129 symbol_table::symbol_record new_sym | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
130 = symbol_table::find_symbol (name (), sc); |
7336 | 131 |
132 tree_identifier *new_id | |
133 = new tree_identifier (new_sym, line (), column ()); | |
5861 | 134 |
135 new_id->copy_base (*this); | |
136 | |
137 return new_id; | |
138 } | |
139 | |
2887 | 140 void |
141 tree_identifier::accept (tree_walker& tw) | |
142 { | |
143 tw.visit_identifier (*this); | |
144 } | |
145 | |
146 /* | |
147 ;;; Local Variables: *** | |
148 ;;; mode: C++ *** | |
149 ;;; End: *** | |
150 */ |