annotate src/symtab.h @ 3258:4964d5391acc

[project @ 1999-07-21 21:51:33 by jwe]
author jwe
date Wed, 21 Jul 1999 21:52:04 +0000
parents d54ef0aa6e82
children 2efa28a91e7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
1 /*
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
2
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2846
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
4
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
6
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
10 later version.
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
11
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
15 for more details.
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
16
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1297
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
20
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
21 */
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
22
383
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 276
diff changeset
23 #if !defined (octave_symtab_h)
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 276
diff changeset
24 #define octave_symtab_h 1
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
25
1297
12ecc2ecf0e3 [project @ 1995-05-01 18:39:43 by jwe]
jwe
parents: 1009
diff changeset
26 #if defined (__GNUG__)
12ecc2ecf0e3 [project @ 1995-05-01 18:39:43 by jwe]
jwe
parents: 1009
diff changeset
27 #pragma interface
12ecc2ecf0e3 [project @ 1995-05-01 18:39:43 by jwe]
jwe
parents: 1009
diff changeset
28 #endif
12ecc2ecf0e3 [project @ 1995-05-01 18:39:43 by jwe]
jwe
parents: 1009
diff changeset
29
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
30 #include <cassert>
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
31
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
32 #include <string>
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
33
220
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
34 #include "SLStack.h"
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
35
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
36 #include "oct-alloc.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
37 #include "str-vec.h"
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
38
2975
b9c107cbe388 [project @ 1997-05-15 20:01:00 by jwe]
jwe
parents: 2956
diff changeset
39 #include "ov.h"
b9c107cbe388 [project @ 1997-05-15 20:01:00 by jwe]
jwe
parents: 2956
diff changeset
40
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents: 2975
diff changeset
41 class octave_lvalue;
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
42
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
43 class string_vector;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
44
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
45 class symbol_record;
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
46 class symbol_table;
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
47
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
48 // Individual records in a symbol table.
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
49
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
50 class
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
51 symbol_record
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
52 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
53 public:
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
54
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
55 // If you add or delete an entry here, you'll also need to change
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
56 // the with parameter in the declaration for symbol_type below...
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
57
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
58 enum TYPE
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
59 {
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
60 UNKNOWN = 0,
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
61 USER_FUNCTION = 1,
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
62 USER_VARIABLE = 2,
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
63 BUILTIN_FUNCTION = 4,
530
c3268005bf98 [project @ 1994-07-20 19:26:33 by jwe]
jwe
parents: 497
diff changeset
64 TEXT_FUNCTION = 8,
c3268005bf98 [project @ 1994-07-20 19:26:33 by jwe]
jwe
parents: 497
diff changeset
65 MAPPER_FUNCTION = 16,
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
66 BUILTIN_VARIABLE = 32,
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
67 BUILTIN_CONSTANT = 64
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
68 };
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
69
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
70 private:
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
71
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
72 // Variables or functions.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
73
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
74 class symbol_def
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
75 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
76 public:
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
77
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
78 symbol_def (const octave_value& val = octave_value (),
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
79 unsigned int sym_type = 0)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
80 : symbol_type (sym_type), eternal (0), read_only (0), help_string (),
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
81 definition (val), next_elem (0), count (1) { }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
82
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
83 ~symbol_def (void) { }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
84
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
85 bool is_constant (void) const
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
86 { return (symbol_type & symbol_record::BUILTIN_CONSTANT); }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
87
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
88 bool is_variable (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
89 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
90 return (symbol_type & symbol_record::USER_VARIABLE
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
91 || symbol_type & symbol_record::BUILTIN_VARIABLE);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
92 }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
93
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
94 bool is_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
95 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
96 return (symbol_type & symbol_record::USER_FUNCTION
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
97 || symbol_type & symbol_record::BUILTIN_FUNCTION);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
98 }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
99
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
100 bool is_user_variable (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
101 { return (symbol_type & symbol_record::USER_VARIABLE); }
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
102
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
103 bool is_text_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
104 { return (symbol_type & symbol_record::TEXT_FUNCTION); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
105
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
106 bool is_mapper_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
107 { return (symbol_type & symbol_record::MAPPER_FUNCTION); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
108
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
109 bool is_user_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
110 { return (symbol_type & symbol_record::USER_FUNCTION); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
111
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
112 bool is_builtin_constant (void) const
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
113 { return (symbol_type & symbol_record::BUILTIN_CONSTANT); }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
114
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
115 bool is_builtin_variable (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
116 { return (symbol_type & symbol_record::BUILTIN_VARIABLE); }
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
117
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
118 bool is_builtin_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
119 { return (symbol_type & symbol_record::BUILTIN_FUNCTION); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
120
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
121 // XXX FIXME XXX
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
122 bool is_map_element (const string& /* elts */) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
123 { return false; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
124
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
125 bool is_defined (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
126 { return definition.is_defined (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
127
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
128 bool is_read_only (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
129 { return read_only; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
130
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
131 bool is_eternal (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
132 { return eternal; }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
133
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
134 int rows (void) const { return definition.rows (); }
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
135 int columns (void) const { return definition.columns (); }
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
136
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
137 string type_name (void) const { return definition.type_name (); }
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
138
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
139 void define (const octave_value& val, unsigned int sym_type)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
140 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
141 definition = val;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
142 symbol_type = sym_type;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
143 }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
144
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
145 void protect (void) { read_only = 1; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
146
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
147 void unprotect (void) { read_only = 0; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
148
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
149 void make_eternal (void) { eternal = 1; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
150
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
151 octave_value& def (void) { return definition; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
152
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
153 string help (void) const { return help_string; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
154
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
155 void document (const string& h) { help_string = h; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
156
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
157 unsigned int type (void) { return symbol_type; }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
158
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
159 void *operator new (size_t size)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
160 { return allocator.alloc (size); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
161
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
162 void operator delete (void *p, size_t size)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
163 { allocator.free (p, size); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
164
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
165 static octave_allocator allocator;
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
166
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
167 // The type of this symbol (see the enum above).
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
168 unsigned int symbol_type : 7;
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
169
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
170 // Nonzero means this variable cannot be cleared.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
171 unsigned int eternal : 1;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
172
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
173 // Nonzero means this variable cannot be given a new value.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
174 unsigned int read_only : 1;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
175
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
176 // The doc string associated with this variable.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
177 string help_string;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
178
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
179 // The value of this definition. See ov.h and related files.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
180 octave_value definition;
767
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 605
diff changeset
181
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
182 // Pointer to next definition in chain. This is used so that
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
183 // variables can hide function definitions, and so that the function
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
184 // definitions can reappear if the variable is cleared.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
185 symbol_def *next_elem;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
186
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
187 // Reference count.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
188 int count;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
189
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3013
diff changeset
190 void dump_symbol_info (void);
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3013
diff changeset
191
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
192 // No copying!
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
193
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
194 symbol_def (const symbol_def& sd);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
195
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
196 symbol_def& operator = (const symbol_def& sd);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
197 };
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
198
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
199 public:
2953
ca7d3625ee01 [project @ 1997-05-09 14:56:52 by jwe]
jwe
parents: 2948
diff changeset
200
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
201 typedef int (*change_function) (void);
2953
ca7d3625ee01 [project @ 1997-05-09 14:56:52 by jwe]
jwe
parents: 2948
diff changeset
202
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
203 symbol_record (void)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
204 : formal_param (0), linked_to_global (0), tagged_static (0),
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
205 nm (), chg_fcn (0), definition (new symbol_def ()),
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
206 next_elem (0) { }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
207
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
208 symbol_record (const string& n, symbol_record *nxt)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
209 : formal_param (0), linked_to_global (0), tagged_static (0),
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
210 nm (n), chg_fcn (0), definition (new symbol_def ()),
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
211 next_elem (nxt) { }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
212
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
213 ~symbol_record (void) { }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
214
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
215 string name (void) const { return nm; }
2975
b9c107cbe388 [project @ 1997-05-15 20:01:00 by jwe]
jwe
parents: 2956
diff changeset
216
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
217 string help (void) const { return definition->help (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
218
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
219 octave_value& def (void) { return definition->def (); }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
220
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
221 void rename (const string& new_name);
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
222
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
223 bool is_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
224 { return definition->is_function (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
225
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
226 bool is_text_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
227 { return definition->is_text_function (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
228
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
229 bool is_mapper_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
230 { return definition->is_mapper_function (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
231
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
232 bool is_user_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
233 { return definition->is_user_function (); }
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
234
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
235 bool is_builtin_function (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
236 { return definition->is_builtin_function (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
237
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
238 bool is_constant (void) const
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
239 { return definition->is_constant (); }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
240
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
241 bool is_builtin_constant (void) const
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
242 { return definition->is_builtin_constant (); }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
243
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
244 bool is_variable (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
245 { return definition->is_variable (); }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
246
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
247 bool is_user_variable (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
248 { return definition->is_user_variable (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
249
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
250 bool is_builtin_variable (void) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
251 { return definition->is_builtin_variable (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
252
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
253 bool is_map_element (const string& elts) const
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
254 { return definition->is_map_element (elts); }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
255
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
256 unsigned int type (void) const { return definition->type (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
257
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
258 bool is_defined (void) const { return definition->is_defined (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
259
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
260 bool is_read_only (void) const { return definition->is_read_only (); }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
261
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
262 bool is_eternal (void) const { return definition->is_eternal (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
263
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
264 void protect (void) { definition->protect (); }
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
265
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
266 void unprotect (void) { definition->unprotect (); }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
267
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
268 void make_eternal (void) { definition->make_eternal (); }
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
269
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
270 void set_change_function (change_function f) { chg_fcn = f; }
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
271
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
272 void define (const octave_value& v, unsigned int sym_type = USER_VARIABLE);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
273
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
274 void define_builtin_var (const octave_value& v);
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
275
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
276 bool define_builtin_const (const octave_value& v);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
277
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
278 bool define (octave_function *f, unsigned int sym_type);
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
279
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
280 void document (const string& h) { definition->document (h); }
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
281
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
282 void clear (void);
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
283
2856
8c516da3c1f7 [project @ 1997-03-31 06:37:21 by jwe]
jwe
parents: 2847
diff changeset
284 void alias (symbol_record *s, bool force = false);
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
285
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
286 void mark_as_formal_parameter (void);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
287 bool is_formal_parameter (void) const { return formal_param; }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
288
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
289 void mark_as_linked_to_global (void);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
290 bool is_linked_to_global (void) const { return linked_to_global; }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
291
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2791
diff changeset
292 void mark_as_static (void);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
293 bool is_static (void) const { return tagged_static; }
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2791
diff changeset
294
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
295 bool hides_fcn (void) const;
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
296 bool hides_builtin (void) const;
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
297
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
298 int rows (void) const { return definition->rows (); }
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
299 int columns (void) const { return definition->columns (); }
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
300
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
301 string type_name (void) const { return definition->type_name (); }
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
302
2975
b9c107cbe388 [project @ 1997-05-15 20:01:00 by jwe]
jwe
parents: 2956
diff changeset
303 octave_value& variable_value (void);
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents: 2975
diff changeset
304 octave_lvalue variable_reference (void);
2390
c2c1482c34c8 [project @ 1996-10-12 19:13:23 by jwe]
jwe
parents: 2086
diff changeset
305
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
306 symbol_record *next (void) const { return next_elem; }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
307
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
308 void chain (symbol_record *s) { next_elem = s; }
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
309
220
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
310 void push_context (void);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
311
220
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
312 void pop_context (void);
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
313
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
314 void print_symbol_info_line (ostream& os);
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
315
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3013
diff changeset
316 void dump_symbol_info (void);
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3013
diff changeset
317
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
318 private:
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
319
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
320 unsigned int formal_param : 1;
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
321 unsigned int linked_to_global : 1;
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
322 unsigned int tagged_static : 1;
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
323
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
324 string nm;
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
325 change_function chg_fcn;
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
326 symbol_def *definition;
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
327 symbol_record *next_elem;
395
ee3da0884aaa [project @ 1994-03-24 09:23:18 by jwe]
jwe
parents: 383
diff changeset
328
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
329 // This should maybe be one stack with a structure containing all the
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
330 // items we need to save for recursive calls...
220
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
331 SLStack <symbol_def *> context;
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
332 SLStack <unsigned int> global_link_context;
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
333
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
334 bool read_only_error (const char *action);
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
335
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
336 void push_def (symbol_def *sd);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
337
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
338 void remove_top_def (void);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
339
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
340 void replace_all_defs (symbol_def *sd);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
341
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
342 void link_to_builtin_variable (void);
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
343
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
344 // No copying!
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
345
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
346 symbol_record (const symbol_record& s);
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
347
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
348 symbol_record& operator = (const symbol_record& s);
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
349 };
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
350
767
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 605
diff changeset
351 // A symbol table.
200
2e4d2596f2c3 [project @ 1993-11-08 20:22:15 by jwe]
jwe
parents: 195
diff changeset
352
2e4d2596f2c3 [project @ 1993-11-08 20:22:15 by jwe]
jwe
parents: 195
diff changeset
353 #define SYMTAB_LOCAL_SCOPE 1
2e4d2596f2c3 [project @ 1993-11-08 20:22:15 by jwe]
jwe
parents: 195
diff changeset
354 #define SYMTAB_GLOBAL_SCOPE 2
2e4d2596f2c3 [project @ 1993-11-08 20:22:15 by jwe]
jwe
parents: 195
diff changeset
355
2e4d2596f2c3 [project @ 1993-11-08 20:22:15 by jwe]
jwe
parents: 195
diff changeset
356 #define SYMTAB_ALL_SCOPES (SYMTAB_LOCAL_SCOPE | SYMTAB_GLOBAL_SCOPE)
2e4d2596f2c3 [project @ 1993-11-08 20:22:15 by jwe]
jwe
parents: 195
diff changeset
357
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
358 #define SYMTAB_ALL_TYPES (symbol_record::USER_FUNCTION \
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
359 | symbol_record::USER_VARIABLE \
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
360 | symbol_record::BUILTIN_FUNCTION \
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
361 | symbol_record::TEXT_FUNCTION \
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
362 | symbol_record::MAPPER_FUNCTION \
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
363 | symbol_record::BUILTIN_VARIABLE \
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3239
diff changeset
364 | symbol_record::BUILTIN_CONSTANT)
200
2e4d2596f2c3 [project @ 1993-11-08 20:22:15 by jwe]
jwe
parents: 195
diff changeset
365
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
366 #define SYMTAB_VARIABLES (symbol_record::USER_VARIABLE \
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
367 | symbol_record::BUILTIN_VARIABLE)
1412
5db963ba9614 [project @ 1995-09-15 08:47:17 by jwe]
jwe
parents: 1315
diff changeset
368
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
369 class
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
370 symbol_table
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
371 {
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
372 public:
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
373
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
374 symbol_table (unsigned int tab_size = 128)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
375 : table_size (tab_size), table (new symbol_record [table_size])
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
376 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
377 assert ((tab_size % 2) == 0);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
378 }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
379
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
380 ~symbol_table (void)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
381 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
382 delete [] table;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
383 }
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
384
2856
8c516da3c1f7 [project @ 1997-03-31 06:37:21 by jwe]
jwe
parents: 2847
diff changeset
385 symbol_record *lookup (const string& nm, bool insert = false,
8c516da3c1f7 [project @ 1997-03-31 06:37:21 by jwe]
jwe
parents: 2847
diff changeset
386 bool warn = false);
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
387
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
388 void rename (const string& old_name, const string& new_name);
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 541
diff changeset
389
2856
8c516da3c1f7 [project @ 1997-03-31 06:37:21 by jwe]
jwe
parents: 2847
diff changeset
390 void clear (bool clear_user_functions = true);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
391 bool clear (const string& nm, bool clear_user_functions = true);
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
392
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 121
diff changeset
393 int size (void) const;
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
394
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
395 Array<symbol_record *>
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
396 symbol_list (int& count, const string_vector& pats = string_vector (),
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
397 unsigned int type = SYMTAB_ALL_TYPES,
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
398 unsigned int scope = SYMTAB_ALL_SCOPES) const;
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
399
195
13c6086c325c [project @ 1993-11-06 10:12:29 by jwe]
jwe
parents: 186
diff changeset
400
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
401 string_vector
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
402 name_list (int& count, const string_vector& pats = string_vector (),
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
403 bool sort = false, unsigned int type = SYMTAB_ALL_TYPES,
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
404 unsigned int scope = SYMTAB_ALL_SCOPES) const;
605
4f65175911a6 [project @ 1994-08-13 20:10:39 by jwe]
jwe
parents: 572
diff changeset
405
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
406
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
407 int maybe_list (const char *header, const string_vector& argv,
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 3011
diff changeset
408 ostream& os, bool show_verbose,
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
409 unsigned type, unsigned scope);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
410
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
411 symbol_record **glob (int& count, const string& pat = string ("*"),
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
412 unsigned int type = SYMTAB_ALL_TYPES,
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2856
diff changeset
413 unsigned int scope = SYMTAB_ALL_SCOPES) const;
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
414
220
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
415 void push_context (void);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
416
220
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
417 void pop_context (void);
f736a3ec137e [project @ 1993-11-14 00:10:26 by jwe]
jwe
parents: 200
diff changeset
418
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
419 void print_stats (void);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
420
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
421 private:
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
422
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
423 unsigned int table_size;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
424
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
425 symbol_record *table;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
426
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1738
diff changeset
427 unsigned int hash (const string& s);
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
428
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
429 // No copying!
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
430
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
431 symbol_table (const symbol_table&);
1962
d329b8ea86e8 [project @ 1996-02-16 04:24:22 by jwe]
jwe
parents: 1884
diff changeset
432
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
433 symbol_table& operator = (const symbol_table&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents: 2979
diff changeset
434 };
2790
ecc1a12678de [project @ 1997-03-05 02:47:54 by jwe]
jwe
parents: 2404
diff changeset
435
8
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
436 #endif
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
437
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
438 /*
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
439 ;;; Local Variables: ***
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
440 ;;; mode: C++ ***
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
441 ;;; End: ***
bd072d0a95f9 [project @ 1993-08-08 03:55:11 by jwe]
jwe
parents:
diff changeset
442 */