⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errormanager.java

📁 antlr最新版本V3源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	{		getErrorState().warnings++;		Message msg = new GrammarNonDeterminismMessage(probe,d);		getErrorState().warningMsgIDs.add(msg.msgID);		getErrorListener().warning(msg);	}	public static void danglingState(DecisionProbe probe,									 DFAState d)	{		getErrorState().warnings++;		Message msg = new GrammarDanglingStateMessage(probe,d);		getErrorState().warningMsgIDs.add(msg.msgID);		Set seen = (Set)emitSingleError.get("danglingState");		if ( !seen.contains(d.dfa.decisionNumber+"|"+d.getAltSet()) ) {			getErrorListener().warning(msg);			// we've seen this decision and this alt set; never again			seen.add(d.dfa.decisionNumber+"|"+d.getAltSet());		}	}	public static void analysisAborted(DecisionProbe probe)	{		getErrorState().warnings++;		Message msg = new GrammarAnalysisAbortedMessage(probe);		getErrorState().warningMsgIDs.add(msg.msgID);		getErrorListener().warning(msg);	}	public static void unreachableAlts(DecisionProbe probe,									   List alts)	{		getErrorState().warnings++;		Message msg = new GrammarUnreachableAltsMessage(probe,alts);		getErrorState().warningMsgIDs.add(msg.msgID);		getErrorListener().warning(msg);	}	public static void insufficientPredicates(DecisionProbe probe,											  List alts)	{		getErrorState().warnings++;		Message msg = new GrammarInsufficientPredicatesMessage(probe,alts);		getErrorState().warningMsgIDs.add(msg.msgID);		getErrorListener().warning(msg);	}	public static void nonLLStarDecision(DecisionProbe probe) {		getErrorState().errors++;		Message msg = new NonRegularDecisionMessage(probe, probe.getNonDeterministicAlts());		getErrorState().errorMsgIDs.add(msg.msgID);		getErrorListener().error(msg);	}	public static void recursionOverflow(DecisionProbe probe,										 DFAState sampleBadState,										 int alt,										 Collection targetRules,										 Collection callSiteStates)	{		getErrorState().warnings++;		Message msg = new RecursionOverflowMessage(probe,sampleBadState, alt,										 targetRules, callSiteStates);		getErrorState().warningMsgIDs.add(msg.msgID);		getErrorListener().warning(msg);	}	/*	// TODO: we can remove I think.  All detected now with cycles check.	public static void leftRecursion(DecisionProbe probe,									 int alt,									 Collection targetRules,									 Collection callSiteStates)	{		getErrorState().warnings++;		Message msg = new LeftRecursionMessage(probe, alt, targetRules, callSiteStates);		getErrorState().warningMsgIDs.add(msg.msgID);		getErrorListener().warning(msg);	}	*/	public static void leftRecursionCycles(Collection cycles) {		getErrorState().errors++;		Message msg = new LeftRecursionCyclesMessage(cycles);		getErrorState().errorMsgIDs.add(msg.msgID);		getErrorListener().warning(msg);	}	public static void grammarError(int msgID,									Grammar g,									Token token,									Object arg,									Object arg2)	{		getErrorState().errors++;		Message msg = new GrammarSemanticsMessage(msgID,g,token,arg,arg2);		getErrorState().errorMsgIDs.add(msgID);		getErrorListener().error(msg);	}	public static void grammarError(int msgID,									Grammar g,									Token token,									Object arg)	{		grammarError(msgID,g,token,arg,null);	}	public static void grammarError(int msgID,									Grammar g,									Token token)	{		grammarError(msgID,g,token,null,null);	}	public static void grammarWarning(int msgID,									  Grammar g,									  Token token,									  Object arg,									  Object arg2)	{		getErrorState().errors++;		Message msg = new GrammarSemanticsMessage(msgID,g,token,arg,arg2);		getErrorState().warningMsgIDs.add(msgID);		getErrorListener().warning(msg);	}	public static void grammarWarning(int msgID,									  Grammar g,									  Token token,									  Object arg)	{		grammarWarning(msgID,g,token,arg,null);	}	public static void grammarWarning(int msgID,									  Grammar g,									  Token token)	{		grammarWarning(msgID,g,token,null,null);	}	public static void syntaxError(int msgID,								   Grammar grammar,								   Token token,								   Object arg,								   antlr.RecognitionException re)	{		getErrorState().errors++;		getErrorState().errorMsgIDs.add(msgID);		getErrorListener().error(			new GrammarSyntaxMessage(msgID,grammar,token,arg,re)		);	}	public static void internalError(Object error, Throwable e) {		StackTraceElement location = getLastNonErrorManagerCodeLocation(e);		String msg = "Exception "+e+"@"+location+": "+error;		error(MSG_INTERNAL_ERROR, msg);	}	public static void internalError(Object error) {		StackTraceElement location =			getLastNonErrorManagerCodeLocation(new Exception());		String msg = location+": "+error;		error(MSG_INTERNAL_ERROR, msg);	}	public static boolean doNotAttemptAnalysis() {		return !getErrorState().errorMsgIDs.and(ERRORS_FORCING_NO_ANALYSIS).isNil();	}	public static boolean doNotAttemptCodeGen() {		return !getErrorState().errorMsgIDs.and(ERRORS_FORCING_NO_CODEGEN).isNil();	}	/** Return first non ErrorManager code location for generating messages */	private static StackTraceElement getLastNonErrorManagerCodeLocation(Throwable e) {		StackTraceElement[] stack = e.getStackTrace();		int i = 0;		for (; i < stack.length; i++) {			StackTraceElement t = stack[i];			if ( t.toString().indexOf("ErrorManager")<0 ) {				break;			}		}		StackTraceElement location = stack[i];		return location;	}	// A S S E R T I O N  C O D E	public static void assertTrue(boolean condition, String message) {		if ( !condition ) {			internalError(message);		}	}	// S U P P O R T  C O D E	protected static boolean initIdToMessageNameMapping() {		// make sure a message exists, even if it's just to indicate a problem		for (int i = 0; i < idToMessageTemplateName.length; i++) {			idToMessageTemplateName[i] = "INVALID MESSAGE ID: "+i;		}		// get list of fields and use it to fill in idToMessageTemplateName mapping		Field[] fields = ErrorManager.class.getFields();		for (int i = 0; i < fields.length; i++) {			Field f = fields[i];			String fieldName = f.getName();			if ( !fieldName.startsWith("MSG_") ) {				continue;			}			String templateName =				fieldName.substring("MSG_".length(),fieldName.length());			int msgID = 0;			try {				// get the constant value from this class object				msgID = f.getInt(ErrorManager.class);			}			catch (IllegalAccessException iae) {				System.err.println("cannot get const value for "+f.getName());				continue;			}			if ( fieldName.startsWith("MSG_") ) {                idToMessageTemplateName[msgID] = templateName;			}		}		return true;	}	/** Use reflection to find list of MSG_ fields and then verify a	 *  template exists for each one from the locale's group.	 */	protected static boolean verifyMessages() {		boolean ok = true;		Field[] fields = ErrorManager.class.getFields();		for (int i = 0; i < fields.length; i++) {			Field f = fields[i];			String fieldName = f.getName();			String templateName =				fieldName.substring("MSG_".length(),fieldName.length());			if ( fieldName.startsWith("MSG_") ) {				if ( !messages.isDefined(templateName) ) {					System.err.println("Message "+templateName+" in locale "+									   locale+" not found");					ok = false;				}			}		}		// check for special templates		if (!messages.isDefined("warning")) {			System.err.println("Message template 'warning' not found in locale "+ locale);			ok = false;		}		if (!messages.isDefined("error")) {			System.err.println("Message template 'error' not found in locale "+ locale);			ok = false;		}		return ok;	}	/** Verify the message format template group */	protected static boolean verifyFormat() {		boolean ok = true;		if (!format.isDefined("location")) {			System.err.println("Format template 'location' not found in " + formatName);			ok = false;		}		if (!format.isDefined("message")) {			System.err.println("Format template 'message' not found in " + formatName);			ok = false;		}		if (!format.isDefined("report")) {			System.err.println("Format template 'report' not found in " + formatName);			ok = false;		}		return ok;	}	/** If there are errors during ErrorManager init, we have no choice	 *  but to go to System.err.	 */	static void rawError(String msg) {		System.err.println(msg);	}	static void rawError(String msg, Throwable e) {		rawError(msg);		e.printStackTrace(System.err);	}	/** I *think* this will allow Tool subclasses to exit gracefully	 *  for GUIs etc...	 */	public static void panic() {		Tool tool = (Tool)threadToToolMap.get(Thread.currentThread());		if ( tool==null ) {			// no tool registered, exit			throw new Error("ANTLR ErrorManager panic");		}		else {			tool.panic();		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -