aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.inl
blob: 3277b3def1635fdc567604102010265d17b7d7e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
namespace antlr3 {

template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken()
{
	m_type = 0;
    m_channel = 0;
	m_lineStart = NULL;
	m_line = 0;
	m_charPositionInLine = 0;
	m_input = NULL;
	m_index = 0;
	m_startIndex = 0;
	m_stopIndex = 0;
}

template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken(ANTLR_UINT32 type)
{
	m_type = type;
	m_channel = 0;
	m_lineStart = NULL;
	m_line = 0;
	m_charPositionInLine = 0;
	m_input = NULL;
	m_index = 0;
	m_startIndex = 0;
	m_stopIndex = 0;
}

template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken(TOKEN_TYPE type)
{
	m_type = type;
	m_channel = 0;
	m_lineStart = NULL;
	m_line = 0;
	m_charPositionInLine = 0;
	m_input = NULL;
	m_index = 0;
	m_startIndex = 0;
	m_stopIndex = 0;
}

template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken( const CommonToken& ctoken )
	:m_tokText( ctoken.m_tokText )
	,UserData(ctoken.UserData)	 
{
	m_type = ctoken.m_type;
	m_channel = ctoken.m_channel;
	m_lineStart = ctoken.m_lineStart;
	m_line = ctoken.m_line;
	m_charPositionInLine = ctoken.m_charPositionInLine;
	m_input = ctoken.m_input;
	m_index = ctoken.m_index;
	m_startIndex = ctoken.m_startIndex;
	m_stopIndex = ctoken.m_stopIndex;
}

template<class ImplTraits>
CommonToken<ImplTraits>& CommonToken<ImplTraits>::operator=( const CommonToken& ctoken )
{
	UserData = ctoken.UserData;
	m_type = ctoken.m_type;
	m_channel = ctoken.m_channel;
	m_lineStart = ctoken.m_lineStart;
	m_line = ctoken.m_line;
	m_charPositionInLine = ctoken.m_charPositionInLine;
	m_input = ctoken.m_input;
	m_index = ctoken.m_index;
	m_startIndex = ctoken.m_startIndex;
	m_stopIndex = ctoken.m_stopIndex;

	m_tokText = ctoken.m_tokText;
	return *this;
}

template<class ImplTraits>
ANTLR_INLINE bool CommonToken<ImplTraits>::operator<( const CommonToken& ctoken ) const
{
	return (m_index < ctoken.m_index);
}

template<class ImplTraits>
bool CommonToken<ImplTraits>::operator==( const CommonToken& ctoken ) const
{
	return ( (m_type == ctoken.m_type) &&
		     (m_channel == ctoken.m_channel) &&
			 (m_lineStart == ctoken.m_lineStart) &&
			 (m_line == ctoken.m_line) &&
			 (m_charPositionInLine == ctoken.m_charPositionInLine) &&
			 (m_input == ctoken.m_input) &&
			 (m_index == ctoken.m_index) &&
			 (m_startIndex == ctoken.m_startIndex) &&
			 (m_stopIndex == ctoken.m_stopIndex) );
}

template<class ImplTraits>
ANTLR_INLINE typename CommonToken<ImplTraits>::InputStreamType* CommonToken<ImplTraits>::get_input() const
{
	return m_input;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER CommonToken<ImplTraits>::get_index() const
{
	return m_index;
}

template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_index( ANTLR_MARKER index )
{
	m_index = index;
}

template<class ImplTraits>
void CommonToken<ImplTraits>::set_input( InputStreamType* input )
{
	m_input = input;
}

template<class ImplTraits>
typename CommonToken<ImplTraits>::StringType const &
CommonToken<ImplTraits>::getText() const
{
	static const StringType EOF_STRING("<EOF>");
	static const StringType EMPTY_STRING("");

	if ( !m_tokText.empty() )
		return m_tokText;

	// EOF is a special case
	//
	if ( m_type == TOKEN_EOF)
	{
		return EOF_STRING;
	}

	// We had nothing installed in the token, create a new string
	// from the input stream
	//
	if ( m_input != NULL)
	{
		return m_tokText = m_input->substr( this->get_startIndex(), this->get_stopIndex() );
	}
	// Nothing to return, there is no input stream
	//
	return EMPTY_STRING;
}

template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_tokText( const StringType& text )
{
	m_tokText = text;
}

template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::setText(ANTLR_UINT8* text)
{
	if( text == NULL )
		m_tokText.clear();
	else
		m_tokText = (const char*) text;
}

template<class ImplTraits>
ANTLR_INLINE void	CommonToken<ImplTraits>::setText(const char* text)
{
	if( text == NULL )
		m_tokText.clear();
	else
		m_tokText = text;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32  CommonToken<ImplTraits>::get_type() const
{
	return m_type;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32  CommonToken<ImplTraits>::getType() const
{
	return m_type;
}

template<class ImplTraits>
ANTLR_INLINE void	CommonToken<ImplTraits>::set_type(ANTLR_UINT32 ttype)
{
	m_type = ttype;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32   CommonToken<ImplTraits>::get_line() const
{
	return m_line;
}

template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_line(ANTLR_UINT32 line)
{
	m_line = line;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_INT32  CommonToken<ImplTraits>::get_charPositionInLine() const
{
	return m_charPositionInLine;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_INT32  CommonToken<ImplTraits>::getCharPositionInLine() const
{
	return this->get_charPositionInLine();
}

template<class ImplTraits>
ANTLR_INLINE void	CommonToken<ImplTraits>::set_charPositionInLine(ANTLR_INT32 pos)
{
	m_charPositionInLine = pos;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32   CommonToken<ImplTraits>::get_channel() const
{
	return m_channel;
}

template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_channel(ANTLR_UINT32 channel)
{
	m_channel = channel;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER  CommonToken<ImplTraits>::get_tokenIndex() const
{
	return m_index;
}

template<class ImplTraits>
ANTLR_INLINE void	CommonToken<ImplTraits>::set_tokenIndex(ANTLR_MARKER tokenIndex)
{
	m_index = tokenIndex;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER   CommonToken<ImplTraits>::get_startIndex() const
{
	return (m_startIndex == -1) ? (ANTLR_MARKER)(m_input->get_data()) : m_startIndex;
}

template<class ImplTraits>
ANTLR_INLINE void	CommonToken<ImplTraits>::set_startIndex(ANTLR_MARKER index)
{
	m_startIndex = index;
}

template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER  CommonToken<ImplTraits>::get_stopIndex() const
{
	return m_stopIndex;
}

template<class ImplTraits>
ANTLR_INLINE void	CommonToken<ImplTraits>::set_stopIndex(ANTLR_MARKER index)
{
	m_stopIndex = index;
}

template<class ImplTraits>
ANTLR_INLINE const typename CommonToken<ImplTraits>::StreamDataType* CommonToken<ImplTraits>::get_lineStart() const
{
	return m_lineStart;
}

template<class ImplTraits>
ANTLR_INLINE void	CommonToken<ImplTraits>::set_lineStart( const StreamDataType* lineStart )
{
	m_lineStart = lineStart;
}

template<class ImplTraits>
typename CommonToken<ImplTraits>::StringType  CommonToken<ImplTraits>::toString() const
{
    StringType  text;
    typedef typename ImplTraits::StringStreamType StringStreamType;
    StringStreamType  outtext; 

    text    =	this->getText();

    if	(text.empty())
		return "";

    /* Now we use our handy dandy string utility to assemble the
     * the reporting string
     * return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+type+">"+channelStr+","+line+":"+getCharPositionInLine()+"]";
     */
    outtext << "[Index: ";
    outtext << (int)this->get_tokenIndex();
    outtext << " (Start: ";
    outtext << (int)this->get_startIndex();
    outtext << "-Stop: ";
    outtext << (int)this->get_stopIndex();
    outtext << ") ='";
    outtext << text;
    outtext << "', type<";
    outtext << (int)m_type;
    outtext << "> ";

    if	(this->get_channel() > TOKEN_DEFAULT_CHANNEL)
    {
		outtext << "(channel = ";
		outtext << (int)this->get_channel();
		outtext << ") ";
    }

    outtext << "Line: ";
    outtext << (int)this->get_line();
    outtext << " LinePos:";
    outtext << (int)this->get_charPositionInLine();
    outtext << "]";

    return  outtext.str();
}

}