Commits

Vincenzo Ampolo  committed 93f8f2d Merge

merged

  • Participants
  • Parent commits dacad3a, 5039819

Comments (0)

Files changed (99)

File d/d-objfile.cc

File contents unchanged.

File d/dmd/access.c

-
-// Copyright (c) 1999-2006 by Digital Mars
-// All Rights Reserved
-// written by Walter Bright
-// http://www.digitalmars.com
-// License for redistribution is by either the Artistic License
-// in artistic.txt, or the GNU General Public License in gnu.txt.
-// See the included readme.txt for details.
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include "root.h"
-#include "mem.h"
-
-#include "enum.h"
-#include "aggregate.h"
-#include "init.h"
-#include "attrib.h"
-#include "scope.h"
-#include "id.h"
-#include "mtype.h"
-#include "declaration.h"
-#include "aggregate.h"
-#include "expression.h"
-#include "module.h"
-
-#define LOG 0
-
-/* Code to do access checks
- */
-
-int hasPackageAccess(Scope *sc, Dsymbol *s);
-
-/****************************************
- * Return PROT access for Dsymbol smember in this declaration.
- */
-
-enum PROT AggregateDeclaration::getAccess(Dsymbol *smember)
-{
-    return PROTpublic;
-}
-
-enum PROT StructDeclaration::getAccess(Dsymbol *smember)
-{
-    enum PROT access_ret = PROTnone;
-
-#if LOG
-    printf("+StructDeclaration::getAccess(this = '%s', smember = '%s')\n",
-	toChars(), smember->toChars());
-#endif
-    if (smember->toParent() == this)
-    {
-	access_ret = smember->prot();
-    }
-    else if (smember->isDeclaration()->isStatic())
-    {
-	access_ret = smember->prot();
-    }
-    return access_ret;
-}
-
-enum PROT ClassDeclaration::getAccess(Dsymbol *smember)
-{
-    enum PROT access_ret = PROTnone;
-
-#if LOG
-    printf("+ClassDeclaration::getAccess(this = '%s', smember = '%s')\n",
-	toChars(), smember->toChars());
-#endif
-    if (smember->toParent() == this)
-    {
-	access_ret = smember->prot();
-    }
-    else
-    {
-	enum PROT access;
-	int i;
-
-	if (smember->isDeclaration()->isStatic())
-	{
-	    access_ret = smember->prot();
-	}
-
-	for (i = 0; i < baseclasses.dim; i++)
-	{   BaseClass *b = (BaseClass *)baseclasses.data[i];
-
-	    access = b->base->getAccess(smember);
-	    switch (access)
-	    {
-		case PROTnone:
-		    break;
-
-		case PROTprivate:
-		    access = PROTnone;	// private members of base class not accessible
-		    break;
-
-		case PROTpackage:
-		case PROTprotected:
-		case PROTpublic:
-		case PROTexport:
-		    // If access is to be tightened
-		    if (b->protection < access)
-			access = b->protection;
-
-		    // Pick path with loosest access
-		    if (access > access_ret)
-			access_ret = access;
-		    break;
-
-		default:
-		    assert(0);
-	    }
-	}
-    }
-#if LOG
-    printf("-ClassDeclaration::getAccess(this = '%s', smember = '%s') = %d\n",
-	toChars(), smember->toChars(), access_ret);
-#endif
-    return access_ret;
-}
-
-/********************************************************
- * Helper function for ClassDeclaration::accessCheck()
- * Returns:
- *	0	no access
- * 	1	access
- */
-
-static int accessCheckX(
-	Dsymbol *smember,
-	Dsymbol *sfunc,
-	AggregateDeclaration *dthis,
-	AggregateDeclaration *cdscope)
-{
-    assert(dthis);
-
-#if 0
-    printf("accessCheckX for %s.%s in function %s() in scope %s\n",
-	dthis->toChars(), smember->toChars(),
-	sfunc ? sfunc->toChars() : "NULL",
-	cdscope ? cdscope->toChars() : "NULL");
-#endif
-    if (dthis->hasPrivateAccess(sfunc) ||
-	dthis->isFriendOf(cdscope))
-    {
-	if (smember->toParent() == dthis)
-	    return 1;
-	else
-	{
-	    ClassDeclaration *cdthis = dthis->isClassDeclaration();
-	    if (cdthis)
-	    {
-		for (int i = 0; i < cdthis->baseclasses.dim; i++)
-		{   BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
-		    enum PROT access;
-
-		    access = b->base->getAccess(smember);
-		    if (access >= PROTprotected ||
-			accessCheckX(smember, sfunc, b->base, cdscope)
-		       )
-			return 1;
-
-		}
-	    }
-	}
-    }
-    else
-    {
-	if (smember->toParent() != dthis)
-	{
-	    ClassDeclaration *cdthis = dthis->isClassDeclaration();
-	    if (cdthis)
-	    {
-		for (int i = 0; i < cdthis->baseclasses.dim; i++)
-		{   BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
-
-		    if (accessCheckX(smember, sfunc, b->base, cdscope))
-			return 1;
-		}
-	    }
-	}
-    }
-    return 0;
-}
-
-/*******************************
- * Do access check for member of this class, this class being the
- * type of the 'this' pointer used to access smember.
- */
-
-void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
-{
-    int result;
-
-    FuncDeclaration *f = sc->func;
-    AggregateDeclaration *cdscope = sc->getStructClassScope();
-    enum PROT access;
-
-#if LOG
-    printf("AggregateDeclaration::accessCheck() for %s.%s in function %s() in scope %s\n",
-	toChars(), smember->toChars(),
-	f ? f->toChars() : NULL,
-	cdscope ? cdscope->toChars() : NULL);
-#endif
-
-    Dsymbol *smemberparent = smember->toParent();
-    if (!smemberparent || !smemberparent->isAggregateDeclaration())
-    {
-#if LOG
-	printf("not an aggregate member\n");
-#endif
-	return;				// then it is accessible
-    }
-
-    // BUG: should enable this check
-    //assert(smember->parent->isBaseOf(this, NULL));
-
-    if (smemberparent == this)
-    {	enum PROT access = smember->prot();
-
-	result = access >= PROTpublic ||
-		hasPrivateAccess(f) ||
-		isFriendOf(cdscope) ||
-		(access == PROTpackage && hasPackageAccess(sc, this));
-#if LOG
-	printf("result1 = %d\n", result);
-#endif
-    }
-    else if ((access = this->getAccess(smember)) >= PROTpublic)
-    {
-	result = 1;
-#if LOG
-	printf("result2 = %d\n", result);
-#endif
-    }
-    else if (access == PROTpackage && hasPackageAccess(sc, this))
-    {
-	result = 1;
-#if LOG
-	printf("result3 = %d\n", result);
-#endif
-    }
-    else
-    {
-	result = accessCheckX(smember, f, this, cdscope);
-#if LOG
-	printf("result4 = %d\n", result);
-#endif
-    }
-    if (!result)
-    {
-	error(loc, "member %s is not accessible", smember->toChars());
-halt();
-    }
-}
-
-/****************************************
- * Determine if this is the same or friend of cd.
- */
-
-int AggregateDeclaration::isFriendOf(AggregateDeclaration *cd)
-{
-#if LOG
-    printf("AggregateDeclaration::isFriendOf(this = '%s', cd = '%s')\n", toChars(), cd ? cd->toChars() : "null");
-#endif
-    if (this == cd)
-	return 1;
-
-    // Friends if both are in the same module
-    //if (toParent() == cd->toParent())
-    if (cd && getModule() == cd->getModule())
-    {
-#if LOG
-	printf("\tin same module\n");
-#endif
-	return 1;
-    }
-
-#if LOG
-    printf("\tnot friend\n");
-#endif
-    return 0;
-}
-
-/****************************************
- * Determine if scope sc has package level access to s.
- */
-
-int hasPackageAccess(Scope *sc, Dsymbol *s)
-{
-#if LOG
-    printf("hasPackageAccess(s = '%s', sc = '%p')\n", s->toChars(), sc);
-#endif
-
-    for (; s; s = s->parent)
-    {
-	if (s->isPackage() && !s->isModule())
-	    break;
-    }
-#if LOG
-    if (s)
-	printf("\tthis is in package '%s'\n", s->toChars());
-#endif
-
-    if (s && s == sc->module->parent)
-    {
-#if LOG
-	printf("\ts is in same package as sc\n");
-#endif
-	return 1;
-    }
-
-
-#if LOG
-    printf("\tno package access\n");
-#endif
-    return 0;
-}
-
-/**********************************
- * Determine if smember has access to private members of this declaration.
- */
-
-int AggregateDeclaration::hasPrivateAccess(Dsymbol *smember)
-{
-    if (smember)
-    {	AggregateDeclaration *cd = NULL;
-	Dsymbol *smemberparent = smember->toParent();
-	if (smemberparent)
-	    cd = smemberparent->isAggregateDeclaration();
-
-#if LOG
-	printf("AggregateDeclaration::hasPrivateAccess(class %s, member %s)\n",
-		toChars(), smember->toChars());
-#endif
-
-	if (this == cd)		// smember is a member of this class
-	{
-#if LOG
-	    printf("\tyes 1\n");
-#endif
-	    return 1;		// so we get private access
-	}
-
-	// If both are members of the same module, grant access
-	while (1)
-	{   Dsymbol *sp = smember->toParent();
-	    if (sp->isFuncDeclaration() && smember->isFuncDeclaration())
-		smember = sp;
-	    else
-		break;
-	}
-	if (!cd && toParent() == smember->toParent())
-	{
-#if LOG
-	    printf("\tyes 2\n");
-#endif
-	    return 1;
-	}
-	if (!cd && getModule() == smember->getModule())
-	{
-#if LOG
-	    printf("\tyes 3\n");
-#endif
-	    return 1;
-	}
-    }
-#if LOG
-    printf("\tno\n");
-#endif
-    return 0;
-}
-
-/****************************************
- * Check access to d for expression e.d
- */
-
-void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d)
-{
-#if LOG
-    if (e)
-    {	printf("accessCheck(%s . %s)\n", e->toChars(), d->toChars());
-	printf("\te->type = %s\n", e->type->toChars());
-    }
-    else
-    {
-	//printf("accessCheck(%s)\n", d->toChars());
-    }
-#endif
-    if (!e)
-    {
-	if (d->prot() == PROTprivate && d->getModule() != sc->module ||
-	    d->prot() == PROTpackage && !hasPackageAccess(sc, d))
-
-	    error(loc, "%s %s.%s is not accessible from %s",
-		d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars());
-    }
-    else if (e->type->ty == Tclass)
-    {   // Do access check
-	ClassDeclaration *cd;
-
-	cd = (ClassDeclaration *)(((TypeClass *)e->type)->sym);
-#if 1
-	if (e->op == TOKsuper)
-	{   ClassDeclaration *cd2;
-
-	    cd2 = sc->func->toParent()->isClassDeclaration();
-	    if (cd2)
-		cd = cd2;
-	}
-#endif
-	cd->accessCheck(loc, sc, d);
-    }
-    else if (e->type->ty == Tstruct)
-    {   // Do access check
-	StructDeclaration *cd;
-
-	cd = (StructDeclaration *)(((TypeStruct *)e->type)->sym);
-	cd->accessCheck(loc, sc, d);
-    }
-}
+
+// Copyright (c) 1999-2006 by Digital Mars
+// All Rights Reserved
+// written by Walter Bright
+// http://www.digitalmars.com
+// License for redistribution is by either the Artistic License
+// in artistic.txt, or the GNU General Public License in gnu.txt.
+// See the included readme.txt for details.
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "root.h"
+#include "mem.h"
+
+#include "enum.h"
+#include "aggregate.h"
+#include "init.h"
+#include "attrib.h"
+#include "scope.h"
+#include "id.h"
+#include "mtype.h"
+#include "declaration.h"
+#include "aggregate.h"
+#include "expression.h"
+#include "module.h"
+
+#define LOG 0
+
+/* Code to do access checks
+ */
+
+int hasPackageAccess(Scope *sc, Dsymbol *s);
+
+/****************************************
+ * Return PROT access for Dsymbol smember in this declaration.
+ */
+
+enum PROT AggregateDeclaration::getAccess(Dsymbol *smember)
+{
+    return PROTpublic;
+}
+
+enum PROT StructDeclaration::getAccess(Dsymbol *smember)
+{
+    enum PROT access_ret = PROTnone;
+
+#if LOG
+    printf("+StructDeclaration::getAccess(this = '%s', smember = '%s')\n",
+	toChars(), smember->toChars());
+#endif
+    if (smember->toParent() == this)
+    {
+	access_ret = smember->prot();
+    }
+    else if (smember->isDeclaration()->isStatic())
+    {
+	access_ret = smember->prot();
+    }
+    return access_ret;
+}
+
+enum PROT ClassDeclaration::getAccess(Dsymbol *smember)
+{
+    enum PROT access_ret = PROTnone;
+
+#if LOG
+    printf("+ClassDeclaration::getAccess(this = '%s', smember = '%s')\n",
+	toChars(), smember->toChars());
+#endif
+    if (smember->toParent() == this)
+    {
+	access_ret = smember->prot();
+    }
+    else
+    {
+	enum PROT access;
+	int i;
+
+	if (smember->isDeclaration()->isStatic())
+	{
+	    access_ret = smember->prot();
+	}
+
+	for (i = 0; i < baseclasses.dim; i++)
+	{   BaseClass *b = (BaseClass *)baseclasses.data[i];
+
+	    access = b->base->getAccess(smember);
+	    switch (access)
+	    {
+		case PROTnone:
+		    break;
+
+		case PROTprivate:
+		    access = PROTnone;	// private members of base class not accessible
+		    break;
+
+		case PROTpackage:
+		case PROTprotected:
+		case PROTpublic:
+		case PROTexport:
+		    // If access is to be tightened
+		    if (b->protection < access)
+			access = b->protection;
+
+		    // Pick path with loosest access
+		    if (access > access_ret)
+			access_ret = access;
+		    break;
+
+		default:
+		    assert(0);
+	    }
+	}
+    }
+#if LOG
+    printf("-ClassDeclaration::getAccess(this = '%s', smember = '%s') = %d\n",
+	toChars(), smember->toChars(), access_ret);
+#endif
+    return access_ret;
+}
+
+/********************************************************
+ * Helper function for ClassDeclaration::accessCheck()
+ * Returns:
+ *	0	no access
+ * 	1	access
+ */
+
+static int accessCheckX(
+	Dsymbol *smember,
+	Dsymbol *sfunc,
+	AggregateDeclaration *dthis,
+	AggregateDeclaration *cdscope)
+{
+    assert(dthis);
+
+#if 0
+    printf("accessCheckX for %s.%s in function %s() in scope %s\n",
+	dthis->toChars(), smember->toChars(),
+	sfunc ? sfunc->toChars() : "NULL",
+	cdscope ? cdscope->toChars() : "NULL");
+#endif
+    if (dthis->hasPrivateAccess(sfunc) ||
+	dthis->isFriendOf(cdscope))
+    {
+	if (smember->toParent() == dthis)
+	    return 1;
+	else
+	{
+	    ClassDeclaration *cdthis = dthis->isClassDeclaration();
+	    if (cdthis)
+	    {
+		for (int i = 0; i < cdthis->baseclasses.dim; i++)
+		{   BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
+		    enum PROT access;
+
+		    access = b->base->getAccess(smember);
+		    if (access >= PROTprotected ||
+			accessCheckX(smember, sfunc, b->base, cdscope)
+		       )
+			return 1;
+
+		}
+	    }
+	}
+    }
+    else
+    {
+	if (smember->toParent() != dthis)
+	{
+	    ClassDeclaration *cdthis = dthis->isClassDeclaration();
+	    if (cdthis)
+	    {
+		for (int i = 0; i < cdthis->baseclasses.dim; i++)
+		{   BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
+
+		    if (accessCheckX(smember, sfunc, b->base, cdscope))
+			return 1;
+		}
+	    }
+	}
+    }
+    return 0;
+}
+
+/*******************************
+ * Do access check for member of this class, this class being the
+ * type of the 'this' pointer used to access smember.
+ */
+
+void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
+{
+    int result;
+
+    FuncDeclaration *f = sc->func;
+    AggregateDeclaration *cdscope = sc->getStructClassScope();
+    enum PROT access;
+
+#if LOG
+    printf("AggregateDeclaration::accessCheck() for %s.%s in function %s() in scope %s\n",
+	toChars(), smember->toChars(),
+	f ? f->toChars() : NULL,
+	cdscope ? cdscope->toChars() : NULL);
+#endif
+
+    Dsymbol *smemberparent = smember->toParent();
+    if (!smemberparent || !smemberparent->isAggregateDeclaration())
+    {
+#if LOG
+	printf("not an aggregate member\n");
+#endif
+	return;				// then it is accessible
+    }
+
+    // BUG: should enable this check
+    //assert(smember->parent->isBaseOf(this, NULL));
+
+    if (smemberparent == this)
+    {	enum PROT access = smember->prot();
+
+	result = access >= PROTpublic ||
+		hasPrivateAccess(f) ||
+		isFriendOf(cdscope) ||
+		(access == PROTpackage && hasPackageAccess(sc, this));
+#if LOG
+	printf("result1 = %d\n", result);
+#endif
+    }
+    else if ((access = this->getAccess(smember)) >= PROTpublic)
+    {
+	result = 1;
+#if LOG
+	printf("result2 = %d\n", result);
+#endif
+    }
+    else if (access == PROTpackage && hasPackageAccess(sc, this))
+    {
+	result = 1;
+#if LOG
+	printf("result3 = %d\n", result);
+#endif
+    }
+    else
+    {
+	result = accessCheckX(smember, f, this, cdscope);
+#if LOG
+	printf("result4 = %d\n", result);
+#endif
+    }
+    if (!result)
+    {
+	error(loc, "member %s is not accessible", smember->toChars());
+    }
+}
+
+/****************************************
+ * Determine if this is the same or friend of cd.
+ */
+
+int AggregateDeclaration::isFriendOf(AggregateDeclaration *cd)
+{
+#if LOG
+    printf("AggregateDeclaration::isFriendOf(this = '%s', cd = '%s')\n", toChars(), cd ? cd->toChars() : "null");
+#endif
+    if (this == cd)
+	return 1;
+
+    // Friends if both are in the same module
+    //if (toParent() == cd->toParent())
+    if (cd && getModule() == cd->getModule())
+    {
+#if LOG
+	printf("\tin same module\n");
+#endif
+	return 1;
+    }
+
+#if LOG
+    printf("\tnot friend\n");
+#endif
+    return 0;
+}
+
+/****************************************
+ * Determine if scope sc has package level access to s.
+ */
+
+int hasPackageAccess(Scope *sc, Dsymbol *s)
+{
+#if LOG
+    printf("hasPackageAccess(s = '%s', sc = '%p')\n", s->toChars(), sc);
+#endif
+
+    for (; s; s = s->parent)
+    {
+	if (s->isPackage() && !s->isModule())
+	    break;
+    }
+#if LOG
+    if (s)
+	printf("\tthis is in package '%s'\n", s->toChars());
+#endif
+
+    if (s && s == sc->module->parent)
+    {
+#if LOG
+	printf("\ts is in same package as sc\n");
+#endif
+	return 1;
+    }
+
+
+#if LOG
+    printf("\tno package access\n");
+#endif
+    return 0;
+}
+
+/**********************************
+ * Determine if smember has access to private members of this declaration.
+ */
+
+int AggregateDeclaration::hasPrivateAccess(Dsymbol *smember)
+{
+    if (smember)
+    {	AggregateDeclaration *cd = NULL;
+	Dsymbol *smemberparent = smember->toParent();
+	if (smemberparent)
+	    cd = smemberparent->isAggregateDeclaration();
+
+#if LOG
+	printf("AggregateDeclaration::hasPrivateAccess(class %s, member %s)\n",
+		toChars(), smember->toChars());
+#endif
+
+	if (this == cd)		// smember is a member of this class
+	{
+#if LOG
+	    printf("\tyes 1\n");
+#endif
+	    return 1;		// so we get private access
+	}
+
+	// If both are members of the same module, grant access
+	while (1)
+	{   Dsymbol *sp = smember->toParent();
+	    if (sp->isFuncDeclaration() && smember->isFuncDeclaration())
+		smember = sp;
+	    else
+		break;
+	}
+	if (!cd && toParent() == smember->toParent())
+	{
+#if LOG
+	    printf("\tyes 2\n");
+#endif
+	    return 1;
+	}
+	if (!cd && getModule() == smember->getModule())
+	{
+#if LOG
+	    printf("\tyes 3\n");
+#endif
+	    return 1;
+	}
+    }
+#if LOG
+    printf("\tno\n");
+#endif
+    return 0;
+}
+
+/****************************************
+ * Check access to d for expression e.d
+ */
+
+void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d)
+{
+#if LOG
+    if (e)
+    {	printf("accessCheck(%s . %s)\n", e->toChars(), d->toChars());
+	printf("\te->type = %s\n", e->type->toChars());
+    }
+    else
+    {
+	//printf("accessCheck(%s)\n", d->toChars());
+    }
+#endif
+    if (!e)
+    {
+	if (d->prot() == PROTprivate && d->getModule() != sc->module ||
+	    d->prot() == PROTpackage && !hasPackageAccess(sc, d))
+
+	    error(loc, "%s %s.%s is not accessible from %s",
+		d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars());
+    }
+    else if (e->type->ty == Tclass)
+    {   // Do access check
+	ClassDeclaration *cd;
+
+	cd = (ClassDeclaration *)(((TypeClass *)e->type)->sym);
+#if 1
+	if (e->op == TOKsuper)
+	{   ClassDeclaration *cd2;
+
+	    cd2 = sc->func->toParent()->isClassDeclaration();
+	    if (cd2)
+		cd = cd2;
+	}
+#endif
+	cd->accessCheck(loc, sc, d);
+    }
+    else if (e->type->ty == Tstruct)
+    {   // Do access check
+	StructDeclaration *cd;
+
+	cd = (StructDeclaration *)(((TypeStruct *)e->type)->sym);
+	cd->accessCheck(loc, sc, d);
+    }
+}

