changeset 658:50383e476c7e

Upgraded frontend to DMD 1.035
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 06 Oct 2008 16:22:11 +0200
parents c42173b3557b
children 43d2ab9833bf
files dmd/attrib.c dmd/class.c dmd/constfold.c dmd/declaration.c dmd/func.c dmd/id.c dmd/id.h dmd/idgen.c dmd/interpret.c dmd/lexer.c dmd/lexer.h dmd/mars.c dmd/mtype.c dmd/mtype.h dmd/parse.c dmd/root.c dmd/root.h
diffstat 17 files changed, 130 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/attrib.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/attrib.c	Mon Oct 06 16:22:11 2008 +0200
@@ -34,7 +34,7 @@
 #include "../gen/enums.h"
 #include "../gen/logger.h"
 
-extern void obj_includelib(char *name);
+extern void obj_includelib(const char *name);
 void obj_startaddress(Symbol *s);
 
 
--- a/dmd/class.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/class.c	Mon Oct 06 16:22:11 2008 +0200
@@ -477,10 +477,22 @@
 	    if (storage_class & STCstatic)
 		error("static class cannot inherit from nested class %s", baseClass->toChars());
 	    if (toParent2() != baseClass->toParent2())
-		error("super class %s is nested within %s, not %s",
+	    {
+		if (toParent2())
+		{
+		    error("is nested within %s, but super class %s is nested within %s",
+			toParent2()->toChars(),
 			baseClass->toChars(),
-			baseClass->toParent2()->toChars(),
-			toParent2()->toChars());
+			baseClass->toParent2()->toChars());
+		}
+		else
+		{
+		    error("is not nested, but super class %s is nested within %s",
+			baseClass->toChars(),
+			baseClass->toParent2()->toChars());
+		}
+		isnested = 0;
+	    }
 	}
 	else if (!(storage_class & STCstatic))
 	{   Dsymbol *s = toParent2();
@@ -579,7 +591,7 @@
      * They must be in this class, not in a base class.
      */
     ctor = (CtorDeclaration *)search(0, Id::ctor, 0);
-    if (ctor && ctor->toParent() != this)
+    if (ctor && (ctor->toParent() != this || !ctor->isCtorDeclaration()))
 	ctor = NULL;
 
 //    dtor = (DtorDeclaration *)search(Id::dtor, 0);
--- a/dmd/constfold.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/constfold.c	Mon Oct 06 16:22:11 2008 +0200
@@ -706,7 +706,11 @@
     {	StringExp *es1 = (StringExp *)e1;
 	StringExp *es2 = (StringExp *)e2;
 
-	assert(es1->sz == es2->sz);
+	if (es1->sz != es2->sz)
+	{
+	    assert(global.errors);
+	    return EXP_CANT_INTERPRET;
+	}
 	if (es1->len == es2->len &&
 	    memcmp(es1->string, es2->string, es1->sz * es1->len) == 0)
 	    cmp = 1;
@@ -1344,7 +1348,14 @@
 	size_t len = es1->len + es2->len;
 	int sz = es1->sz;
 
-	assert(sz == es2->sz);
+	if (sz != es2->sz)
+	{
+	    /* Can happen with:
+	     *   auto s = "foo"d ~ "bar"c;
+	     */
+	    assert(global.errors);
+	    return e;
+	}
 	s = mem.malloc((len + 1) * sz);
 	memcpy(s, es1->string, es1->len * sz);
 	memcpy((unsigned char *)s + es1->len * sz, es2->string, es2->len * sz);
--- a/dmd/declaration.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/declaration.c	Mon Oct 06 16:22:11 2008 +0200
@@ -898,6 +898,9 @@
 
     if (init)
     {
+	sc = sc->push();
+	sc->stc &= ~(STCconst | STCinvariant | STCpure);
+
 	ArrayInitializer *ai = init->isArrayInitializer();
 	if (ai && tb->ty == Taarray)
 	{
@@ -1031,6 +1034,7 @@
 		    init = i2;		// no errors, keep result
 	    }
 	}
+	sc = sc->pop();
     }
 }
 
