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"
9 #include "atn/LexerModeAction.h"
11 using namespace antlr4;
12 using namespace antlr4::atn;
13 using namespace antlr4::misc;
15 LexerModeAction::LexerModeAction(int mode) : _mode(mode) {
18 int LexerModeAction::getMode() {
22 LexerActionType LexerModeAction::getActionType() const {
23 return LexerActionType::MODE;
26 bool LexerModeAction::isPositionDependent() const {
30 void LexerModeAction::execute(Lexer *lexer) {
31 lexer->setMode(_mode);
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);
41 bool LexerModeAction::operator == (const LexerAction &obj) const {
46 const LexerModeAction *action = dynamic_cast<const LexerModeAction *>(&obj);
47 if (action == nullptr) {
51 return _mode == action->_mode;
54 std::string LexerModeAction::toString() const {
55 return "mode(" + std::to_string(_mode) + ")";