File d/dmd/aggregate.h

-
-// Compiler implementation of the D programming language
-// Copyright (c) 1999-2008 by Digital Mars
-// All Rights Reserved
-// written by Walter Bright
-// http://www.digitalmars.com
-// License for redistribution is by either the Artistic License
-// in artistic.txt, or the GNU General Public License in gnu.txt.
-// See the included readme.txt for details.
-
-#ifndef DMD_AGGREGATE_H
-#define DMD_AGGREGATE_H
-
-#ifdef __DMC__
-#pragma once
-#endif /* __DMC__ */
-
-#include "root.h"
-#include "dsymbol.h"
-
-struct Identifier;
-struct Type;
-struct TypeFunction;
-struct Expression;
-struct FuncDeclaration;
-struct CtorDeclaration;
-struct DtorDeclaration;
-struct InvariantDeclaration;
-struct NewDeclaration;
-struct DeleteDeclaration;
-struct InterfaceDeclaration;
-struct ClassInfoDeclaration;
-struct VarDeclaration;
-struct dt_t;
-
-
-struct AggregateDeclaration : ScopeDsymbol
-{
-    Type *type;
-    unsigned storage_class;
-    enum PROT protection;
-    Type *handle;		// 'this' type
-    target_size_t structsize;	// size of struct
-    target_size_t alignsize;		// size of struct for alignment purposes
-    target_size_t structalign;	// struct member alignment in effect
-    int hasUnions;		// set if aggregate has overlapping fields
-    Array fields;		// VarDeclaration fields
-    unsigned sizeok;		// set when structsize contains valid data
-				// 0: no size
-				// 1: size is correct
-				// 2: cannot determine size; fwd referenced
-    int isdeprecated;		// !=0 if deprecated
-    Scope *scope;		// !=NULL means context to use
-
-    // Special member functions
-    InvariantDeclaration *inv;		// invariant
-    NewDeclaration *aggNew;		// allocator
-    DeleteDeclaration *aggDelete;	// deallocator
-
-    FuncDeclarations dtors;	// Array of destructors
+
+// Compiler implementation of the D programming language
+// Copyright (c) 1999-2008 by Digital Mars
+// All Rights Reserved
+// written by Walter Bright
+// http://www.digitalmars.com
+// License for redistribution is by either the Artistic License
+// in artistic.txt, or the GNU General Public License in gnu.txt.
+// See the included readme.txt for details.
+
+/* NOTE: This file has been patched from the original DMD distribution to
+   work with the GDC compiler.
+
+   Modified by David Friedman, December 2006
+*/
+
+#ifndef DMD_AGGREGATE_H
+#define DMD_AGGREGATE_H
+
+#ifdef __DMC__
+#pragma once
+#endif /* __DMC__ */
+
+#include "root.h"
+#include "dsymbol.h"
+
+struct Identifier;
+struct Type;
+struct TypeFunction;
+struct Expression;
+struct FuncDeclaration;
+struct CtorDeclaration;
+struct DtorDeclaration;
+struct InvariantDeclaration;
+struct NewDeclaration;
+struct DeleteDeclaration;
+struct InterfaceDeclaration;
+struct ClassInfoDeclaration;
+struct VarDeclaration;
+struct dt_t;
+
+
+struct AggregateDeclaration : ScopeDsymbol
+{
+    Type *type;
+    unsigned storage_class;
+    enum PROT protection;
+    Type *handle;		// 'this' type
+    target_size_t structsize;	// size of struct
+    target_size_t alignsize;	// size of struct for alignment purposes
+    target_size_t structalign;	// struct member alignment in effect
+    int hasUnions;		// set if aggregate has overlapping fields
+    Array fields;		// VarDeclaration fields
+    unsigned sizeok;		// set when structsize contains valid data
+				// 0: no size
+				// 1: size is correct
+				// 2: cannot determine size; fwd referenced
+    int isdeprecated;		// !=0 if deprecated
+    Scope *scope;		// !=NULL means context to use
+
+    // Special member functions
+    InvariantDeclaration *inv;		// invariant
+    NewDeclaration *aggNew;		// allocator
+    DeleteDeclaration *aggDelete;	// deallocator
+
+    FuncDeclarations dtors;	// Array of destructors
     FuncDeclaration *dtor;	// aggregate destructor
-    
-    Expressions * attributes;
-
-#ifdef IN_GCC
-    Array methods;              // flat list of all methods for debug information
-#endif
-
-    AggregateDeclaration(Loc loc, Identifier *id);
-    void semantic2(Scope *sc);
-    void semantic3(Scope *sc);
-    void inlineScan();
-    target_size_t size(Loc loc);
-    static void alignmember(target_size_t salign, target_size_t size, target_size_t *poffset);
-    Type *getType();
-    void addField(Scope *sc, VarDeclaration *v);
-    int isDeprecated();		// is aggregate deprecated?
-    FuncDeclaration *buildDtor(Scope *sc);
-
-    void emitComment(Scope *sc);
-    void toDocBuffer(OutBuffer *buf);
-
-    // For access checking
-    virtual PROT getAccess(Dsymbol *smember);	// determine access to smember
-    int isFriendOf(AggregateDeclaration *cd);
-    int hasPrivateAccess(Dsymbol *smember);	// does smember have private access to members of this class?
-    void accessCheck(Loc loc, Scope *sc, Dsymbol *smember);
-
-    enum PROT prot();
-
-    // Back end
-    Symbol *stag;		// tag symbol for debug data
-    Symbol *sinit;
-    Symbol *toInitializer();
-
-    AggregateDeclaration *isAggregateDeclaration() { return this; }
-};
-
-struct AnonymousAggregateDeclaration : AggregateDeclaration
-{
-    AnonymousAggregateDeclaration()
-	: AggregateDeclaration(0, NULL)
-    {
-    }
-
-    AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; }
-};
-
-struct StructDeclaration : AggregateDeclaration
-{
-    int zeroInit;		// !=0 if initialize with 0 fill
-#if V2
-    int hasIdentityAssign;	// !=0 if has identity opAssign
-    FuncDeclaration *cpctor;	// generated copy-constructor, if any
-
-    FuncDeclarations postblits;	// Array of postblit functions
-    FuncDeclaration *postblit;	// aggregate postblit
-#endif
-
-    StructDeclaration(Loc loc, Identifier *id);
-    Dsymbol *syntaxCopy(Dsymbol *s);
-    void semantic(Scope *sc);
-    void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
-    char *mangle();
-    char *kind();
-    Expression *cloneMembers();
-    void toDocBuffer(OutBuffer *buf);
-
-    PROT getAccess(Dsymbol *smember);	// determine access to smember
-
-    void toObjFile(int multiobj);			// compile to .obj file
-    void toDt(dt_t **pdt);
-    void toDebug();			// to symbolic debug info
-
-    StructDeclaration *isStructDeclaration() { return this; }
-};
-
-struct UnionDeclaration : StructDeclaration
-{
-    UnionDeclaration(Loc loc, Identifier *id);
-    Dsymbol *syntaxCopy(Dsymbol *s);
-    char *kind();
-
-    UnionDeclaration *isUnionDeclaration() { return this; }
-};
-
-struct BaseClass
-{
-    Type *type;				// (before semantic processing)
-    enum PROT protection;		// protection for the base interface
-
-    ClassDeclaration *base;
-    target_ptrdiff_t offset;				// 'this' pointer offset
-    Array vtbl;				// for interfaces: Array of FuncDeclaration's
-					// making up the vtbl[]
-
-    int baseInterfaces_dim;
-    BaseClass *baseInterfaces;		// if BaseClass is an interface, these
-					// are a copy of the InterfaceDeclaration::interfaces
-
-    BaseClass();
-    BaseClass(Type *type, enum PROT protection);
-
-    int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
-    void copyBaseInterfaces(BaseClasses *);
-};
-
-extern int CLASSINFO_SIZE;
-
-struct ClassDeclaration : AggregateDeclaration
-{
-    static ClassDeclaration *object;
-    static ClassDeclaration *classinfo;
-
-    ClassDeclaration *baseClass;	// NULL only if this is Object
-    CtorDeclaration *ctor;
-    CtorDeclaration *defaultCtor;	// default constructor
-    FuncDeclaration *staticCtor;
-    FuncDeclaration *staticDtor;
-    Array vtbl;				// Array of FuncDeclaration's making up the vtbl[]
-    Array vtblFinal;			// More FuncDeclaration's that aren't in vtbl[]
-
-    BaseClasses baseclasses;		// Array of BaseClass's; first is super,
-					// rest are Interface's
-
-    int interfaces_dim;
-    BaseClass **interfaces;		// interfaces[interfaces_dim] for this class
-					// (does not include baseClass)
-
-    BaseClasses *vtblInterfaces;	// array of base interfaces that have
-					// their own vtbl[]
-
-    ClassInfoDeclaration *vclassinfo;	// the ClassInfo object for this ClassDeclaration
-    int com;				// !=0 if this is a COM class (meaning
-					// it derives from IUnknown)
-    int isauto;				// !=0 if this is an auto class
-    int isabstract;			// !=0 if abstract class
-
-    int isnested;			// !=0 if is nested
-    VarDeclaration *vthis;		// 'this' parameter if this class is nested
-
-    int inuse;				// to prevent recursive attempts
-
-    ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
-    Dsymbol *syntaxCopy(Dsymbol *s);
-    void semantic(Scope *sc);
-    void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
-    int isBaseOf2(ClassDeclaration *cd);
-
-    #define OFFSET_RUNTIME 0x76543210
-    virtual int isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset);
-
-    Dsymbol *search(Loc, Identifier *ident, int flags);
-#if V2
-    int isFuncHidden(FuncDeclaration *fd);
-#endif
-    FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
-    void interfaceSemantic(Scope *sc);
-    int isNested();
-    int isCOMclass();
-    virtual int isCOMinterface();
-#if V2
-    virtual int isCPPinterface();
-#endif
-    int isAbstract();
-    virtual int vtblOffset();
-    char *kind();
-    char *mangle();
-    void toDocBuffer(OutBuffer *buf);
-
-    PROT getAccess(Dsymbol *smember);	// determine access to smember
-
-    void addLocalClass(ClassDeclarations *);
-
-    // Back end
-    void toObjFile(int multiobj);			// compile to .obj file
-    void toDebug();
-    unsigned baseVtblOffset(BaseClass *bc);
-    Symbol *toSymbol();
-    Symbol *toVtblSymbol();
-    void toDt(dt_t **pdt);
-    void toDt2(dt_t **pdt, ClassDeclaration *cd);
-
-    Symbol *vtblsym;
-
-    ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
-};
-
-struct InterfaceDeclaration : ClassDeclaration
-{
-#if V2
-    int cpp;				// !=0 if this is a C++ interface
-#endif
-    InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
-    Dsymbol *syntaxCopy(Dsymbol *s);
-    void semantic(Scope *sc);
-    int isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset);
-    int isBaseOf(BaseClass *bc, target_ptrdiff_t *poffset);
-    char *kind();
-    int vtblOffset();
-#if V2
-    int isCPPinterface();
-#endif
-    virtual int isCOMinterface();
-
-    void toObjFile(int multiobj);			// compile to .obj file
-    Symbol *toSymbol();
-
-    InterfaceDeclaration *isInterfaceDeclaration() { return this; }
-};
-
-#endif /* DMD_AGGREGATE_H */
+
+    Expressions * attributes;   // GCC decl/type attributes
+#ifdef IN_GCC
+    Array methods;              // flat list of all methods for debug information
+#endif
+
+    AggregateDeclaration(Loc loc, Identifier *id);
+    void semantic2(Scope *sc);
+    void semantic3(Scope *sc);
+    void inlineScan();
+    target_size_t size(Loc loc);
+    static void alignmember(target_size_t salign, target_size_t size, target_size_t *poffset);
+    Type *getType();
+    void addField(Scope *sc, VarDeclaration *v);
+    int isDeprecated();		// is aggregate deprecated?
+    FuncDeclaration *buildDtor(Scope *sc);
+
+    void emitComment(Scope *sc);
+    void toDocBuffer(OutBuffer *buf);
+
+    // For access checking
+    virtual PROT getAccess(Dsymbol *smember);	// determine access to smember
+    int isFriendOf(AggregateDeclaration *cd);
+    int hasPrivateAccess(Dsymbol *smember);	// does smember have private access to members of this class?
+    void accessCheck(Loc loc, Scope *sc, Dsymbol *smember);
+
+    enum PROT prot();
+
+    // Back end
+    Symbol *stag;		// tag symbol for debug data
+    Symbol *sinit;
+    Symbol *toInitializer();
+
+    AggregateDeclaration *isAggregateDeclaration() { return this; }
+};
+
+struct AnonymousAggregateDeclaration : AggregateDeclaration
+{
+    AnonymousAggregateDeclaration()
+	: AggregateDeclaration(0, NULL)
+    {
+    }
+
+    AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; }
+};
+
+struct StructDeclaration : AggregateDeclaration
+{
+    int zeroInit;		// !=0 if initialize with 0 fill
+#if V2
+    int hasIdentityAssign;	// !=0 if has identity opAssign
+    FuncDeclaration *cpctor;	// generated copy-constructor, if any
+
+    FuncDeclarations postblits;	// Array of postblit functions
+    FuncDeclaration *postblit;	// aggregate postblit
+#endif
+
+    StructDeclaration(Loc loc, Identifier *id);
+    Dsymbol *syntaxCopy(Dsymbol *s);
+    void semantic(Scope *sc);
+    void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
+    char *mangle();
+    char *kind();
+    Expression *cloneMembers();
+    void toDocBuffer(OutBuffer *buf);
+
+    PROT getAccess(Dsymbol *smember);	// determine access to smember
+
+    void toObjFile(int multiobj);			// compile to .obj file
+    void toDt(dt_t **pdt);
+    void toDebug();			// to symbolic debug info
+
+    StructDeclaration *isStructDeclaration() { return this; }
+};
+
+struct UnionDeclaration : StructDeclaration
+{
+    UnionDeclaration(Loc loc, Identifier *id);
+    Dsymbol *syntaxCopy(Dsymbol *s);
+    char *kind();
+
+    UnionDeclaration *isUnionDeclaration() { return this; }
+};
+
+struct BaseClass
+{
+    Type *type;				// (before semantic processing)
+    enum PROT protection;		// protection for the base interface
+
+    ClassDeclaration *base;
+    target_ptrdiff_t offset;		// 'this' pointer offset
+    Array vtbl;				// for interfaces: Array of FuncDeclaration's
+					// making up the vtbl[]
+
+    int baseInterfaces_dim;
+    BaseClass *baseInterfaces;		// if BaseClass is an interface, these
+					// are a copy of the InterfaceDeclaration::interfaces
+
+    BaseClass();
+    BaseClass(Type *type, enum PROT protection);
+
+    int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
+    void copyBaseInterfaces(BaseClasses *);
+};
+
+extern int CLASSINFO_SIZE;		// value of ClassInfo.size
+
+struct ClassDeclaration : AggregateDeclaration
+{
+    static ClassDeclaration *object;
+    static ClassDeclaration *classinfo;
+
+    ClassDeclaration *baseClass;	// NULL only if this is Object
+    CtorDeclaration *ctor;
+    CtorDeclaration *defaultCtor;	// default constructor
+    FuncDeclaration *staticCtor;
+    FuncDeclaration *staticDtor;
+    Array vtbl;				// Array of FuncDeclaration's making up the vtbl[]
+    Array vtblFinal;			// More FuncDeclaration's that aren't in vtbl[]
+
+    BaseClasses baseclasses;		// Array of BaseClass's; first is super,
+					// rest are Interface's
+
+    int interfaces_dim;
+    BaseClass **interfaces;		// interfaces[interfaces_dim] for this class
+					// (does not include baseClass)
+
+    BaseClasses *vtblInterfaces;	// array of base interfaces that have
+					// their own vtbl[]
+
+    ClassInfoDeclaration *vclassinfo;	// the ClassInfo object for this ClassDeclaration
+    int com;				// !=0 if this is a COM class (meaning
+					// it derives from IUnknown)
+    int isauto;				// !=0 if this is an auto class
+    int isabstract;			// !=0 if abstract class
+
+    int isnested;			// !=0 if is nested
+    VarDeclaration *vthis;		// 'this' parameter if this class is nested
+
+    int inuse;				// to prevent recursive attempts
+
+    ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
+    Dsymbol *syntaxCopy(Dsymbol *s);
+    void semantic(Scope *sc);
+    void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
+    int isBaseOf2(ClassDeclaration *cd);
+
+    #define OFFSET_RUNTIME 0x76543210
+    virtual int isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset);
+
+    Dsymbol *search(Loc, Identifier *ident, int flags);
+#if V2
+    int isFuncHidden(FuncDeclaration *fd);
+#endif
+    FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
+    void interfaceSemantic(Scope *sc);
+    int isNested();
+    int isCOMclass();
+    virtual int isCOMinterface();
+#if V2
+    virtual int isCPPinterface();
+#endif
+    int isAbstract();
+    virtual int vtblOffset();
+    char *kind();
+    char *mangle();
+    void toDocBuffer(OutBuffer *buf);
+
+    PROT getAccess(Dsymbol *smember);	// determine access to smember
+
+    void addLocalClass(ClassDeclarations *);
+
+    // Back end
+    void toObjFile(int multiobj);			// compile to .obj file
+    void toDebug();
+    unsigned baseVtblOffset(BaseClass *bc);
+    Symbol *toSymbol();
+    Symbol *toVtblSymbol();
+    void toDt(dt_t **pdt);
+    void toDt2(dt_t **pdt, ClassDeclaration *cd);
+
+    Symbol *vtblsym;
+
+    ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
+};
+
+struct InterfaceDeclaration : ClassDeclaration
+{
+#if V2
+    int cpp;				// !=0 if this is a C++ interface
+#endif
+    InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
+    Dsymbol *syntaxCopy(Dsymbol *s);
+    void semantic(Scope *sc);
+    int isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset);
+    int isBaseOf(BaseClass *bc, target_ptrdiff_t *poffset);
+    char *kind();
+    int vtblOffset();
+#if V2
+    int isCPPinterface();
+#endif
+    virtual int isCOMinterface();
+
+    void toObjFile(int multiobj);			// compile to .obj file
+    Symbol *toSymbol();
+
+    InterfaceDeclaration *isInterfaceDeclaration() { return this; }
+};
+
+#endif /* DMD_AGGREGATE_H */