--- a/dmd/func.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/func.c	Mon Oct 06 16:22:11 2008 +0200
@@ -140,6 +140,9 @@
     //printf("function storage_class = x%x\n", storage_class);
     Dsymbol *parent = toParent();
 
+    if (ident == Id::ctor && !isCtorDeclaration())
+	error("_ctor is reserved for constructors");
+
     if (isConst() || isAuto() || isScope())
 	error("functions cannot be const or auto");
 
@@ -2543,7 +2546,7 @@
 	sa->push(s);
 	Expression *e = new IdentifierExp(0, id);
 	e = new AddAssignExp(0, e, new IntegerExp(-1));
-	e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(1));
+	e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0));
 	s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL);
 	sa->push(s);
 	if (fbody)
--- a/dmd/id.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/id.c	Mon Oct 06 16:22:11 2008 +0200
@@ -164,9 +164,9 @@
 Identifier *Id::aaKeys;
 Identifier *Id::aaValues;
 Identifier *Id::aaRehash;
+Identifier *Id::GNU_asm;
 Identifier *Id::lib;
 Identifier *Id::msg;
-Identifier *Id::GNU_asm;
 Identifier *Id::intrinsic;
 Identifier *Id::va_intrinsic;
 Identifier *Id::no_typeinfo;
@@ -346,9 +346,9 @@
     aaKeys = Lexer::idPool("_aaKeys");
     aaValues = Lexer::idPool("_aaValues");
     aaRehash = Lexer::idPool("_aaRehash");
+    GNU_asm = Lexer::idPool("GNU_asm");
     lib = Lexer::idPool("lib");
     msg = Lexer::idPool("msg");
-    GNU_asm = Lexer::idPool("GNU_asm");
     intrinsic = Lexer::idPool("intrinsic");
     va_intrinsic = Lexer::idPool("va_intrinsic");
     no_typeinfo = Lexer::idPool("no_typeinfo");
--- a/dmd/id.h	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/id.h	Mon Oct 06 16:22:11 2008 +0200
@@ -166,9 +166,9 @@
     static Identifier *aaKeys;
     static Identifier *aaValues;
     static Identifier *aaRehash;
+    static Identifier *GNU_asm;
     static Identifier *lib;
     static Identifier *msg;
-    static Identifier *GNU_asm;
     static Identifier *intrinsic;
     static Identifier *va_intrinsic;
     static Identifier *no_typeinfo;
--- a/dmd/idgen.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/idgen.c	Mon Oct 06 16:22:11 2008 +0200
@@ -1,6 +1,6 @@
 
 // Compiler implementation of the D programming language
-// Copyright (c) 1999-2006 by Digital Mars
+// Copyright (c) 1999-2008 by Digital Mars
 // All Rights Reserved
 // written by Walter Bright
 // http://www.digitalmars.com
@@ -22,8 +22,8 @@
 
 struct Msgtable
 {
-	char *ident;	// name to use in DMD source
-	char *name;	// name in D executable
+	const char *ident;	// name to use in DMD source
+	const char *name;	// name in D executable
 };
 
 Msgtable msgtable[] =
@@ -209,9 +209,9 @@
     { "aaRehash", "_aaRehash" },
 
     // For pragma's
+    { "GNU_asm" },
     { "lib" },
     { "msg" },
-    { "GNU_asm" },
 
     // LLVMDC pragma's
     { "intrinsic" },
@@ -225,7 +225,7 @@
     { "vaarg", "va_arg" },
     { "llvmdc" },
 
-    // For toHash/toString
+    // For special functions
     { "tohash", "toHash" },
     { "tostring", "toString" },
 
@@ -260,7 +260,7 @@
 	fprintf(fp, "{\n");
 
 	for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
