Home | History | Annotate | Download | only in tool
      1 /*
      2  * [The "BSD license"]
      3  *  Copyright (c) 2010 Terence Parr
      4  *  All rights reserved.
      5  *
      6  *  Redistribution and use in source and binary forms, with or without
      7  *  modification, are permitted provided that the following conditions
      8  *  are met:
      9  *  1. Redistributions of source code must retain the above copyright
     10  *      notice, this list of conditions and the following disclaimer.
     11  *  2. Redistributions in binary form must reproduce the above copyright
     12  *      notice, this list of conditions and the following disclaimer in the
     13  *      documentation and/or other materials provided with the distribution.
     14  *  3. The name of the author may not be used to endorse or promote products
     15  *      derived from this software without specific prior written permission.
     16  *
     17  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 package org.antlr.tool;
     29 
     30 import org.antlr.analysis.DFAState;
     31 import org.antlr.analysis.DecisionProbe;
     32 import org.antlr.analysis.Label;
     33 import org.antlr.analysis.NFAState;
     34 import org.stringtemplate.v4.ST;
     35 
     36 import java.util.Collection;
     37 import java.util.List;
     38 
     39 /** Indicates recursion overflow.  A DFA state tried add an NFA configuration
     40  *  with NFA state p that was mentioned in its stack context too many times.
     41  */
     42 public class RecursionOverflowMessage extends Message {
     43 	public DecisionProbe probe;
     44 	public DFAState sampleBadState;
     45 	public int alt;
     46 	public Collection<String> targetRules;
     47 	public Collection<? extends Collection<? extends NFAState>> callSiteStates;
     48 
     49 	public RecursionOverflowMessage(DecisionProbe probe,
     50 									DFAState sampleBadState,
     51 									int alt,
     52 									Collection<String> targetRules,
     53 									Collection<? extends Collection<? extends NFAState>> callSiteStates)
     54 	{
     55 		super(ErrorManager.MSG_RECURSION_OVERLOW);
     56 		this.probe = probe;
     57 		this.sampleBadState = sampleBadState;
     58 		this.alt = alt;
     59 		this.targetRules = targetRules;
     60 		this.callSiteStates = callSiteStates;
     61 	}
     62 
     63 	@Override
     64 	public String toString() {
     65 		GrammarAST decisionASTNode = probe.dfa.getDecisionASTNode();
     66 		line = decisionASTNode.getLine();
     67 		column = decisionASTNode.getCharPositionInLine();
     68 		String fileName = probe.dfa.nfa.grammar.getFileName();
     69 		if ( fileName!=null ) {
     70 			file = fileName;
     71 		}
     72 
     73 		ST st = getMessageTemplate();
     74 		st.add("targetRules", targetRules);
     75 		st.add("alt", alt);
     76 		st.add("callSiteStates", callSiteStates);
     77 
     78 		List<Label> labels =
     79 			probe.getSampleNonDeterministicInputSequence(sampleBadState);
     80 		String input = probe.getInputSequenceDisplay(labels);
     81 		st.add("input", input);
     82 
     83 		return super.toString(st);
     84 	}
     85 
     86 }
     87