Mercurial > octave-nkf
annotate src/pt-id.cc @ 11117:3cbc0d77db48 ss-3-3-53
update version info for snapshot
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 19 Oct 2010 02:25:32 -0400 |
parents | 34e51d4e199b |
children | fd0a3ac60b0e |
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 | |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
48 maybe_missing_function_hook (name ()); |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
49 if (error_state) |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
50 return; |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
51 |
2887 | 52 if (l == -1 && c == -1) |
53 ::error ("`%s' undefined", name ().c_str ()); | |
54 else | |
55 ::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
|
56 name ().c_str (), l, c); |
2887 | 57 } |
58 | |
59 octave_value_list | |
2971 | 60 tree_identifier::rvalue (int nargout) |
2887 | 61 { |
62 octave_value_list retval; | |
63 | |
64 if (error_state) | |
65 return retval; | |
66 | |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
67 octave_value val = xsym ().find (); |
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 ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
83 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 octave_value_list tmp_args; |
2887 | 85 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
86 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
|
87 } |
2887 | 88 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
89 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
90 if (print_result () && nargout == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 val.print_with_name (octave_stdout, name ()); |
7336 | 92 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
93 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
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, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
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 } |