annotate src/pt-id.h @ 8950:d865363208d6

include <iosfwd> instead of <iostream> in header files
author John W. Eaton <jwe@octave.org>
date Tue, 10 Mar 2009 13:55:52 -0400
parents eb63fbe60fab
children c5f03874ea2a
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
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8913
diff changeset
3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007,
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8913
diff changeset
4 2008, 2009 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
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
27 #include <iosfwd>
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 ())
7753
e76a4a6e3c47 initialize args_evaluated; delete useless statement
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
55 : tree_expression (l, c), sym (s), scope (sc) { }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
56
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
57 ~tree_identifier (void) { }
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
58
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4192
diff changeset
59 bool has_magic_end (void) const { return (name () == "__end__"); }
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4192
diff changeset
60
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
61 bool is_identifier (void) const { return true; }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
62
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
63 // 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
64 // 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
65 std::string name (void) const { return sym.name (); }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
66
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
67 bool is_defined (void) { return xsym().is_defined (); }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
68
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
69 bool is_variable (void) { return xsym().is_variable (); }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
70
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
71 // 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
72 //
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
73 // * 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
74 // 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
75 // we parsed it, parse it again.
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
76 //
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
77 // * 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
78 // 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
79 //
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
80 // * 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
81 // function file to parse.
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 // * 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
84 // then .mex files, then .m files.
2971
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
85
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
86 octave_value
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
87 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
88 octave_value_list& evaluated_args, bool& args_evaluated)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
89 {
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
90 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
91 }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
92
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
93 void mark_global (void) { xsym().mark_global (); }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
94
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
95 void mark_as_static (void) { xsym().init_persistent (); }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
96
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
97 void mark_as_formal_parameter (void) { xsym().mark_formal (); }
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
98
3010
1aeb8869e464 [project @ 1997-06-01 19:24:02 by jwe]
jwe
parents: 2988
diff changeset
99 // 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
100 // 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
101
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
102 bool lvalue_ok (void) const { return true; }
3010
1aeb8869e464 [project @ 1997-06-01 19:24:02 by jwe]
jwe
parents: 2988
diff changeset
103
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
104 octave_value rvalue1 (int nargout = 1);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
105
2971
f2be17e6f1ea [project @ 1997-05-15 18:55:44 by jwe]
jwe
parents: 2960
diff changeset
106 octave_value_list rvalue (int nargout);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
107
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents: 2971
diff changeset
108 octave_lvalue lvalue (void);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
109
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
110 void eval_undefined_error (void);
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
111
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7753
diff changeset
112 tree_identifier *dup (symbol_table::scope_id scope,
8913
35cd375d4bb3 make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
113 symbol_table::context_id context) const;
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5307
diff changeset
114
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
115 void accept (tree_walker& tw);
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
116
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
117 private:
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
118
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
119 // The symbol record that this identifier references.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
120 symbol_table::symbol_record sym;
2988
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
121
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
122 symbol_table::scope_id scope;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
123
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
124 // 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
125 // 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
126 // new scope.
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
127 symbol_table::symbol_record& xsym (void)
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
128 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
129 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
130
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
131 if (scope != curr_scope)
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 scope = curr_scope;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
134 sym = symbol_table::insert (sym.name ());
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
135 }
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 return sym;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
138 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7677
diff changeset
139
2988
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
140 // No copying!
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
141
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
142 tree_identifier (const tree_identifier&);
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
143
daa1ed1f5462 [project @ 1997-05-16 07:23:15 by jwe]
jwe
parents: 2980
diff changeset
144 tree_identifier& operator = (const tree_identifier&);
2887
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
145 };
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
146
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
147 #endif
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
148
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 ;;; Local Variables: ***
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
151 ;;; mode: C++ ***
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
152 ;;; End: ***
4b71bb90c388 [project @ 1997-04-28 01:20:55 by jwe]
jwe
parents:
diff changeset
153 */