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"
8 #include "support/CPPUtils.h"
10 #include "atn/LexerIndexedCustomAction.h"
12 using namespace antlr4;
13 using namespace antlr4::atn;
14 using namespace antlr4::misc;
16 LexerIndexedCustomAction::LexerIndexedCustomAction(int offset, Ref<LexerAction> const& action)
17 : _offset(offset), _action(action) {
20 int LexerIndexedCustomAction::getOffset() const {
24 Ref<LexerAction> LexerIndexedCustomAction::getAction() const {
28 LexerActionType LexerIndexedCustomAction::getActionType() const {
29 return _action->getActionType();
32 bool LexerIndexedCustomAction::isPositionDependent() const {
36 void LexerIndexedCustomAction::execute(Lexer *lexer) {
37 // assume the input stream position was properly set by the calling code
38 _action->execute(lexer);
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);
48 bool LexerIndexedCustomAction::operator == (const LexerAction &obj) const {
53 const LexerIndexedCustomAction *action = dynamic_cast<const LexerIndexedCustomAction *>(&obj);
54 if (action == nullptr) {
58 return _offset == action->_offset && *_action == *action->_action;
61 std::string LexerIndexedCustomAction::toString() const {
62 return antlrcpp::toString(this);