File d/dmd/array.c

-
-// Copyright (c) 1999-2006 by Digital Mars
-// All Rights Reserved
-// written by Walter Bright
-// www.digitalmars.com
-// License for redistribution is by either the Artistic License
-// in artistic.txt, or the GNU General Public License in gnu.txt.
-// See the included readme.txt for details.
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <assert.h>
-
-#if _MSC_VER
-#include <malloc.h>
-#endif
-
-#if IN_GCC
-#include "gdc_alloca.h"
-#endif
-
-#if _WIN32
-#include <windows.h>
-#endif
-
-#ifndef _WIN32
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <utime.h>
-#endif
-
-#include "port.h"
-#include "root.h"
-#include "dchar.h"
-#include "mem.h"
-
-
-/********************************* Array ****************************/
-
-Array::Array()
-{
-    data = NULL;
-    dim = 0;
-    allocdim = 0;
-}
-
-Array::~Array()
-{
-    mem.free(data);
-}
-
-void Array::mark()
-{   unsigned u;
-
-    mem.mark(data);
-    for (u = 0; u < dim; u++)
-	mem.mark(data[u]);	// BUG: what if arrays of Object's?
-}
-
-void Array::reserve(unsigned nentries)
-{
-    //printf("Array::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes);
-    if (allocdim - dim < nentries)
-    {
-	allocdim = dim + nentries;
-	data = (void **)mem.realloc(data, allocdim * sizeof(*data));
-    }
-}
-
-void Array::setDim(unsigned newdim)
-{
-    if (dim < newdim)
-    {
-	reserve(newdim - dim);
-    }
-    dim = newdim;
-}
-
-void Array::fixDim()
-{
-    if (dim != allocdim)
-    {	data = (void **)mem.realloc(data, dim * sizeof(*data));
-	allocdim = dim;
-    }
-}
-
-void Array::push(void *ptr)
-{
-    reserve(1);
-    data[dim++] = ptr;
-}
-
-void *Array::pop()
-{
-    return data[--dim];
-}
-
-void Array::shift(void *ptr)
-{
-    reserve(1);
-    memmove(data + 1, data, dim * sizeof(*data));
-    data[0] = ptr;
-    dim++;
-}
-
-void Array::insert(unsigned index, void *ptr)
-{
-    reserve(1);
-    memmove(data + index + 1, data + index, (dim - index) * sizeof(*data));
-    data[index] = ptr;
-    dim++;
-}
-
-
-void Array::insert(unsigned index, Array *a)
-{
-    if (a)
-    {	unsigned d;
-
-	d = a->dim;
-	reserve(d);
-	if (dim != index)
-	    memmove(data + index + d, data + index, (dim - index) * sizeof(*data));
-	memcpy(data + index, a->data, d * sizeof(*data));
-	dim += d;
-    }
-}
-
-
-/***********************************
- * Append array a to this array.
- */
-
-void Array::append(Array *a)
-{
-    insert(dim, a);
-}
-
-void Array::remove(unsigned i)
-{
-    memmove(data + i, data + i + 1, (dim - i) * sizeof(data[0]));
-    dim--;
-}
-
-char *Array::toChars()
-{
-    unsigned len;
-    unsigned u;
-    char **buf;
-    char *str;
-    char *p;
-
-    buf = (char **)alloca(dim * sizeof(char *));
-    len = 2;
-    for (u = 0; u < dim; u++)
-    {
-	buf[u] = ((Object *)data[u])->toChars();
-	len += strlen(buf[u]) + 1;
-    }
-    str = (char *)mem.malloc(len);
-
-    str[0] = '[';
-    p = str + 1;
-    for (u = 0; u < dim; u++)
-    {
-	if (u)
-	    *p++ = ',';
-	len = strlen(buf[u]);
-	memcpy(p,buf[u],len);
-	p += len;
-    }
-    *p++ = ']';
-    *p = 0;
-    return str;
-}
-
-void Array::zero()
-{
-    memset(data,0,dim * sizeof(data[0]));
-}
-
-void *Array::tos()
-{
-    return dim ? data[dim - 1] : NULL;
-}
-
-int
-#if _WIN32
-  __cdecl
-#endif
-	Array_sort_compare(const void *x, const void *y)
-{
-    Object *ox = *(Object **)x;
-    Object *oy = *(Object **)y;
-
-    return ox->compare(oy);
-}
-
-void Array::sort()
-{
-    if (dim)
-    {
-	qsort(data, dim, sizeof(Object *), Array_sort_compare);
-    }
-}
-
-Array *Array::copy()
-{
-    Array *a = new Array();
-
-    a->setDim(dim);
-    memcpy(a->data, data, dim * sizeof(void *));
-    return a;
-}
-
+
+// Copyright (c) 1999-2006 by Digital Mars
+// All Rights Reserved
+// written by Walter Bright
+// www.digitalmars.com
+// License for redistribution is by either the Artistic License
+// in artistic.txt, or the GNU General Public License in gnu.txt.
+// See the included readme.txt for details.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+
+#if _MSC_VER
+#include <malloc.h>
+#endif
+
+#if IN_GCC
+#include "gdc_alloca.h"
+#endif
+
+#if _WIN32
+#include <windows.h>
+#endif
+
+#ifndef _WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <utime.h>
+#endif
+
+#include "port.h"
+#include "root.h"
+#include "dchar.h"
+#include "mem.h"
+
+
+/********************************* Array ****************************/
+
+Array::Array()
+{
+    data = NULL;
+    dim = 0;
+    allocdim = 0;
+}
+
+Array::~Array()
+{
+    mem.free(data);
+}
+
+void Array::mark()
+{   unsigned u;
+
+    mem.mark(data);
+    for (u = 0; u < dim; u++)
+	mem.mark(data[u]);	// BUG: what if arrays of Object's?
+}
+
+void Array::reserve(unsigned nentries)
+{
+    //printf("Array::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes);
+    if (allocdim - dim < nentries)
+    {
+	allocdim = dim + nentries;
+	data = (void **)mem.realloc(data, allocdim * sizeof(*data));
+    }
+}
+
+void Array::setDim(unsigned newdim)
+{
+    if (dim < newdim)
+    {
+	reserve(newdim - dim);
+    }
+    dim = newdim;
+}
+
+void Array::fixDim()
+{
+    if (dim != allocdim)
+    {	data = (void **)mem.realloc(data, dim * sizeof(*data));
+	allocdim = dim;
+    }
+}
+
+void Array::push(void *ptr)
+{
+    reserve(1);
+    data[dim++] = ptr;
+}
+
+void *Array::pop()
+{
+    return data[--dim];
+}
+
+void Array::shift(void *ptr)
+{
+    reserve(1);
+    memmove(data + 1, data, dim * sizeof(*data));
+    data[0] = ptr;
+    dim++;
+}
+
+void Array::insert(unsigned index, void *ptr)
+{
+    reserve(1);
+    memmove(data + index + 1, data + index, (dim - index) * sizeof(*data));
+    data[index] = ptr;
+    dim++;
+}
+
+
+void Array::insert(unsigned index, Array *a)
+{
+    if (a)
+    {	unsigned d;
+
+	d = a->dim;
+	reserve(d);
+	if (dim != index)
+	    memmove(data + index + d, data + index, (dim - index) * sizeof(*data));
+	memcpy(data + index, a->data, d * sizeof(*data));
+	dim += d;
+    }
+}
+
+
+/***********************************
+ * Append array a to this array.
+ */
+
+void Array::append(Array *a)
+{
+    insert(dim, a);
+}
+
+void Array::remove(unsigned i)
+{
+    memmove(data + i, data + i + 1, (dim - i) * sizeof(data[0]));
+    dim--;
+}
+
+char *Array::toChars()
+{
+    unsigned len;
+    unsigned u;
+    char **buf;
+    char *str;
+    char *p;
+
+    buf = (char **)alloca(dim * sizeof(char *));
+    len = 2;
+    for (u = 0; u < dim; u++)
+    {
+	buf[u] = ((Object *)data[u])->toChars();
+	len += strlen(buf[u]) + 1;
+    }
+    str = (char *)mem.malloc(len);
+
+    str[0] = '[';
+    p = str + 1;
+    for (u = 0; u < dim; u++)
+    {
+	if (u)
+	    *p++ = ',';
+	len = strlen(buf[u]);
+	memcpy(p,buf[u],len);
+	p += len;
+    }
+    *p++ = ']';
+    *p = 0;
+    return str;
+}
+
+void Array::zero()
+{
+    memset(data,0,dim * sizeof(data[0]));
+}
+
+void *Array::tos()
+{
+    return dim ? data[dim - 1] : NULL;
+}
+
+int
+#if _WIN32
+  __cdecl
+#endif
+	Array_sort_compare(const void *x, const void *y)
+{
+    Object *ox = *(Object **)x;
+    Object *oy = *(Object **)y;
+
+    return ox->compare(oy);
+}
+
+void Array::sort()
+{
+    if (dim)
+    {
+	qsort(data, dim, sizeof(Object *), Array_sort_compare);
+    }
+}
+
+Array *Array::copy()
+{
+    Array *a = new Array();
+
+    a->setDim(dim);
+    memcpy(a->data, data, dim * sizeof(void *));
+    return a;
+}
+

