]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/LexerChannelAction.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / LexerChannelAction.cpp
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #include "misc/MurmurHash.h"
7 #include "Lexer.h"
8
9 #include "atn/LexerChannelAction.h"
10
11 using namespace antlr4::atn;
12 using namespace antlr4::misc;
13
14 LexerChannelAction::LexerChannelAction(int channel) : _channel(channel) {
15 }
16
17 int LexerChannelAction::getChannel() const {
18   return _channel;
19 }
20
21 LexerActionType LexerChannelAction::getActionType() const {
22   return LexerActionType::CHANNEL;
23 }
24
25 bool LexerChannelAction::isPositionDependent() const {
26   return false;
27 }
28
29 void LexerChannelAction::execute(Lexer *lexer) {
30   lexer->setChannel(_channel);
31 }
32
33 size_t LexerChannelAction::hashCode() const {
34   size_t hash = MurmurHash::initialize();
35   hash = MurmurHash::update(hash, static_cast<size_t>(getActionType()));
36   hash = MurmurHash::update(hash, _channel);
37   return MurmurHash::finish(hash, 2);
38 }
39
40 bool LexerChannelAction::operator == (const LexerAction &obj) const {
41   if (&obj == this) {
42     return true;
43   }
44
45   const LexerChannelAction *action = dynamic_cast<const LexerChannelAction *>(&obj);
46   if (action == nullptr) {
47     return false;
48   }
49
50   return _channel == action->_channel;
51 }
52
53 std::string LexerChannelAction::toString() const {
54   return "channel(" + std::to_string(_channel) + ")";
55 }