-	{   char *id = msgtable[i].ident;
+	{   const char *id = msgtable[i].ident;
 
 	    fprintf(fp,"    static Identifier *%s;\n", id);
 	}
@@ -285,8 +285,8 @@
 	fprintf(fp, "#include \"lexer.h\"\n");
 
 	for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
-	{   char *id = msgtable[i].ident;
-	    char *p = msgtable[i].name;
+	{   const char *id = msgtable[i].ident;
+	    const char *p = msgtable[i].name;
 
 	    if (!p)
 		p = id;
@@ -297,8 +297,8 @@
 	fprintf(fp, "{\n");
 
 	for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
-	{   char *id = msgtable[i].ident;
-	    char *p = msgtable[i].name;
+	{   const char *id = msgtable[i].ident;
+	    const char *p = msgtable[i].name;
 
 	    if (!p)
 		p = id;
--- a/dmd/interpret.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/interpret.c	Mon Oct 06 16:22:11 2008 +0200
@@ -77,10 +77,11 @@
 	return NULL;
     }
 
-    //printf("test2 %d, %p\n", semanticRun, scope);
     if (semanticRun == 0 && scope)
     {
 	semantic3(scope);
+    if (global.errors)  // if errors compiling this function
+        return NULL;
     }
     if (semanticRun < 2)
 	return NULL;
--- a/dmd/lexer.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/lexer.c	Mon Oct 06 16:22:11 2008 +0200
@@ -88,7 +88,7 @@
 
 /************************* Token **********************************************/
 
-char *Token::tochars[TOKMAX];
+const char *Token::tochars[TOKMAX];
 
 void *Token::operator new(size_t size)
 {   Token *t;
@@ -110,8 +110,8 @@
 }
 #endif
 
-char *Token::toChars()
-{   char *p;
+const char *Token::toChars()
+{   const char *p;
     static char buffer[3 + 3 * sizeof(value) + 1];
 
     p = buffer;
@@ -239,8 +239,8 @@
     return p;
 }
 
-char *Token::toChars(enum TOK value)
-{   char *p;
+const char *Token::toChars(enum TOK value)
+{   const char *p;
     static char buffer[3 + 3 * sizeof(value) + 1];
 
     p = tochars[value];
@@ -467,7 +467,7 @@
     while (p[idx])
     {   dchar_t dc;
 
-	char *q = utf_decodeChar((unsigned char *)p, len, &idx, &dc);
+	const char *q = utf_decodeChar((unsigned char *)p, len, &idx, &dc);
 	if (q)
 	    goto Linvalid;
 
@@ -718,7 +718,7 @@
 		    {	unsigned major = 0;
 			unsigned minor = 0;
 
-			for (char *p = global.version + 1; 1; p++)
+			for (const char *p = global.version + 1; 1; p++)
 			{
 			    char c = *p;
 			    if (isdigit(c))
@@ -2186,13 +2186,15 @@
 		break;
 	    if (d >= r)
 		break;
-	    if (n && n * r + d <= n)
+	    uinteger_t n2 = n * r;
+	    //printf("n2 / r = %llx, n = %llx\n", n2/r, n);
+	    if (n2 / r != n || n2 + d < n)
 	    {
 		error ("integer overflow");
 		break;
 	    }
 
-	    n = n * r + d;
+	    n = n2 + d;
 	    p++;
 	}
 #endif
@@ -2603,7 +2605,7 @@
     unsigned char *s = p;
     size_t len;
     size_t idx;
-    char *msg;
+    const char *msg;
 
     c = *s;
     assert(c & 0x80);
@@ -2801,7 +2803,7 @@
  */
 
 struct Keyword
-{   char *name;
+{   const char *name;
     enum TOK value;
 };
 
@@ -2928,6 +2930,7 @@
     {	"__overloadset", TOKoverloadset	},
     {	"__FILE__",	TOKfile		},
     {	"__LINE__",	TOKline		},
+    {	"shared",	TOKshared	},
 #endif
 };
 
@@ -2953,7 +2956,7 @@
     cmtable_init();
 
     for (u = 0; u < nkeywords; u++)
-    {	char *s;
+    {	const char *s;
 
 	//printf("keyword[%d] = '%s'\n",u, keywords[u].name);
 	s = keywords[u].name;
--- a/dmd/lexer.h	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/lexer.h	Mon Oct 06 16:22:11 2008 +0200
@@ -158,6 +158,7 @@
 	TOKtls,
 	TOKline,
 	TOKfile,
+    TOKshared,
 #endif
 
 // LLVMDC specific
@@ -240,13 +241,13 @@
     real_t float80value; // can't use this in a union!
 #endif
 
-    static char *tochars[TOKMAX];
+    static const char *tochars[TOKMAX];
     static void *operator new(size_t sz);
 
     int isKeyword();
     void print();
-    char *toChars();
-    static char *toChars(enum TOK);
+    const char *toChars();
+    static const char *toChars(enum TOK);
 };
 
 struct Lexer
--- a/dmd/mars.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/mars.c	Mon Oct 06 16:22:11 2008 +0200
@@ -65,7 +65,7 @@
 
     copyright = "Copyright (c) 1999-2008 by Digital Mars and Tomas Lindquist Olsen";
     written = "written by Walter Bright and Tomas Lindquist Olsen";
-    version = "v1.034";
+    version = "v1.035";
     llvmdc_version = "0.1";
     global.structalign = 8;
 
--- a/dmd/mtype.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/mtype.c	Mon Oct 06 16:22:11 2008 +0200
@@ -789,8 +789,8 @@
 
 TypeBasic::TypeBasic(TY ty)
 	: Type(ty, NULL)
-{   char *c;
-    char *d;
+{   const char *c;
+    const char *d;
     unsigned flags;
 
 #define TFLAGSintegral	1
@@ -935,7 +935,7 @@
 
 char *TypeBasic::toChars()
 {
-    return dstring;
+    return (char *)dstring;
 }
 
 void TypeBasic::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
--- a/dmd/mtype.h	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/mtype.h	Mon Oct 06 16:22:11 2008 +0200
@@ -266,8 +266,8 @@
 
 struct TypeBasic : Type
 {
-    char *dstring;
-    char *cstring;
+    const char *dstring;
+    const char *cstring;
     unsigned flags;
 
     TypeBasic(TY ty);
--- a/dmd/parse.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/parse.c	Mon Oct 06 16:22:11 2008 +0200
@@ -2374,6 +2374,7 @@
     Loc loc = this->loc;
     Token *t;
     int braces;
+    int brackets;
 
     switch (token.value)
     {
@@ -2461,6 +2462,39 @@
 	    return is;
 
 	case TOKlbracket:
+	    /* Scan ahead to see if it is an array initializer or
+	     * an expression.
+	     * If it ends with a ';', it is an array initializer.
+	     */
+	    brackets = 1;
+	    for (t = peek(&token); 1; t = peek(t))
+	    {
+		switch (t->value)
+		{
+		    case TOKlbracket:
+			brackets++;
+			continue;
+
+		    case TOKrbracket:
+			if (--brackets == 0)
+			{   t = peek(t);
+			    if (t->value != TOKsemicolon &&
+				t->value != TOKcomma &&
+				t->value != TOKrcurly)
+				goto Lexpression;
+			    break;
+			}
+			continue;
+
+		    case TOKeof:
+			break;
+
+		    default:
+			continue;
+		}
+		break;
+	    }
+
 	    ia = new ArrayInitializer(loc);
 	    nextToken();
 	    comma = 0;
@@ -4247,7 +4281,7 @@
 	    nextToken();
 	    if (token.value != TOKrbracket)
 	    {
-		while (1)
+		while (token.value != TOKeof)
 		{
 		    Expression *e = parseAssignExp();
 		    if (token.value == TOKcolon && (keys || values->dim == 0))
@@ -4525,10 +4559,13 @@
 		tk = peek(tk);		// skip over right parenthesis
 		switch (tk->value)
 		{
+		    case TOKnot:
+			tk = peek(tk);
+			if (tk->value == TOKis)	// !is
+			    break;
 		    case TOKdot:
 		    case TOKplusplus:
 		    case TOKminusminus:
-		    case TOKnot:
 		    case TOKdelete:
 		    case TOKnew:
 		    case TOKlparen:
@@ -5149,6 +5186,7 @@
 void Parser::addComment(Dsymbol *s, unsigned char *blockComment)
 {
     s->addComment(combineComments(blockComment, token.lineComment));
+    token.lineComment = NULL;
 }
 
 
--- a/dmd/root.c	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/root.c	Mon Oct 06 16:22:11 2008 +0200
@@ -188,7 +188,7 @@
 
 char *Object::toChars()
 {
-    return "Object";
+    return (char *)"Object";
 }
 
 dchar *Object::toDchars()
@@ -312,13 +312,13 @@
 {
 }
 
-char *FileName::combine(char *path, char *name)
+char *FileName::combine(const char *path, const char *name)
 {   char *f;
     size_t pathlen;
     size_t namelen;
 
     if (!path || !*path)
-	return name;
+	return (char *)name;
     pathlen = strlen(path);
     namelen = strlen(name);
     f = (char *)mem.malloc(pathlen + 1 + namelen + 1);
@@ -744,16 +744,16 @@
  *	cwd	if !=0, search current directory before searching path
  */
 
-char *FileName::searchPath(Array *path, char *name, int cwd)
+char *FileName::searchPath(Array *path, const char *name, int cwd)
 {
     if (absolute(name))
     {
-	return exists(name) ? name : NULL;
+	return exists(name) ? (char *)name : NULL;
     }
     if (cwd)
     {
 	if (exists(name))
-	    return name;
+	    return (char *)name;
     }
     if (path)
     {	unsigned i;
@@ -1438,7 +1438,7 @@
 #endif
 }
 
-void OutBuffer::prependstring(char *string)
+void OutBuffer::prependstring(const char *string)
 {   unsigned len;
 
     len = strlen(string);
@@ -1698,7 +1698,7 @@
  * Return index just past right.
  */
 
-unsigned OutBuffer::bracket(unsigned i, char *left, unsigned j, char *right)
+unsigned OutBuffer::bracket(unsigned i, const char *left, unsigned j, const char *right)
 {
     size_t leftlen = strlen(left);
     size_t rightlen = strlen(right);
--- a/dmd/root.h	Mon Oct 06 14:37:00 2008 +0200
+++ b/dmd/root.h	Mon Oct 06 16:22:11 2008 +0200
@@ -131,14 +131,14 @@
     static char *path(const char *);
     static char *replaceName(char *path, char *name);
 
-    static char *combine(char *path, char *name);
+    static char *combine(const char *path, const char *name);
     static Array *splitPath(const char *path);
     static FileName *defaultExt(const char *name, const char *ext);
     static FileName *forceExt(const char *name, const char *ext);
     int equalsExt(const char *ext);
 
     void CopyTo(FileName *to);
-    static char *searchPath(Array *path, char *name, int cwd);
+    static char *searchPath(Array *path, const char *name, int cwd);
     static int exists(const char *name);
     static void ensurePathExists(const char *path);
 };
@@ -267,7 +267,7 @@
     void writestring(const char *string);
     void writedstring(const char *string);
     void writedstring(const wchar_t *string);
-    void prependstring(char *string);
+    void prependstring(const char *string);
     void writenl();			// write newline
     void writeByte(unsigned b);
     void writebyte(unsigned b) { writeByte(b); }
@@ -288,7 +288,7 @@
     void printf(const unsigned short *format, ...);
 #endif
     void bracket(char left, char right);
-    unsigned bracket(unsigned i, char *left, unsigned j, char *right);
+    unsigned bracket(unsigned i, const char *left, unsigned j, const char *right);
     void spread(unsigned offset, unsigned nbytes);
     unsigned insert(unsigned offset, const void *data, unsigned nbytes);
     void remove(unsigned offset, unsigned nbytes);