[antlr-interest] Fixed unreachable code warnings in C# codegen

Ney, Richard richard.ney at aspect.com
Mon Nov 4 16:20:09 PST 2002


I modified the section in genBlockFinish to eliminate the break in the
default condition of the case statements if it isn't reachable due to the
throwing of an exception.


	private void genBlockFinish(CSharpBlockFinishingInfo howToFinish,
String noViableAction)
	{

		if (howToFinish.needAnErrorClause &&
			(howToFinish.generatedAnIf ||
howToFinish.generatedSwitch))
		{
			if ( howToFinish.generatedAnIf )
			{
				println("else");
				println("{");
			}
			else
			{
				//if (howToFinish.generatedSwitch)
println("break; /* howToFinish.generatedSwitch */");
				println("{");
			}
			tabs++;
			println(noViableAction);
			//if (howToFinish.generatedSwitch) println("break;
/* howToFinish.generatedSwitch */");
			tabs--;			
			println("}");
		}

		if (howToFinish.postscript != null)
		{
			if (howToFinish.generatedSwitch && noViableAction !=
null)
			{
				// Check to make sure that noViableAction is
only a throw statement
				if (noViableAction.indexOf("throw") == 0 ||
noViableAction.indexOf("goto") == 0)
				{
					// Remove the break statement since
it isn't reachable with a throw exception or goto
					int endOfBreak =
howToFinish.postscript.indexOf("break;") + 6;
					String newPostScript =
howToFinish.postscript.substring(endOfBreak);
					println(newPostScript);
				}
				else
				{
					println(howToFinish.postscript);
				}
			}
			else
			{
				println(howToFinish.postscript);
			}
		}
	}


-Richard

----------------------------------------------------------------------------
------------------------
Richard Ney	Aspect Communications
Principal Software Engineer
http://www.aspect.com <http://www.aspect.com>
Main:  408.325.2200
mailto:richard.ney at aspect.com <mailto:richard.ney at aspect.com>
SJ Office: 408.325.2464
    	Home Office: 916.797.9602
----------------------------------------------------------------------------
------------------------

The Three Laws of Infernal Dynamics:
1. An object in motion will always be headed in the wrong direction.
2. An object at rest will always be in the wrong place.
3. The energy required to change either of these states will always be more
than you wish to expend, but never so much as to make the task appear
prospectively impossible.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20021104/a8012155/attachment.html


More information about the antlr-interest mailing list