diff dmd2/parse.c @ 1526:54b3c1394d62

Merged dmdfe 2.031.
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 07 Jul 2009 02:26:11 +0100
parents 638d16625da2
children e4f7b5d9c68a
line wrap: on
line diff
--- a/dmd2/parse.c	Mon Jul 06 23:57:27 2009 +0100
+++ b/dmd2/parse.c	Tue Jul 07 02:26:11 2009 +0100
@@ -3144,6 +3144,7 @@
     Condition *condition;
     Statement *ifbody;
     Statement *elsebody;
+    bool isfinal;
     Loc loc = this->loc;
 
     //printf("parseStatement()\n");
@@ -3245,13 +3246,21 @@
 	    goto Ldeclaration;
 	}
 
+	case TOKfinal:
+	    if (peekNext() == TOKswitch)
+	    {
+		nextToken();
+		isfinal = TRUE;
+		goto Lswitch;
+	    }
+	    goto Ldeclaration;
+
 	CASE_BASIC_TYPES:
 	case TOKtypedef:
 	case TOKalias:
 	case TOKconst:
 	case TOKauto:
 	case TOKextern:
-	case TOKfinal:
 	case TOKinvariant:
 #if DMDV2
 	case TOKimmutable:
@@ -3651,15 +3660,17 @@
 	}
 
 	case TOKswitch:
-	{   Expression *condition;
-	    Statement *body;
-
+	    isfinal = FALSE;
+	    goto Lswitch;
+
+	Lswitch:
+	{
 	    nextToken();
 	    check(TOKlparen);
-	    condition = parseExpression();
+	    Expression *condition = parseExpression();
 	    check(TOKrparen);
-	    body = parseStatement(PSscope);
-	    s = new SwitchStatement(loc, condition, body);
+	    Statement *body = parseStatement(PSscope);
+	    s = new SwitchStatement(loc, condition, body, isfinal);
 	    break;
 	}
 
@@ -3667,6 +3678,7 @@
 	{   Expression *exp;
 	    Statements *statements;
 	    Array cases;	// array of Expression's
+	    Expression *last = NULL;
 
 	    while (1)
 	    {
@@ -3678,6 +3690,20 @@
 	    }
 	    check(TOKcolon);
 
+#if DMDV2
+	    /* case exp: .. case last:
+	     */
+	    if (token.value == TOKslice)
+	    {
+		if (cases.dim > 1)
+		    error("only one case allowed for start of case range");
+		nextToken();
+		check(TOKcase);
+		last = parseAssignExp();
+		check(TOKcolon);
+	    }
+#endif
+
 	    statements = new Statements();
 	    while (token.value != TOKcase &&
 		   token.value != TOKdefault &&
@@ -3688,11 +3714,20 @@
 	    s = new CompoundStatement(loc, statements);
 	    s = new ScopeStatement(loc, s);
 
-	    // Keep cases in order by building the case statements backwards
-	    for (int i = cases.dim; i; i--)
+#if DMDV2
+	    if (last)
 	    {
-		exp = (Expression *)cases.data[i - 1];
-		s = new CaseStatement(loc, exp, s);
+		s = new CaseRangeStatement(loc, exp, last, s);
+	    }
+	    else
+#endif
+	    {
+		// Keep cases in order by building the case statements backwards
+		for (int i = cases.dim; i; i--)
+		{
+		    exp = (Expression *)cases.data[i - 1];
+		    s = new CaseStatement(loc, exp, s);
+		}
 	    }
 	    break;
 	}
@@ -4024,6 +4059,8 @@
  *	needId	0	no identifier
  *		1	identifier optional
  *		2	must have identifier
+ * Output:
+ *	if *pt is not NULL, it is set to the ending token, which would be endtok
  */
 
 int Parser::isDeclaration(Token *t, int needId, enum TOK endtok, Token **pt)
@@ -4062,7 +4099,7 @@
 	goto Lisnot;
 
 Lis:
-    //printf("\tis declaration\n");
+    //printf("\tis declaration, t = %s\n", t->toChars());
     return TRUE;
 
 Lisnot:
@@ -4357,7 +4394,6 @@
 int Parser::isParameters(Token **pt)
 {   // This code parallels parseParameters()
     Token *t = *pt;
-    int tmp;
 
     //printf("isParameters()\n");
     if (t->value != TOKlparen)
@@ -4366,6 +4402,7 @@
     t = peek(t);
     for (;1; t = peek(t))
     {
+     L1:
 	switch (t->value)
 	{
 	    case TOKrparen:
@@ -4380,12 +4417,23 @@
 	    case TOKinout:
 	    case TOKref:
 	    case TOKlazy:
+	    case TOKfinal:
+		continue;
+
 	    case TOKconst:
 	    case TOKinvariant:
 	    case TOKimmutable:
 	    case TOKshared:
-	    case TOKfinal:
-		continue;
+		t = peek(t);
+		if (t->value == TOKlparen)
+		{
+		    t = peek(t);
+		    if (!isDeclaration(t, 0, TOKrparen, &t))
+			return FALSE;
+		    t = peek(t);	// skip past closing ')'
+		    goto L2;
+		}
+		goto L1;
 
 #if 0
 	    case TOKstatic:
@@ -4404,9 +4452,10 @@
 #endif
 
 	    default:
-		if (!isBasicType(&t))
+	    {	if (!isBasicType(&t))
 		    return FALSE;
-		tmp = FALSE;
+	    L2:
+		int tmp = FALSE;
 		if (t->value != TOKdotdotdot &&
 		    !isDeclarator(&t, &tmp, TOKreserved))
 		    return FALSE;
@@ -4420,6 +4469,7 @@
 		    t = peek(t);
 		    break;
 		}
+	    }
 	    L3:
 		if (t->value == TOKcomma)
 		{