GNU Octave  8.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-2023 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 "error.h"
33 #include "token.h"
34 
36 
37 token::token (int tv, const filepos& beg_pos, const filepos& end_pos)
38  : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
39  m_end_pos (end_pos), m_tok_val (tv), m_type_tag (generic_token),
40  m_tok_info (), m_orig_text ()
41 { }
42 
43 token::token (int tv, bool is_kw, const filepos& beg_pos,
44  const filepos& end_pos)
45  : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
46  m_end_pos (end_pos), m_tok_val (tv),
47  m_type_tag (is_kw ? keyword_token : generic_token), m_tok_info (),
48  m_orig_text ()
49 { }
50 
51 token::token (int tv, const char *s, const filepos& beg_pos,
52  const filepos& end_pos)
53  : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
54  m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token),
55  m_tok_info (s), m_orig_text ()
56 { }
57 
58 token::token (int tv, const std::string& s, const filepos& beg_pos,
59  const filepos& end_pos)
60  : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
61  m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token),
62  m_tok_info (s), m_orig_text ()
63 { }
64 
65 token::token (int tv, const octave_value& val, const std::string& s,
66  const filepos& beg_pos, const filepos& end_pos)
67  : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
68  m_end_pos (end_pos), m_tok_val (tv), m_type_tag (numeric_token),
69  m_tok_info (val), m_orig_text (s)
70 { }
71 
72 token::token (int tv, end_tok_type t, const filepos& beg_pos,
73  const filepos& end_pos)
74  : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
75  m_end_pos (end_pos), m_tok_val (tv), m_type_tag (ettype_token),
76  m_tok_info (t), m_orig_text ()
77 { }
78 
79 token::token (int tv, const std::string& meth, const std::string& cls,
80  const filepos& beg_pos, const filepos& end_pos)
81  : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
82  m_end_pos (end_pos), m_tok_val (tv), m_type_tag (scls_name_token),
83  m_tok_info (meth, cls), m_orig_text ()
84 { }
85 
87 {
88  if (m_type_tag == string_token)
89  delete m_tok_info.m_str;
90  else if (m_type_tag == numeric_token)
91  delete m_tok_info.m_num;
92  else if (m_type_tag == scls_name_token)
94 }
95 
96 std::string
97 token::text (void) const
98 {
100  return *m_tok_info.m_str;
101 }
102 
104 token::number (void) const
105 {
107  return *m_tok_info.m_num;
108 }
109 
111 token::ttype (void) const
112 {
113  return m_type_tag;
114 }
115 
117 token::ettype (void) const
118 {
120  return m_tok_info.m_et;
121 }
122 
123 std::string
125 {
128 }
129 
130 std::string
132 {
135 }
136 
137 std::string
138 token::text_rep (void) const
139 {
140  return m_orig_text;
141 }
142 
OCTAVE_END_NAMESPACE(octave)
Definition: token.h:39
std::string text(void) const
Definition: token.cc:97
std::string text_rep(void) const
Definition: token.cc:138
std::string superclass_method_name(void) const
Definition: token.cc:124
octave_value number(void) const
Definition: token.cc:104
end_tok_type ettype(void) const
Definition: token.cc:117
token(int tv, const filepos &beg_pos, const filepos &end_pos)
Definition: token.cc:37
tok_info m_tok_info
Definition: token.h:206
token_type
Definition: token.h:43
@ numeric_token
Definition: token.h:47
@ ettype_token
Definition: token.h:48
@ string_token
Definition: token.h:46
@ scls_name_token
Definition: token.h:49
std::string m_orig_text
Definition: token.h:208
end_tok_type
Definition: token.h:53
token_type ttype(void) const
Definition: token.cc:111
std::string superclass_class_name(void) const
Definition: token.cc:131
token_type m_type_tag
Definition: token.h:147
~token(void)
Definition: token.cc:86
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void panic_if(bool cond)
Definition: error.h:512
std::string * m_str
Definition: token.h:171
end_tok_type m_et
Definition: token.h:175
superclass_info * m_superclass_info
Definition: token.h:203
octave_value * m_num
Definition: token.h:173