Mercurial > octave
annotate libinterp/parse-tree/token.cc @ 26376:00f796120a6d stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 02 Jan 2019 16:32:43 -0500 |
parents | 6652d3823428 |
children | ea624b1c5571 |
rev | line source |
---|---|
142 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
3 Copyright (C) 1993-2019 John W. Eaton |
142 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
142 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
142 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
142 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
142 | 25 #endif |
26 | |
1343 | 27 #include <cassert> |
142 | 28 |
24362
3fc24b792a24
avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
29 #include "symrec.h" |
142 | 30 #include "token.h" |
31 | |
23372 | 32 namespace octave |
9476 | 33 { |
23372 | 34 token::token (int tv, int l, int c) |
35 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), | |
36 m_tok_val (tv), m_type_tag (generic_token), m_tok_info (), | |
37 m_orig_text () | |
38 { } | |
39 | |
40 token::token (int tv, bool is_kw, int l, int c) | |
41 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), | |
42 m_tok_val (tv), m_type_tag (is_kw ? keyword_token : generic_token), | |
43 m_tok_info (), m_orig_text () | |
44 { } | |
9476 | 45 |
23372 | 46 token::token (int tv, const char *s, int l, int c) |
47 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), | |
48 m_tok_val (tv), m_type_tag (string_token), m_tok_info (s), | |
49 m_orig_text () | |
50 { } | |
51 | |
52 token::token (int tv, const std::string& s, int l, int c) | |
53 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), | |
54 m_tok_val (tv), m_type_tag (string_token), m_tok_info (s), | |
55 m_orig_text () | |
56 { } | |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
57 |
23372 | 58 token::token (int tv, double d, const std::string& s, int l, int c) |
59 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), | |
60 m_tok_val (tv), m_type_tag (double_token), m_tok_info (d), | |
61 m_orig_text (s) | |
62 { } | |
63 | |
64 token::token (int tv, end_tok_type t, int l, int c) | |
65 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), | |
66 m_tok_val (tv), m_type_tag (ettype_token), m_tok_info (t), | |
67 m_orig_text () | |
68 { } | |
142 | 69 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
23656
diff
changeset
|
70 token::token (int tv, const symbol_record& sr, int l, int c) |
23372 | 71 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), |
72 m_tok_val (tv), m_type_tag (sym_rec_token), m_tok_info (sr), | |
73 m_orig_text () | |
74 { } | |
142 | 75 |
23372 | 76 token::token (int tv, const std::string& method_nm, |
77 const std::string& class_nm, int l, int c) | |
78 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c), | |
79 m_tok_val (tv), m_type_tag (scls_name_token), | |
80 m_tok_info (method_nm, class_nm), m_orig_text () | |
81 { } | |
82 | |
83 token::~token (void) | |
84 { | |
85 if (m_type_tag == string_token) | |
86 delete m_tok_info.m_str; | |
87 | |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23372
diff
changeset
|
88 if (m_type_tag == sym_rec_token) |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23372
diff
changeset
|
89 delete m_tok_info.m_sr; |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23372
diff
changeset
|
90 |
23372 | 91 if (m_type_tag == scls_name_token) |
92 delete m_tok_info.m_superclass_info; | |
93 } | |
16360
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16267
diff
changeset
|
94 |
23372 | 95 std::string |
96 token::text (void) const | |
97 { | |
98 assert (m_type_tag == string_token); | |
99 return *m_tok_info.m_str; | |
100 } | |
142 | 101 |
23372 | 102 std::string |
103 token::symbol_name (void) const | |
104 { | |
105 assert (m_type_tag == sym_rec_token); | |
106 return m_tok_info.m_sr->name (); | |
107 } | |
16267
15f55df088e7
6/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16257
diff
changeset
|
108 |
23372 | 109 double |
110 token::number (void) const | |
111 { | |
112 assert (m_type_tag == double_token); | |
113 return m_tok_info.m_num; | |
114 } | |
115 | |
116 token::token_type | |
117 token::ttype (void) const | |
118 { | |
119 return m_type_tag; | |
120 } | |
142 | 121 |
23372 | 122 token::end_tok_type |
123 token::ettype (void) const | |
124 { | |
125 assert (m_type_tag == ettype_token); | |
126 return m_tok_info.m_et; | |
127 } | |
128 | |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
23656
diff
changeset
|
129 symbol_record |
23372 | 130 token::sym_rec (void) const |
131 { | |
132 assert (m_type_tag == sym_rec_token); | |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23372
diff
changeset
|
133 return *m_tok_info.m_sr; |
23372 | 134 } |
142 | 135 |
23372 | 136 std::string |
137 token::superclass_method_name (void) const | |
138 { | |
139 assert (m_type_tag == scls_name_token); | |
140 return m_tok_info.m_superclass_info->m_method_nm; | |
141 } | |
142 | |
143 std::string | |
144 token::superclass_class_name (void) const | |
145 { | |
146 assert (m_type_tag == scls_name_token); | |
147 return m_tok_info.m_superclass_info->m_class_nm; | |
148 } | |
149 | |
150 std::string | |
151 token::text_rep (void) const | |
152 { | |
153 return m_orig_text; | |
154 } | |
9476 | 155 } |