diff --git a/src/atn/PredictionContext.d.ts b/src/atn/PredictionContext.d.ts deleted file mode 100644 index 6a99e3b..0000000 --- a/src/atn/PredictionContext.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) The ANTLR Project. All rights reserved. - * Use of this file is governed by the BSD 3-clause license that - * can be found in the LICENSE.txt file in the project root. - */ - -import { HashCode } from "../misc/HashCode.ts"; - -export abstract class PredictionContext { - // eslint-disable-next-line @typescript-eslint/naming-convention - public static EMPTY_RETURN_STATE: number; - // eslint-disable-next-line @typescript-eslint/naming-convention - public static EMPTY: PredictionContext; - - // eslint-disable-next-line @typescript-eslint/naming-convention - public static trace_atn_sim: boolean; - - public constructor(cachedHashCode: number); - - public isEmpty(): boolean; - - public hasEmptyPath(): boolean; - - public hashCode(): number; - - public updateHashCode(hash: HashCode): void; - - public abstract equals(obj: unknown): boolean; - public abstract get length(): number; - public abstract getParent(index: number): PredictionContext | null; - public abstract getReturnState(index: number): number; - -} diff --git a/src/atn/PredictionContext.js b/src/atn/PredictionContext.js deleted file mode 100644 index 91d5a4f..0000000 --- a/src/atn/PredictionContext.js +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) The ANTLR Project. All rights reserved. - * Use of this file is governed by the BSD 3-clause license that - * can be found in the LICENSE.txt file in the project root. - */ - -export class PredictionContext { - constructor(cachedHashCode) { - this.cachedHashCode = cachedHashCode; - } - - /** - * Stores the computed hash code of this {@link PredictionContext}. The hash - * code is computed in parts to match the following reference algorithm. - * - *
- * private int referenceHashCode() { - * int hash = {@link MurmurHash//initialize MurmurHash.initialize}({@link - * //INITIAL_HASH}); - * - * for (int i = 0; i < {@link //size()}; i++) { - * hash = {@link MurmurHash//update MurmurHash.update}(hash, {@link //getParent - * getParent}(i)); - * } - * - * for (int i = 0; i < {@link //size()}; i++) { - * hash = {@link MurmurHash//update MurmurHash.update}(hash, {@link - * //getReturnState getReturnState}(i)); - * } - * - * hash = {@link MurmurHash//finish MurmurHash.finish}(hash, 2// {@link - * //size()}); - * return hash; - * } - *- * This means only the {@link //EMPTY} context is in set. - */ - isEmpty() { - return this === PredictionContext.EMPTY; - } - - hasEmptyPath() { - return this.getReturnState(this.length - 1) === PredictionContext.EMPTY_RETURN_STATE; - } - - hashCode() { - return this.cachedHashCode; - } - - updateHashCode(hash) { - hash.update(this.cachedHashCode); - } -} - -/** - * Represents {@code $} in local context prediction, which means wildcard. - * {@code//+x =//}. - */ -PredictionContext.EMPTY = null; - -/** - * Represents {@code $} in an array in full context mode, when {@code $} - * doesn't mean wildcard: {@code $ + x = [$,x]}. Here, - * {@code $} = {@link //EMPTY_RETURN_STATE}. - */ -PredictionContext.EMPTY_RETURN_STATE = 0x7FFFFFFF; - -PredictionContext.globalNodeCount = 1; -PredictionContext.id = PredictionContext.globalNodeCount; -PredictionContext.trace_atn_sim = false; diff --git a/src/atn/PredictionContext.ts b/src/atn/PredictionContext.ts new file mode 100644 index 0000000..5ed1023 --- /dev/null +++ b/src/atn/PredictionContext.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) The ANTLR Project. All rights reserved. + * Use of this file is governed by the BSD 3-clause license that + * can be found in the LICENSE.txt file in the project root. + */ + +/* eslint-disable @typescript-eslint/naming-convention, jsdoc/require-returns, jsdoc/require-param */ + +import { HashCode } from "../misc/HashCode.js"; + +export abstract class PredictionContext { + /** + * Represents {@code $} in an array in full context mode, when {@code $} + * doesn't mean wildcard: {@code $ + x = [$,x]}. Here, + * {@code $} = {@link //EMPTY_RETURN_STATE}. + */ + public static readonly EMPTY_RETURN_STATE = 0x7FFFFFFF; + + // Temporarily here. Should be moved to EmptyPredictionContext. It's initialized in that context class. + public static EMPTY: PredictionContext; + + public static trace_atn_sim = false; + + private cachedHashCode: number; + + public constructor(cachedHashCode: number) { + this.cachedHashCode = cachedHashCode; + } + + public isEmpty(): boolean { + return false; + } + + public hasEmptyPath(): boolean { + return this.getReturnState(this.length - 1) === PredictionContext.EMPTY_RETURN_STATE; + } + + public hashCode(): number { + return this.cachedHashCode; + } + + public updateHashCode(hash: HashCode): void { + hash.update(this.cachedHashCode); + } + + public abstract getParent(index: number): PredictionContext | null; + public abstract getReturnState(index: number): number; + public abstract get length(): number; + public abstract equals(obj: unknown): boolean; +}