<commit_before>/*
 [The "BSD license"]
 Copyright (c) 2011 <NAME>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.antlr.v4.runtime.atn;

import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.dfa.*;
import org.antlr.v4.runtime.misc.OrderedHashSet;
import org.stringtemplate.v4.misc.MultiMap;

import java.util.*;

public class ParserATNSimulator extends ATNSimulator {
	public static boolean debug = true;
	public static boolean dfa_debug = false;

	public static int ATN_failover = 0;
	public static int predict_calls = 0;

	protected BaseRecognizer parser;

	public Map<RuleContext, DFA[]> ctxToDFAs;
	public Map<RuleContext, DFA>[] decisionToDFAPerCtx; // TODO: USE THIS ONE
	public DFA[] decisionToDFA;
	protected boolean userWantsCtxSensitive = false;

	protected Set<ATNConfig> closureBusy = new HashSet<ATNConfig>();

	/** Upon entry for prediction, we might need to execute actions and
	 *  we need to know original context passed to us from parser or
	 *  lexer.  This is the stack and any args, locals, labels, etc...
	 *  Meaningless across adaptivePredict() calls but easier as field
	 *  than passing down many function calls.
	protected RuleContext _ctx;
	 */

	public ParserATNSimulator(ATN atn) {
		super(atn);
		ctxToDFAs = new HashMap<RuleContext, DFA[]>();
		decisionToDFA = new DFA[atn.getNumberOfDecisions()];
	}

	public ParserATNSimulator(BaseRecognizer parser, ATN atn) {
		super(atn);
		this.parser = parser;
		ctxToDFAs = new HashMap<RuleContext, DFA[]>();
		decisionToDFA = new DFA[atn.getNumberOfDecisions()+1];
//		DOTGenerator dot = new DOTGenerator(null);
//		System.out.println(dot.getDOT(atn.rules.get(0), parser.getRuleNames()));
//		System.out.println(dot.getDOT(atn.rules.get(1), parser.getRuleNames()));
	}

	public int adaptivePredict(TokenStream input, int decision, RuleContext originalContext) {
		predict_calls++;
//		this._ctx = originalContext;
		DFA dfa = decisionToDFA[decision];
		if ( dfa==null || dfa.s0==null ) {
			ATNState startState = atn.decisionToState.get(decision);
			decisionToDFA[decision] = dfa = new DFA(startState);
			dfa.decision = decision;
			return predictATN(dfa, input, decision, originalContext, false);
		}
		else {
			//dump(dfa);
			// start with the DFA
			int m = input.mark();
			int alt = execDFA(input, dfa, dfa.s0, originalContext);
			input.seek(m);
			return alt;
		}
	}

	public int predictATN(DFA dfa, TokenStream input,
						  int decision,
						  RuleContext originalContext,
						  boolean useContext)
	{
		if ( originalContext==null ) originalContext = RuleContext.EMPTY;
		RuleContext ctx = RuleContext.EMPTY;
		if ( useContext  ) ctx = originalContext;
		OrderedHashSet<ATNConfig> s0_closure = computeStartState(dfa.atnStartState, ctx, originalContext);<commit_msg>rm dead code<commit_after>/*
 [The "BSD license"]
 Copyright (c) 2011 <NAME>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.antlr.v4.runtime.atn;

import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.dfa.*;
import org.antlr.v4.runtime.misc.OrderedHashSet;
import org.stringtemplate.v4.misc.MultiMap;

import java.util.*;

public class ParserATNSimulator extends ATNSimulator {
	public static boolean debug = true;
	public static boolean dfa_debug = false;

	public static int ATN_failover = 0;
	public static int predict_calls = 0;

	protected BaseRecognizer parser;

	public Map<RuleContext, DFA[]> ctxToDFAs;
	public Map<RuleContext, DFA>[] decisionToDFAPerCtx; // TODO: USE THIS ONE
	public DFA[] decisionToDFA;
	protected boolean userWantsCtxSensitive = false;

	protected Set<ATNConfig> closureBusy = new HashSet<ATNConfig>();

	public ParserATNSimulator(ATN atn) {
		super(atn);
		ctxToDFAs = new HashMap<RuleContext, DFA[]>();
		decisionToDFA = new DFA[atn.getNumberOfDecisions()];
	}

	public ParserATNSimulator(BaseRecognizer parser, ATN atn) {
		super(atn);
		this.parser = parser;
		ctxToDFAs = new HashMap<RuleContext, DFA[]>();
		decisionToDFA = new DFA[atn.getNumberOfDecisions()+1];
//		DOTGenerator dot = new DOTGenerator(null);
//		System.out.println(dot.getDOT(atn.rules.get(0), parser.getRuleNames()));
//		System.out.println(dot.getDOT(atn.rules.get(1), parser.getRuleNames()));
	}

	public int adaptivePredict(TokenStream input, int decision, RuleContext originalContext) {
		predict_calls++;
		DFA dfa = decisionToDFA[decision];
		if ( dfa==null || dfa.s0==null ) {
			ATNState startState = atn.decisionToState.get(decision);
			decisionToDFA[decision] = dfa = new DFA(startState);
			dfa.decision = decision;
			return predictATN(dfa, input, decision, originalContext, false);
		}
		else {
			//dump(dfa);
			// start with the DFA
			int m = input.mark();
			int alt = execDFA(input, dfa, dfa.s0, originalContext);
			input.seek(m);
			return alt;
		}
	}

	public int predictATN(DFA dfa, TokenStream input,
						  int decision,
						  RuleContext originalContext,
						  boolean useContext)
	{
		if ( originalContext==null ) originalContext = RuleContext.EMPTY;
		RuleContext ctx = RuleContext.EMPTY;
		if ( useContext  ) ctx = originalContext;
		OrderedHashSet<ATNConfig> s0_closure = computeStartState(dfa.atnStartState, ctx, originalContext);
{'fraction_non_alphanumeric': 0.08596938775510204, 'fraction_numerical': 0.00510204081632653, 'mean_word_length': 4.479385045422782, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4740252', 'n_tokens_mistral': 2539, 'n_tokens_neox': 2280, 'n_words': 830}