]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/LexerPushModeAction.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / LexerPushModeAction.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/LexerPushModeAction.h"
10
11 using namespace antlr4;
12 using namespace antlr4::atn;
13 using namespace antlr4::misc;
14
15 LexerPushModeAction::LexerPushModeAction(int mode) : _mode(mode) {
16 }
17
18 int LexerPushModeAction::getMode() const {
19   return _mode;
20 }
21
22 LexerActionType LexerPushModeAction::getActionType() const {
23   return LexerActionType::PUSH_MODE;
24 }
25
26 bool LexerPushModeAction::isPositionDependent() const {
27   return false;
28 }
29
30 void LexerPushModeAction::execute(Lexer *lexer) {
31   lexer->pushMode(_mode);
32 }
33
34 size_t LexerPushModeAction::hashCode() const {
35   size_t hash = MurmurHash::initialize();
36   hash = MurmurHash::update(hash, static_cast<size_t>(getActionType()));
37   hash = MurmurHash::update(hash, _mode);
38   return MurmurHash::finish(hash, 2);
39 }
40
41 bool LexerPushModeAction::operator == (const LexerAction &obj) const {
42   if (&obj == this) {
43     return true;
44   }
45
46   const LexerPushModeAction *action = dynamic_cast<const LexerPushModeAction *>(&obj);
47   if (action == nullptr) {
48     return false;
49   }
50
51   return _mode == action->_mode;
52 }
53
54 std::string LexerPushModeAction::toString() const {
55   return "pushMode(" + std::to_string(_mode) + ")";
56 }