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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
142
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
1 /*
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
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
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
4
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
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
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
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
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
16
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
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
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
20
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
21 */
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
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
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
25 #endif
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
26
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1315
diff changeset
27 #include <cassert>
142
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
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
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
30 #include "token.h"
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
31
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
32 namespace octave
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 7336
diff changeset
33 {
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
34 token::token (int tv, int l, int c)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
35 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
36 m_tok_val (tv), m_type_tag (generic_token), m_tok_info (),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
37 m_orig_text ()
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
38 { }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
39
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
40 token::token (int tv, bool is_kw, int l, int c)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
41 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
42 m_tok_val (tv), m_type_tag (is_kw ? keyword_token : generic_token),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
43 m_tok_info (), m_orig_text ()
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
44 { }
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 7336
diff changeset
45
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
46 token::token (int tv, const char *s, int l, int c)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
47 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
48 m_tok_val (tv), m_type_tag (string_token), m_tok_info (s),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
49 m_orig_text ()
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
50 { }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
51
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
52 token::token (int tv, const std::string& s, int l, int c)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
53 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
54 m_tok_val (tv), m_type_tag (string_token), m_tok_info (s),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
55 m_orig_text ()
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
56 { }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
57
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
58 token::token (int tv, double d, const std::string& s, int l, int c)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
59 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
60 m_tok_val (tv), m_type_tag (double_token), m_tok_info (d),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
61 m_orig_text (s)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
62 { }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
63
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
64 token::token (int tv, end_tok_type t, int l, int c)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
65 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
66 m_tok_val (tv), m_type_tag (ettype_token), m_tok_info (t),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
67 m_orig_text ()
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
68 { }
142
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
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
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
71 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
72 m_tok_val (tv), m_type_tag (sym_rec_token), m_tok_info (sr),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
73 m_orig_text ()
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
74 { }
142
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
75
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
76 token::token (int tv, const std::string& method_nm,
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
77 const std::string& class_nm, int l, int c)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
78 : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
79 m_tok_val (tv), m_type_tag (scls_name_token),
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
80 m_tok_info (method_nm, class_nm), m_orig_text ()
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
81 { }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
82
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
83 token::~token (void)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
84 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
85 if (m_type_tag == string_token)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
86 delete m_tok_info.m_str;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
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
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
91 if (m_type_tag == scls_name_token)
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
92 delete m_tok_info.m_superclass_info;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
93 }
16360
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
94
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
95 std::string
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
96 token::text (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
97 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
98 assert (m_type_tag == string_token);
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
99 return *m_tok_info.m_str;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
100 }
142
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
101
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
102 std::string
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
103 token::symbol_name (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
104 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
105 assert (m_type_tag == sym_rec_token);
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
106 return m_tok_info.m_sr->name ();
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
107 }
16267
15f55df088e7 6/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16257
diff changeset
108
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
109 double
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
110 token::number (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
111 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
112 assert (m_type_tag == double_token);
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
113 return m_tok_info.m_num;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
114 }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
115
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
116 token::token_type
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
117 token::ttype (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
118 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
119 return m_type_tag;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
120 }
142
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
121
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
122 token::end_tok_type
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
123 token::ettype (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
124 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
125 assert (m_type_tag == ettype_token);
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
126 return m_tok_info.m_et;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
127 }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
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
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
130 token::sym_rec (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
131 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
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
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
134 }
142
6906d6591452 [project @ 1993-10-04 00:40:57 by jwe]
jwe
parents:
diff changeset
135
23372
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
136 std::string
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
137 token::superclass_method_name (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
138 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
139 assert (m_type_tag == scls_name_token);
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
140 return m_tok_info.m_superclass_info->m_method_nm;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
141 }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
142
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
143 std::string
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
144 token::superclass_class_name (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
145 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
146 assert (m_type_tag == scls_name_token);
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
147 return m_tok_info.m_superclass_info->m_class_nm;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
148 }
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
149
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
150 std::string
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
151 token::text_rep (void) const
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
152 {
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
153 return m_orig_text;
8a23ed65ef21 modernize token sources
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
154 }
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 7336
diff changeset
155 }