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 |
2980
|
36 #include "pt-exp.h" |
7336
|
37 #include "symtab.h" |
2887
|
38 |
|
39 // Symbols from the symbol table. |
|
40 |
|
41 class |
2971
|
42 tree_identifier : public tree_expression |
2887
|
43 { |
|
44 friend class tree_index_expression; |
|
45 |
|
46 public: |
|
47 |
|
48 tree_identifier (int l = -1, int c = -1) |
7336
|
49 : tree_expression (l, c), sym () { } |
2887
|
50 |
7336
|
51 tree_identifier (const symbol_table::symbol_record& s, int l = -1, int c = -1) |
2971
|
52 : tree_expression (l, c), sym (s) { } |
2887
|
53 |
|
54 ~tree_identifier (void) { } |
|
55 |
4267
|
56 bool has_magic_end (void) const { return (name () == "__end__"); } |
|
57 |
3933
|
58 bool is_identifier (void) const { return true; } |
2887
|
59 |
7336
|
60 std::string name (void) const { return sym.name (); } |
2887
|
61 |
7336
|
62 bool is_defined (void) { return sym.is_defined (); } |
|
63 |
|
64 bool is_variable (void) { return sym.is_variable (); } |
2887
|
65 |
7336
|
66 // Try to find a definition for an identifier. Here's how: |
|
67 // |
|
68 // * If the identifier is already defined and is a function defined |
|
69 // in an function file that has been modified since the last time |
|
70 // we parsed it, parse it again. |
|
71 // |
|
72 // * If the identifier is not defined, try to find a builtin |
|
73 // variable or an already compiled function with the same name. |
|
74 // |
|
75 // * If the identifier is still undefined, try looking for an |
|
76 // function file to parse. |
|
77 // |
|
78 // * On systems that support dynamic linking, we prefer .oct files, |
|
79 // then .mex files, then .m files. |
2971
|
80 |
|
81 octave_value |
7336
|
82 do_lookup (bool& script_file_executed, bool exec_script = true) |
|
83 { |
|
84 // FIXME -- SYMTAB: what about executing script files? |
|
85 octave_value_list evaluated_args; |
|
86 bool args_evaluated; |
|
87 return sym.find (0, string_vector (), evaluated_args, args_evaluated); |
|
88 } |
2887
|
89 |
7336
|
90 octave_value |
|
91 do_lookup (tree_argument_list *args, const string_vector& arg_names, |
|
92 octave_value_list& evaluated_args, bool& args_evaluated) |
|
93 { |
|
94 return sym.find (args, arg_names, evaluated_args, args_evaluated); |
|
95 } |
2887
|
96 |
7336
|
97 void mark_global (void) { sym.mark_global (); } |
|
98 |
|
99 void mark_as_static (void) { sym.init_persistent (); } |
|
100 |
|
101 void mark_as_formal_parameter (void) { sym.mark_formal (); } |
2887
|
102 |
3010
|
103 // We really need to know whether this symbol referst to a variable |
|
104 // or a function, but we may not know that yet. |
|
105 |
3933
|
106 bool lvalue_ok (void) const { return true; } |
3010
|
107 |
2971
|
108 octave_value rvalue (void); |
2887
|
109 |
2971
|
110 octave_value_list rvalue (int nargout); |
2887
|
111 |
2979
|
112 octave_lvalue lvalue (void); |
2887
|
113 |
|
114 void eval_undefined_error (void); |
|
115 |
7336
|
116 tree_identifier *dup (symbol_table::scope_id scope); |
5861
|
117 |
2887
|
118 void accept (tree_walker& tw); |
|
119 |
|
120 private: |
|
121 |
|
122 // The symbol record that this identifier references. |
7336
|
123 symbol_table::symbol_record sym; |
2988
|
124 |
|
125 // No copying! |
|
126 |
|
127 tree_identifier (const tree_identifier&); |
|
128 |
|
129 tree_identifier& operator = (const tree_identifier&); |
2887
|
130 }; |
|
131 |
|
132 #endif |
|
133 |
|
134 /* |
|
135 ;;; Local Variables: *** |
|
136 ;;; mode: C++ *** |
|
137 ;;; End: *** |
|
138 */ |