142
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
9476
|
4 2007, 2009 John W. Eaton |
142
|
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. |
142
|
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/>. |
142
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
142
|
26 #endif |
|
27 |
1343
|
28 #include <cassert> |
142
|
29 |
1288
|
30 #include "error.h" |
4055
|
31 #include "oct-obj.h" |
1352
|
32 #include "symtab.h" |
142
|
33 #include "token.h" |
|
34 #include "utils.h" |
|
35 |
529
|
36 token::token (int l, int c) |
142
|
37 { |
|
38 line_num = l; |
|
39 column_num = c; |
|
40 type_tag = generic_token; |
|
41 } |
|
42 |
3523
|
43 token::token (const std::string& s, int l, int c) |
142
|
44 { |
|
45 line_num = l; |
|
46 column_num = c; |
|
47 type_tag = string_token; |
3523
|
48 str = new std::string (s); |
142
|
49 } |
|
50 |
3523
|
51 token::token (double d, const std::string& s, int l, int c) |
142
|
52 { |
|
53 line_num = l; |
|
54 column_num = c; |
|
55 type_tag = double_token; |
|
56 num = d; |
1971
|
57 orig_text = s; |
142
|
58 } |
|
59 |
529
|
60 token::token (end_tok_type t, int l, int c) |
142
|
61 { |
|
62 line_num = l; |
|
63 column_num = c; |
|
64 type_tag = ettype_token; |
|
65 et = t; |
|
66 } |
|
67 |
529
|
68 token::token (plot_tok_type t, int l, int c) |
142
|
69 { |
|
70 line_num = l; |
|
71 column_num = c; |
|
72 type_tag = pttype_token; |
|
73 pt = t; |
|
74 } |
|
75 |
7336
|
76 token::token (symbol_table::symbol_record *s, int l, int c) |
142
|
77 { |
|
78 line_num = l; |
|
79 column_num = c; |
|
80 type_tag = sym_rec_token; |
|
81 sr = s; |
|
82 } |
|
83 |
9476
|
84 token::token (symbol_table::symbol_record *cls, |
|
85 symbol_table::symbol_record *pkg, int l, int c) |
|
86 { |
|
87 line_num = l; |
|
88 column_num = c; |
|
89 type_tag = meta_rec_token; |
|
90 mc.cr = cls; |
|
91 mc.pr = pkg; |
|
92 } |
|
93 |
|
94 token::token (symbol_table::symbol_record *mth, |
|
95 symbol_table::symbol_record *cls, |
|
96 symbol_table::symbol_record *pkg, int l, int c) |
|
97 { |
|
98 line_num = l; |
|
99 column_num = c; |
|
100 type_tag = scls_rec_token; |
|
101 sc.mr = mth; |
|
102 sc.cr = cls; |
|
103 sc.pr = pkg; |
|
104 } |
|
105 |
142
|
106 token::~token (void) |
|
107 { |
|
108 if (type_tag == string_token) |
1755
|
109 delete str; |
142
|
110 } |
|
111 |
3536
|
112 std::string |
1755
|
113 token::text (void) |
142
|
114 { |
|
115 assert (type_tag == string_token); |
1755
|
116 return *str; |
142
|
117 } |
|
118 |
|
119 double |
|
120 token::number (void) |
|
121 { |
|
122 assert (type_tag == double_token); |
|
123 return num; |
|
124 } |
|
125 |
|
126 token::end_tok_type |
|
127 token::ettype (void) |
|
128 { |
|
129 assert (type_tag == ettype_token); |
|
130 return et; |
|
131 } |
|
132 |
|
133 token::plot_tok_type |
|
134 token::pttype (void) |
|
135 { |
|
136 assert (type_tag == pttype_token); |
|
137 return pt; |
|
138 } |
|
139 |
7336
|
140 symbol_table::symbol_record * |
142
|
141 token::sym_rec (void) |
|
142 { |
|
143 assert (type_tag == sym_rec_token); |
|
144 return sr; |
|
145 } |
|
146 |
9476
|
147 symbol_table::symbol_record * |
|
148 token::method_rec (void) |
|
149 { |
|
150 assert (type_tag == scls_rec_token); |
|
151 return sc.mr; |
|
152 } |
|
153 |
|
154 symbol_table::symbol_record * |
|
155 token::class_rec (void) |
|
156 { |
|
157 assert (type_tag == scls_rec_token); |
|
158 return sc.cr; |
|
159 } |
|
160 |
|
161 symbol_table::symbol_record * |
|
162 token::package_rec (void) |
|
163 { |
|
164 assert (type_tag == scls_rec_token); |
|
165 return sc.pr; |
|
166 } |
|
167 |
|
168 symbol_table::symbol_record * |
|
169 token::meta_class_rec (void) |
|
170 { |
|
171 assert (type_tag == meta_rec_token); |
|
172 return mc.cr; |
|
173 } |
|
174 |
|
175 symbol_table::symbol_record * |
|
176 token::meta_package_rec (void) |
|
177 { |
|
178 assert (type_tag == meta_rec_token); |
|
179 return mc.pr; |
|
180 } |
|
181 |
3536
|
182 std::string |
581
|
183 token::text_rep (void) |
|
184 { |
|
185 return orig_text; |
|
186 } |