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