diff -uNr dmd-1.017/dmd/src/dmd/attrib.c dmd-1.018/dmd/src/dmd/attrib.c
--- dmd-1.017/dmd/src/dmd/attrib.c 2007-04-10 14:38:58.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/attrib.c 2007-06-29 15:32:04.000000000 +0200
@@ -1132,6 +1132,7 @@
se = se->toUTF8(sc);
Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
p.loc = loc;
+ p.nextToken();
decl = p.parseDeclDefs(0);
if (p.token.value != TOKeof)
{
diff -uNr dmd-1.017/dmd/src/dmd/class.c dmd-1.018/dmd/src/dmd/class.c
--- dmd-1.017/dmd/src/dmd/class.c 2007-04-10 14:38:58.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/class.c 2007-06-29 21:46:12.000000000 +0200
@@ -523,7 +523,7 @@
alignsize = 0;
structalign = 0;
- sc->pop();
+ sc = sc->pop();
scope = scx ? scx : new Scope(*sc);
scope->setNoFree();
diff -uNr dmd-1.017/dmd/src/dmd/dsymbol.c dmd-1.018/dmd/src/dmd/dsymbol.c
--- dmd-1.017/dmd/src/dmd/dsymbol.c 2007-04-10 23:41:06.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/dsymbol.c 2007-06-30 17:47:10.000000000 +0200
@@ -870,6 +870,14 @@
v->init = new ExpInitializer(0, e);
v->storage_class |= STCconst;
}
+ else if (ce->op == TOKarrayliteral)
+ { /* It is for an array literal, so the
+ * length will be a const.
+ */
+ Expression *e = new IntegerExp(0, ((ArrayLiteralExp *)ce)->elements->dim, Type::tsize_t);
+ v->init = new ExpInitializer(0, e);
+ v->storage_class |= STCconst;
+ }
else if (ce->op == TOKtuple)
{ /* It is for an expression tuple, so the
* length will be a const.
diff -uNr dmd-1.017/dmd/src/dmd/expression.c dmd-1.018/dmd/src/dmd/expression.c
--- dmd-1.017/dmd/src/dmd/expression.c 2007-06-25 22:02:34.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/expression.c 2007-07-01 00:20:34.000000000 +0200
@@ -296,6 +296,7 @@
void expandTuples(Expressions *exps)
{
+ //printf("expandTuples()\n");
if (exps)
{
for (size_t i = 0; i < exps->dim; i++)
@@ -303,6 +304,23 @@
if (!arg)
continue;
+ // Look for tuple with 0 members
+ if (arg->op == TOKtype)
+ { TypeExp *e = (TypeExp *)arg;
+ if (e->type->toBasetype()->ty == Ttuple)
+ { TypeTuple *tt = (TypeTuple *)e->type->toBasetype();
+
+ if (!tt->arguments || tt->arguments->dim == 0)
+ {
+ exps->remove(i);
+ if (i == exps->dim)
+ return;
+ i--;
+ continue;
+ }
+ }
+ }
+
// Inline expand all the tuples
while (arg->op == TOKtuple)
{ TupleExp *te = (TupleExp *)arg;
@@ -655,7 +673,14 @@
{
Expression *e;
if (!size)
+ {
+#ifdef DEBUG
fprintf(stdmsg, "No expression copy for: %s\n", toChars());
+ printf("op = %d\n", op);
+ dump(0);
+#endif
+ assert(0);
+ }
e = (Expression *)mem.malloc(size);
return (Expression *)memcpy(e, this, size);
}
@@ -848,8 +873,14 @@
int Expression::checkSideEffect(int flag)
{
if (flag == 0)
- error("%s has no effect in expression (%s)",
+ { if (op == TOKimport)
+ {
+ error("%s has no effect", toChars());
+ }
+ else
+ error("%s has no effect in expression (%s)",
Token::toChars(op), toChars());
+ }
return 0;
}
@@ -999,10 +1030,14 @@
char *IntegerExp::toChars()
{
+#if 1
+ return Expression::toChars();
+#else
static char buffer[sizeof(value) * 3 + 1];
sprintf(buffer, "%jd", value);
return buffer;
+#endif
}
integer_t IntegerExp::toInteger()
@@ -2425,6 +2460,13 @@
this->elements = elements;
}
+ArrayLiteralExp::ArrayLiteralExp(Loc loc, Expression *e)
+ : Expression(loc, TOKarrayliteral, sizeof(ArrayLiteralExp))
+{
+ elements = new Expressions;
+ elements->push(e);
+}
+
Expression *ArrayLiteralExp::syntaxCopy()
{
return new ArrayLiteralExp(loc, arraySyntaxCopy(elements));
@@ -2656,7 +2698,7 @@
{
this->sd = sd;
this->elements = elements;
- this->s = NULL;
+ this->sym = NULL;
this->soffset = 0;
this->fillHoles = 1;
}
@@ -4387,6 +4429,7 @@
se = se->toUTF8(sc);
Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
p.loc = loc;
+ p.nextToken();
Expression *e = p.parseExpression();
if (p.token.value != TOKeof)
error("incomplete mixin expression (%s)", se->toChars());
@@ -4755,6 +4798,12 @@
#endif
assert(0);
}
+ else if (ident == Id::stringof)
+ { char *s = ie->toChars();
+ e = new StringExp(loc, s, strlen(s), 'c');
+ e = e->semantic(sc);
+ return e;
+ }
error("undefined identifier %s", toChars());
type = Type::tvoid;
return this;
@@ -5350,6 +5399,24 @@
e1 = new DsymbolExp(loc, se->sds);
e1 = e1->semantic(sc);
}
+#if 1 // patch for #540 by Oskar Linde
+ else if (e1->op == TOKdotexp)
+ {
+ DotExp *de = (DotExp *) e1;
+
+ if (de->e2->op == TOKimport)
+ { // This should *really* be moved to ScopeExp::semantic()
+ ScopeExp *se = (ScopeExp *)de->e2;
+ de->e2 = new DsymbolExp(loc, se->sds);
+ de->e2 = de->e2->semantic(sc);
+ }
+
+ if (de->e2->op == TOKtemplate)
+ { TemplateExp *te = (TemplateExp *) de->e2;
+ e1 = new DotTemplateExp(loc,de->e1,te->td);
+ }
+ }
+#endif
}
if (e1->op == TOKcomma)
@@ -7153,7 +7220,7 @@
}
else
{
- error("Can only append to dynamic arrays, not %s ~= %s", tb1->toChars(), tb2->toChars());
+ error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars());
type = Type::tint32;
e = this;
}
@@ -7580,7 +7647,7 @@
Expression *CatExp::semantic(Scope *sc)
{ Expression *e;
- //printf("CatExp::semantic()\n");
+ //printf("CatExp::semantic() %s\n", toChars());
if (!type)
{
BinExp::semanticp(sc);
@@ -7606,12 +7673,22 @@
e2->type->equals(tb1->next))
{
type = tb1->next->arrayOf();
+ if (tb2->ty == Tarray)
+ { // Make e2 into [e2]
+ e2 = new ArrayLiteralExp(e2->loc, e2);
+ e2->type = type;
+ }
return this;
}
else if ((tb2->ty == Tsarray || tb2->ty == Tarray) &&
e1->type->equals(tb2->next))
{
type = tb2->next->arrayOf();
+ if (tb1->ty == Tarray)
+ { // Make e1 into [e1]
+ e1 = new ArrayLiteralExp(e1->loc, e1);
+ e1->type = type;
+ }
return this;
}
@@ -8365,6 +8442,9 @@
unsigned cs0;
unsigned cs1;
+#if LOGSEMANTIC
+ printf("CondExp::semantic('%s')\n", toChars());
+#endif
if (type)
return this;
@@ -8417,6 +8497,22 @@
else
{
typeCombine(sc);
+ switch (e1->type->toBasetype()->ty)
+ {
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ e2 = e2->castTo(sc, e1->type);
+ break;
+ }
+ switch (e2->type->toBasetype()->ty)
+ {
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ e1 = e1->castTo(sc, e2->type);
+ break;
+ }
}
return this;
}
diff -uNr dmd-1.017/dmd/src/dmd/expression.h dmd-1.018/dmd/src/dmd/expression.h
--- dmd-1.017/dmd/src/dmd/expression.h 2007-06-25 22:01:02.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/expression.h 2007-06-30 23:56:26.000000000 +0200
@@ -349,6 +349,7 @@
Expressions *elements;
ArrayLiteralExp(Loc loc, Expressions *elements);
+ ArrayLiteralExp(Loc loc, Expression *e);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
@@ -400,7 +401,7 @@
Expressions *elements; // parallels sd->fields[] with
// NULL entries for fields to skip
- Symbol *s; // back end symbol to initialize with literal
+ Symbol *sym; // back end symbol to initialize with literal
size_t soffset; // offset from start of s
int fillHoles; // fill alignment 'holes' with zero
@@ -540,6 +541,7 @@
VarExp(Loc loc, Declaration *var);
int equals(Object *o);
Expression *semantic(Scope *sc);
+ Expression *optimize(int result);
Expression *interpret(InterState *istate);
void dump(int indent);
char *toChars();
diff -uNr dmd-1.017/dmd/src/dmd/func.c dmd-1.018/dmd/src/dmd/func.c
--- dmd-1.017/dmd/src/dmd/func.c 2007-04-10 14:38:58.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/func.c 2007-06-30 23:30:48.000000000 +0200
@@ -333,19 +333,21 @@
}
// This is an 'introducing' function.
+
+ // Verify this doesn't override previous final function
+ if (cd->baseClass)
+ { Dsymbol *s = cd->baseClass->search(loc, ident, 0);
+ if (s)
+ {
+ FuncDeclaration *f = s->isFuncDeclaration();
+ f = f->overloadExactMatch(type);
+ if (f && f->isFinal() && f->prot() != PROTprivate)
+ error("cannot override final function %s", f->toPrettyChars());
+ }
+ }
+
if (isFinal())
{
- // Verify this doesn't override previous final function
- if (cd->baseClass)
- { Dsymbol *s = cd->baseClass->search(loc, ident, 0);
- if (s)
- {
- FuncDeclaration *f = s->isFuncDeclaration();
- f = f->overloadExactMatch(type);
- if (f && f->isFinal())
- error("cannot override final function %s", f->toPrettyChars());
- }
- }
cd->vtblFinal.push(this);
}
else
@@ -604,6 +606,7 @@
sc2->structalign = 8;
sc2->incontract = 0;
sc2->tf = NULL;
+ sc2->noctor = 0;
// Declare 'this'
ad = isThis();
diff -uNr dmd-1.017/dmd/src/dmd/inline.c dmd-1.018/dmd/src/dmd/inline.c
--- dmd-1.017/dmd/src/dmd/inline.c 2007-06-23 20:08:08.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/inline.c 2007-06-30 18:55:10.000000000 +0200
@@ -822,14 +822,14 @@
Statement *WhileStatement::inlineScan(InlineScanState *iss)
{
condition = condition->inlineScan(iss);
- body = body->inlineScan(iss);
+ body = body ? body->inlineScan(iss) : NULL;
return this;
}
Statement *DoStatement::inlineScan(InlineScanState *iss)
{
- body = body->inlineScan(iss);
+ body = body ? body->inlineScan(iss) : NULL;
condition = condition->inlineScan(iss);
return this;
}
@@ -871,7 +871,7 @@
{
//printf("SwitchStatement::inlineScan()\n");
condition = condition->inlineScan(iss);
- body = body->inlineScan(iss);
+ body = body ? body->inlineScan(iss) : NULL;
if (sdefault)
sdefault = (DefaultStatement *)sdefault->inlineScan(iss);
if (cases)
diff -uNr dmd-1.017/dmd/src/dmd/interpret.c dmd-1.018/dmd/src/dmd/interpret.c
--- dmd-1.017/dmd/src/dmd/interpret.c 2007-06-25 22:07:30.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/interpret.c 2007-06-30 22:32:38.000000000 +0200
@@ -1135,7 +1135,7 @@
if (!expsx)
{ expsx = new Expressions();
expsx->setDim(elements->dim);
- for (size_t j = 0; j < i; j++)
+ for (size_t j = 0; j < elements->dim; j++)
{
expsx->data[j] = elements->data[j];
}
@@ -1941,6 +1941,7 @@
}
else
error("%s failed", toChars());
+ goto Lcant;
}
else
goto Lcant;
diff -uNr dmd-1.017/dmd/src/dmd/lexer.c dmd-1.018/dmd/src/dmd/lexer.c
--- dmd-1.017/dmd/src/dmd/lexer.c 2007-06-20 01:54:08.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/lexer.c 2007-06-30 19:37:34.000000000 +0200
@@ -400,6 +400,7 @@
{
//printf("peekPastParen()\n");
int parens = 1;
+ int curlynest = 0;
while (1)
{
tk = peek(tk);
@@ -417,6 +418,20 @@
tk = peek(tk);
break;
+ case TOKlcurly:
+ curlynest++;
+ continue;
+
+ case TOKrcurly:
+ if (--curlynest >= 0)
+ continue;
+ break;
+
+ case TOKsemicolon:
+ if (curlynest)
+ continue;
+ break;
+
case TOKeof:
break;
diff -uNr dmd-1.017/dmd/src/dmd/mars.c dmd-1.018/dmd/src/dmd/mars.c
--- dmd-1.017/dmd/src/dmd/mars.c 2007-06-22 15:22:02.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/mars.c 2007-06-26 16:48:26.000000000 +0200
@@ -60,7 +60,7 @@
copyright = "Copyright (c) 1999-2007 by Digital Mars";
written = "written by Walter Bright";
- version = "v1.017";
+ version = "v1.018";
global.structalign = 8;
memset(¶ms, 0, sizeof(Param));
diff -uNr dmd-1.017/dmd/src/dmd/mars.h dmd-1.018/dmd/src/dmd/mars.h
--- dmd-1.017/dmd/src/dmd/mars.h 2007-04-10 14:38:58.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/mars.h 2007-06-30 12:28:00.000000000 +0200
@@ -29,7 +29,8 @@
/* Changes for the GDC compiler by David Friedman */
#endif
-#define BREAKABI 1 // not ready to break the ABI just yet
+#define V2 0 // Version 2.0 features
+#define BREAKABI 1 // 0 if not ready to break the ABI just yet
struct Array;
diff -uNr dmd-1.017/dmd/src/dmd/module.c dmd-1.018/dmd/src/dmd/module.c
--- dmd-1.017/dmd/src/dmd/module.c 2007-04-10 14:39:00.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/module.c 2007-06-29 15:32:24.000000000 +0200
@@ -577,6 +577,7 @@
#endif
}
Parser p(this, buf, buflen, docfile != NULL);
+ p.nextToken();
members = p.parseModule();
md = p.md;
numlines = p.loc.linnum;
diff -uNr dmd-1.017/dmd/src/dmd/mtype.c dmd-1.018/dmd/src/dmd/mtype.c
--- dmd-1.017/dmd/src/dmd/mtype.c 2007-06-25 21:29:18.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/mtype.c 2007-07-01 01:24:40.000000000 +0200
@@ -607,7 +607,8 @@
if (v->init->isVoidInitializer())
error(e->loc, "%s.init is void", v->toChars());
else
- { e = v->init->toExpression();
+ { Loc loc = e->loc;
+ e = v->init->toExpression();
if (e->op == TOKassign || e->op == TOKconstruct)
{
e = ((AssignExp *)e)->e2;
@@ -622,6 +623,9 @@
e = v->type->defaultInit();
}
}
+ e = e->optimize(WANTvalue | WANTinterpret);
+// if (!e->isConst())
+// error(loc, ".init cannot be evaluated at compile time");
}
return e;
}
@@ -2019,6 +2023,7 @@
{
case Tfunction:
case Tnone:
+ case Ttuple:
error(loc, "can't have array of %s", tbn->toChars());
tn = next = tint32;
break;
@@ -2362,6 +2367,13 @@
{
//printf("TypePointer::semantic()\n");
Type *n = next->semantic(loc, sc);
+ switch (n->toBasetype()->ty)
+ {
+ case Ttuple:
+ error(loc, "can't have pointer to %s", n->toChars());
+ n = tint32;
+ break;
+ }
if (n != next)
deco = NULL;
next = n;
@@ -3906,20 +3918,7 @@
#endif
if (ident == Id::init)
{
- if (e->op == TOKvar)
- {
- VarExp *ve = (VarExp *)e;
- VarDeclaration *v = ve->var->isVarDeclaration();
-
- assert(v);
- if (v->init)
- { if (v->init->isVoidInitializer())
- error(e->loc, "%s.init is void", v->toChars());
- else
- return v->init->toExpression();
- }
- }
- return defaultInit();
+ return Type::dotExp(sc, e, ident);
}
return sym->basetype->dotExp(sc, e, ident);
}
diff -uNr dmd-1.017/dmd/src/dmd/optimize.c dmd-1.018/dmd/src/dmd/optimize.c
--- dmd-1.017/dmd/src/dmd/optimize.c 2007-04-22 01:10:12.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/optimize.c 2007-07-01 00:55:52.000000000 +0200
@@ -62,6 +62,15 @@
return this;
}
+Expression *VarExp::optimize(int result)
+{
+ if (result & WANTinterpret)
+ {
+ return fromConstInitializer(this);
+ }
+ return this;
+}
+
Expression *TupleExp::optimize(int result)
{
for (size_t i = 0; i < exps->dim; i++)
diff -uNr dmd-1.017/dmd/src/dmd/parse.c dmd-1.018/dmd/src/dmd/parse.c
--- dmd-1.017/dmd/src/dmd/parse.c 2007-05-09 17:45:18.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/parse.c 2007-07-01 01:18:10.000000000 +0200
@@ -60,7 +60,7 @@
linkage = LINKd;
endloc = 0;
inBrackets = 0;
- nextToken(); // start up the scanner
+ //nextToken(); // start up the scanner
}
Array *Parser::parseModule()
@@ -501,7 +501,7 @@
case TOKcolon:
nextToken();
-#if 1
+#if 0
a = NULL;
#else
a = parseDeclDefs(0); // grab declarations up to closing curly bracket
diff -uNr dmd-1.017/dmd/src/dmd/scope.c dmd-1.018/dmd/src/dmd/scope.c
--- dmd-1.017/dmd/src/dmd/scope.c 2007-04-10 14:39:00.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/scope.c 2007-06-29 21:49:22.000000000 +0200
@@ -26,21 +26,26 @@
Scope *Scope::freelist = NULL;
void *Scope::operator new(size_t size)
-{ Scope *s;
-
+{
if (freelist)
{
- s = freelist;
+ Scope *s = freelist;
freelist = s->enclosing;
+ //printf("freelist %p\n", s);
+ assert(s->flags & SCOPEfree);
+ s->flags &= ~SCOPEfree;
return s;
}
- return ::operator new(size);
+ void *p = ::operator new(size);
+ //printf("new %p\n", p);
+ return p;
}
Scope::Scope()
{ // Create root scope
+ //printf("Scope::Scope() %p\n", this);
this->module = NULL;
this->scopesym = NULL;
this->sd = NULL;
@@ -75,6 +80,8 @@
Scope::Scope(Scope *enclosing)
{
+ //printf("Scope::Scope(enclosing = %p) %p\n", enclosing, this);
+ assert(!(enclosing->flags & SCOPEfree));
this->module = enclosing->module;
this->func = enclosing->func;
this->parent = enclosing->parent;
@@ -87,6 +94,15 @@
this->fes = enclosing->fes;
this->structalign = enclosing->structalign;
this->enclosing = enclosing;
+#ifdef DEBUG
+ if (enclosing->enclosing)
+ assert(!(enclosing->enclosing->flags & SCOPEfree));
+ if (this == enclosing->enclosing)
+ {
+ printf("this = %p, enclosing = %p, enclosing->enclosing = %p\n", this, enclosing, enclosing->enclosing);
+ }
+ assert(this != enclosing->enclosing);
+#endif
this->slabel = NULL;
this->linkage = enclosing->linkage;
this->protection = enclosing->protection;
@@ -148,7 +164,7 @@
Scope *Scope::pop()
{
- //printf("Scope::pop()\n");
+ //printf("Scope::pop() %p nofree = %d\n", this, nofree);
Scope *enc = enclosing;
if (enclosing)
@@ -157,6 +173,7 @@
if (!nofree)
{ enclosing = freelist;
freelist = this;
+ flags |= SCOPEfree;
}
return enc;
@@ -323,9 +340,18 @@
void Scope::setNoFree()
{ Scope *sc;
+ //int i = 0;
+ //printf("Scope::setNoFree(this = %p)\n", this);
for (sc = this; sc; sc = sc->enclosing)
{
+ //printf("\tsc = %p\n", sc);
sc->nofree = 1;
+
+ assert(!(flags & SCOPEfree));
+ //assert(sc != sc->enclosing);
+ //assert(!sc->enclosing || sc != sc->enclosing->enclosing);
+ //if (++i == 10)
+ //assert(0);
}
}
diff -uNr dmd-1.017/dmd/src/dmd/scope.h dmd-1.018/dmd/src/dmd/scope.h
--- dmd-1.017/dmd/src/dmd/scope.h 2007-04-10 14:38:58.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/scope.h 2007-06-29 21:33:20.000000000 +0200
@@ -76,6 +76,7 @@
unsigned flags;
#define SCOPEctor 1 // constructor type
#define SCOPEstaticif 2 // inside static if
+#define SCOPEfree 4 // is on free list
AnonymousAggregateDeclaration *anonAgg; // for temporary analysis
diff -uNr dmd-1.017/dmd/src/dmd/statement.c dmd-1.018/dmd/src/dmd/statement.c
--- dmd-1.017/dmd/src/dmd/statement.c 2007-06-25 22:33:58.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/statement.c 2007-07-01 01:32:58.000000000 +0200
@@ -251,6 +251,7 @@
se = se->toUTF8(sc);
Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
p.loc = loc;
+ p.nextToken();
Statements *statements = new Statements();
while (p.token.value != TOKeof)
@@ -781,7 +782,7 @@
Statement *WhileStatement::syntaxCopy()
{
- WhileStatement *s = new WhileStatement(loc, condition->syntaxCopy(), body->syntaxCopy());
+ WhileStatement *s = new WhileStatement(loc, condition->syntaxCopy(), body ? body->syntaxCopy() : NULL);
return s;
}
@@ -821,7 +822,8 @@
Scope *scd = sc->push();
scd->sbreak = this;
scd->scontinue = this;
- body = body->semantic(scd);
+ if (body)
+ body = body->semantic(scd);
scd->pop();
sc->noctor--;
@@ -841,12 +843,13 @@
int WhileStatement::usesEH()
{
- return body->usesEH();
+ return body ? body->usesEH() : 0;
}
int WhileStatement::fallOffEnd()
{
- body->fallOffEnd();
+ if (body)
+ body->fallOffEnd();
return TRUE;
}
@@ -863,7 +866,8 @@
condition->toCBuffer(buf, hgs);
buf->writebyte(')');
buf->writenl();
- body->toCBuffer(buf, hgs);
+ if (body)
+ body->toCBuffer(buf, hgs);
}
/******************************** DoStatement ***************************/
@@ -877,7 +881,7 @@
Statement *DoStatement::syntaxCopy()
{
- DoStatement *s = new DoStatement(loc, body->syntaxCopy(), condition->syntaxCopy());
+ DoStatement *s = new DoStatement(loc, body ? body->syntaxCopy() : NULL, condition->syntaxCopy());
return s;
}
@@ -885,7 +889,8 @@
Statement *DoStatement::semantic(Scope *sc)
{
sc->noctor++;
- body = body->semanticScope(sc, this, this);
+ if (body)
+ body = body->semanticScope(sc, this, this);
sc->noctor--;
condition = condition->semantic(sc);
condition = resolveProperties(sc, condition);
@@ -907,12 +912,13 @@
int DoStatement::usesEH()
{
- return body->usesEH();
+ return body ? body->usesEH() : 0;
}
int DoStatement::fallOffEnd()
{
- body->fallOffEnd();
+ if (body)
+ body->fallOffEnd();
return TRUE;
}
@@ -927,7 +933,8 @@
{
buf->writestring("do");
buf->writenl();
- body->toCBuffer(buf, hgs);
+ if (body)
+ body->toCBuffer(buf, hgs);
buf->writestring("while (");
condition->toCBuffer(buf, hgs);
buf->writebyte(')');
@@ -1192,7 +1199,14 @@
{
arg->type = e->type;
Initializer *ie = new ExpInitializer(0, e);
- var = new VarDeclaration(loc, arg->type, arg->ident, ie);
+ VarDeclaration *v = new VarDeclaration(loc, arg->type, arg->ident, ie);
+ if (e->isConst())
+ v->storage_class |= STCconst;
+#if V2
+ else
+ v->storage_class |= STCfinal;
+#endif
+ var = v;
}
}
else
@@ -2057,12 +2071,13 @@
int SwitchStatement::usesEH()
{
- return body->usesEH();
+ return body ? body->usesEH() : 0;
}
int SwitchStatement::fallOffEnd()
{
- body->fallOffEnd();
+ if (body)
+ body->fallOffEnd();
return TRUE; // need to do this better
}
@@ -2821,7 +2836,7 @@
Statement *SynchronizedStatement::syntaxCopy()
{
Expression *e = exp ? exp->syntaxCopy() : NULL;
- SynchronizedStatement *s = new SynchronizedStatement(loc, e, body->syntaxCopy());
+ SynchronizedStatement *s = new SynchronizedStatement(loc, e, body ? body->syntaxCopy() : NULL);
return s;
}
@@ -2843,7 +2858,8 @@
exp = exp->semantic(sc);
}
}
- body = body->semantic(sc);
+ if (body)
+ body = body->semantic(sc);
return this;
}
@@ -2864,7 +2880,7 @@
int SynchronizedStatement::fallOffEnd()
{
- return body->fallOffEnd();
+ return body ? body->fallOffEnd() : TRUE;
}
void SynchronizedStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
@@ -2894,7 +2910,7 @@
Statement *WithStatement::syntaxCopy()
{
- WithStatement *s = new WithStatement(loc, exp->syntaxCopy(), body->syntaxCopy());
+ WithStatement *s = new WithStatement(loc, exp->syntaxCopy(), body ? body->syntaxCopy() : NULL);
return s;
}
@@ -2950,7 +2966,8 @@
}
sc = sc->push(sym);
- body = body->semantic(sc);
+ if (body)
+ body = body->semantic(sc);
sc->pop();
@@ -2962,17 +2979,18 @@
buf->writestring("with (");
exp->toCBuffer(buf, hgs);
buf->writestring(")\n");
- body->toCBuffer(buf, hgs);
+ if (body)
+ body->toCBuffer(buf, hgs);
}
int WithStatement::usesEH()
{
- return body->usesEH();
+ return body ? body->usesEH() : 0;
}
int WithStatement::fallOffEnd()
{
- return body->fallOffEnd();
+ return body ? body->fallOffEnd() : TRUE;
}
/******************************** TryCatchStatement ***************************/
@@ -3015,7 +3033,7 @@
char *si = c->loc.toChars();
char *sj = cj->loc.toChars();
- if (c->type->implicitConvTo(cj->type))
+ if (c->type->toBasetype()->implicitConvTo(cj->type->toBasetype()))
error("catch at %s hides catch at %s", sj, si);
}
}
@@ -3343,7 +3361,7 @@
Statement *VolatileStatement::semantic(Scope *sc)
{
- statement = statement->semantic(sc);
+ statement = statement ? statement->semantic(sc) : NULL;
return this;
}
@@ -3351,7 +3369,7 @@
{
Statements *a;
- a = statement->flatten(sc);
+ a = statement ? statement->flatten(sc) : NULL;
if (a)
{ for (int i = 0; i < a->dim; i++)
{ Statement *s = (Statement *)a->data[i];
@@ -3366,7 +3384,7 @@
int VolatileStatement::fallOffEnd()
{
- return statement->fallOffEnd();
+ return statement ? statement->fallOffEnd() : TRUE;
}
void VolatileStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
diff -uNr dmd-1.017/dmd/src/dmd/template.c dmd-1.018/dmd/src/dmd/template.c
--- dmd-1.017/dmd/src/dmd/template.c 2007-06-24 22:57:46.000000000 +0200
+++ dmd-1.018/dmd/src/dmd/template.c 2007-06-29 15:35:40.000000000 +0200
@@ -1144,6 +1144,10 @@
}
if (equals(at))
goto Lexact;
+ else if (ty == Tclass && at->ty == Tclass)
+ {
+ return (MATCH) implicitConvTo(at);
+ }
else if (ty == Tsarray && at->ty == Tarray &&
next->equals(at->next))
{
diff -uNr dmd-1.017/dmd/src/phobos/std/bind.d dmd-1.018/dmd/src/phobos/std/bind.d
--- dmd-1.017/dmd/src/phobos/std/bind.d 2007-06-26 11:32:44.000000000 +0200
+++ dmd-1.018/dmd/src/phobos/std/bind.d 2007-07-01 11:10:38.000000000 +0200
@@ -761,7 +761,7 @@
static if (is(T == void)) { // void means that we aren't adding anything
alias tmp res;
} else {
- alias tmp.prependT!(T) res;
+ alias tmp.meta.prependT!(T) res;
}
}
diff -uNr dmd-1.017/dmd/src/phobos/std/date.d dmd-1.018/dmd/src/phobos/std/date.d
--- dmd-1.017/dmd/src/phobos/std/date.d 2007-06-26 11:32:44.000000000 +0200
+++ dmd-1.018/dmd/src/phobos/std/date.d 2007-07-01 11:10:38.000000000 +0200
@@ -763,6 +763,7 @@
{
case TIME_ZONE_ID_STANDARD:
case TIME_ZONE_ID_DAYLIGHT:
+ case TIME_ZONE_ID_UNKNOWN:
//printf("bias = %d\n", tzi.Bias);
//printf("standardbias = %d\n", tzi.StandardBias);
//printf("daylightbias = %d\n", tzi.DaylightBias);
diff -uNr dmd-1.017/dmd/src/phobos/std/intrinsic.d dmd-1.018/dmd/src/phobos/std/intrinsic.d
--- dmd-1.017/dmd/src/phobos/std/intrinsic.d 2007-06-26 11:32:44.000000000 +0200
+++ dmd-1.018/dmd/src/phobos/std/intrinsic.d 2007-07-01 11:10:38.000000000 +0200
@@ -37,6 +37,7 @@
* The return value is undefined if v is zero.
* Example:
* ---
+ * import std.stdio;
* import std.intrinsic;
*
* int main()
@@ -46,9 +47,9 @@
*
* v = 0x21;
* x = bsf(v);
- * printf("bsf(x%x) = %d\n", v, x);
+ * writefln("bsf(x%x) = %d", v, x);
* x = bsr(v);
- * printf("bsr(x%x) = %d\n", v, x);
+ * writefln("bsr(x%x) = %d", v, x);
* return 0;
* }
* ---
@@ -88,6 +89,7 @@
*
* Example:
* ---
+import std.stdio;
import std.intrinsic;
int main()
@@ -97,20 +99,20 @@
array[0] = 2;
array[1] = 0x100;
- printf("btc(array, 35) = %d\n", btc(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
+ writefln("btc(array, 35) = %d", btc(array, 35));
+ writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
- printf("btc(array, 35) = %d\n", btc(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
+ writefln("btc(array, 35) = %d", btc(array, 35));
+ writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
- printf("bts(array, 35) = %d\n", bts(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
+ writefln("bts(array, 35) = %d", bts(array, 35));
+ writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
- printf("btr(array, 35) = %d\n", btr(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
+ writefln("btr(array, 35) = %d", btr(array, 35));
+ writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
- printf("bt(array, 1) = %d\n", bt(array, 1));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
+ writefln("bt(array, 1) = %d", bt(array, 1));
+ writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
return 0;
}
diff -uNr dmd-1.017/dmd/src/phobos/std/metastrings.d dmd-1.018/dmd/src/phobos/std/metastrings.d
--- dmd-1.017/dmd/src/phobos/std/metastrings.d 2007-06-26 11:32:44.000000000 +0200
+++ dmd-1.018/dmd/src/phobos/std/metastrings.d 2007-07-01 11:10:38.000000000 +0200
@@ -34,7 +34,7 @@
void main()
{
- char[] s = Format!("Arg %s = %s", "foo", 27);
+ string s = Format!("Arg %s = %s", "foo", 27);
writefln(s); // "Arg foo = 27"
}
* ---
@@ -51,7 +51,7 @@
const char[] Format = ToString!(A[0]) ~ Format!(A[1..$]);
}
-template FormatString(char[] F, A...)
+template FormatString(string F, A...)
{
static if (F.length == 0)
const char[] FormatString = Format!(A);
@@ -85,9 +85,11 @@
static if (I < 0)
const char[] ToString = "-" ~ ToString!(cast(ulong)(-I));
else
- const char[] ToString = ToString!(cast(uint)I);
+ const char[] ToString = ToString!(cast(ulong)I);
}
+static assert(ToString!(0x100000000) == "4294967296");
+
/// ditto
template ToString(uint U)
{
@@ -131,7 +133,7 @@
}
/// ditto
-template ToString(char[] S)
+template ToString(string S)
{
const char[] ToString = S;
}
@@ -144,7 +146,7 @@
unittest
{
- char[] s = Format!("hel%slo", "world", -138, 'c', true);
+ string s = Format!("hel%slo", "world", -138, 'c', true);
assert(s == "helworldlo-138ctrue");
}
@@ -159,7 +161,7 @@
* .rest = s
*/
-template ParseUinteger(char[] s)
+template ParseUinteger(string s)
{
static if (s.length == 0)
{ const char[] value = "";
@@ -186,7 +188,7 @@
* .rest = s
*/
-template ParseInteger(char[] s)
+template ParseInteger(string s)
{
static if (s.length == 0)
{ const char[] value = "";
diff -uNr dmd-1.017/dmd/src/phobos/std/string.d dmd-1.018/dmd/src/phobos/std/string.d
--- dmd-1.017/dmd/src/phobos/std/string.d 2007-06-26 11:32:44.000000000 +0200
+++ dmd-1.018/dmd/src/phobos/std/string.d 2007-07-01 11:10:38.000000000 +0200
@@ -263,8 +263,8 @@
}
/******************************************
- * find, ifind _find first occurrance of c in string s.
- * rfind, irfind _find last occurrance of c in string s.
+ * find, ifind _find first occurrence of c in string s.
+ * rfind, irfind _find last occurrence of c in string s.
*
* find, rfind are case sensitive; ifind, irfind are case insensitive.
* Returns:
@@ -479,8 +479,8 @@
/******************************************
- * find, ifind _find first occurrance of sub[] in string s[].
- * rfind, irfind _find last occurrance of sub[] in string s[].
+ * find, ifind _find first occurrence of sub[] in string s[].
+ * rfind, irfind _find last occurrence of sub[] in string s[].
*
* find, rfind are case sensitive; ifind, irfind are case insensitive.
* Returns:
@@ -612,7 +612,7 @@
{
size_t imax = s.length - sublength;
- for (i = 0; i < imax; i++)
+ for (i = 0; i <= imax; i++)
{
if (icmp(s[i .. i + sublength], sub) == 0)
return i;
@@ -658,6 +658,9 @@
i = ifind(sPlts, sPlts);
assert(i == 0);
+ i = ifind("\u0100", "\u0100");
+ assert(i == 0);
+
// Thanks to Carlos Santander B. and zwang
i = ifind("sus mejores cortesanos. Se embarcaron en el puerto de Dubai y",
"page-break-before");
@@ -807,10 +810,10 @@
* Convert string s[] to lower case.
*/
-char[] tolower(char[] s)
+string tolower(string s)
{
- bool changed;
- auto r = s;
+ int changed;
+ char[] r;
for (size_t i = 0; i < s.length; i++)
{
@@ -820,13 +823,13 @@
if (!changed)
{
r = s.dup;
- changed = true;
+ changed = 1;
}
r[i] = cast(char) (c + (cast(char)'a' - 'A'));
}
- else if (c >= 0x7F)
+ else if (c > 0x7F)
{
- foreach(size_t j, dchar dc; s[i .. length])
+ foreach (size_t j, dchar dc; s[i .. length])
{
if (std.uni.isUniUpper(dc))
{
@@ -834,20 +837,22 @@
if (!changed)
{
r = s[0 .. i + j].dup;
- changed = true;
+ changed = 2;
}
}
if (changed)
{
- if (r.length != i + j)
- r = r[0 .. i + j];
+ if (changed == 1)
+ { r = r[0 .. i + j];
+ changed = 2;
+ }
std.utf.encode(r, dc);
}
}
break;
}
}
- return r;
+ return changed ? r : s;
}
unittest
@@ -870,16 +875,21 @@
s2 = tolower(s1);
assert(cmp(s2, "a\u0461b\u0461d") == 0);
assert(s2 !is s1);
+
+ s1 = "\u0130";
+ s2 = tolower(s1);
+ assert(s2 == "i");
+ assert(s2 !is s1);
}
/************************************
* Convert string s[] to upper case.
*/
-char[] toupper(char[] s)
+string toupper(string s)
{
- bool changed;
- auto r = s;
+ int changed;
+ char[] r;
for (size_t i = 0; i < s.length; i++)
{
@@ -889,13 +899,13 @@
if (!changed)
{
r = s.dup;
- changed = true;
+ changed = 1;
}
r[i] = cast(char) (c - (cast(char)'a' - 'A'));
}
- else if (c >= 0x7F)
+ else if (c > 0x7F)
{
- foreach(size_t j, dchar dc; s[i .. length])
+ foreach (size_t j, dchar dc; s[i .. length])
{
if (std.uni.isUniLower(dc))
{
@@ -903,20 +913,22 @@
if (!changed)
{
r = s[0 .. i + j].dup;
- changed = true;
+ changed = 2;
}
}
if (changed)
{
- if (r.length != i + j)
- r = r[0 .. i + j];
+ if (changed == 1)
+ { r = r[0 .. i + j];
+ changed = 2;
+ }
std.utf.encode(r, dc);
}
}
break;
}
}
- return r;
+ return changed ? r : s;
}
unittest