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 |
7336
|
68 token::token (symbol_table::symbol_record *s, int l, int c) |
142
|
69 { |
|
70 line_num = l; |
|
71 column_num = c; |
|
72 type_tag = sym_rec_token; |
|
73 sr = s; |
|
74 } |
|
75 |
9476
|
76 token::token (symbol_table::symbol_record *cls, |
|
77 symbol_table::symbol_record *pkg, int l, int c) |
|
78 { |
|
79 line_num = l; |
|
80 column_num = c; |
|
81 type_tag = meta_rec_token; |
|
82 mc.cr = cls; |
|
83 mc.pr = pkg; |
|
84 } |
|
85 |
|
86 token::token (symbol_table::symbol_record *mth, |
|
87 symbol_table::symbol_record *cls, |
|
88 symbol_table::symbol_record *pkg, int l, int c) |
|
89 { |
|
90 line_num = l; |
|
91 column_num = c; |
|
92 type_tag = scls_rec_token; |
|
93 sc.mr = mth; |
|
94 sc.cr = cls; |
|
95 sc.pr = pkg; |
|
96 } |
|
97 |
142
|
98 token::~token (void) |
|
99 { |
|
100 if (type_tag == string_token) |
1755
|
101 delete str; |
142
|
102 } |
|
103 |
3536
|
104 std::string |
1755
|
105 token::text (void) |
142
|
106 { |
|
107 assert (type_tag == string_token); |
1755
|
108 return *str; |
142
|
109 } |
|
110 |
|
111 double |
|
112 token::number (void) |
|
113 { |
|
114 assert (type_tag == double_token); |
|
115 return num; |
|
116 } |
|
117 |
|
118 token::end_tok_type |
|
119 token::ettype (void) |
|
120 { |
|
121 assert (type_tag == ettype_token); |
|
122 return et; |
|
123 } |
|
124 |
7336
|
125 symbol_table::symbol_record * |
142
|
126 token::sym_rec (void) |
|
127 { |
|
128 assert (type_tag == sym_rec_token); |
|
129 return sr; |
|
130 } |
|
131 |
9476
|
132 symbol_table::symbol_record * |
|
133 token::method_rec (void) |
|
134 { |
|
135 assert (type_tag == scls_rec_token); |
|
136 return sc.mr; |
|
137 } |
|
138 |
|
139 symbol_table::symbol_record * |
|
140 token::class_rec (void) |
|
141 { |
|
142 assert (type_tag == scls_rec_token); |
|
143 return sc.cr; |
|
144 } |
|
145 |
|
146 symbol_table::symbol_record * |
|
147 token::package_rec (void) |
|
148 { |
|
149 assert (type_tag == scls_rec_token); |
|
150 return sc.pr; |
|
151 } |
|
152 |
|
153 symbol_table::symbol_record * |
|
154 token::meta_class_rec (void) |
|
155 { |
|
156 assert (type_tag == meta_rec_token); |
|
157 return mc.cr; |
|
158 } |
|
159 |
|
160 symbol_table::symbol_record * |
|
161 token::meta_package_rec (void) |
|
162 { |
|
163 assert (type_tag == meta_rec_token); |
|
164 return mc.pr; |
|
165 } |
|
166 |
3536
|
167 std::string |
581
|
168 token::text_rep (void) |
|
169 { |
|
170 return orig_text; |
|
171 } |