[Issue 3827] automatic joining of adjacent strings is bad

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 13 23:53:12 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3827


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #15 from Don <clugdbug at yahoo.com.au> 2010-11-13 23:51:58 PST ---
(In reply to comment #14)
> you don't need to mess with associativity rules, you just need to be able to
> handle two or three ast cases:
> 
> 1. (~ str str)        ie  str ~ str
> 2. (~ (~ x str) str)  ie  x ~ str ~ str
> 3. (~ str (~ str x))  ie  str ~ (str ~ x)

Like this (optimize.c, line 1023):

Expression *CatExp::optimize(int result)
{   Expression *e;

    //printf("CatExp::optimize(%d) %s\n", result, toChars());
    e1 = e1->optimize(result);
    e2 = e2->optimize(result);

+    if (e1->op == TOKcat && (e2->op == TOKstring || e2->op == TOKnull)
+            && (((CatExp *)e1)->e2->op == TOKstring || ((CatExp *)e1)->e2->op
== TOKnull))
+    {
+        // Convert  (e ~ str) ~ str into  e ~ (str ~ str)
+        CatExp *ce = ((CatExp *)e1);
+        e1 = ce->e1;
+        ce->e1 = ce->e2;
+        ce->e2 = e2;
+        e2 = ce;       
+    }
    e = Cat(type, e1, e2);
    if (e == EXP_CANT_INTERPRET)
        e = this;
    return e;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list