Mercurial > hg > octave-nkf
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 |
rev | line source |
---|---|
2887 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 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 #if !defined (octave_tree_identifier_h) | |
25 #define octave_tree_identifier_h 1 | |
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 | 28 #include <string> |
29 | |
2943 | 30 class octave_value; |
31 class octave_value_list; | |
2887 | 32 class octave_function; |
33 | |
34 class tree_walker; | |
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 | 37 #include "pt-exp.h" |
7336 | 38 #include "symtab.h" |
2887 | 39 |
40 // Symbols from the symbol table. | |
41 | |
42 class | |
2971 | 43 tree_identifier : public tree_expression |
2887 | 44 { |
45 friend class tree_index_expression; | |
46 | |
47 public: | |
48 | |
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 | 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 | 56 |
57 ~tree_identifier (void) { } | |
58 | |
4267 | 59 bool has_magic_end (void) const { return (name () == "__end__"); } |
60 | |
3933 | 61 bool is_identifier (void) const { return true; } |
2887 | 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 | 65 std::string name (void) const { return sym.name (); } |
2887 | 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 | 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 | 70 |
7336 | 71 // Try to find a definition for an identifier. Here's how: |
72 // | |
73 // * If the identifier is already defined and is a function defined | |
74 // in an function file that has been modified since the last time | |
75 // we parsed it, parse it again. | |
76 // | |
77 // * If the identifier is not defined, try to find a builtin | |
78 // variable or an already compiled function with the same name. | |
79 // | |
80 // * If the identifier is still undefined, try looking for an | |
81 // function file to parse. | |
82 // | |
83 // * On systems that support dynamic linking, we prefer .oct files, | |
84 // then .mex files, then .m files. | |
2971 | 85 |
86 octave_value | |
7336 | 87 do_lookup (tree_argument_list *args, const string_vector& arg_names, |
88 octave_value_list& evaluated_args, bool& args_evaluated) | |
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 | 91 } |
2887 | 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 | 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 | 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 | 98 |
3010 | 99 // We really need to know whether this symbol referst to a variable |
100 // or a function, but we may not know that yet. | |
101 | |
3933 | 102 bool lvalue_ok (void) const { return true; } |
3010 | 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 | 105 |
2971 | 106 octave_value_list rvalue (int nargout); |
2887 | 107 |
2979 | 108 octave_lvalue lvalue (void); |
2887 | 109 |
110 void eval_undefined_error (void); | |
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 | 114 |
2887 | 115 void accept (tree_walker& tw); |
116 | |
117 private: | |
118 | |
119 // The symbol record that this identifier references. | |
7336 | 120 symbol_table::symbol_record sym; |
2988 | 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 | 140 // No copying! |
141 | |
142 tree_identifier (const tree_identifier&); | |
143 | |
144 tree_identifier& operator = (const tree_identifier&); | |
2887 | 145 }; |
146 | |
147 #endif | |
148 | |
149 /* | |
150 ;;; Local Variables: *** | |
151 ;;; mode: C++ *** | |
152 ;;; End: *** | |
153 */ |