- removed goto, it's evil

Sun, 23 Feb 2014 17:21:18 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 23 Feb 2014 17:21:18 +0200
changeset 111
87d9ebd3ef34
parent 110
7a7a53f1d51b
child 112
def56932f938

- removed goto, it's evil

src/LexerScanner.cc file | annotate | diff | comparison | revisions
src/Parser.cc file | annotate | diff | comparison | revisions
src/Parser.h file | annotate | diff | comparison | revisions
src/Tokens.h file | annotate | diff | comparison | revisions
--- a/src/LexerScanner.cc	Wed Feb 12 06:50:13 2014 +0200
+++ b/src/LexerScanner.cc	Sun Feb 23 17:21:18 2014 +0200
@@ -92,7 +92,6 @@
 	"eventdef",
 	"for",
 	"funcdef",
-	"goto",
 	"if",
 	"int",
 	"mainloop",
--- a/src/Parser.cc	Wed Feb 12 06:50:13 2014 +0200
+++ b/src/Parser.cc	Sun Feb 23 17:21:18 2014 +0200
@@ -122,10 +122,6 @@
 				ParseVar();
 				break;
 
-			case TK_Goto:
-				ParseGoto();
-				break;
-
 			case TK_If:
 				ParseIf();
 				break;
@@ -183,17 +179,6 @@
 
 			default:
 			{
-				// Check for labels
-				Lexer::Token next;
-
-				if (TokenIs (TK_Symbol) &&
-					mLexer->PeekNext (&next) &&
-					next.type ==TK_Colon)
-				{
-					ParseLabel();
-					break;
-				}
-
 				// Check if it's a command
 				CommandInfo* comm = FindCommandByName (GetTokenString());
 
@@ -232,17 +217,6 @@
 		if (mStateSpawnDefined == false)
 			Error ("script must have a state named `stateSpawn`!");
 
-		// Ensure no goto target is left undefined
-		if (mUndefinedLabels.IsEmpty() == false)
-		{
-			StringList names;
-
-			for (UndefinedLabel& undf : mUndefinedLabels)
-				names << undf.name;
-
-			Error ("labels `%1` are referenced via `goto` but are not defined\n", names);
-		}
-
 		// Dump the last state's onenter and mainloop
 		writeMemberBuffers();
 
@@ -265,7 +239,7 @@
 
 	// stateSpawn is special - it *must* be defined. If we
 	// encountered it, then mark down that we have it.
-	if (-statename == "statespawn")
+	if (statename.ToLowercase() == "statespawn")
 		mStateSpawnDefined = true;
 
 	// Must end in a colon
@@ -415,34 +389,6 @@
 
 // ============================================================================
 //
-void BotscriptParser::ParseGoto()
-{
-	CheckNotToplevel();
-
-	// Get the name of the label
-	mLexer->MustGetNext (TK_Symbol);
-
-	// Find the mark this goto statement points to
-	String target = GetTokenString();
-	ByteMark* mark = buffer()->FindMarkByName (target);
-
-	// If not set, define it
-	if (mark == null)
-	{
-		UndefinedLabel undf;
-		undf.name = target;
-		undf.target = buffer()->AddMark (target);
-		mUndefinedLabels << undf;
-	}
-
-	// Add a reference to the mark.
-	buffer()->WriteDWord (DH_Goto);
-	buffer()->AddReference (mark);
-	mLexer->MustGetNext (TK_Semicolon);
-}
-
-// ============================================================================
-//
 void BotscriptParser::ParseIf()
 {
 	CheckNotToplevel();
@@ -864,35 +810,6 @@
 	mLexer->GetNext (TK_Semicolon);
 }
 
-// ============================================================================
-//
-void BotscriptParser::ParseLabel()
-{
-	CheckNotToplevel();
-	String labelName = GetTokenString();
-	ByteMark* mark = null;
-
-	// See if a mark already exists for this label
-	for (UndefinedLabel& label : mUndefinedLabels)
-	{
-		if (label.name != labelName)
-			continue;
-
-		mark = label.target;
-		buffer()->AdjustMark (mark);
-
-		// No longer undefined
-		mUndefinedLabels.Remove (label);
-		break;
-	}
-
-	// Not found in unmarked lists, define it now
-	if (mark == null)
-		buffer()->AddMark (labelName);
-
-	mLexer->MustGetNext (TK_Colon);
-}
-
 // =============================================================================
 //
 void BotscriptParser::ParseEventdef()
--- a/src/Parser.h	Wed Feb 12 06:50:13 2014 +0200
+++ b/src/Parser.h	Sun Feb 23 17:21:18 2014 +0200
@@ -46,14 +46,6 @@
 class Variable;
 
 // ============================================================================
-//
-struct UndefinedLabel
-{
-	String		name;
-	ByteMark*	target;
-};
-
-// ============================================================================
 // Mark types
 //
 named_enum MarkType
@@ -234,7 +226,6 @@
 		bool					mGotMainLoop;
 		int						mScopeCursor;
 		bool					mCanElse;
-		List<UndefinedLabel>	mUndefinedLabels;
 		int						mHighestGlobalVarIndex;
 		int						mHighestStateVarIndex;
 
--- a/src/Tokens.h	Wed Feb 12 06:50:13 2014 +0200
+++ b/src/Tokens.h	Sun Feb 23 17:21:18 2014 +0200
@@ -95,7 +95,6 @@
 	TK_Eventdef,
 	TK_For,
 	TK_Funcdef,
-	TK_Goto,
 	TK_If,
 	TK_Int,
 	TK_Mainloop,

mercurial