File d/dmd/arraytypes.h

-
-// Compiler implementation of the D programming language
-// Copyright (c) 2006-2007 by Digital Mars
-// All Rights Reserved
-// written by Walter Bright
-// http://www.digitalmars.com
-// License for redistribution is by either the Artistic License
-// in artistic.txt, or the GNU General Public License in gnu.txt.
-// See the included readme.txt for details.
-
-#ifndef DMD_ARRAYTYPES_H
-#define DMD_ARRAYTYPES_H
-
-#ifdef __DMC__
-#pragma once
-#endif /* __DMC__ */
-
-
-#include "root.h"
-
-struct Expression;
-struct Statement;
-struct BaseClass;
-struct TemplateParameter;
-struct FuncDeclaration;
-struct Identifier;
-struct Initializer;
-
-struct TemplateParameters : Array { };
-
-struct Expressions : Array { };
-
-struct Statements : Array { };
-
-struct BaseClasses : Array { };
-
-struct ClassDeclarations : Array { };
-
-struct Dsymbols : Array { };
-
-struct Objects : Array { };
-
-struct FuncDeclarations : Array { };
-
-struct Arguments : Array { };
-
-struct Identifiers : Array { };
-
-struct Initializers : Array { };
-
-#endif
+
+// Compiler implementation of the D programming language
+// Copyright (c) 2006-2007 by Digital Mars
+// All Rights Reserved
+// written by Walter Bright
+// http://www.digitalmars.com
+// License for redistribution is by either the Artistic License
+// in artistic.txt, or the GNU General Public License in gnu.txt.
+// See the included readme.txt for details.
+
+#ifndef DMD_ARRAYTYPES_H
+#define DMD_ARRAYTYPES_H
+
+#ifdef __DMC__
+#pragma once
+#endif /* __DMC__ */
+
+
+#include "root.h"
+
+struct Expression;
+struct Statement;
+struct BaseClass;
+struct TemplateParameter;
+struct FuncDeclaration;
+struct Identifier;
+struct Initializer;
+
+struct TemplateParameters : Array { };
+
+struct Expressions : Array { };
+
+struct Statements : Array { };
+
+struct BaseClasses : Array { };
+
+struct ClassDeclarations : Array { };
+
+struct Dsymbols : Array { };
+
+struct Objects : Array { };
+
+struct FuncDeclarations : Array { };
+
+struct Arguments : Array { };
+
+struct Identifiers : Array { };
+
+struct Initializers : Array { };
+
+#endif

