GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
token.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <cassert>
31
32#include "token.h"
33
34namespace octave
35{
36 token::token (int tv, const filepos& beg_pos, const filepos& end_pos)
37 : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
38 m_end_pos (end_pos), m_tok_val (tv), m_type_tag (generic_token),
39 m_tok_info (), m_orig_text ()
40 { }
41
42 token::token (int tv, bool is_kw, const filepos& beg_pos,
43 const filepos& end_pos)
44 : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
45 m_end_pos (end_pos), m_tok_val (tv),
46 m_type_tag (is_kw ? keyword_token : generic_token), m_tok_info (),
47 m_orig_text ()
48 { }
49
50 token::token (int tv, const char *s, const filepos& beg_pos,
51 const filepos& end_pos)
52 : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
53 m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token),
54 m_tok_info (s), m_orig_text ()
55 { }
56
57 token::token (int tv, const std::string& s, const filepos& beg_pos,
58 const filepos& end_pos)
59 : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
60 m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token),
61 m_tok_info (s), m_orig_text ()
62 { }
63
64 token::token (int tv, const octave_value& val, const std::string& s,
65 const filepos& beg_pos, const filepos& end_pos)
66 : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
67 m_end_pos (end_pos), m_tok_val (tv), m_type_tag (numeric_token),
68 m_tok_info (val), m_orig_text (s)
69 { }
70
71 token::token (int tv, end_tok_type t, const filepos& beg_pos,
72 const filepos& end_pos)
73 : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
74 m_end_pos (end_pos), m_tok_val (tv), m_type_tag (ettype_token),
75 m_tok_info (t), m_orig_text ()
76 { }
77
78 token::token (int tv, const std::string& meth, const std::string& cls,
79 const filepos& beg_pos, const filepos& end_pos)
80 : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
81 m_end_pos (end_pos), m_tok_val (tv), m_type_tag (scls_name_token),
82 m_tok_info (meth, cls), m_orig_text ()
83 { }
84
86 {
88 delete m_tok_info.m_str;
89 else if (m_type_tag == numeric_token)
90 delete m_tok_info.m_num;
91 else if (m_type_tag == scls_name_token)
93 }
94
95 std::string
96 token::text (void) const
97 {
98 assert (m_type_tag == string_token);
99 return *m_tok_info.m_str;
100 }
101
103 token::number (void) const
104 {
105 assert (m_type_tag == numeric_token);
106 return *m_tok_info.m_num;
107 }
108
110 token::ttype (void) const
111 {
112 return m_type_tag;
113 }
114
116 token::ettype (void) const
117 {
118 assert (m_type_tag == ettype_token);
119 return m_tok_info.m_et;
120 }
121
122 std::string
124 {
125 assert (m_type_tag == scls_name_token);
127 }
128
129 std::string
131 {
132 assert (m_type_tag == scls_name_token);
134 }
135
136 std::string
137 token::text_rep (void) const
138 {
139 return m_orig_text;
140 }
141}
std::string superclass_class_name(void) const
Definition: token.cc:130
end_tok_type ettype(void) const
Definition: token.cc:116
token_type ttype(void) const
Definition: token.cc:110
tok_info m_tok_info
Definition: token.h:206
token(int tv, const filepos &beg_pos, const filepos &end_pos)
Definition: token.cc:36
std::string superclass_method_name(void) const
Definition: token.cc:123
octave_value number(void) const
Definition: token.cc:103
token_type m_type_tag
Definition: token.h:147
std::string text(void) const
Definition: token.cc:96
~token(void)
Definition: token.cc:85
@ ettype_token
Definition: token.h:48
@ numeric_token
Definition: token.h:47
@ string_token
Definition: token.h:46
@ scls_name_token
Definition: token.h:49
std::string m_orig_text
Definition: token.h:208
std::string text_rep(void) const
Definition: token.cc:137
std::string * m_str
Definition: token.h:171
end_tok_type m_et
Definition: token.h:175
octave_value * m_num
Definition: token.h:173
superclass_info * m_superclass_info
Definition: token.h:203