Mercurial > octave
annotate libinterp/parse-tree/token.cc @ 26441:ea624b1c5571 stable
token.cc: Fix static analyzer detected issues (bug #55347).
* token.cc (~token): Use if/else if tree for mutually exclusive options.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 04 Jan 2019 21:21:59 -0800 |
parents | 00f796120a6d |
children | 581d01526b34 |
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; | |
26441
ea624b1c5571
token.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
87 else if (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
|
88 delete m_tok_info.m_sr; |
26441
ea624b1c5571
token.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
89 else if (m_type_tag == scls_name_token) |
23372 | 90 delete m_tok_info.m_superclass_info; |
91 } | |
16360
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16267
diff
changeset
|
92 |
23372 | 93 std::string |
94 token::text (void) const | |
95 { | |
96 assert (m_type_tag == string_token); | |
97 return *m_tok_info.m_str; | |
98 } | |
142 | 99 |
23372 | 100 std::string |
101 token::symbol_name (void) const | |
102 { | |
103 assert (m_type_tag == sym_rec_token); | |
104 return m_tok_info.m_sr->name (); | |
105 } | |
16267
15f55df088e7
6/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16257
diff
changeset
|
106 |
23372 | 107 double |
108 token::number (void) const | |
109 { | |
110 assert (m_type_tag == double_token); | |
111 return m_tok_info.m_num; | |
112 } | |
113 | |
114 token::token_type | |
115 token::ttype (void) const | |
116 { | |
117 return m_type_tag; | |
118 } | |
142 | 119 |
23372 | 120 token::end_tok_type |
121 token::ettype (void) const | |
122 { | |
123 assert (m_type_tag == ettype_token); | |
124 return m_tok_info.m_et; | |
125 } | |
126 | |
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
|
127 symbol_record |
23372 | 128 token::sym_rec (void) const |
129 { | |
130 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
|
131 return *m_tok_info.m_sr; |
23372 | 132 } |
142 | 133 |
23372 | 134 std::string |
135 token::superclass_method_name (void) const | |
136 { | |
137 assert (m_type_tag == scls_name_token); | |
138 return m_tok_info.m_superclass_info->m_method_nm; | |
139 } | |
140 | |
141 std::string | |
142 token::superclass_class_name (void) const | |
143 { | |
144 assert (m_type_tag == scls_name_token); | |
145 return m_tok_info.m_superclass_info->m_class_nm; | |
146 } | |
147 | |
148 std::string | |
149 token::text_rep (void) const | |
150 { | |
151 return m_orig_text; | |
152 } | |
9476 | 153 } |