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.
6 #include "misc/MurmurHash.h"
7 #include "support/CPPUtils.h"
10 #include "atn/LexerCustomAction.h"
12 using namespace antlr4;
13 using namespace antlr4::atn;
14 using namespace antlr4::misc;
16 LexerCustomAction::LexerCustomAction(size_t ruleIndex, size_t actionIndex) : _ruleIndex(ruleIndex), _actionIndex(actionIndex) {
19 size_t LexerCustomAction::getRuleIndex() const {
23 size_t LexerCustomAction::getActionIndex() const {
27 LexerActionType LexerCustomAction::getActionType() const {
28 return LexerActionType::CUSTOM;
31 bool LexerCustomAction::isPositionDependent() const {
35 void LexerCustomAction::execute(Lexer *lexer) {
36 lexer->action(nullptr, _ruleIndex, _actionIndex);
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);
47 bool LexerCustomAction::operator == (const LexerAction &obj) const {
52 const LexerCustomAction *action = dynamic_cast<const LexerCustomAction *>(&obj);
53 if (action == nullptr) {
57 return _ruleIndex == action->_ruleIndex && _actionIndex == action->_actionIndex;
60 std::string LexerCustomAction::toString() const {
61 return antlrcpp::toString(this);