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