Mercurial > hg > octave-lyh
annotate src/pt-id.cc @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | fd0a3ac60b0e |
children | 460a3c6d8bf1 3d3c002ccc60 d174210ce1ec |
rev | line source |
---|---|
2887 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2887 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2887 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2887 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "error.h" | |
28 #include "oct-obj.h" | |
2979 | 29 #include "oct-lvalue.h" |
2900 | 30 #include "pager.h" |
3770 | 31 #include "pt-bp.h" |
2887 | 32 #include "pt-const.h" |
33 #include "pt-id.h" | |
34 #include "pt-walk.h" | |
2900 | 35 #include "symtab.h" |
2887 | 36 #include "utils.h" |
2956 | 37 #include "variables.h" |
2887 | 38 |
39 // Symbols from the symbol table. | |
40 | |
41 void | |
42 tree_identifier::eval_undefined_error (void) | |
43 { | |
44 int l = line (); | |
45 int c = column (); | |
46 | |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
47 maybe_missing_function_hook (name ()); |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
48 if (error_state) |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
49 return; |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
50 |
2887 | 51 if (l == -1 && c == -1) |
52 ::error ("`%s' undefined", name ().c_str ()); | |
53 else | |
54 ::error ("`%s' undefined near line %d column %d", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
55 name ().c_str (), l, c); |
2887 | 56 } |
57 | |
58 octave_value_list | |
2971 | 59 tree_identifier::rvalue (int nargout) |
2887 | 60 { |
61 octave_value_list retval; | |
62 | |
63 if (error_state) | |
64 return retval; | |
65 | |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
66 octave_value val = xsym ().find (); |
2887 | 67 |
7336 | 68 if (val.is_defined ()) |
2887 | 69 { |
7336 | 70 // GAGME -- this would be cleaner if we required |
71 // parens to indicate function calls. | |
72 // | |
73 // If this identifier refers to a function, we need to know | |
74 // whether it is indexed so that we can do the same thing | |
75 // for `f' and `f()'. If the index is present, return the | |
76 // function object and let tree_index_expression::rvalue | |
77 // handle indexing. Otherwise, arrange to call the function | |
78 // here, so that we don't return the function definition as | |
79 // a value. | |
80 | |
81 if (val.is_function () && ! is_postfix_indexed ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
82 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
83 octave_value_list tmp_args; |
2887 | 84 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 retval = val.do_multi_index_op (nargout, tmp_args); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
86 } |
2887 | 87 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
89 if (print_result () && nargout == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
90 val.print_with_name (octave_stdout, name ()); |
7336 | 91 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
92 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
93 } |
2887 | 94 } |
7336 | 95 else |
96 eval_undefined_error (); | |
2887 | 97 |
98 return retval; | |
99 } | |
100 | |
2971 | 101 octave_value |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7924
diff
changeset
|
102 tree_identifier::rvalue1 (int nargout) |
2971 | 103 { |
104 octave_value retval; | |
105 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7924
diff
changeset
|
106 octave_value_list tmp = rvalue (nargout); |
2971 | 107 |
108 if (! tmp.empty ()) | |
109 retval = tmp(0); | |
110 | |
111 return retval; | |
112 } | |
113 | |
2979 | 114 octave_lvalue |
2971 | 115 tree_identifier::lvalue (void) |
116 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
117 return octave_lvalue (&(xsym().varref ())); |
2971 | 118 } |
119 | |
5861 | 120 tree_identifier * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
121 tree_identifier::dup (symbol_table::scope_id sc, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 symbol_table::context_id) const |
5861 | 123 { |
7336 | 124 // The new tree_identifier object contains a symbol_record |
125 // entry from the duplicated scope. | |
5861 | 126 |
7336 | 127 // FIXME -- is this the best way? |
128 symbol_table::symbol_record new_sym | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
129 = symbol_table::find_symbol (name (), sc); |
7336 | 130 |
131 tree_identifier *new_id | |
132 = new tree_identifier (new_sym, line (), column ()); | |
5861 | 133 |
134 new_id->copy_base (*this); | |
135 | |
136 return new_id; | |
137 } | |
138 | |
2887 | 139 void |
140 tree_identifier::accept (tree_walker& tw) | |
141 { | |
142 tw.visit_identifier (*this); | |
143 } |