annotate src/pt-id.h @ 7752:40c428ea3408

initial implementation of dbup and dbdown
author John W. Eaton <jwe@octave.org>
date Sun, 04 May 2008 03:42:19 -0400
parents db02cc0ba8f2
children e76a4a6e3c47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
1 /*
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 John W. Eaton
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
5
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
7
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
11 option) any later version.
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
12
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
16 for more details.
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
17
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
20 <http://www.gnu.org/licenses/>.
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
21
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
22 */
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
23
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
24 #if !defined (octave_tree_identifier_h)
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
25 #define octave_tree_identifier_h 1
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
26
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3010
diff changeset
27 #include <iostream>
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
28 #include <string>
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
29
2943
e6dfc3ea6299 [project @ 1997-05-08 02:31:59 by jwe]
jwe
parents: 2887
diff changeset
30 class octave_value;
e6dfc3ea6299 [project @ 1997-05-08 02:31:59 by jwe]
jwe
parents: 2887
diff changeset
31 class octave_value_list;
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
32 class octave_function;
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
33
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
34 class tree_walker;
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
35
7677
db02cc0ba8f2 handle breakpoints in tree_identifier::do_lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
36 #include "pt-bp.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents: 2979
diff changeset
37 #include "pt-exp.h"
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
38 #include "symtab.h"
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
39
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
40 // Symbols from the symbol table.
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
41
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
42 class
2971
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
43 tree_identifier : public tree_expression
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
44 {
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
45 friend class tree_index_expression;
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
46
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
47 public:
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
48
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
49 tree_identifier (int l = -1, int c = -1)
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
50 : tree_expression (l, c), sym (), scope (-1) { }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
51
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
52 tree_identifier (const symbol_table::symbol_record& s,
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
53 int l = -1, int c = -1,
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
54 symbol_table::scope_id sc = symbol_table::current_scope ())
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
55 : tree_expression (l, c), sym (s), scope (sc)
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
56 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
57 symbol_table::scope_id curr_scope = symbol_table::current_scope ();
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
58 }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
59
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
60 ~tree_identifier (void) { }
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
61
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4192
diff changeset
62 bool has_magic_end (void) const { return (name () == "__end__"); }
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4192
diff changeset
63
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
64 bool is_identifier (void) const { return true; }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
65
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
66 // The name doesn't change with scope, so use sym instead of
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
67 // accessing it through sym so that this function may remain const.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
68 std::string name (void) const { return sym.name (); }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
69
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
70 bool is_defined (void) { return xsym().is_defined (); }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
71
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
72 bool is_variable (void) { return xsym().is_variable (); }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
73
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
74 // Try to find a definition for an identifier. Here's how:
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
75 //
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
76 // * If the identifier is already defined and is a function defined
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
77 // in an function file that has been modified since the last time
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
78 // we parsed it, parse it again.
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
79 //
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
80 // * If the identifier is not defined, try to find a builtin
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
81 // variable or an already compiled function with the same name.
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
82 //
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
83 // * If the identifier is still undefined, try looking for an
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
84 // function file to parse.
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
85 //
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
86 // * On systems that support dynamic linking, we prefer .oct files,
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
87 // then .mex files, then .m files.
2971
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
88
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
89 octave_value
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
90 do_lookup (tree_argument_list *args, const string_vector& arg_names,
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
91 octave_value_list& evaluated_args, bool& args_evaluated)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
92 {
7677
db02cc0ba8f2 handle breakpoints in tree_identifier::do_lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
93 MAYBE_DO_BREAKPOINT;
db02cc0ba8f2 handle breakpoints in tree_identifier::do_lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
94
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
95 return xsym().find (args, arg_names, evaluated_args, args_evaluated);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
96 }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
97
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
98 void mark_global (void) { xsym().mark_global (); }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
99
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
100 void mark_as_static (void) { xsym().init_persistent (); }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
101
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
102 void mark_as_formal_parameter (void) { xsym().mark_formal (); }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
103
3010
1aeb8869e464 [project @ 1997-06-01 19:24:02 by jwe]
jwe
parents: 2988
diff changeset
104 // We really need to know whether this symbol referst to a variable
1aeb8869e464 [project @ 1997-06-01 19:24:02 by jwe]
jwe
parents: 2988
diff changeset
105 // or a function, but we may not know that yet.
1aeb8869e464 [project @ 1997-06-01 19:24:02 by jwe]
jwe
parents: 2988
diff changeset
106
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
107 bool lvalue_ok (void) const { return true; }
3010
1aeb8869e464 [project @ 1997-06-01 19:24:02 by jwe]
jwe
parents: 2988
diff changeset
108
2971
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
109 octave_value rvalue (void);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
110
2971
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
111 octave_value_list rvalue (int nargout);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
112
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents: 2971
diff changeset
113 octave_lvalue lvalue (void);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
114
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
115 void eval_undefined_error (void);
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
116
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
117 tree_identifier *dup (symbol_table::scope_id scope);
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5307
diff changeset
118
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
119 void accept (tree_walker& tw);
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
120
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
121 private:
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
122
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
123 // The symbol record that this identifier references.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
124 symbol_table::symbol_record sym;
2988
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
125
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
126 symbol_table::scope_id scope;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
127
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
128 // A script may be executed in multiple scopes. If the last one was
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
129 // different from the one we are in now, update sym to be from the
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
130 // new scope.
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
131 symbol_table::symbol_record& xsym (void)
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
132 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
133 symbol_table::scope_id curr_scope = symbol_table::current_scope ();
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
134
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
135 if (scope != curr_scope)
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
136 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
137 scope = curr_scope;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
138 sym = symbol_table::insert (sym.name ());
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
139 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
140
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
141 return sym;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
142 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
143
2988
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
144 // No copying!
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
145
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
146 tree_identifier (const tree_identifier&);
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
147
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
148 tree_identifier& operator = (const tree_identifier&);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
149 };
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
150
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
151 #endif
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
152
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
153 /*
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
154 ;;; Local Variables: ***
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
155 ;;; mode: C++ ***
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
156 ;;; End: ***
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
157 */