2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.rfc7950.antlr;
10 import org.antlr.v4.runtime.CharStream;
11 import org.antlr.v4.runtime.TokenSource;
12 import org.antlr.v4.runtime.misc.Pair;
15 * Intermediate general token implementation. This cuts {@code channel}, {@code text} fields completely, as we typically
16 * we do not use them. {@code type} and {@code charPositionInLine} are cut down to a single byte, and {@code line} is
17 * cut down to an unsigned short. {@code startIndex} and {@code stopIndex} are kept at full four-byte range, this making
18 * this implementation useful beyond 64K-char file mark.
21 * This class ends up costing 32/48/32/32 bytes instead of 48/64/48/48 bytes, a saving of 33% in the same scenarios as
22 * {@link Token12122} across all possible file sizes.
24 final class Token12144 extends AbstractSourceToken {
25 private final byte type;
26 private final short line;
27 private final byte charPositionInLine;
29 private final int startIndex;
30 private final int stopIndex;
32 Token12144(final Pair<TokenSource, CharStream> source, final int type, final int line, final int charPositionInLine,
33 final int startIndex, final int stopIndex) {
35 this.type = (byte) type;
36 this.line = (short) line;
37 this.charPositionInLine = (byte) charPositionInLine;
38 this.startIndex = startIndex;
39 this.stopIndex = stopIndex;
43 public int getType() {
48 public int getLine() {
49 return Short.toUnsignedInt(line);
53 public int getCharPositionInLine() {
54 return Byte.toUnsignedInt(charPositionInLine);
58 public int getStartIndex() {
63 public int getStopIndex() {