]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/LexerCustomAction.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / LexerCustomAction.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 "support/CPPUtils.h"
8 #include "Lexer.h"
9
10 #include "atn/LexerCustomAction.h"
11
12 using namespace antlr4;
13 using namespace antlr4::atn;
14 using namespace antlr4::misc;
15
16 LexerCustomAction::LexerCustomAction(size_t ruleIndex, size_t actionIndex) : _ruleIndex(ruleIndex), _actionIndex(actionIndex) {
17 }
18
19 size_t LexerCustomAction::getRuleIndex() const {
20   return _ruleIndex;
21 }
22
23 size_t LexerCustomAction::getActionIndex() const {
24   return _actionIndex;
25 }
26
27 LexerActionType LexerCustomAction::getActionType() const {
28   return LexerActionType::CUSTOM;
29 }
30
31 bool LexerCustomAction::isPositionDependent() const {
32   return true;
33 }
34
35 void LexerCustomAction::execute(Lexer *lexer) {
36   lexer->action(nullptr, _ruleIndex, _actionIndex);
37 }
38
39 size_t LexerCustomAction::hashCode() const {
40   size_t hash = MurmurHash::initialize();
41   hash = MurmurHash::update(hash, static_cast<size_t>(getActionType()));
42   hash = MurmurHash::update(hash, _ruleIndex);
43   hash = MurmurHash::update(hash, _actionIndex);
44   return MurmurHash::finish(hash, 3);
45 }
46
47 bool LexerCustomAction::operator == (const LexerAction &obj) const {
48   if (&obj == this) {
49     return true;
50   }
51
52   const LexerCustomAction *action = dynamic_cast<const LexerCustomAction *>(&obj);
53   if (action == nullptr) {
54     return false;
55   }
56
57   return _ruleIndex == action->_ruleIndex && _actionIndex == action->_actionIndex;
58 }
59
60 std::string LexerCustomAction::toString() const {
61   return antlrcpp::toString(this);
62 }