File d/dmd/artistic.txt

-
-
-
-
-			 The "Artistic License"
-
-				Preamble
-
-The intent of this document is to state the conditions under which a
-Package may be copied, such that the Copyright Holder maintains some
-semblance of artistic control over the development of the package,
-while giving the users of the package the right to use and distribute
-the Package in a more-or-less customary fashion, plus the right to make
-reasonable modifications.
-
-Definitions:
-
-	"Package" refers to the collection of files distributed by the
-	Copyright Holder, and derivatives of that collection of files
-	created through textual modification.
-
-	"Standard Version" refers to such a Package if it has not been
-	modified, or has been modified in accordance with the wishes
-	of the Copyright Holder as specified below.
-
-	"Copyright Holder" is whoever is named in the copyright or
-	copyrights for the package.
-
-	"You" is you, if you're thinking about copying or distributing
-	this Package.
-
-	"Reasonable copying fee" is whatever you can justify on the
-	basis of media cost, duplication charges, time of people involved,
-	and so on.  (You will not be required to justify it to the
-	Copyright Holder, but only to the computing community at large
-	as a market that must bear the fee.)
-
-	"Freely Available" means that no fee is charged for the item
-	itself, though there may be fees involved in handling the item.
-	It also means that recipients of the item may redistribute it
-	under the same conditions they received it.
-
-1. You may make and give away verbatim copies of the source form of the
-Standard Version of this Package without restriction, provided that you
-duplicate all of the original copyright notices and associated disclaimers.
-
-2. You may apply bug fixes, portability fixes and other modifications
-derived from the Public Domain or from the Copyright Holder.  A Package
-modified in such a way shall still be considered the Standard Version.
-
-3. You may otherwise modify your copy of this Package in any way, provided
-that you insert a prominent notice in each changed file stating how and
-when you changed that file, and provided that you do at least ONE of the
-following:
-
-    a) place your modifications in the Public Domain or otherwise make them
-    Freely Available, such as by posting said modifications to Usenet or
-    an equivalent medium, or placing the modifications on a major archive
-    site such as uunet.uu.net, or by allowing the Copyright Holder to include
-    your modifications in the Standard Version of the Package.
-
-    b) use the modified Package only within your corporation or organization.
-
-    c) rename any non-standard executables so the names do not conflict
-    with standard executables, which must also be provided, and provide
-    a separate manual page for each non-standard executable that clearly
-    documents how it differs from the Standard Version.
-
-    d) make other distribution arrangements with the Copyright Holder.
-
-4. You may distribute the programs of this Package in object code or
-executable form, provided that you do at least ONE of the following:
-
-    a) distribute a Standard Version of the executables and library files,
-    together with instructions (in the manual page or equivalent) on where
-    to get the Standard Version.
-
-    b) accompany the distribution with the machine-readable source of
-    the Package with your modifications.
-
-    c) give non-standard executables non-standard names, and clearly
-    document the differences in manual pages (or equivalent), together
-    with instructions on where to get the Standard Version.
-
-    d) make other distribution arrangements with the Copyright Holder.
-
-5. You may charge a reasonable copying fee for any distribution of this
-Package.  You may charge any fee you choose for support of this
-Package.  You may not charge a fee for this Package itself.  However,
-you may distribute this Package in aggregate with other (possibly
-commercial) programs as part of a larger (possibly commercial) software
-distribution provided that you do not advertise this Package as a
-product of your own.  You may embed this Package's interpreter within
-an executable of yours (by linking); this shall be construed as a mere
-form of aggregation, provided that the complete Standard Version of the
-interpreter is so embedded.
-
-6. The source code and object code supplied as input to or produced as
-output from the programs of this Package do not automatically fall
-under the copyright of this Package, but belong to whoever generated
-them, and may be sold commercially, and may be aggregated with this
-Package.
-
-7. Aggregation of this Package with a commercial distribution is always
-permitted provided that the use of this Package is embedded; that is,
-when no overt attempt is made to make this Package's interfaces visible
-to the end user of the commercial distribution.  Such use shall not be
-construed as a distribution of this Package.
-
-8. The name of the Copyright Holder may not be used to endorse or promote
-products derived from this software without specific prior written permission.
-
-9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
-				The End
+
+
+
+
+			 The "Artistic License"
+
+				Preamble
+
+The intent of this document is to state the conditions under which a
+Package may be copied, such that the Copyright Holder maintains some
+semblance of artistic control over the development of the package,
+while giving the users of the package the right to use and distribute
+the Package in a more-or-less customary fashion, plus the right to make
+reasonable modifications.
+
+Definitions:
+
+	"Package" refers to the collection of files distributed by the
+	Copyright Holder, and derivatives of that collection of files
+	created through textual modification.
+
+	"Standard Version" refers to such a Package if it has not been
+	modified, or has been modified in accordance with the wishes
+	of the Copyright Holder as specified below.
+
+	"Copyright Holder" is whoever is named in the copyright or
+	copyrights for the package.
+
+	"You" is you, if you're thinking about copying or distributing
+	this Package.
+
+	"Reasonable copying fee" is whatever you can justify on the
+	basis of media cost, duplication charges, time of people involved,
+	and so on.  (You will not be required to justify it to the
+	Copyright Holder, but only to the computing community at large
+	as a market that must bear the fee.)
+
+	"Freely Available" means that no fee is charged for the item
+	itself, though there may be fees involved in handling the item.
+	It also means that recipients of the item may redistribute it
+	under the same conditions they received it.
+
+1. You may make and give away verbatim copies of the source form of the
+Standard Version of this Package without restriction, provided that you
+duplicate all of the original copyright notices and associated disclaimers.
+
+2. You may apply bug fixes, portability fixes and other modifications
+derived from the Public Domain or from the Copyright Holder.  A Package
+modified in such a way shall still be considered the Standard Version.
+
+3. You may otherwise modify your copy of this Package in any way, provided
+that you insert a prominent notice in each changed file stating how and
+when you changed that file, and provided that you do at least ONE of the
+following:
+
+    a) place your modifications in the Public Domain or otherwise make them
+    Freely Available, such as by posting said modifications to Usenet or
+    an equivalent medium, or placing the modifications on a major archive
+    site such as uunet.uu.net, or by allowing the Copyright Holder to include
+    your modifications in the Standard Version of the Package.
+
+    b) use the modified Package only within your corporation or organization.
+