Mercurial > octave
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 |
rev | line source |
---|---|
2887 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007 |
4 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 | |
3503 | 27 #include <iostream> |
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 ()) |
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 | 59 |
60 ~tree_identifier (void) { } | |
61 | |
4267 | 62 bool has_magic_end (void) const { return (name () == "__end__"); } |
63 | |
3933 | 64 bool is_identifier (void) const { return true; } |
2887 | 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 | 68 std::string name (void) const { return sym.name (); } |
2887 | 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 | 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 | 73 |
7336 | 74 // Try to find a definition for an identifier. Here's how: |
75 // | |
76 // * If the identifier is already defined and is a function defined | |
77 // in an function file that has been modified since the last time | |
78 // we parsed it, parse it again. | |
79 // | |
80 // * If the identifier is not defined, try to find a builtin | |
81 // variable or an already compiled function with the same name. | |
82 // | |
83 // * If the identifier is still undefined, try looking for an | |
84 // function file to parse. | |
85 // | |
86 // * On systems that support dynamic linking, we prefer .oct files, | |
87 // then .mex files, then .m files. | |
2971 | 88 |
89 octave_value | |
7336 | 90 do_lookup (tree_argument_list *args, const string_vector& arg_names, |
91 octave_value_list& evaluated_args, bool& args_evaluated) | |
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 | 96 } |
2887 | 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 | 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 | 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 | 103 |
3010 | 104 // We really need to know whether this symbol referst to a variable |
105 // or a function, but we may not know that yet. | |
106 | |
3933 | 107 bool lvalue_ok (void) const { return true; } |
3010 | 108 |
2971 | 109 octave_value rvalue (void); |
2887 | 110 |
2971 | 111 octave_value_list rvalue (int nargout); |
2887 | 112 |
2979 | 113 octave_lvalue lvalue (void); |
2887 | 114 |
115 void eval_undefined_error (void); | |
116 | |
7336 | 117 tree_identifier *dup (symbol_table::scope_id scope); |
5861 | 118 |
2887 | 119 void accept (tree_walker& tw); |
120 | |
121 private: | |
122 | |
123 // The symbol record that this identifier references. | |
7336 | 124 symbol_table::symbol_record sym; |
2988 | 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 | 144 // No copying! |
145 | |
146 tree_identifier (const tree_identifier&); | |
147 | |
148 tree_identifier& operator = (const tree_identifier&); | |
2887 | 149 }; |
150 | |
151 #endif | |
152 | |
153 /* | |
154 ;;; Local Variables: *** | |
155 ;;; mode: C++ *** | |
156 ;;; End: *** | |
157 */ |