Merge 1.072

This commit is contained in:
kai
2012-02-02 03:13:27 +01:00
parent 81082996e1
commit f9201e8352
72 changed files with 7739 additions and 3484 deletions

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2006 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -76,18 +76,15 @@ enum PROT ClassDeclaration::getAccess(Dsymbol *smember)
}
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];
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = (*baseclasses)[i];
access = b->base->getAccess(smember);
enum PROT access = b->base->getAccess(smember);
switch (access)
{
case PROTnone:
@@ -153,11 +150,9 @@ static int accessCheckX(
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);
for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
{ BaseClass *b = (*cdthis->baseclasses)[i];
enum PROT access = b->base->getAccess(smember);
if (access >= PROTprotected ||
accessCheckX(smember, sfunc, b->base, cdscope)
)
@@ -174,8 +169,8 @@ static int accessCheckX(
ClassDeclaration *cdthis = dthis->isClassDeclaration();
if (cdthis)
{
for (int i = 0; i < cdthis->baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)cdthis->baseclasses->data[i];
for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
{ BaseClass *b = (*cdthis->baseclasses)[i];
if (accessCheckX(smember, sfunc, b->base, cdscope))
return 1;
@@ -219,12 +214,12 @@ void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
//assert(smember->parent->isBaseOf(this, NULL));
if (smemberparent == this)
{ enum PROT access = smember->prot();
{ enum PROT access2 = smember->prot();
result = access >= PROTpublic ||
result = access2 >= PROTpublic ||
hasPrivateAccess(f) ||
isFriendOf(cdscope) ||
(access == PROTpackage && hasPackageAccess(sc, this));
(access2 == PROTpackage && hasPackageAccess(sc, this));
#if LOG
printf("result1 = %d\n", result);
#endif

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -61,7 +61,7 @@ struct AggregateDeclaration : ScopeDsymbol
unsigned alignsize; // size of struct for alignment purposes
unsigned structalign; // struct member alignment in effect
int hasUnions; // set if aggregate has overlapping fields
Array fields; // VarDeclaration fields
VarDeclarations fields; // VarDeclaration fields
unsigned sizeok; // set when structsize contains valid data
// 0: no size
// 1: size is correct
@@ -82,6 +82,7 @@ struct AggregateDeclaration : ScopeDsymbol
Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration
CtorDeclaration *defaultCtor; // default constructor
Dsymbol *aliasthis; // forward unresolved lookups to aliasthis
bool noDefaultCtor; // no default construction
#endif
FuncDeclarations dtors; // Array of destructors
@@ -99,6 +100,8 @@ struct AggregateDeclaration : ScopeDsymbol
static void alignmember(unsigned salign, unsigned size, unsigned *poffset);
Type *getType();
void addField(Scope *sc, VarDeclaration *v);
int firstFieldInUnion(int indx); // first field in union that includes indx
int numFieldsInUnion(int firstIndex); // #fields in union starting at index
int isDeprecated(); // is aggregate deprecated?
FuncDeclaration *buildDtor(Scope *sc);
int isNested();
@@ -146,6 +149,7 @@ struct StructDeclaration : AggregateDeclaration
#if DMDV2
int hasIdentityAssign; // !=0 if has identity opAssign
FuncDeclaration *cpctor; // generated copy-constructor, if any
FuncDeclaration *eq; // bool opEquals(ref const T), if any
FuncDeclarations postblits; // Array of postblit functions
FuncDeclaration *postblit; // aggregate postblit
@@ -202,17 +206,17 @@ struct BaseClass
ClassDeclaration *base;
int offset; // 'this' pointer offset
Array vtbl; // for interfaces: Array of FuncDeclaration's
FuncDeclarations vtbl; // for interfaces: Array of FuncDeclaration's
// making up the vtbl[]
int baseInterfaces_dim;
size_t 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);
int fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newinstance);
void copyBaseInterfaces(BaseClasses *);
};
@@ -227,6 +231,7 @@ struct ClassDeclaration : AggregateDeclaration
{
static ClassDeclaration *object;
static ClassDeclaration *classinfo;
static ClassDeclaration *errorException;
ClassDeclaration *baseClass; // NULL only if this is Object
#if DMDV1
@@ -235,13 +240,13 @@ struct ClassDeclaration : AggregateDeclaration
#endif
FuncDeclaration *staticCtor;
FuncDeclaration *staticDtor;
Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
Dsymbols vtbl; // Array of FuncDeclaration's making up the vtbl[]
Dsymbols 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;
size_t interfaces_dim;
BaseClass **interfaces; // interfaces[interfaces_dim] for this class
// (does not include baseClass)

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -13,7 +13,7 @@
#include "rmem.h"
#include "stringtable.h"
#include "aav.h"
#include "expression.h"
#include "statement.h"
@@ -31,7 +31,7 @@ extern int binary(const char *p , const char **tab, int high);
* Hash table of array op functions already generated or known about.
*/
StringTable arrayfuncs;
AA *arrayfuncs;
#endif
/**********************************************
@@ -125,192 +125,195 @@ Expression *BinExp::arrayOp(Scope *sc)
size_t namelen = buf.offset;
buf.writeByte(0);
char *name = (char *)buf.extractData();
char *name = buf.toChars();
Identifier *ident = Lexer::idPool(name);
/* Look up name in hash table
*/
#if IN_DMD
FuncDeclaration **pfd = (FuncDeclaration **)_aaGet(&arrayfuncs, ident);
FuncDeclaration *fd = (FuncDeclaration *)*pfd;
#elif IN_LLVM
StringValue *sv = sc->module->arrayfuncs.update(name, namelen);
FuncDeclaration *fd = (FuncDeclaration *)sv->ptrvalue;
#endif
if (!fd)
{
// /* Some of the array op functions are written as library functions,
// * presumably to optimize them with special CPU vector instructions.
// * List those library functions here, in alpha order.
// */
// static const char *libArrayopFuncs[] =
// {
// "_arrayExpSliceAddass_a",
// "_arrayExpSliceAddass_d", // T[]+=T
// "_arrayExpSliceAddass_f", // T[]+=T
// "_arrayExpSliceAddass_g",
// "_arrayExpSliceAddass_h",
// "_arrayExpSliceAddass_i",
// "_arrayExpSliceAddass_k",
// "_arrayExpSliceAddass_s",
// "_arrayExpSliceAddass_t",
// "_arrayExpSliceAddass_u",
// "_arrayExpSliceAddass_w",
//
// "_arrayExpSliceDivass_d", // T[]/=T
// "_arrayExpSliceDivass_f", // T[]/=T
//
// "_arrayExpSliceMinSliceAssign_a",
// "_arrayExpSliceMinSliceAssign_d", // T[]=T-T[]
// "_arrayExpSliceMinSliceAssign_f", // T[]=T-T[]
// "_arrayExpSliceMinSliceAssign_g",
// "_arrayExpSliceMinSliceAssign_h",
// "_arrayExpSliceMinSliceAssign_i",
// "_arrayExpSliceMinSliceAssign_k",
// "_arrayExpSliceMinSliceAssign_s",
// "_arrayExpSliceMinSliceAssign_t",
// "_arrayExpSliceMinSliceAssign_u",
// "_arrayExpSliceMinSliceAssign_w",
//
// "_arrayExpSliceMinass_a",
// "_arrayExpSliceMinass_d", // T[]-=T
// "_arrayExpSliceMinass_f", // T[]-=T
// "_arrayExpSliceMinass_g",
// "_arrayExpSliceMinass_h",
// "_arrayExpSliceMinass_i",
// "_arrayExpSliceMinass_k",
// "_arrayExpSliceMinass_s",
// "_arrayExpSliceMinass_t",
// "_arrayExpSliceMinass_u",
// "_arrayExpSliceMinass_w",
//
// "_arrayExpSliceMulass_d", // T[]*=T
// "_arrayExpSliceMulass_f", // T[]*=T
// "_arrayExpSliceMulass_i",
// "_arrayExpSliceMulass_k",
// "_arrayExpSliceMulass_s",
// "_arrayExpSliceMulass_t",
// "_arrayExpSliceMulass_u",
// "_arrayExpSliceMulass_w",
//
// "_arraySliceExpAddSliceAssign_a",
// "_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
// "_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
// "_arraySliceExpAddSliceAssign_g",
// "_arraySliceExpAddSliceAssign_h",
// "_arraySliceExpAddSliceAssign_i",
// "_arraySliceExpAddSliceAssign_k",
// "_arraySliceExpAddSliceAssign_s",
// "_arraySliceExpAddSliceAssign_t",
// "_arraySliceExpAddSliceAssign_u",
// "_arraySliceExpAddSliceAssign_w",
//
// "_arraySliceExpDivSliceAssign_d", // T[]=T[]/T
// "_arraySliceExpDivSliceAssign_f", // T[]=T[]/T
//
// "_arraySliceExpMinSliceAssign_a",
// "_arraySliceExpMinSliceAssign_d", // T[]=T[]-T
// "_arraySliceExpMinSliceAssign_f", // T[]=T[]-T
// "_arraySliceExpMinSliceAssign_g",
// "_arraySliceExpMinSliceAssign_h",
// "_arraySliceExpMinSliceAssign_i",
// "_arraySliceExpMinSliceAssign_k",
// "_arraySliceExpMinSliceAssign_s",
// "_arraySliceExpMinSliceAssign_t",
// "_arraySliceExpMinSliceAssign_u",
// "_arraySliceExpMinSliceAssign_w",
//
// "_arraySliceExpMulSliceAddass_d", // T[] += T[]*T
// "_arraySliceExpMulSliceAddass_f",
// "_arraySliceExpMulSliceAddass_r",
//
// "_arraySliceExpMulSliceAssign_d", // T[]=T[]*T
// "_arraySliceExpMulSliceAssign_f", // T[]=T[]*T
// "_arraySliceExpMulSliceAssign_i",
// "_arraySliceExpMulSliceAssign_k",
// "_arraySliceExpMulSliceAssign_s",
// "_arraySliceExpMulSliceAssign_t",
// "_arraySliceExpMulSliceAssign_u",
// "_arraySliceExpMulSliceAssign_w",
//
// "_arraySliceExpMulSliceMinass_d", // T[] -= T[]*T
// "_arraySliceExpMulSliceMinass_f",
// "_arraySliceExpMulSliceMinass_r",
//
// "_arraySliceSliceAddSliceAssign_a",
// "_arraySliceSliceAddSliceAssign_d", // T[]=T[]+T[]
// "_arraySliceSliceAddSliceAssign_f", // T[]=T[]+T[]
// "_arraySliceSliceAddSliceAssign_g",
// "_arraySliceSliceAddSliceAssign_h",
// "_arraySliceSliceAddSliceAssign_i",
// "_arraySliceSliceAddSliceAssign_k",
// "_arraySliceSliceAddSliceAssign_r", // T[]=T[]+T[]
// "_arraySliceSliceAddSliceAssign_s",
// "_arraySliceSliceAddSliceAssign_t",
// "_arraySliceSliceAddSliceAssign_u",
// "_arraySliceSliceAddSliceAssign_w",
//
// "_arraySliceSliceAddass_a",
// "_arraySliceSliceAddass_d", // T[]+=T[]
// "_arraySliceSliceAddass_f", // T[]+=T[]
// "_arraySliceSliceAddass_g",
// "_arraySliceSliceAddass_h",
// "_arraySliceSliceAddass_i",
// "_arraySliceSliceAddass_k",
// "_arraySliceSliceAddass_s",
// "_arraySliceSliceAddass_t",
// "_arraySliceSliceAddass_u",
// "_arraySliceSliceAddass_w",
//
// "_arraySliceSliceMinSliceAssign_a",
// "_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[]
// "_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[]
// "_arraySliceSliceMinSliceAssign_g",
// "_arraySliceSliceMinSliceAssign_h",
// "_arraySliceSliceMinSliceAssign_i",
// "_arraySliceSliceMinSliceAssign_k",
// "_arraySliceSliceMinSliceAssign_r", // T[]=T[]-T[]
// "_arraySliceSliceMinSliceAssign_s",
// "_arraySliceSliceMinSliceAssign_t",
// "_arraySliceSliceMinSliceAssign_u",
// "_arraySliceSliceMinSliceAssign_w",
//
// "_arraySliceSliceMinass_a",
// "_arraySliceSliceMinass_d", // T[]-=T[]
// "_arraySliceSliceMinass_f", // T[]-=T[]
// "_arraySliceSliceMinass_g",
// "_arraySliceSliceMinass_h",
// "_arraySliceSliceMinass_i",
// "_arraySliceSliceMinass_k",
// "_arraySliceSliceMinass_s",
// "_arraySliceSliceMinass_t",
// "_arraySliceSliceMinass_u",
// "_arraySliceSliceMinass_w",
//
// "_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[]
// "_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[]
// "_arraySliceSliceMulSliceAssign_i",
// "_arraySliceSliceMulSliceAssign_k",
// "_arraySliceSliceMulSliceAssign_s",
// "_arraySliceSliceMulSliceAssign_t",
// "_arraySliceSliceMulSliceAssign_u",
// "_arraySliceSliceMulSliceAssign_w",
//
// "_arraySliceSliceMulass_d", // T[]*=T[]
// "_arraySliceSliceMulass_f", // T[]*=T[]
// "_arraySliceSliceMulass_i",
// "_arraySliceSliceMulass_k",
// "_arraySliceSliceMulass_s",
// "_arraySliceSliceMulass_t",
// "_arraySliceSliceMulass_u",
// "_arraySliceSliceMulass_w",
// };
//
// int i = binary(name, libArrayopFuncs, sizeof(libArrayopFuncs) / sizeof(char *));
// if (i == -1)
// {
// #ifdef DEBUG // Make sure our array is alphabetized
// for (i = 0; i < sizeof(libArrayopFuncs) / sizeof(char *); i++)
// {
// if (strcmp(name, libArrayopFuncs[i]) == 0)
// assert(0);
// }
// #endif
#if IN_DMD
static const char *libArrayopFuncs[] =
{
"_arrayExpSliceAddass_a",
"_arrayExpSliceAddass_d", // T[]+=T
"_arrayExpSliceAddass_f", // T[]+=T
"_arrayExpSliceAddass_g",
"_arrayExpSliceAddass_h",
"_arrayExpSliceAddass_i",
"_arrayExpSliceAddass_k",
"_arrayExpSliceAddass_s",
"_arrayExpSliceAddass_t",
"_arrayExpSliceAddass_u",
"_arrayExpSliceAddass_w",
"_arrayExpSliceDivass_d", // T[]/=T
"_arrayExpSliceDivass_f", // T[]/=T
"_arrayExpSliceMinSliceAssign_a",
"_arrayExpSliceMinSliceAssign_d", // T[]=T-T[]
"_arrayExpSliceMinSliceAssign_f", // T[]=T-T[]
"_arrayExpSliceMinSliceAssign_g",
"_arrayExpSliceMinSliceAssign_h",
"_arrayExpSliceMinSliceAssign_i",
"_arrayExpSliceMinSliceAssign_k",
"_arrayExpSliceMinSliceAssign_s",
"_arrayExpSliceMinSliceAssign_t",
"_arrayExpSliceMinSliceAssign_u",
"_arrayExpSliceMinSliceAssign_w",
"_arrayExpSliceMinass_a",
"_arrayExpSliceMinass_d", // T[]-=T
"_arrayExpSliceMinass_f", // T[]-=T
"_arrayExpSliceMinass_g",
"_arrayExpSliceMinass_h",
"_arrayExpSliceMinass_i",
"_arrayExpSliceMinass_k",
"_arrayExpSliceMinass_s",
"_arrayExpSliceMinass_t",
"_arrayExpSliceMinass_u",
"_arrayExpSliceMinass_w",
"_arrayExpSliceMulass_d", // T[]*=T
"_arrayExpSliceMulass_f", // T[]*=T
"_arrayExpSliceMulass_i",
"_arrayExpSliceMulass_k",
"_arrayExpSliceMulass_s",
"_arrayExpSliceMulass_t",
"_arrayExpSliceMulass_u",
"_arrayExpSliceMulass_w",
"_arraySliceExpAddSliceAssign_a",
"_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
"_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
"_arraySliceExpAddSliceAssign_g",
"_arraySliceExpAddSliceAssign_h",
"_arraySliceExpAddSliceAssign_i",
"_arraySliceExpAddSliceAssign_k",
"_arraySliceExpAddSliceAssign_s",
"_arraySliceExpAddSliceAssign_t",
"_arraySliceExpAddSliceAssign_u",
"_arraySliceExpAddSliceAssign_w",
"_arraySliceExpDivSliceAssign_d", // T[]=T[]/T
"_arraySliceExpDivSliceAssign_f", // T[]=T[]/T
"_arraySliceExpMinSliceAssign_a",
"_arraySliceExpMinSliceAssign_d", // T[]=T[]-T
"_arraySliceExpMinSliceAssign_f", // T[]=T[]-T
"_arraySliceExpMinSliceAssign_g",
"_arraySliceExpMinSliceAssign_h",
"_arraySliceExpMinSliceAssign_i",
"_arraySliceExpMinSliceAssign_k",
"_arraySliceExpMinSliceAssign_s",
"_arraySliceExpMinSliceAssign_t",
"_arraySliceExpMinSliceAssign_u",
"_arraySliceExpMinSliceAssign_w",
"_arraySliceExpMulSliceAddass_d", // T[] += T[]*T
"_arraySliceExpMulSliceAddass_f",
"_arraySliceExpMulSliceAddass_r",
"_arraySliceExpMulSliceAssign_d", // T[]=T[]*T
"_arraySliceExpMulSliceAssign_f", // T[]=T[]*T
"_arraySliceExpMulSliceAssign_i",
"_arraySliceExpMulSliceAssign_k",
"_arraySliceExpMulSliceAssign_s",
"_arraySliceExpMulSliceAssign_t",
"_arraySliceExpMulSliceAssign_u",
"_arraySliceExpMulSliceAssign_w",
"_arraySliceExpMulSliceMinass_d", // T[] -= T[]*T
"_arraySliceExpMulSliceMinass_f",
"_arraySliceExpMulSliceMinass_r",
"_arraySliceSliceAddSliceAssign_a",
"_arraySliceSliceAddSliceAssign_d", // T[]=T[]+T[]
"_arraySliceSliceAddSliceAssign_f", // T[]=T[]+T[]
"_arraySliceSliceAddSliceAssign_g",
"_arraySliceSliceAddSliceAssign_h",
"_arraySliceSliceAddSliceAssign_i",
"_arraySliceSliceAddSliceAssign_k",
"_arraySliceSliceAddSliceAssign_r", // T[]=T[]+T[]
"_arraySliceSliceAddSliceAssign_s",
"_arraySliceSliceAddSliceAssign_t",
"_arraySliceSliceAddSliceAssign_u",
"_arraySliceSliceAddSliceAssign_w",
"_arraySliceSliceAddass_a",
"_arraySliceSliceAddass_d", // T[]+=T[]
"_arraySliceSliceAddass_f", // T[]+=T[]
"_arraySliceSliceAddass_g",
"_arraySliceSliceAddass_h",
"_arraySliceSliceAddass_i",
"_arraySliceSliceAddass_k",
"_arraySliceSliceAddass_s",
"_arraySliceSliceAddass_t",
"_arraySliceSliceAddass_u",
"_arraySliceSliceAddass_w",
"_arraySliceSliceMinSliceAssign_a",
"_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[]
"_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[]
"_arraySliceSliceMinSliceAssign_g",
"_arraySliceSliceMinSliceAssign_h",
"_arraySliceSliceMinSliceAssign_i",
"_arraySliceSliceMinSliceAssign_k",
"_arraySliceSliceMinSliceAssign_r", // T[]=T[]-T[]
"_arraySliceSliceMinSliceAssign_s",
"_arraySliceSliceMinSliceAssign_t",
"_arraySliceSliceMinSliceAssign_u",
"_arraySliceSliceMinSliceAssign_w",
"_arraySliceSliceMinass_a",
"_arraySliceSliceMinass_d", // T[]-=T[]
"_arraySliceSliceMinass_f", // T[]-=T[]
"_arraySliceSliceMinass_g",
"_arraySliceSliceMinass_h",
"_arraySliceSliceMinass_i",
"_arraySliceSliceMinass_k",
"_arraySliceSliceMinass_s",
"_arraySliceSliceMinass_t",
"_arraySliceSliceMinass_u",
"_arraySliceSliceMinass_w",
"_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[]
"_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[]
"_arraySliceSliceMulSliceAssign_i",
"_arraySliceSliceMulSliceAssign_k",
"_arraySliceSliceMulSliceAssign_s",
"_arraySliceSliceMulSliceAssign_t",
"_arraySliceSliceMulSliceAssign_u",
"_arraySliceSliceMulSliceAssign_w",
"_arraySliceSliceMulass_d", // T[]*=T[]
"_arraySliceSliceMulass_f", // T[]*=T[]
"_arraySliceSliceMulass_i",
"_arraySliceSliceMulass_k",
"_arraySliceSliceMulass_s",
"_arraySliceSliceMulass_t",
"_arraySliceSliceMulass_u",
"_arraySliceSliceMulass_w",
};
int i = binary(name, libArrayopFuncs, sizeof(libArrayopFuncs) / sizeof(char *));
if (i == -1)
{
#ifdef DEBUG // Make sure our array is alphabetized
for (i = 0; i < sizeof(libArrayopFuncs) / sizeof(char *); i++)
{
if (strcmp(name, libArrayopFuncs[i]) == 0)
assert(0);
}
#endif
#endif
/* Not in library, so generate it.
* Construct the function body:
* foreach (i; 0 .. p.length) for (size_t i = 0; i < p.length; i++)
@@ -320,13 +323,13 @@ Expression *BinExp::arrayOp(Scope *sc)
Parameters *fparams = new Parameters();
Expression *loopbody = buildArrayLoop(fparams);
Parameter *p = (Parameter *)fparams->data[0 /*fparams->dim - 1*/];
Parameter *p = (*fparams)[0 /*fparams->dim - 1*/];
#if DMDV1
// for (size_t i = 0; i < p.length; i++)
Initializer *init = new ExpInitializer(0, new IntegerExp(0, 0, Type::tsize_t));
Dsymbol *d = new VarDeclaration(0, Type::tsize_t, Id::p, init);
Statement *s1 = new ForStatement(0,
new DeclarationStatement(0, d),
new ExpStatement(0, d),
new CmpExp(TOKlt, 0, new IdentifierExp(0, Id::p), new ArrayLengthExp(0, new IdentifierExp(0, p->ident))),
new PostExp(TOKplusplus, 0, new IdentifierExp(0, Id::p)),
new ExpStatement(0, loopbody));
@@ -346,32 +349,33 @@ Expression *BinExp::arrayOp(Scope *sc)
*/
TypeFunction *ftype = new TypeFunction(fparams, type, 0, LINKc);
//printf("ftype: %s\n", ftype->toChars());
fd = new FuncDeclaration(0, 0, Lexer::idPool(name), STCundefined, ftype);
fd = new FuncDeclaration(loc, 0, ident, STCundefined, ftype);
fd->fbody = fbody;
fd->protection = PROTpublic;
fd->linkage = LINKd;
// special attention for array ops
fd->isArrayOp = true;
fd->linkage = LINKc;
fd->isArrayOp = 1;
sc->module->importedFrom->members->push(fd);
sc = sc->push();
sc->parent = sc->module->importedFrom;
sc->stc = 0;
sc->linkage = LINKd;
sc->linkage = LINKc;
fd->semantic(sc);
fd->semantic2(sc);
fd->semantic3(sc);
sc->pop();
// }
// else
// { /* In library, refer to it.
// */
// // FIXME
// fd = FuncDeclaration::genCfunc(NULL, type, name);
// }
#if IN_DMD
}
else
{ /* In library, refer to it.
*/
fd = FuncDeclaration::genCfunc(type, ident);
}
*pfd = fd; // cache symbol in hash table
#elif IN_LLVM
sv->ptrvalue = fd; // cache symbol in hash table
#endif
}
/* Call the function fd(arguments)
@@ -438,6 +442,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X
@@ -471,6 +478,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X
@@ -526,7 +536,7 @@ Expression *AssignExp::buildArrayLoop(Parameters *fparams)
ex2 = new CastExp(0, ex2, e1->type->nextOf());
#endif
Expression *ex1 = e1->buildArrayLoop(fparams);
Parameter *param = (Parameter *)fparams->data[0];
Parameter *param = (*fparams)[0];
param->storageClass = 0;
Expression *e = new AssignExp(0, ex1, ex2);
return e;
@@ -539,7 +549,7 @@ Expression *Str##AssignExp::buildArrayLoop(Parameters *fparams) \
*/ \
Expression *ex2 = e2->buildArrayLoop(fparams); \
Expression *ex1 = e1->buildArrayLoop(fparams); \
Parameter *param = (Parameter *)fparams->data[0]; \
Parameter *param = (*fparams)[0]; \
param->storageClass = 0; \
Expression *e = new Str##AssignExp(0, ex1, ex2); \
return e; \
@@ -553,6 +563,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X
@@ -589,6 +602,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X

View File

@@ -26,26 +26,40 @@ struct FuncDeclaration;
struct Identifier;
struct Initializer;
struct TemplateParameters : Array { };
typedef ArrayBase<struct TemplateParameter> TemplateParameters;
struct Expressions : Array { };
typedef ArrayBase<struct Expression> Expressions;
struct Statements : Array { };
typedef ArrayBase<struct Statement> Statements;
struct BaseClasses : Array { };
typedef ArrayBase<struct BaseClass> BaseClasses;
struct ClassDeclarations : Array { };
typedef ArrayBase<struct ClassDeclaration> ClassDeclarations;
struct Dsymbols : Array { };
typedef ArrayBase<struct Dsymbol> Dsymbols;
struct Objects : Array { };
typedef ArrayBase<struct Object> Objects;
struct FuncDeclarations : Array { };
typedef ArrayBase<struct FuncDeclaration> FuncDeclarations;
struct Parameters : Array { };
typedef ArrayBase<struct Parameter> Parameters;
struct Identifiers : Array { };
typedef ArrayBase<struct Identifier> Identifiers;
struct Initializers : Array { };
typedef ArrayBase<struct Initializer> Initializers;
typedef ArrayBase<struct VarDeclaration> VarDeclarations;
typedef ArrayBase<struct Type> Types;
typedef ArrayBase<struct ScopeDsymbol> ScopeDsymbols;
typedef ArrayBase<struct StaticDtorDeclaration> StaticDtorDeclarations;
typedef ArrayBase<struct SharedStaticDtorDeclaration> SharedStaticDtorDeclarations;
typedef ArrayBase<struct Module> Modules;
typedef ArrayBase<struct CaseStatement> CaseStatements;
typedef ArrayBase<struct TemplateInstance> TemplateInstances;
typedef ArrayBase<struct Symbol> Symbols;
#endif

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -51,13 +51,13 @@ void obj_startaddress(Symbol *s);
/********************************* AttribDeclaration ****************************/
AttribDeclaration::AttribDeclaration(Array *decl)
AttribDeclaration::AttribDeclaration(Dsymbols *decl)
: Dsymbol()
{
this->decl = decl;
}
Array *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd)
Dsymbols *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd)
{
return decl;
}
@@ -65,12 +65,13 @@ Array *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd)
int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
{
int m = 0;
Array *d = include(sc, sd);
Dsymbols *d = include(sc, sd);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
//printf("\taddMember %s to %s\n", s->toChars(), sd->toChars());
m |= s->addMember(sc, sd, m | memnum);
}
}
@@ -100,7 +101,7 @@ void AttribDeclaration::setScopeNewSc(Scope *sc,
newsc->structalign = structalign;
}
for (unsigned i = 0; i < decl->dim; i++)
{ Dsymbol *s = (Dsymbol *)decl->data[i];
{ Dsymbol *s = decl->tdata()[i];
s->setScope(newsc); // yes, the only difference from semanticNewSc()
}
@@ -135,7 +136,7 @@ void AttribDeclaration::semanticNewSc(Scope *sc,
newsc->structalign = structalign;
}
for (unsigned i = 0; i < decl->dim; i++)
{ Dsymbol *s = (Dsymbol *)decl->data[i];
{ Dsymbol *s = decl->tdata()[i];
s->semantic(newsc);
}
@@ -149,14 +150,14 @@ void AttribDeclaration::semanticNewSc(Scope *sc,
void AttribDeclaration::semantic(Scope *sc)
{
Array *d = include(sc, NULL);
Dsymbols *d = include(sc, NULL);
//printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = (Dsymbol *)d->data[i];
Dsymbol *s = d->tdata()[i];
s->semantic(sc);
}
@@ -165,12 +166,12 @@ void AttribDeclaration::semantic(Scope *sc)
void AttribDeclaration::semantic2(Scope *sc)
{
Array *d = include(sc, NULL);
Dsymbols *d = include(sc, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
for (size_t i = 0; i < d->dim; i++)
{ Dsymbol *s = d->tdata()[i];
s->semantic2(sc);
}
}
@@ -178,12 +179,12 @@ void AttribDeclaration::semantic2(Scope *sc)
void AttribDeclaration::semantic3(Scope *sc)
{
Array *d = include(sc, NULL);
Dsymbols *d = include(sc, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
for (size_t i = 0; i < d->dim; i++)
{ Dsymbol *s = d->tdata()[i];
s->semantic3(sc);
}
}
@@ -191,12 +192,12 @@ void AttribDeclaration::semantic3(Scope *sc)
void AttribDeclaration::inlineScan()
{
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
//printf("AttribDeclaration::inlineScan %s\n", s->toChars());
s->inlineScan();
}
@@ -205,14 +206,15 @@ void AttribDeclaration::inlineScan()
void AttribDeclaration::addComment(unsigned char *comment)
{
//printf("AttribDeclaration::addComment %s\n", comment);
if (comment)
{
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
//printf("AttribDeclaration::addComment %s\n", s->toChars());
s->addComment(comment);
}
@@ -232,12 +234,12 @@ void AttribDeclaration::emitComment(Scope *sc)
* Hence, Ddoc omits attributes from template members.
*/
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
//printf("AttribDeclaration::emitComment %s\n", s->toChars());
s->emitComment(sc);
}
@@ -248,12 +250,12 @@ void AttribDeclaration::emitComment(Scope *sc)
void AttribDeclaration::toObjFile(int multiobj)
{
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->toObjFile(multiobj);
}
}
@@ -263,12 +265,12 @@ int AttribDeclaration::cvMember(unsigned char *p)
{
int nwritten = 0;
int n;
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
n = s->cvMember(p);
if (p)
p += n;
@@ -281,13 +283,13 @@ int AttribDeclaration::cvMember(unsigned char *p)
int AttribDeclaration::hasPointers()
{
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = (Dsymbol *)d->data[i];
Dsymbol *s = d->tdata()[i];
if (s->hasPointers())
return 1;
}
@@ -295,6 +297,22 @@ int AttribDeclaration::hasPointers()
return 0;
}
bool AttribDeclaration::hasStaticCtorOrDtor()
{
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = (*d)[i];
if (s->hasStaticCtorOrDtor())
return TRUE;
}
}
return FALSE;
}
const char *AttribDeclaration::kind()
{
return "attribute";
@@ -302,19 +320,19 @@ const char *AttribDeclaration::kind()
int AttribDeclaration::oneMember(Dsymbol **ps)
{
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
return Dsymbol::oneMembers(d, ps);
}
void AttribDeclaration::checkCtorConstInit()
{
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->checkCtorConstInit();
}
}
@@ -325,12 +343,12 @@ void AttribDeclaration::checkCtorConstInit()
void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses)
{
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->addLocalClass(aclasses);
}
}
@@ -344,7 +362,7 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
if (decl->dim == 0)
buf->writestring("{}");
else if (decl->dim == 1)
((Dsymbol *)decl->data[0])->toCBuffer(buf, hgs);
(decl->tdata()[0])->toCBuffer(buf, hgs);
else
{
buf->writenl();
@@ -352,7 +370,7 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
for (unsigned i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
Dsymbol *s = decl->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -367,7 +385,7 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************* StorageClassDeclaration ****************************/
StorageClassDeclaration::StorageClassDeclaration(StorageClass stc, Array *decl)
StorageClassDeclaration::StorageClassDeclaration(StorageClass stc, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->stc = stc;
@@ -509,7 +527,7 @@ void StorageClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* LinkDeclaration ****************************/
LinkDeclaration::LinkDeclaration(enum LINK p, Array *decl)
LinkDeclaration::LinkDeclaration(enum LINK p, Dsymbols *decl)
: AttribDeclaration(decl)
{
//printf("LinkDeclaration(linkage = %d, decl = %p)\n", p, decl);
@@ -552,7 +570,7 @@ void LinkDeclaration::semantic3(Scope *sc)
sc->linkage = linkage;
for (unsigned i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
Dsymbol *s = decl->tdata()[i];
s->semantic3(sc);
}
@@ -595,7 +613,7 @@ char *LinkDeclaration::toChars()
/********************************* ProtDeclaration ****************************/
ProtDeclaration::ProtDeclaration(enum PROT p, Array *decl)
ProtDeclaration::ProtDeclaration(enum PROT p, Dsymbols *decl)
: AttribDeclaration(decl)
{
protection = p;
@@ -632,9 +650,9 @@ void ProtDeclaration::importAll(Scope *sc)
newsc->explicitProtection = 1;
}
for (int i = 0; i < decl->dim; i++)
for (size_t i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
Dsymbol *s = (*decl)[i];
s->importAll(newsc);
}
@@ -677,7 +695,7 @@ void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* AlignDeclaration ****************************/
AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl)
AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->loc = loc;
@@ -721,7 +739,7 @@ void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* AnonDeclaration ****************************/
AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl)
AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->loc = loc;
@@ -742,6 +760,12 @@ void AnonDeclaration::semantic(Scope *sc)
{
//printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this);
if (sem == 1)
{ //printf("already completed\n");
scope = NULL;
return; // semantic() already completed
}
Scope *scx = NULL;
if (scope)
{ sc = scope;
@@ -789,7 +813,7 @@ void AnonDeclaration::semantic(Scope *sc)
for (unsigned i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
Dsymbol *s = decl->tdata()[i];
s->semantic(sc);
if (isunion)
@@ -882,7 +906,7 @@ void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
for (unsigned i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
Dsymbol *s = decl->tdata()[i];
//buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -912,7 +936,7 @@ static bool parseStringExp(Expression* e, std::string& res)
return false;
}
PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl)
PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->loc = loc;
@@ -942,15 +966,16 @@ void PragmaDeclaration::setScope(Scope *sc)
}
else
{
Expression *e = (Expression *)args->data[0];
Expression *e = args->tdata()[0];
e = e->semantic(sc);
e = e->optimize(WANTvalue | WANTinterpret);
args->data[0] = (void *)e;
if (e->op != TOKstring)
args->tdata()[0] = e;
StringExp* se = e->toString();
if (!se)
{
error("string expected, not '%s'", e->toChars());
}
PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e));
PragmaScope* pragma = new PragmaScope(this, sc->parent, se);
assert(sc);
pragma->setScope(sc);
@@ -980,13 +1005,13 @@ void PragmaDeclaration::semantic(Scope *sc)
{
for (size_t i = 0; i < args->dim; i++)
{
Expression *e = (Expression *)args->data[i];
Expression *e = args->tdata()[i];
e = e->semantic(sc);
e = e->optimize(WANTvalue | WANTinterpret);
if (e->op == TOKstring)
StringExp *se = e->toString();
if (se)
{
StringExp *se = (StringExp *)e;
fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string);
}
else
@@ -1002,16 +1027,18 @@ void PragmaDeclaration::semantic(Scope *sc)
error("string expected for library name");
else
{
Expression *e = (Expression *)args->data[0];
Expression *e = args->tdata()[0];
e = e->semantic(sc);
e = e->optimize(WANTvalue | WANTinterpret);
args->data[0] = (void *)e;
if (e->op != TOKstring)
args->tdata()[0] = e;
if (e->op == TOKerror)
goto Lnodecl;
StringExp *se = e->toString();
if (!se)
error("string expected for library name, not '%s'", e->toChars());
else if (global.params.verbose)
{
StringExp *se = (StringExp *)e;
char *name = (char *)mem.malloc(se->len + 1);
memcpy(name, se->string, se->len);
name[se->len] = 0;
@@ -1043,10 +1070,11 @@ void PragmaDeclaration::semantic(Scope *sc)
if (!d)
error("first argument of GNU_asm must be a function or variable declaration");
e = (Expression *)args->data[1];
e = args->tdata()[1];
e = e->semantic(sc);
e = e->optimize(WANTvalue);
if (e->op == TOKstring && ((StringExp *)e)->sz == 1)
e = e->toString();
if (e && ((StringExp *)e)->sz == 1)
s = ((StringExp *)e);
else
error("second argument of GNU_asm must be a char string");
@@ -1307,7 +1335,7 @@ void PragmaDeclaration::semantic(Scope *sc)
{
for (unsigned i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
Dsymbol *s = decl->tdata()[i];
s->semantic(sc);
@@ -1492,7 +1520,7 @@ void PragmaDeclaration::toObjFile(int multiobj)
* so instead append the library name to the list to be passed
* to the linker.
*/
global.params.libfiles->push((void *) name);
global.params.libfiles->push(name);
#else
error("pragma lib not supported");
#endif
@@ -1533,7 +1561,7 @@ void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* ConditionalDeclaration ****************************/
ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl)
ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl)
: AttribDeclaration(decl)
{
//printf("ConditionalDeclaration::ConditionalDeclaration()\n");
@@ -1558,7 +1586,7 @@ int ConditionalDeclaration::oneMember(Dsymbol **ps)
//printf("ConditionalDeclaration::oneMember(), inc = %d\n", condition->inc);
if (condition->inc)
{
Array *d = condition->include(NULL, NULL) ? decl : elsedecl;
Dsymbols *d = condition->include(NULL, NULL) ? decl : elsedecl;
return Dsymbol::oneMembers(d, ps);
}
*ps = NULL;
@@ -1577,9 +1605,9 @@ void ConditionalDeclaration::emitComment(Scope *sc)
/* If generating doc comment, be careful because if we're inside
* a template, then include(NULL, NULL) will fail.
*/
Array *d = decl ? decl : elsedecl;
Dsymbols *d = decl ? decl : elsedecl;
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->emitComment(sc);
}
}
@@ -1587,7 +1615,7 @@ void ConditionalDeclaration::emitComment(Scope *sc)
// Decide if 'then' or 'else' code should be included
Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd)
Dsymbols *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd)
{
//printf("ConditionalDeclaration::include()\n");
assert(condition);
@@ -1596,14 +1624,14 @@ Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd)
void ConditionalDeclaration::setScope(Scope *sc)
{
Array *d = include(sc, NULL);
Dsymbols *d = include(sc, NULL);
//printf("\tConditionalDeclaration::setScope '%s', d = %p\n",toChars(), d);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{
Dsymbol *s = (Dsymbol *)d->data[i];
Dsymbol *s = d->tdata()[i];
s->setScope(sc);
}
@@ -1612,14 +1640,14 @@ void ConditionalDeclaration::setScope(Scope *sc)
void ConditionalDeclaration::importAll(Scope *sc)
{
Array *d = include(sc, NULL);
Dsymbols *d = include(sc, NULL);
//printf("\tConditionalDeclaration::importAll '%s', d = %p\n",toChars(), d);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{
Dsymbol *s = (Dsymbol *)d->data[i];
Dsymbol *s = d->tdata()[i];
s->importAll(sc);
}
@@ -1636,7 +1664,7 @@ void ConditionalDeclaration::addComment(unsigned char *comment)
if (comment)
{
Array *d = decl;
Dsymbols *d = decl;
for (int j = 0; j < 2; j++)
{
@@ -1645,7 +1673,7 @@ void ConditionalDeclaration::addComment(unsigned char *comment)
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s;
s = (Dsymbol *)d->data[i];
s = d->tdata()[i];
//printf("ConditionalDeclaration::addComment %s\n", s->toChars());
s->addComment(comment);
}
@@ -1667,7 +1695,7 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
for (unsigned i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
Dsymbol *s = decl->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -1683,7 +1711,7 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
for (unsigned i = 0; i < elsedecl->dim; i++)
{
Dsymbol *s = (Dsymbol *)elsedecl->data[i];
Dsymbol *s = elsedecl->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -1699,7 +1727,7 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/***************************** StaticIfDeclaration ****************************/
StaticIfDeclaration::StaticIfDeclaration(Condition *condition,
Array *decl, Array *elsedecl)
Dsymbols *decl, Dsymbols *elsedecl)
: ConditionalDeclaration(condition, decl, elsedecl)
{
//printf("StaticIfDeclaration::StaticIfDeclaration()\n");
@@ -1757,7 +1785,7 @@ void StaticIfDeclaration::setScope(Scope *sc)
void StaticIfDeclaration::semantic(Scope *sc)
{
Array *d = include(sc, sd);
Dsymbols *d = include(sc, sd);
//printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d);
if (d)
@@ -1769,7 +1797,7 @@ void StaticIfDeclaration::semantic(Scope *sc)
for (unsigned i = 0; i < d->dim; i++)
{
Dsymbol *s = (Dsymbol *)d->data[i];
Dsymbol *s = d->tdata()[i];
s->semantic(sc);
}
@@ -1821,12 +1849,12 @@ void CompileDeclaration::compileIt(Scope *sc)
exp = exp->semantic(sc);
exp = resolveProperties(sc, exp);
exp = exp->optimize(WANTvalue | WANTinterpret);
if (exp->op != TOKstring)
StringExp *se = exp->toString();
if (!se)
{ exp->error("argument to mixin must be a string, not (%s)", exp->toChars());
}
else
{
StringExp *se = (StringExp *)exp;
se = se->toUTF8(sc);
Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
p.loc = loc;

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -23,18 +23,16 @@ struct LabelDsymbol;
struct Initializer;
struct Module;
struct Condition;
#ifdef _DH
struct HdrGenState;
#endif
/**************************************************************/
struct AttribDeclaration : Dsymbol
{
Array *decl; // array of Dsymbol's
Dsymbols *decl; // array of Dsymbol's
AttribDeclaration(Array *decl);
virtual Array *include(Scope *sc, ScopeDsymbol *s);
AttribDeclaration(Dsymbols *decl);
virtual Dsymbols *include(Scope *sc, ScopeDsymbol *s);
int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
void setScopeNewSc(Scope *sc,
StorageClass newstc, enum LINK linkage, enum PROT protection, int explictProtection,
@@ -51,6 +49,7 @@ struct AttribDeclaration : Dsymbol
const char *kind();
int oneMember(Dsymbol **ps);
int hasPointers();
bool hasStaticCtorOrDtor();
void checkCtorConstInit();
void addLocalClass(ClassDeclarations *);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -71,7 +70,7 @@ struct StorageClassDeclaration: AttribDeclaration
{
StorageClass stc;
StorageClassDeclaration(StorageClass stc, Array *decl);
StorageClassDeclaration(StorageClass stc, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void setScope(Scope *sc);
void semantic(Scope *sc);
@@ -84,7 +83,7 @@ struct LinkDeclaration : AttribDeclaration
{
enum LINK linkage;
LinkDeclaration(enum LINK p, Array *decl);
LinkDeclaration(enum LINK p, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void setScope(Scope *sc);
void semantic(Scope *sc);
@@ -97,7 +96,7 @@ struct ProtDeclaration : AttribDeclaration
{
enum PROT protection;
ProtDeclaration(enum PROT p, Array *decl);
ProtDeclaration(enum PROT p, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void importAll(Scope *sc);
void setScope(Scope *sc);
@@ -111,7 +110,7 @@ struct AlignDeclaration : AttribDeclaration
{
unsigned salign;
AlignDeclaration(Loc loc, unsigned sa, Array *decl);
AlignDeclaration(Loc loc, unsigned sa, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void setScope(Scope *sc);
void semantic(Scope *sc);
@@ -123,7 +122,7 @@ struct AnonDeclaration : AttribDeclaration
int isunion;
int sem; // 1 if successful semantic()
AnonDeclaration(Loc loc, int isunion, Array *decl);
AnonDeclaration(Loc loc, int isunion, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -134,7 +133,7 @@ struct PragmaDeclaration : AttribDeclaration
{
Expressions *args; // array of Expression's
PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl);
PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
void setScope(Scope *sc);
@@ -154,13 +153,13 @@ struct PragmaDeclaration : AttribDeclaration
struct ConditionalDeclaration : AttribDeclaration
{
Condition *condition;
Array *elsedecl; // array of Dsymbol's for else block
Dsymbols *elsedecl; // array of Dsymbol's for else block
ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl);
ConditionalDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl);
Dsymbol *syntaxCopy(Dsymbol *s);
int oneMember(Dsymbol **ps);
void emitComment(Scope *sc);
Array *include(Scope *sc, ScopeDsymbol *s);
Dsymbols *include(Scope *sc, ScopeDsymbol *s);
void addComment(unsigned char *comment);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toJsonBuffer(OutBuffer *buf);
@@ -173,7 +172,7 @@ struct StaticIfDeclaration : ConditionalDeclaration
ScopeDsymbol *sd;
int addisdone;
StaticIfDeclaration(Condition *condition, Array *decl, Array *elsedecl);
StaticIfDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl);
Dsymbol *syntaxCopy(Dsymbol *s);
int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
void semantic(Scope *sc);

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -123,6 +123,8 @@ MATCH Expression::implicitConvTo(Type *t)
toChars(), type->toChars(), t->toChars());
#endif
//static int nest; if (++nest == 10) halt();
if (t == Type::terror)
return MATCHnomatch;
if (!type)
{ error("%s is not an expression", toChars());
type = Type::terror;
@@ -377,8 +379,8 @@ MATCH StructLiteralExp::implicitConvTo(Type *t)
((TypeStruct *)type)->sym == ((TypeStruct *)t)->sym)
{
m = MATCHconst;
for (int i = 0; i < elements->dim; i++)
{ Expression *e = (Expression *)elements->data[i];
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (*elements)[i];
Type *te = e->type;
if (t->mod == 0)
te = te->mutableOf();
@@ -397,8 +399,7 @@ MATCH StructLiteralExp::implicitConvTo(Type *t)
#endif
MATCH StringExp::implicitConvTo(Type *t)
{ MATCH m;
{
#if 0
printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n",
toChars(), committed, type->toChars(), t->toChars());
@@ -466,14 +467,18 @@ MATCH ArrayLiteralExp::implicitConvTo(Type *t)
result = MATCHnomatch;
}
for (int i = 0; i < elements->dim; i++)
{ Expression *e = (Expression *)elements->data[i];
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (*elements)[i];
MATCH m = (MATCH)e->implicitConvTo(tb->nextOf());
if (m < result)
result = m; // remember worst match
if (result == MATCHnomatch)
break; // no need to check for worse
}
if (!result)
result = type->implicitConvTo(t);
return result;
}
else
@@ -581,7 +586,6 @@ MATCH DelegateExp::implicitConvTo(Type *t)
if (result == 0)
{
// Look for pointers to functions where the functions are overloaded.
FuncDeclaration *f;
t = t->toBasetype();
if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction &&
@@ -663,6 +667,12 @@ Expression *Expression::castTo(Scope *sc, Type *t)
}
Expression *ErrorExp::castTo(Scope *sc, Type *t)
{
return this;
}
Expression *RealExp::castTo(Scope *sc, Type *t)
{ Expression *e = this;
if (type != t)
@@ -745,8 +755,6 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
* will result in a copy.
* The this->string member is considered immutable.
*/
StringExp *se;
Type *tb;
int copied = 0;
//printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed);
@@ -757,7 +765,7 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
return new ErrorExp();
}
se = this;
StringExp *se = this;
if (!committed)
{ se = (StringExp *)copy();
se->committed = 1;
@@ -769,7 +777,7 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
return se;
}
tb = t->toBasetype();
Type *tb = t->toBasetype();
//printf("\ttype = %s\n", type->toChars());
if (tb->ty == Tdelegate && type->toBasetype()->ty != Tdelegate)
return Expression::castTo(sc, t);
@@ -913,7 +921,11 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
}
se->string = buffer.extractData();
se->len = newlen;
se->sz = tb->nextOf()->size();
{
d_uns64 szx = tb->nextOf()->size();
assert(szx <= 255);
se->sz = (unsigned char)szx;
}
break;
default:
@@ -928,9 +940,9 @@ L2:
// See if need to truncate or extend the literal
if (tb->ty == Tsarray)
{
int dim2 = ((TypeSArray *)tb)->dim->toInteger();
dinteger_t dim2 = ((TypeSArray *)tb)->dim->toInteger();
//printf("dim from = %d, to = %d\n", se->len, dim2);
//printf("dim from = %d, to = %d\n", (int)se->len, (int)dim2);
// Changing dimensions
if (dim2 != se->len)
@@ -1038,10 +1050,10 @@ Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t)
e = (ArrayLiteralExp *)copy();
e->elements = (Expressions *)elements->copy();
for (int i = 0; i < elements->dim; i++)
{ Expression *ex = (Expression *)elements->data[i];
for (size_t i = 0; i < elements->dim; i++)
{ Expression *ex = (*elements)[i];
ex = ex->castTo(sc, tb->nextOf());
e->elements->data[i] = (void *)ex;
(*e->elements)[i] = ex;
}
e->type = t;
return e;
@@ -1081,7 +1093,6 @@ Expression *AssocArrayLiteralExp::castTo(Scope *sc, Type *t)
e->type = t;
return e;
}
L1:
return e->Expression::castTo(sc, t);
}

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -31,6 +31,7 @@
ClassDeclaration *ClassDeclaration::classinfo;
ClassDeclaration *ClassDeclaration::object;
ClassDeclaration *ClassDeclaration::errorException;
ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses)
: AggregateDeclaration(loc, id)
@@ -170,6 +171,12 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
Type::typeinfoshared->error("%s", msg);
Type::typeinfoshared = this;
}
if (id == Id::TypeInfo_Wild)
{ if (Type::typeinfowild)
Type::typeinfowild->error("%s", msg);
Type::typeinfowild = this;
}
#endif
}
@@ -179,6 +186,12 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
object = this;
}
if (id == Id::Error)
{ if (errorException)
errorException->error("%s", msg);
errorException = this;
}
if (id == Id::ClassInfo)
{ if (classinfo)
classinfo->error("%s", msg);
@@ -213,7 +226,7 @@ Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s)
cd->storage_class |= storage_class;
cd->baseclasses->setDim(this->baseclasses->dim);
for (int i = 0; i < cd->baseclasses->dim; i++)
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
BaseClass *b = (BaseClass *)this->baseclasses->data[i];
BaseClass *b2 = new BaseClass(b->type->syntaxCopy(), b->protection);
@@ -225,9 +238,7 @@ Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s)
}
void ClassDeclaration::semantic(Scope *sc)
{ int i;
unsigned offset;
{
//printf("ClassDeclaration::semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this);
//printf("\tparent = %p, '%s'\n", sc->parent, sc->parent ? sc->parent->toChars() : "");
//printf("sc->stc = %x\n", sc->stc);
@@ -278,7 +289,7 @@ void ClassDeclaration::semantic(Scope *sc)
}
// Expand any tuples in baseclasses[]
for (i = 0; i < baseclasses->dim; )
for (size_t i = 0; i < baseclasses->dim; )
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
b->type = b->type->semantic(loc, sc);
Type *tb = b->type->toBasetype();
@@ -368,7 +379,7 @@ void ClassDeclaration::semantic(Scope *sc)
// Treat the remaining entries in baseclasses as interfaces
// Check for errors, handle forward references
for (i = (baseClass ? 1 : 0); i < baseclasses->dim; )
for (size_t i = (baseClass ? 1 : 0); i < baseclasses->dim; )
{ TypeClass *tc;
BaseClass *b;
Type *tb;
@@ -490,7 +501,7 @@ void ClassDeclaration::semantic(Scope *sc)
{
interfaceSemantic(sc);
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->addMember(sc, this, 1);
@@ -536,9 +547,9 @@ void ClassDeclaration::semantic(Scope *sc)
if (ad)
t = ad->handle;
else if (fd)
{ AggregateDeclaration *ad = fd->isMember2();
if (ad)
t = ad->handle;
{ AggregateDeclaration *ad2 = fd->isMember2();
if (ad2)
t = ad2->handle;
else
{
t = new TypePointer(Type::tvoid);
@@ -594,13 +605,13 @@ void ClassDeclaration::semantic(Scope *sc)
}
structsize = sc->offset;
Scope scsave = *sc;
int members_dim = members->dim;
size_t members_dim = members->dim;
sizeok = 0;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (i = 0; i < members_dim; i++)
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
@@ -612,7 +623,7 @@ void ClassDeclaration::semantic(Scope *sc)
}
}
for (i = 0; i < members_dim; i++)
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->semantic(sc);
}
@@ -688,7 +699,7 @@ void ClassDeclaration::semantic(Scope *sc)
#endif
// Allocate instance of each new interface
for (i = 0; i < vtblInterfaces->dim; i++)
for (size_t i = 0; i < vtblInterfaces->dim; i++)
{
BaseClass *b = (BaseClass *)vtblInterfaces->data[i];
unsigned thissize = PTRSIZE;
@@ -737,7 +748,7 @@ void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
if (baseclasses->dim)
buf->writestring(" : ");
}
for (int i = 0; i < baseclasses->dim; i++)
for (size_t i = 0; i < baseclasses->dim; i++)
{
BaseClass *b = (BaseClass *)baseclasses->data[i];
@@ -751,7 +762,7 @@ void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
buf->writeByte('{');
buf->writenl();
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
@@ -787,7 +798,7 @@ int ClassDeclaration::isBaseOf2(ClassDeclaration *cd)
if (!cd)
return 0;
//printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd->toChars());
for (int i = 0; i < cd->baseclasses->dim; i++)
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)cd->baseclasses->data[i];
if (b->base == this || isBaseOf2(b->base))
@@ -807,16 +818,18 @@ int ClassDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
*poffset = 0;
while (cd)
{
if (this == cd->baseClass)
return 1;
/* cd->baseClass might not be set if cd is forward referenced.
*/
if (!cd->baseClass && cd->baseclasses->dim && !cd->isInterfaceDeclaration())
{
cd->semantic(NULL);
if (!cd->baseClass)
cd->error("base class is forward referenced by %s", toChars());
}
if (this == cd->baseClass)
return 1;
cd = cd->baseClass;
}
return 0;
@@ -831,7 +844,7 @@ int ClassDeclaration::isBaseInfoComplete()
{
if (!baseClass)
return ident == Id::Object;
for (int i = 0; i < baseclasses->dim; i++)
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
if (!b->base || !b->base->isBaseInfoComplete())
return 0;
@@ -844,14 +857,14 @@ Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
Dsymbol *s;
//printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars());
if (scope)
if (scope && !symtab)
{ Scope *sc = scope;
sc->mustsemantic++;
semantic(sc);
sc->mustsemantic--;
}
if (!members || !symtab || scope)
if (!members || !symtab)
{
error("is forward referenced when looking for '%s'", ident->toChars());
//*(char*)0=0;
@@ -863,9 +876,7 @@ Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
{
// Search bases classes in depth-first, left to right order
int i;
for (i = 0; i < baseclasses->dim; i++)
for (size_t i = 0; i < baseclasses->dim; i++)
{
BaseClass *b = (BaseClass *)baseclasses->data[i];
@@ -912,7 +923,10 @@ int ClassDeclaration::isFuncHidden(FuncDeclaration *fd)
}
FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration();
//printf("%s fdstart = %p\n", s->kind(), fdstart);
return !overloadApply(getModule(), fdstart, &isf, fd);
if (overloadApply(fdstart, &isf, fd))
return 0;
return !fd->parent->isTemplateMixin();
}
#endif
@@ -924,24 +938,58 @@ int ClassDeclaration::isFuncHidden(FuncDeclaration *fd)
FuncDeclaration *ClassDeclaration::findFunc(Identifier *ident, TypeFunction *tf)
{
//printf("ClassDeclaration::findFunc(%s, %s) %s\n", ident->toChars(), tf->toChars(), toChars());
FuncDeclaration *fdmatch = NULL;
FuncDeclaration *fdambig = NULL;
ClassDeclaration *cd = this;
Array *vtbl = &cd->vtbl;
Dsymbols *vtbl = &cd->vtbl;
while (1)
{
for (size_t i = 0; i < vtbl->dim; i++)
{
FuncDeclaration *fd = ((Dsymbol*)vtbl->data[i])->isFuncDeclaration();
FuncDeclaration *fd = (*vtbl)[i]->isFuncDeclaration();
if (!fd)
continue; // the first entry might be a ClassInfo
//printf("\t[%d] = %s\n", i, fd->toChars());
if (ident == fd->ident &&
//tf->equals(fd->type)
fd->type->covariant(tf) == 1
)
{ //printf("\t\tfound\n");
return fd;
fd->type->covariant(tf) == 1)
{ //printf("fd->parent->isClassDeclaration() = %p", fd->parent->isClassDeclaration());
if (!fdmatch)
goto Lfd;
{
// Function type matcing: exact > covariant
int m1 = tf->equals(fd ->type) ? MATCHexact : MATCHnomatch;
int m2 = tf->equals(fdmatch->type) ? MATCHexact : MATCHnomatch;
if (m1 > m2)
goto Lfd;
else if (m1 < m2)
goto Lfdmatch;
}
{
// The way of definition: non-mixin > mixin
int m1 = fd ->parent->isClassDeclaration() ? MATCHexact : MATCHnomatch;
int m2 = fdmatch->parent->isClassDeclaration() ? MATCHexact : MATCHnomatch;
if (m1 > m2)
goto Lfd;
else if (m1 < m2)
goto Lfdmatch;
}
Lambig:
fdambig = fd;
//printf("Lambig fdambig = %s %s [%s]\n", fdambig->toChars(), fdambig->type->toChars(), fdambig->loc.toChars());
continue;
Lfd:
fdmatch = fd, fdambig = NULL;
//printf("Lfd fdmatch = %s %s [%s]\n", fdmatch->toChars(), fdmatch->type->toChars(), fdmatch->loc.toChars());
continue;
Lfdmatch:
continue;
}
//else printf("\t\t%d\n", fd->type->covariant(tf));
}
@@ -951,7 +999,9 @@ FuncDeclaration *ClassDeclaration::findFunc(Identifier *ident, TypeFunction *tf)
cd = cd->baseClass;
}
return NULL;
if (fdambig)
error("ambiguous virtual function %s", fdambig->toChars());
return fdmatch;
}
void ClassDeclaration::interfaceSemantic(Scope *sc)
@@ -1001,7 +1051,7 @@ int ClassDeclaration::isAbstract()
{
if (isabstract)
return TRUE;
for (int i = 1; i < vtbl.dim; i++)
for (size_t i = 1; i < vtbl.dim; i++)
{
FuncDeclaration *fd = ((Dsymbol *)vtbl.data[i])->isFuncDeclaration();
@@ -1078,8 +1128,7 @@ Dsymbol *InterfaceDeclaration::syntaxCopy(Dsymbol *s)
}
void InterfaceDeclaration::semantic(Scope *sc)
{ int i;
{
//printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type);
if (inuse)
return;
@@ -1116,7 +1165,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
}
// Expand any tuples in baseclasses[]
for (i = 0; i < baseclasses->dim; )
for (size_t i = 0; i < baseclasses->dim; )
{ BaseClass *b = (BaseClass *)baseclasses->data[0];
b->type = b->type->semantic(loc, sc);
Type *tb = b->type->toBasetype();
@@ -1137,7 +1186,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
}
// Check for errors, handle forward references
for (i = 0; i < baseclasses->dim; )
for (size_t i = 0; i < baseclasses->dim; )
{ TypeClass *tc;
BaseClass *b;
Type *tb;
@@ -1200,11 +1249,11 @@ void InterfaceDeclaration::semantic(Scope *sc)
vtbl.push(this); // leave room at vtbl[0] for classinfo
// Cat together the vtbl[]'s from base interfaces
for (i = 0; i < interfaces_dim; i++)
for (size_t i = 0; i < interfaces_dim; i++)
{ BaseClass *b = interfaces[i];
// Skip if b has already appeared
for (int k = 0; k < i; k++)
for (size_t k = 0; k < i; k++)
{
if (b == interfaces[k])
goto Lcontinue;
@@ -1212,12 +1261,12 @@ void InterfaceDeclaration::semantic(Scope *sc)
// Copy vtbl[] from base class
if (b->base->vtblOffset())
{ int d = b->base->vtbl.dim;
{ size_t d = b->base->vtbl.dim;
if (d > 1)
{
vtbl.reserve(d - 1);
for (int j = 1; j < d; j++)
vtbl.push(b->base->vtbl.data[j]);
for (size_t j = 1; j < d; j++)
vtbl.push((Dsymbol *)b->base->vtbl.data[j]);
}
}
else
@@ -1229,23 +1278,26 @@ void InterfaceDeclaration::semantic(Scope *sc)
;
}
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
Dsymbol *s = (*members)[i];
s->addMember(sc, this, 1);
}
sc = sc->push(this);
sc->stc &= STCsafe | STCtrusted | STCsystem;
sc->parent = this;
if (isCOMinterface())
sc->linkage = LINKwindows;
sc->structalign = 8;
sc->protection = PROTpublic;
sc->explicitProtection = 0;
structalign = sc->structalign;
sc->offset = PTRSIZE * 2;
inuse++;
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
Dsymbol *s = (*members)[i];
s->semantic(sc);
}
inuse--;
@@ -1338,7 +1390,7 @@ int InterfaceDeclaration::isBaseOf(BaseClass *bc, int *poffset)
int InterfaceDeclaration::isBaseInfoComplete()
{
assert(!baseClass);
for (int i = 0; i < baseclasses->dim; i++)
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
if (!b->base || !b->base->isBaseInfoComplete ())
return 0;
@@ -1411,10 +1463,9 @@ BaseClass::BaseClass(Type *type, enum PROT protection)
* by base classes)
*/
int BaseClass::fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance)
int BaseClass::fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newinstance)
{
ClassDeclaration *id = base;
int j;
int result = 0;
//printf("BaseClass::fillVtbl(this='%s', cd='%s')\n", base->toChars(), cd->toChars());
@@ -1422,7 +1473,7 @@ int BaseClass::fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance)
vtbl->setDim(base->vtbl.dim);
// first entry is ClassInfo reference
for (j = base->vtblOffset(); j < base->vtbl.dim; j++)
for (size_t j = base->vtblOffset(); j < base->vtbl.dim; j++)
{
FuncDeclaration *ifd = ((Dsymbol *)base->vtbl.data[j])->isFuncDeclaration();
FuncDeclaration *fd;

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -39,7 +39,7 @@ Expression *StructDeclaration::cloneMembers()
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
Type *tv = v->type->toBasetype();
size_t dim = 1;
dinteger_t dim = (tv->ty == Tsarray ? 1 : 0);
while (tv->ty == Tsarray)
{ TypeSArray *ta = (TypeSArray *)tv;
dim *= ((TypeSArray *)tv)->dim->toInteger();
@@ -49,10 +49,10 @@ Expression *StructDeclaration::cloneMembers()
{ TypeStruct *ts = (TypeStruct *)tv;
StructDeclaration *sd = ts->sym;
if (sd->opclone)
{ Expression *ex;
{
// this.v
ex = new ThisExp(0);
Expression *ex = new ThisExp(0);
ex = new DotVarExp(0, ex, v, 0);
if (dim == 1)
@@ -96,7 +96,7 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
Type *tv = v->type->toBasetype();
size_t dim = 1;
dinteger_t dim = (tv->ty == Tsarray ? 1 : 0);
while (tv->ty == Tsarray)
{ TypeSArray *ta = (TypeSArray *)tv;
dim *= ((TypeSArray *)tv)->dim->toInteger();
@@ -139,7 +139,7 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
*/
if (e)
{ //printf("Building __fieldDtor()\n");
DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__fieldDtor"));
DtorDeclaration *dd = new DtorDeclaration(loc, 0, Lexer::idPool("__fieldDtor"));
dd->fbody = new ExpStatement(0, e);
dtors.shift(dd);
members->push(dd);
@@ -164,7 +164,7 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
ex = new CallExp(0, ex);
e = Expression::combine(ex, e);
}
DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__aggrDtor"));
DtorDeclaration *dd = new DtorDeclaration(loc, 0, Lexer::idPool("__aggrDtor"));
dd->fbody = new ExpStatement(0, e);
members->push(dd);
dd->semantic(sc);

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -20,18 +20,17 @@
#include "module.h"
#include "template.h"
#include "lexer.h"
#ifdef _DH
#include "mtype.h"
#include "scope.h"
#endif
#include "arraytypes.h"
int findCondition(Array *ids, Identifier *ident)
int findCondition(Strings *ids, Identifier *ident)
{
if (ids)
{
for (int i = 0; i < ids->dim; i++)
for (size_t i = 0; i < ids->dim; i++)
{
const char *id = (const char *)ids->data[i];
const char *id = (*ids)[i];
if (strcmp(id, ident->toChars()) == 0)
return TRUE;
@@ -74,8 +73,8 @@ void DebugCondition::setGlobalLevel(unsigned level)
void DebugCondition::addGlobalIdent(const char *ident)
{
if (!global.params.debugids)
global.params.debugids = new Array();
global.params.debugids->push((void *)ident);
global.params.debugids = new Strings();
global.params.debugids->push((char *)ident);
}
@@ -98,7 +97,7 @@ int DebugCondition::include(Scope *sc, ScopeDsymbol *s)
inc = 1;
else
{ if (!mod->debugidsNot)
mod->debugidsNot = new Array();
mod->debugidsNot = new Strings();
mod->debugidsNot->push(ident->toChars());
}
}
@@ -135,8 +134,10 @@ void VersionCondition::checkPredefined(Loc loc, const char *ident)
* redefinition breaks makefiles and older builds.
*/
"Posix",
"D_NET",
#endif
"OSX", "FreeBSD",
"OpenBSD",
"Solaris",
"LittleEndian", "BigEndian",
"all",
@@ -173,8 +174,8 @@ void VersionCondition::addGlobalIdent(const char *ident)
void VersionCondition::addPredefinedGlobalIdent(const char *ident)
{
if (!global.params.versionids)
global.params.versionids = new Array();
global.params.versionids->push((void *)ident);
global.params.versionids = new Strings();
global.params.versionids->push((char *)ident);
}
@@ -199,7 +200,7 @@ int VersionCondition::include(Scope *sc, ScopeDsymbol *s)
else
{
if (!mod->versionidsNot)
mod->versionidsNot = new Array();
mod->versionidsNot = new Strings();
mod->versionidsNot->push(ident->toChars());
}
}
@@ -307,13 +308,14 @@ int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
inc = 2;
return 0;
}
unsigned errors = global.errors;
global.gag++; // suppress printing of error messages
targ = targ->semantic(loc, sc);
global.gag--;
if (errors != global.errors) // if any errors happened
{ inc = 2; // then condition is false
global.errors = errors;
Type *t = targ->trySemantic(loc, sc);
if (t)
targ = t;
else
inc = 2; // condition is false
if (!t)
{
}
else if (id && tspec)
{
@@ -326,19 +328,19 @@ int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
TemplateParameters parameters;
parameters.setDim(1);
parameters.data[0] = (void *)&tp;
parameters[0] = &tp;
Objects dedtypes;
dedtypes.setDim(1);
m = targ->deduceType(NULL, tspec, &parameters, &dedtypes);
m = targ->deduceType(sc, tspec, &parameters, &dedtypes);
if (m == MATCHnomatch ||
(m != MATCHexact && tok == TOKequal))
inc = 2;
else
{
inc = 1;
Type *tded = (Type *)dedtypes.data[0];
Type *tded = (Type *)dedtypes[0];
if (!tded)
tded = targ;
Dsymbol *s = new AliasDeclaration(loc, id, tded);

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -17,15 +17,12 @@ struct OutBuffer;
struct Module;
struct Scope;
struct ScopeDsymbol;
#ifdef _DH
struct DebugCondition;
#include "lexer.h" // dmdhg
#endif
enum TOK;
#ifdef _DH
struct HdrGenState;
#endif
int findCondition(Array *ids, Identifier *ident);
int findCondition(Strings *ids, Identifier *ident);
struct Condition
{

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -36,12 +36,10 @@ extern "C" bool real_isnan (const real_t *);
static real_t zero; // work around DMC bug for now
#if __FreeBSD__
#define fmodl fmod // hack for now, fix later
#endif
#define LOG 0
int RealEquals(real_t x1, real_t x2);
Expression *expType(Type *type, Expression *e)
{
if (type != e->type)
@@ -495,7 +493,7 @@ Expression *Mod(Type *type, Expression *e1, Expression *e2)
{ real_t r2 = e2->toReal();
#ifdef __DMC__
c = fmodl(e1->toReal(), r2) + fmodl(e1->toImaginary(), r2) * I;
c = Port::fmodl(e1->toReal(), r2) + Port::fmodl(e1->toImaginary(), r2) * I;
#elif defined(IN_GCC)
c = complex_t(e1->toReal() % r2, e1->toImaginary() % r2);
#elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) || defined(__thumb__)
@@ -503,14 +501,14 @@ Expression *Mod(Type *type, Expression *e1, Expression *e2)
// arm also doesn't like fmodl
c = complex_t(fmod(e1->toReal(), r2), fmod(e1->toImaginary(), r2));
#else
c = complex_t(fmodl(e1->toReal(), r2), fmodl(e1->toImaginary(), r2));
c = complex_t(Port::fmodl(e1->toReal(), r2), Port::fmodl(e1->toImaginary(), r2));
#endif
}
else if (e2->type->isimaginary())
{ real_t i2 = e2->toImaginary();
#ifdef __DMC__
c = fmodl(e1->toReal(), i2) + fmodl(e1->toImaginary(), i2) * I;
c = Port::fmodl(e1->toReal(), i2) + Port::fmodl(e1->toImaginary(), i2) * I;
#elif defined(IN_GCC)
c = complex_t(e1->toReal() % i2, e1->toImaginary() % i2);
#elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) || defined(__thumb__)
@@ -518,7 +516,7 @@ Expression *Mod(Type *type, Expression *e1, Expression *e2)
// arm also doesn't like fmodl
c = complex_t(fmod(e1->toReal(), i2), fmod(e1->toImaginary(), i2));
#else
c = complex_t(fmodl(e1->toReal(), i2), fmodl(e1->toImaginary(), i2));
c = complex_t(Port::fmodl(e1->toReal(), i2), Port::fmodl(e1->toImaginary(), i2));
#endif
}
else
@@ -545,6 +543,21 @@ Expression *Mod(Type *type, Expression *e1, Expression *e2)
e2 = new IntegerExp(loc, 1, e2->type);
n2 = 1;
}
if (n2 == -1 && !type->isunsigned())
{ // Check for int.min % -1
if (n1 == 0xFFFFFFFF80000000ULL && type->toBasetype()->ty != Tint64)
{
e2->error("integer overflow: int.min % -1");
e2 = new IntegerExp(loc, 1, e2->type);
n2 = 1;
}
else if (n1 == 0x8000000000000000LL) // long.min % -1
{
e2->error("integer overflow: long.min % -1");
e2 = new IntegerExp(loc, 1, e2->type);
n2 = 1;
}
}
if (e1->type->isunsigned() || e2->type->isunsigned())
n = ((d_uns64) n1) % ((d_uns64) n2);
else
@@ -567,7 +580,9 @@ Expression *Shr(Type *type, Expression *e1, Expression *e2)
Loc loc = e1->loc;
dinteger_t value = e1->toInteger();
unsigned count = e2->toInteger();
dinteger_t dcount = e2->toInteger();
assert(dcount <= 0xFFFFFFFF);
unsigned count = (unsigned)dcount;
switch (e1->type->toBasetype()->ty)
{
case Tint8:
@@ -575,6 +590,7 @@ Expression *Shr(Type *type, Expression *e1, Expression *e2)
break;
case Tuns8:
case Tchar:
value = (d_uns8)(value) >> count;
break;
@@ -583,6 +599,7 @@ Expression *Shr(Type *type, Expression *e1, Expression *e2)
break;
case Tuns16:
case Twchar:
value = (d_uns16)(value) >> count;
break;
@@ -591,6 +608,7 @@ Expression *Shr(Type *type, Expression *e1, Expression *e2)
break;
case Tuns32:
case Tdchar:
value = (d_uns32)(value) >> count;
break;
@@ -617,23 +635,28 @@ Expression *Ushr(Type *type, Expression *e1, Expression *e2)
Loc loc = e1->loc;
dinteger_t value = e1->toInteger();
unsigned count = e2->toInteger();
dinteger_t dcount = e2->toInteger();
assert(dcount <= 0xFFFFFFFF);
unsigned count = (unsigned)dcount;
switch (e1->type->toBasetype()->ty)
{
case Tint8:
case Tuns8:
assert(0); // no way to trigger this
case Tchar:
// Possible only with >>>=. >>> always gets promoted to int.
value = (value & 0xFF) >> count;
break;
case Tint16:
case Tuns16:
assert(0); // no way to trigger this
case Twchar:
// Possible only with >>>=. >>> always gets promoted to int.
value = (value & 0xFFFF) >> count;
break;
case Tint32:
case Tuns32:
case Tdchar:
value = (value & 0xFFFFFFFF) >> count;
break;
@@ -741,8 +764,8 @@ Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2)
else
{
for (size_t i = 0; i < es1->elements->dim; i++)
{ Expression *ee1 = (Expression *)es1->elements->data[i];
Expression *ee2 = (Expression *)es2->elements->data[i];
{ Expression *ee1 = (*es1->elements)[i];
Expression *ee2 = (*es2->elements)[i];
Expression *v = Equal(TOKequal, Type::tint32, ee1, ee2);
if (v == EXP_CANT_INTERPRET)
@@ -755,9 +778,9 @@ Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2)
}
else if (e1->op == TOKarrayliteral && e2->op == TOKstring)
{ // Swap operands and use common code
Expression *e = e1;
Expression *etmp = e1;
e1 = e2;
e2 = e;
e2 = etmp;
goto Lsa;
}
else if (e1->op == TOKstring && e2->op == TOKarrayliteral)
@@ -771,10 +794,11 @@ Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2)
cmp = 0;
else
{
cmp = 1; // if dim1 winds up being 0
for (size_t i = 0; i < dim1; i++)
{
uinteger_t c = es1->charAt(i);
Expression *ee2 = (Expression *)es2->elements->data[i];
Expression *ee2 = (*es2->elements)[i];
if (ee2->isConst() != 1)
return EXP_CANT_INTERPRET;
cmp = (c == ee2->toInteger());
@@ -800,8 +824,8 @@ Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2)
{
cmp = 1;
for (size_t i = 0; i < es1->elements->dim; i++)
{ Expression *ee1 = (Expression *)es1->elements->data[i];
Expression *ee2 = (Expression *)es2->elements->data[i];
{ Expression *ee1 = (*es1->elements)[i];
Expression *ee2 = (*es2->elements)[i];
if (ee1 == ee2)
continue;
@@ -885,11 +909,11 @@ Expression *Identity(enum TOK op, Type *type, Expression *e1, Expression *e2)
cmp = (es1->var == es2->var && es1->offset == es2->offset);
}
else if (e1->isConst() == 1 && e2->isConst() == 1)
else
{
return Equal((op == TOKidentity) ? TOKequal : TOKnotequal,
type, e1, e2);
else
assert(0);
}
if (op == TOKnotidentity)
cmp ^= 1;
return new IntegerExp(loc, cmp, type);
@@ -1134,7 +1158,7 @@ Expression *Cast(Type *type, Type *to, Expression *e1)
assert(sd);
Expressions *elements = new Expressions;
for (size_t i = 0; i < sd->fields.dim; i++)
{ Dsymbol *s = (Dsymbol *)sd->fields.data[i];
{ Dsymbol *s = sd->fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v);
@@ -1197,10 +1221,13 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
uinteger_t i = e2->toInteger();
if (i >= es1->len)
{
e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len);
e = new ErrorExp();
}
else
{ unsigned value = es1->charAt(i);
e = new IntegerExp(loc, value, type);
{
e = new IntegerExp(loc, es1->charAt(i), type);
}
}
else if (e1->type->toBasetype()->ty == Tsarray && e2->op == TOKint64)
@@ -1209,30 +1236,38 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
uinteger_t i = e2->toInteger();
if (i >= length)
{ e2->error("array index %ju is out of bounds %s[0 .. %ju]", i, e1->toChars(), length);
{
e1->error("array index %ju is out of bounds %s[0 .. %ju]", i, e1->toChars(), length);
e = new ErrorExp();
}
else if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2))
else if (e1->op == TOKarrayliteral)
{ ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
e = (Expression *)ale->elements->data[i];
e = ale->elements->tdata()[i];
e->type = type;
if (e->checkSideEffect(2))
e = EXP_CANT_INTERPRET;
}
}
else if (e1->type->toBasetype()->ty == Tarray && e2->op == TOKint64)
{
uinteger_t i = e2->toInteger();
if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2))
if (e1->op == TOKarrayliteral)
{ ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
if (i >= ale->elements->dim)
{ e2->error("array index %ju is out of bounds %s[0 .. %u]", i, e1->toChars(), ale->elements->dim);
{
e1->error("array index %ju is out of bounds %s[0 .. %u]", i, e1->toChars(), ale->elements->dim);
e = new ErrorExp();
}
else
{ e = (Expression *)ale->elements->data[i];
{ e = ale->elements->tdata()[i];
e->type = type;
if (e->checkSideEffect(2))
e = EXP_CANT_INTERPRET;
}
}
}
else if (e1->op == TOKassocarrayliteral && !e1->checkSideEffect(2))
else if (e1->op == TOKassocarrayliteral)
{
AssocArrayLiteralExp *ae = (AssocArrayLiteralExp *)e1;
/* Search the keys backwards, in case there are duplicate keys
@@ -1240,13 +1275,15 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
for (size_t i = ae->keys->dim; i;)
{
i--;
Expression *ekey = (Expression *)ae->keys->data[i];
Expression *ekey = ae->keys->tdata()[i];
Expression *ex = Equal(TOKequal, Type::tbool, ekey, e2);
if (ex == EXP_CANT_INTERPRET)
return ex;
if (ex->isBool(TRUE))
{ e = (Expression *)ae->values->data[i];
{ e = ae->values->tdata()[i];
e->type = type;
if (e->checkSideEffect(2))
e = EXP_CANT_INTERPRET;
break;
}
}
@@ -1274,9 +1311,12 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
uinteger_t iupr = upr->toInteger();
if (iupr > es1->len || ilwr > iupr)
{
e1->error("string slice [%ju .. %ju] is out of bounds", ilwr, iupr);
e = new ErrorExp();
}
else
{ dinteger_t value;
{
void *s;
size_t len = iupr - ilwr;
int sz = es1->sz;
@@ -1301,14 +1341,17 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
uinteger_t iupr = upr->toInteger();
if (iupr > es1->elements->dim || ilwr > iupr)
{
e1->error("array slice [%ju .. %ju] is out of bounds", ilwr, iupr);
e = new ErrorExp();
}
else
{
Expressions *elements = new Expressions();
elements->setDim(iupr - ilwr);
memcpy(elements->data,
es1->elements->data + ilwr,
(iupr - ilwr) * sizeof(es1->elements->data[0]));
memcpy(elements->tdata(),
es1->elements->tdata() + ilwr,
(iupr - ilwr) * sizeof(es1->elements->tdata()[0]));
e = new ArrayLiteralExp(e1->loc, elements);
e->type = type;
}
@@ -1349,8 +1392,11 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
dinteger_t v = e->toInteger();
size_t len = utf_codeLength(sz, v);
size_t len = (t->ty == tn->ty) ? 1 : utf_codeLength(sz, v);
s = mem.malloc((len + 1) * sz);
if (t->ty == tn->ty)
memcpy((unsigned char *)s, &v, sz);
else
utf_encode(sz, s, v);
// Add terminating 0
@@ -1370,6 +1416,24 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
e->type = type;
return e;
}
else if (e1->op == TOKnull && e2->op == TOKnull)
{
if (type == e1->type)
{
// Handle null ~= null
if (t1->ty == Tarray && t2 == t1->nextOf())
{
e = new ArrayLiteralExp(e1->loc, e2);
e->type = type;
return e;
}
else
return e1;
}
if (type == e2->type)
return e2;
return new NullExp(e1->loc, type);
}
else if (e1->op == TOKstring && e2->op == TOKstring)
{
// Concatenate the strings
@@ -1377,7 +1441,6 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
StringExp *es1 = (StringExp *)e1;
StringExp *es2 = (StringExp *)e2;
StringExp *es;
Type *t;
size_t len = es1->len + es2->len;
int sz = es1->sz;
@@ -1399,10 +1462,62 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
es = new StringExp(loc, s, len);
es->sz = sz;
es->committed = es1->committed | es2->committed;
if (es1->committed)
t = es1->type;
else
t = es2->type;
es->type = type;
e = es;
}
else if (e2->op == TOKstring && e1->op == TOKarrayliteral &&
t1->nextOf()->isintegral())
{
// Concatenate the strings
StringExp *es1 = (StringExp *)e2;
ArrayLiteralExp *es2 = (ArrayLiteralExp *)e1;
size_t len = es1->len + es2->elements->dim;
int sz = es1->sz;
void *s = mem.malloc((len + 1) * sz);
memcpy((char *)s + sz * es2->elements->dim, es1->string, es1->len * sz);
for (size_t i = 0; i < es2->elements->dim; i++)
{ Expression *es2e = es2->elements->tdata()[i];
if (es2e->op != TOKint64)
return EXP_CANT_INTERPRET;
dinteger_t v = es2e->toInteger();
memcpy((unsigned char *)s + i * sz, &v, sz);
}
// Add terminating 0
memset((unsigned char *)s + len * sz, 0, sz);
StringExp *es = new StringExp(loc, s, len);
es->sz = sz;
es->committed = 0;
es->type = type;
e = es;
}
else if (e1->op == TOKstring && e2->op == TOKarrayliteral &&
t2->nextOf()->isintegral())
{
// Concatenate the strings
StringExp *es1 = (StringExp *)e1;
ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
size_t len = es1->len + es2->elements->dim;
int sz = es1->sz;
void *s = mem.malloc((len + 1) * sz);
memcpy(s, es1->string, es1->len * sz);
for (size_t i = 0; i < es2->elements->dim; i++)
{ Expression *es2e = es2->elements->tdata()[i];
if (es2e->op != TOKint64)
return EXP_CANT_INTERPRET;
dinteger_t v = es2e->toInteger();
memcpy((unsigned char *)s + (es1->len + i) * sz, &v, sz);
}
// Add terminating 0
memset((unsigned char *)s + len * sz, 0, sz);
StringExp *es = new StringExp(loc, s, len);
es->sz = sz;
es->committed = 0; //es1->committed;
es->type = type;
e = es;
}
@@ -1412,13 +1527,20 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
void *s;
StringExp *es1 = (StringExp *)e1;
StringExp *es;
Type *t;
int sz = es1->sz;
dinteger_t v = e2->toInteger();
size_t len = es1->len + utf_codeLength(sz, v);
// Is it a concatentation of homogenous types?
// (char[] ~ char, wchar[]~wchar, or dchar[]~dchar)
bool homoConcat = (sz == t2->size());
size_t len = es1->len;
len += homoConcat ? 1 : utf_codeLength(sz, v);
s = mem.malloc((len + 1) * sz);
memcpy(s, es1->string, es1->len * sz);
if (homoConcat)
memcpy((unsigned char *)s + (sz * es1->len), &v, sz);
else
utf_encode(sz, (unsigned char *)s + (sz * es1->len), v);
// Add terminating 0
@@ -1427,7 +1549,6 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
es = new StringExp(loc, s, len);
es->sz = sz;
es->committed = es1->committed;
t = es1->type;
es->type = type;
e = es;
}
@@ -1437,7 +1558,6 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
void *s;
StringExp *es2 = (StringExp *)e2;
StringExp *es;
Type *t;
size_t len = 1 + es2->len;
int sz = es2->sz;
dinteger_t v = e1->toInteger();
@@ -1452,7 +1572,6 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
es = new StringExp(loc, s, len);
es->sz = sz;
es->committed = es2->committed;
t = es2->type;
es->type = type;
e = es;
}

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -111,7 +111,7 @@ void Declaration::checkModify(Loc loc, Scope *sc, Type *t)
if (fd &&
((fd->isCtorDeclaration() && storage_class & STCfield) ||
(fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) &&
fd->toParent() == toParent()
fd->toParent2() == toParent()
)
{
VarDeclaration *v = isVarDeclaration();
@@ -194,7 +194,7 @@ Type *TupleDeclaration::getType()
/* It's only a type tuple if all the Object's are types
*/
for (size_t i = 0; i < objects->dim; i++)
{ Object *o = (Object *)objects->data[i];
{ Object *o = (*objects)[i];
if (o->dyncast() != DYNCAST_TYPE)
{
@@ -221,7 +221,7 @@ Type *TupleDeclaration::getType()
#else
Parameter *arg = new Parameter(STCin, t, NULL, NULL);
#endif
args->data[i] = (void *)arg;
(*args)[i] = arg;
if (!t->deco)
hasdeco = 0;
}
@@ -238,7 +238,7 @@ int TupleDeclaration::needThis()
{
//printf("TupleDeclaration::needThis(%s)\n", toChars());
for (size_t i = 0; i < objects->dim; i++)
{ Object *o = (Object *)objects->data[i];
{ Object *o = (*objects)[i];
if (o->dyncast() == DYNCAST_EXPRESSION)
{ Expression *e = (Expression *)o;
if (e->op == TOKdsymbol)
@@ -262,10 +262,8 @@ TypedefDeclaration::TypedefDeclaration(Loc loc, Identifier *id, Type *basetype,
this->type = new TypeTypedef(this);
this->basetype = basetype->toBasetype();
this->init = init;
#ifdef _DH
this->htype = NULL;
this->hbasetype = NULL;
#endif
this->sem = 0;
this->loc = loc;
#if IN_DMD
@@ -284,7 +282,7 @@ Dsymbol *TypedefDeclaration::syntaxCopy(Dsymbol *s)
assert(!s);
TypedefDeclaration *st;
st = new TypedefDeclaration(loc, ident, basetype, init);
#ifdef _DH
// Syntax copy for header file
if (!htype) // Don't overwrite original
{ if (type) // Make copy for both old and new instances
@@ -302,26 +300,43 @@ Dsymbol *TypedefDeclaration::syntaxCopy(Dsymbol *s)
}
else
st->hbasetype = hbasetype->syntaxCopy();
#endif
return st;
}
void TypedefDeclaration::semantic(Scope *sc)
{
//printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem);
if (sem == 0)
{ sem = 1;
if (sem == SemanticStart)
{ sem = SemanticIn;
parent = sc->parent;
int errors = global.errors;
Type *savedbasetype = basetype;
basetype = basetype->semantic(loc, sc);
sem = 2;
if (errors != global.errors)
{
basetype = savedbasetype;
sem = SemanticStart;
return;
}
sem = SemanticDone;
#if DMDV2
type = type->addStorageClass(storage_class);
#endif
Type *savedtype = type;
type = type->semantic(loc, sc);
if (sc->parent->isFuncDeclaration() && init)
semantic2(sc);
if (errors != global.errors)
{
basetype = savedbasetype;
type = savedtype;
sem = SemanticStart;
return;
}
storage_class |= sc->stc & STCdeprecated;
}
else if (sem == 1)
else if (sem == SemanticIn)
{
error("circular definition");
}
@@ -330,11 +345,18 @@ void TypedefDeclaration::semantic(Scope *sc)
void TypedefDeclaration::semantic2(Scope *sc)
{
//printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem);
if (sem == 2)
{ sem = 3;
if (sem == SemanticDone)
{ sem = Semantic2Done;
if (init)
{
init = init->semantic(sc, basetype);
Initializer *savedinit = init;
int errors = global.errors;
init = init->semantic(sc, basetype, WANTinterpret);
if (errors != global.errors)
{
init = savedinit;
return;
}
ExpInitializer *ie = init->isExpInitializer();
if (ie)
@@ -379,10 +401,8 @@ AliasDeclaration::AliasDeclaration(Loc loc, Identifier *id, Type *type)
this->loc = loc;
this->type = type;
this->aliassym = NULL;
#ifdef _DH
this->htype = NULL;
this->haliassym = NULL;
#endif
this->overnext = NULL;
this->inSemantic = 0;
this->importprot = PROTundefined;
@@ -397,10 +417,8 @@ AliasDeclaration::AliasDeclaration(Loc loc, Identifier *id, Dsymbol *s)
this->loc = loc;
this->type = NULL;
this->aliassym = s;
#ifdef _DH
this->htype = NULL;
this->haliassym = NULL;
#endif
this->overnext = NULL;
this->inSemantic = 0;
assert(s);
@@ -415,7 +433,6 @@ Dsymbol *AliasDeclaration::syntaxCopy(Dsymbol *s)
sa = new AliasDeclaration(loc, ident, type->syntaxCopy());
else
sa = new AliasDeclaration(loc, ident, aliassym->syntaxCopy(NULL));
#ifdef _DH
// Syntax copy for header file
if (!htype) // Don't overwrite original
{ if (type) // Make copy for both old and new instances
@@ -433,7 +450,6 @@ Dsymbol *AliasDeclaration::syntaxCopy(Dsymbol *s)
}
else
sa->haliassym = haliassym->syntaxCopy(s);
#endif
return sa;
}
@@ -464,6 +480,9 @@ void AliasDeclaration::semantic(Scope *sc)
// type. If it is a symbol, then aliassym is set and type is NULL -
// toAlias() will return aliasssym.
int errors = global.errors;
Type *savedtype = type;
Dsymbol *s;
Type *t;
Expression *e;
@@ -476,7 +495,7 @@ void AliasDeclaration::semantic(Scope *sc)
s = type->toDsymbol(sc);
if (s
#if DMDV2
` && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())
&& ((s->getType() && type->equals(s->getType())) || s->isEnumMember())
#endif
)
goto L2; // it's a symbolic alias
@@ -516,11 +535,15 @@ void AliasDeclaration::semantic(Scope *sc)
}
else if (t)
{
type = t;
type = t->semantic(loc, sc);
//printf("\talias resolved to type %s\n", type->toChars());
}
if (overnext)
ScopeDsymbol::multiplyDefined(0, this, overnext);
this->inSemantic = 0;
if (errors != global.errors)
type = savedtype;
return;
L2:
@@ -534,6 +557,7 @@ void AliasDeclaration::semantic(Scope *sc)
}
else
{
Dsymbol *savedovernext = overnext;
FuncDeclaration *f = s->toAlias()->isFuncDeclaration();
if (f)
{
@@ -549,15 +573,25 @@ void AliasDeclaration::semantic(Scope *sc)
}
}
if (overnext)
ScopeDsymbol::multiplyDefined(0, s, overnext);
ScopeDsymbol::multiplyDefined(0, this, overnext);
if (s == this)
{
assert(global.errors);
s = NULL;
}
if (errors != global.errors)
{
type = savedtype;
overnext = savedovernext;
aliassym = NULL;
inSemantic = 0;
return;
}
}
//printf("setting aliassym %s to %s %s\n", toChars(), s->kind(), s->toChars());
if (!type || type->ty != Terror)
{ //printf("setting aliassym %s to %s %s\n", toChars(), s->kind(), s->toChars());
aliassym = s;
}
this->inSemantic = 0;
}
@@ -619,7 +653,7 @@ Dsymbol *AliasDeclaration::toAlias()
//static int count; if (++count == 75) exit(0); //*(char*)0=0;
if (inSemantic)
{ error("recursive alias declaration");
aliassym = new TypedefDeclaration(loc, ident, Type::terror, NULL);
aliassym = new AliasDeclaration(loc, ident, Type::terror);
type = Type::terror;
}
else if (!aliassym && scope)
@@ -631,7 +665,7 @@ Dsymbol *AliasDeclaration::toAlias()
void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring("alias ");
#if 0 && _DH
#if 0
if (hgs->hdrgen)
{
if (haliassym)
@@ -674,10 +708,8 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer
assert(type || init);
this->type = type;
this->init = init;
#ifdef _DH
this->htype = NULL;
this->hinit = NULL;
#endif
this->loc = loc;
offset = 0;
noscope = 0;
@@ -691,7 +723,11 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer
aliassym = NULL;
onstack = 0;
canassign = 0;
value = NULL;
ctfeAdrOnStack = (size_t)(-1);
#if DMDV2
rundtor = NULL;
edtor = NULL;
#endif
#if IN_LLVM
aggrIndex = 0;
@@ -726,7 +762,6 @@ Dsymbol *VarDeclaration::syntaxCopy(Dsymbol *s)
sv = new VarDeclaration(loc, type ? type->syntaxCopy() : NULL, ident, init);
sv->storage_class = storage_class;
}
#ifdef _DH
// Syntax copy for header file
if (!htype) // Don't overwrite original
{ if (type) // Make copy for both old and new instances
@@ -744,7 +779,6 @@ Dsymbol *VarDeclaration::syntaxCopy(Dsymbol *s)
}
else
sv->hinit = hinit->syntaxCopy();
#endif
return sv;
}
@@ -759,6 +793,11 @@ void VarDeclaration::semantic(Scope *sc)
//if (strcmp(toChars(), "mul") == 0) halt();
#endif
if (scope)
{ sc = scope;
scope = NULL;
}
storage_class |= sc->stc;
if (storage_class & STCextern && init)
error("extern symbols cannot have initializers");
@@ -773,6 +812,7 @@ void VarDeclaration::semantic(Scope *sc)
if (!type)
{ inuse++;
type = init->inferType(sc);
type = type->semantic(loc, sc);
inuse--;
inferred = 1;
@@ -949,10 +989,10 @@ void VarDeclaration::semantic(Scope *sc)
}
// If it's a member template
AggregateDeclaration *ad = ti->tempdecl->isMember();
if (ad && storage_class != STCundefined)
AggregateDeclaration *ad2 = ti->tempdecl->isMember();
if (ad2 && storage_class != STCundefined)
{
error("cannot use template to add field to aggregate '%s'", ad->toChars());
error("cannot use template to add field to aggregate '%s'", ad2->toChars());
}
}
}
@@ -1061,7 +1101,7 @@ void VarDeclaration::semantic(Scope *sc)
Expression *e = init->toExpression();
if (!e)
{
init = init->semantic(sc, type);
init = init->semantic(sc, type, 0); // Don't need to interpret
e = init->toExpression();
if (!e)
{ error("is not a static and cannot have static initializer");
@@ -1080,7 +1120,7 @@ void VarDeclaration::semantic(Scope *sc)
ei->exp = ei->exp->semantic(sc);
if (!ei->exp->implicitConvTo(type))
{
int dim = ((TypeSArray *)t)->dim->toInteger();
dinteger_t dim = ((TypeSArray *)t)->dim->toInteger();
// If multidimensional static array, treat as one large array
while (1)
{
@@ -1162,7 +1202,7 @@ void VarDeclaration::semantic(Scope *sc)
}
else
{
init = init->semantic(sc, type);
init = init->semantic(sc, type, WANTinterpret);
if (fd && isConst() && !isStatic())
{ // Make it static
storage_class |= STCstatic;
@@ -1180,9 +1220,7 @@ void VarDeclaration::semantic(Scope *sc)
if (!global.errors && !inferred)
{
unsigned errors = global.errors;
global.gag++;
//printf("+gag\n");
unsigned errors = global.startGagging();
Expression *e;
Initializer *i2 = init;
inuse++;
@@ -1194,15 +1232,11 @@ void VarDeclaration::semantic(Scope *sc)
}
else if (si || ai)
{ i2 = init->syntaxCopy();
i2 = i2->semantic(sc, type);
i2 = i2->semantic(sc, type, WANTinterpret);
}
inuse--;
global.gag--;
//printf("-gag\n");
if (errors != global.errors) // if errors happened
if (global.endGagging(errors)) // if errors happened
{
if (global.gag == 0)
global.errors = errors; // act as if nothing happened
#if DMDV2
/* Save scope for later use, to try again
*/
@@ -1276,7 +1310,7 @@ void VarDeclaration::semantic2(Scope *sc)
printf("type = %p\n", ei->exp->type);
}
#endif
init = init->semantic(sc, type);
init = init->semantic(sc, type, WANTinterpret);
inuse--;
}
}
@@ -1384,8 +1418,12 @@ void VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
// The current function
FuncDeclaration *fdthis = sc->parent->isFuncDeclaration();
if (fdv && fdthis)
if (fdv && fdthis && fdv != fdthis && fdthis->ident != Id::ensure)
{
/* __ensure is always called directly,
* so it never becomes closure.
*/
if (loc.filename)
fdthis->getLevel(loc, fdv);
nestedref = 1;
@@ -1496,6 +1534,15 @@ Expression *VarDeclaration::callScopeDtor(Scope *sc)
return e;
}
/******************************************
*/
void ObjectNotFound(Identifier *id)
{
Type::error(0, "%s not found. object.d may be incorrectly installed or corrupt.", id->toChars());
fatal();
}
/********************************* ClassInfoDeclaration ****************************/

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -214,10 +214,8 @@ struct TypedefDeclaration : Declaration
const char *kind();
Type *getType();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#ifdef _DH
Type *htype;
Type *hbasetype;
#endif
void toDocBuffer(OutBuffer *buf);
@@ -258,10 +256,8 @@ struct AliasDeclaration : Declaration
Type *getType();
Dsymbol *toAlias();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#ifdef _DH
Type *htype;
Dsymbol *haliassym;
#endif
void toDocBuffer(OutBuffer *buf);
@@ -286,12 +282,25 @@ struct VarDeclaration : Declaration
// 2: on stack, run destructor anyway
int canassign; // it can be assigned to
Dsymbol *aliassym; // if redone as alias to another symbol
Expression *value; // when interpreting, this is the value
// (NULL if value not determinable)
// When interpreting, these point to the value (NULL if value not determinable)
// The index of this variable on the CTFE stack, -1 if not allocated
size_t ctfeAdrOnStack;
// The various functions are used only to detect compiler CTFE bugs
Expression *getValue();
bool hasValue();
void setValueNull();
void setValueWithoutChecking(Expression *newval);
void createRefValue(Expression *newval);
void setRefValue(Expression *newval);
void setStackValue(Expression *newval);
void createStackValue(Expression *newval);
#if DMDV2
VarDeclaration *rundtor; // if !NULL, rundtor is tested at runtime to see
// if the destructor should be run. Used to prevent
// dtor calls on postblitted vars
Expression *edtor; // if !=NULL, does the destruction of the variable
#endif
VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init);
@@ -300,10 +309,8 @@ struct VarDeclaration : Declaration
void semantic2(Scope *sc);
const char *kind();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#ifdef _DH
Type *htype;
Initializer *hinit;
#endif
AggregateDeclaration *isThis();
int needThis();
int isImportedSymbol();
@@ -663,9 +670,18 @@ enum BUILTIN
BUILTINtan, // std.math.tan
BUILTINsqrt, // std.math.sqrt
BUILTINfabs, // std.math.fabs
BUILTINatan2, // std.math.atan2
BUILTINrndtol, // std.math.rndtol
BUILTINexpm1, // std.math.expm1
BUILTINexp2, // std.math.exp2
BUILTINyl2x, // std.math.yl2x
BUILTINyl2xp1, // std.math.yl2xp1
BUILTINbsr, // core.bitop.bsr
BUILTINbsf, // core.bitop.bsf
BUILTINbswap, // core.bitop.bswap
};
Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments);
Expression *eval_builtin(Loc loc, enum BUILTIN builtin, Expressions *arguments);
#else
enum BUILTIN { };
@@ -673,7 +689,7 @@ enum BUILTIN { };
struct FuncDeclaration : Declaration
{
Array *fthrows; // Array of Type's of exceptions (not used)
Types *fthrows; // Array of Type's of exceptions (not used)
Statement *frequire;
Statement *fensure;
Statement *fbody;
@@ -693,7 +709,8 @@ struct FuncDeclaration : Declaration
#if IN_GCC
VarDeclaration *v_argptr; // '_argptr' variable
#endif
Dsymbols *parameters; // Array of VarDeclaration's for parameters
VarDeclaration *v_argsave; // save area for args passed in registers for variadic functions
VarDeclarations *parameters; // Array of VarDeclaration's for parameters
DsymbolTable *labtab; // statement label symbol table
Declaration *overnext; // next in overload list
Loc endloc; // location of closing curly bracket
@@ -736,9 +753,14 @@ struct FuncDeclaration : Declaration
int tookAddressOf; // set if someone took the address of
// this function
Dsymbols closureVars; // local variables in this function
VarDeclarations closureVars; // local variables in this function
// which are referenced by nested
// functions
unsigned flags;
#define FUNCFLAGpurityInprocess 1 // working on determining purity
#define FUNCFLAGsafetyInprocess 2 // working on determining safety
#define FUNCFLAGnothrowInprocess 4 // working on determining nothrow
#else
int nestedFrameRef; // !=0 if nested variables referenced
#endif
@@ -946,6 +968,7 @@ struct StaticCtorDeclaration : FuncDeclaration
int isVirtual();
int addPreInvariant();
int addPostInvariant();
bool hasStaticCtorOrDtor();
void emitComment(Scope *sc);
void toJsonBuffer(OutBuffer *buf);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -973,6 +996,7 @@ struct StaticDtorDeclaration : FuncDeclaration
AggregateDeclaration *isThis();
int isStaticDestructor();
int isVirtual();
bool hasStaticCtorOrDtor();
int addPreInvariant();
int addPostInvariant();
void emitComment(Scope *sc);
@@ -1052,9 +1076,7 @@ struct DeleteDeclaration : FuncDeclaration
int isVirtual();
int addPreInvariant();
int addPostInvariant();
#ifdef _DH
DeleteDeclaration *isDeleteDeclaration() { return this; }
#endif
};
#endif /* DMD_DECLARATION_H */

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2007 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -60,8 +60,8 @@ void arrayExpressionScanForNestedRef(Scope *sc, Expressions *a)
//printf("arrayExpressionScanForNestedRef(%p)\n", a);
if (a)
{
for (int i = 0; i < a->dim; i++)
{ Expression *e = (Expression *)a->data[i];
for (size_t i = 0; i < a->dim; i++)
{ Expression *e = (*a)[i];
if (e)
{

100
dmd/doc.c
View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -65,9 +65,11 @@ struct MacroSection : Section
void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
};
typedef ArrayBase<Section> Sections;
struct DocComment
{
Array sections; // Section*[]
Sections sections; // Section*[]
Section *summary;
Section *copyright;
@@ -133,6 +135,7 @@ LINK = <a href=\"$0\">$0</a>\n\
LINK2 = <a href=\"$1\">$+</a>\n\
LPAREN= (\n\
RPAREN= )\n\
DOLLAR= $\n\
\n\
RED = <font color=red>$0</font>\n\
BLUE = <font color=blue>$0</font>\n\
@@ -222,7 +225,7 @@ void Module::gendocfile()
global.params.ddocfiles->shift(p);
// Override with the ddoc macro files from the command line
for (int i = 0; i < global.params.ddocfiles->dim; i++)
for (size_t i = 0; i < global.params.ddocfiles->dim; i++)
{
FileName f((char *)global.params.ddocfiles->data[i], 0);
File file(&f);
@@ -249,12 +252,14 @@ void Module::gendocfile()
Macro::define(&macrotable, (unsigned char *)"TITLE", 5, (unsigned char *)p, strlen(p));
}
time_t t;
// Set time macros
{ time_t t;
time(&t);
char *p = ctime(&t);
p = mem.strdup(p);
Macro::define(&macrotable, (unsigned char *)"DATETIME", 8, (unsigned char *)p, strlen(p));
Macro::define(&macrotable, (unsigned char *)"YEAR", 4, (unsigned char *)p + 20, 4);
}
char *docfilename = docfile->toChars();
Macro::define(&macrotable, (unsigned char *)"DOCFILENAME", 11, (unsigned char *)docfilename, strlen(docfilename));
@@ -374,6 +379,12 @@ void escapeDdocString(OutBuffer *buf, unsigned start)
unsigned char c = buf->data[u];
switch(c)
{
case '$':
buf->remove(u, 1);
buf->insert(u, "$(DOLLAR)", 9);
u += 8;
break;
case '(':
buf->remove(u, 1); //remove the (
buf->insert(u, "$(LPAREN)", 9); //insert this instead
@@ -519,7 +530,7 @@ void ScopeDsymbol::emitMemberComments(Scope *sc)
buf->writestring(m);
unsigned offset2 = buf->offset; // to see if we write anything
sc = sc->push(this);
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
//printf("\ts = '%s'\n", s->toChars());
@@ -691,7 +702,7 @@ void EnumDeclaration::emitComment(Scope *sc)
// if (!comment)
{ if (isAnonymous() && members)
{
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->emitComment(sc);
@@ -792,29 +803,35 @@ void prefix(OutBuffer *buf, Dsymbol *s)
}
}
void Declaration::toDocBuffer(OutBuffer *buf)
void declarationToDocBuffer(Declaration *decl, OutBuffer *buf, TemplateDeclaration *td)
{
//printf("Declaration::toDocbuffer() %s, originalType = %p\n", toChars(), originalType);
if (ident)
//printf("declarationToDocBuffer() %s, originalType = %s, td = %s\n", decl->toChars(), decl->originalType ? decl->originalType->toChars() : "--", td ? td->toChars() : "--");
if (decl->ident)
{
prefix(buf, this);
prefix(buf, decl);
if (type)
if (decl->type)
{ HdrGenState hgs;
hgs.ddoc = 1;
if (originalType)
{ //originalType->print();
originalType->toCBuffer(buf, ident, &hgs);
Type *origType = decl->originalType ? decl->originalType : decl->type;
if (origType->ty == Tfunction)
{
TypeFunction *attrType = (TypeFunction*)(decl->ident == Id::ctor ? origType : decl->type);
((TypeFunction*)origType)->toCBufferWithAttributes(buf, decl->ident, &hgs, attrType, td);
}
else
type->toCBuffer(buf, ident, &hgs);
origType->toCBuffer(buf, decl->ident, &hgs);
}
else
buf->writestring(ident->toChars());
buf->writestring(decl->ident->toChars());
buf->writestring(";\n");
}
}
void Declaration::toDocBuffer(OutBuffer *buf)
{
declarationToDocBuffer(this, buf, NULL);
}
void AliasDeclaration::toDocBuffer(OutBuffer *buf)
{
@@ -859,31 +876,9 @@ void FuncDeclaration::toDocBuffer(OutBuffer *buf)
td->onemember == this)
{ /* It's a function template
*/
HdrGenState hgs;
unsigned o = buf->offset;
TypeFunction *tf = (TypeFunction *)type;
hgs.ddoc = 1;
prefix(buf, td);
if (tf)
{ if (tf->nextOf())
tf->nextOf()->toCBuffer(buf, NULL, &hgs);
else
buf->writestring("auto");
}
buf->writeByte(' ');
buf->writestring(ident->toChars());
buf->writeByte('(');
for (int i = 0; i < td->origParameters->dim; i++)
{
TemplateParameter *tp = (TemplateParameter *)td->origParameters->data[i];
if (i)
buf->writestring(", ");
tp->toCBuffer(buf, &hgs);
}
buf->writeByte(')');
Parameter::argsToCBuffer(buf, &hgs, tf ? tf->parameters : NULL, tf ? tf->varargs : 0);
buf->writestring(";\n");
declarationToDocBuffer(this, buf, td);
highlightCode(NULL, this, buf, o);
}
@@ -894,6 +889,7 @@ void FuncDeclaration::toDocBuffer(OutBuffer *buf)
}
}
#if DMDV1
void CtorDeclaration::toDocBuffer(OutBuffer *buf)
{
HdrGenState hgs;
@@ -902,7 +898,7 @@ void CtorDeclaration::toDocBuffer(OutBuffer *buf)
Parameter::argsToCBuffer(buf, &hgs, arguments, varargs);
buf->writestring(";\n");
}
#endif
void AggregateDeclaration::toDocBuffer(OutBuffer *buf)
{
@@ -965,7 +961,7 @@ void ClassDeclaration::toDocBuffer(OutBuffer *buf)
buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
}
int any = 0;
for (int i = 0; i < baseclasses->dim; i++)
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *bc = (BaseClass *)baseclasses->data[i];
if (bc->protection == PROTprivate)
@@ -1021,8 +1017,7 @@ DocComment::DocComment()
}
DocComment *DocComment::parse(Scope *sc, Dsymbol *s, unsigned char *comment)
{ unsigned idlen;
{
//printf("parse(%s): '%s'\n", s->toChars(), comment);
if (sc->lastdc && isDitto(comment))
return NULL;
@@ -1033,16 +1028,16 @@ DocComment *DocComment::parse(Scope *sc, Dsymbol *s, unsigned char *comment)
dc->parseSections(comment);
for (int i = 0; i < dc->sections.dim; i++)
{ Section *s = (Section *)dc->sections.data[i];
for (size_t i = 0; i < dc->sections.dim; i++)
{ Section *sec = dc->sections[i];
if (icmp("copyright", s->name, s->namelen) == 0)
if (icmp("copyright", sec->name, sec->namelen) == 0)
{
dc->copyright = s;
dc->copyright = sec;
}
if (icmp("macros", s->name, s->namelen) == 0)
if (icmp("macros", sec->name, sec->namelen) == 0)
{
dc->macros = s;
dc->macros = sec;
}
}
@@ -1178,8 +1173,8 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
if (sections.dim)
{
buf->writestring("$(DDOC_SECTIONS \n");
for (int i = 0; i < sections.dim; i++)
{ Section *sec = (Section *)sections.data[i];
for (size_t i = 0; i < sections.dim; i++)
{ Section *sec = sections[i];
if (sec->nooutput)
continue;
@@ -1756,7 +1751,7 @@ Parameter *isFunctionParameter(Dsymbol *s, unsigned char *p, unsigned len)
if (tf->parameters)
{
for (size_t k = 0; k < tf->parameters->dim; k++)
{ Parameter *arg = (Parameter *)tf->parameters->data[k];
{ Parameter *arg = (*tf->parameters)[k];
if (arg->ident && cmp(arg->ident->toChars(), p, len) == 0)
{
@@ -2015,7 +2010,6 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
break;
}
}
Ldone:
if (inCode)
s->error("unmatched --- in DDoc comment");
;

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -119,15 +119,15 @@ int Dsymbol::oneMember(Dsymbol **ps)
* Same as Dsymbol::oneMember(), but look at an array of Dsymbols.
*/
int Dsymbol::oneMembers(Array *members, Dsymbol **ps)
int Dsymbol::oneMembers(Dsymbols *members, Dsymbol **ps)
{
//printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0);
Dsymbol *s = NULL;
if (members)
{
for (int i = 0; i < members->dim; i++)
{ Dsymbol *sx = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *sx = (*members)[i];
int x = sx->oneMember(ps);
//printf("\t[%d] kind %s = %d, s = %p\n", i, sx->kind(), x, *ps);
@@ -163,6 +163,12 @@ int Dsymbol::hasPointers()
return 0;
}
bool Dsymbol::hasStaticCtorOrDtor()
{
//printf("Dsymbol::hasStaticCtorOrDtor() %s\n", toChars());
return FALSE;
}
char *Dsymbol::toChars()
{
return ident ? ident->toChars() : (char *)"__anonymous";
@@ -212,12 +218,14 @@ const char *Dsymbol::toPrettyChars()
char *Dsymbol::locToChars()
{
OutBuffer buf;
char *p;
if (!loc.filename) // avoid bug 5861.
{
Module *m = getModule();
if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
return loc.toChars();
}
@@ -541,35 +549,29 @@ int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
void Dsymbol::error(const char *format, ...)
{
//printf("Dsymbol::error()\n");
if (!global.gag)
if (!loc.filename) // avoid bug 5861.
{
char *p = locToChars();
if (*p)
fprintf(stdmsg, "%s: ", p);
mem.free(p);
fprintf(stdmsg, "Error: ");
if (isAnonymous())
fprintf(stdmsg, "%s ", kind());
else
fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
Module *m = getModule();
if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
va_list ap;
va_start(ap, format);
vfprintf(stdmsg, format, ap);
verror(loc, format, ap);
va_end(ap);
fprintf(stdmsg, "\n");
fflush(stdmsg);
}
global.errors++;
//fatal();
}
void Dsymbol::error(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verror(loc, format, ap);
va_end(ap);
}
void Dsymbol::verror(Loc loc, const char *format, va_list ap)
{
if (!global.gag)
{
char *p = loc.toChars();
@@ -583,13 +585,15 @@ void Dsymbol::error(Loc loc, const char *format, ...)
fprintf(stdmsg, "Error: ");
fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
va_list ap;
va_start(ap, format);
vfprintf(stdmsg, format, ap);
va_end(ap);
fprintf(stdmsg, "\n");
fflush(stdmsg);
//halt();
}
else
{
global.gaggedErrors++;
}
global.errors++;
@@ -604,21 +608,24 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
// Don't complain if we're inside a deprecated symbol's scope
for (Dsymbol *sp = sc->parent; sp; sp = sp->parent)
{ if (sp->isDeprecated())
return;
goto L1;
}
for (; sc; sc = sc->enclosing)
for (Scope *sc2 = sc; sc2; sc2 = sc2->enclosing)
{
if (sc->scopesym && sc->scopesym->isDeprecated())
return;
if (sc2->scopesym && sc2->scopesym->isDeprecated())
goto L1;
// If inside a StorageClassDeclaration that is deprecated
if (sc->stc & STCdeprecated)
return;
if (sc2->stc & STCdeprecated)
goto L1;
}
error(loc, "is deprecated");
}
L1:
;
}
/**********************************
@@ -631,6 +638,10 @@ Module *Dsymbol::getModule()
Dsymbol *s;
//printf("Dsymbol::getModule()\n");
TemplateDeclaration *td = getFuncTemplateDecl(this);
if (td)
return td->getModule();
s = this;
while (s)
{
@@ -684,19 +695,19 @@ enum PROT Dsymbol::prot()
*/
Array *Dsymbol::arraySyntaxCopy(Array *a)
Dsymbols *Dsymbol::arraySyntaxCopy(Dsymbols *a)
{
Array *b = NULL;
Dsymbols *b = NULL;
if (a)
{
b = a->copy();
for (int i = 0; i < b->dim; i++)
for (size_t i = 0; i < b->dim; i++)
{
Dsymbol *s = (Dsymbol *)b->data[i];
Dsymbol *s = (*b)[i];
s = s->syntaxCopy(NULL);
b->data[i] = (void *)s;
(*b)[i] = s;
}
}
return b;
@@ -799,8 +810,8 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
else if (imports)
{
// Look in imported modules
for (int i = 0; i < imports->dim; i++)
{ ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i];
for (size_t i = 0; i < imports->dim; i++)
{ ScopeDsymbol *ss = (*imports)[i];
Dsymbol *s2;
// If private import, don't search it
@@ -863,13 +874,11 @@ void ScopeDsymbol::importScope(ScopeDsymbol *s, enum PROT protection)
if (s != this)
{
if (!imports)
imports = new Array();
imports = new ScopeDsymbols();
else
{
for (int i = 0; i < imports->dim; i++)
{ ScopeDsymbol *ss;
ss = (ScopeDsymbol *) imports->data[i];
for (size_t i = 0; i < imports->dim; i++)
{ ScopeDsymbol *ss = (*imports)[i];
if (ss == s) // if already imported
{
if (protection > prots[i])
@@ -953,28 +962,41 @@ Dsymbol *ScopeDsymbol::symtabInsert(Dsymbol *s)
return symtab->insert(s);
}
/***************************************
* Determine number of Dsymbols, folding in AttribDeclaration members.
/****************************************
* Return true if any of the members are static ctors or static dtors, or if
* any members have members that are.
*/
#if DMDV2
size_t ScopeDsymbol::dim(Array *members)
bool ScopeDsymbol::hasStaticCtorOrDtor()
{
size_t n = 0;
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
AttribDeclaration *a = s->isAttribDeclaration();
{ Dsymbol *member = (*members)[i];
if (a)
{
n += dim(a->decl);
}
else
n++;
if (member->hasStaticCtorOrDtor())
return TRUE;
}
}
return FALSE;
}
/***************************************
* Determine number of Dsymbols, folding in AttribDeclaration members.
*/
#if DMDV2
static int dimDg(void *ctx, size_t n, Dsymbol *)
{
++*(size_t *)ctx;
return 0;
}
size_t ScopeDsymbol::dim(Dsymbols *members)
{
size_t n = 0;
if (members)
foreach(members, &dimDg, &n);
return n;
}
#endif
@@ -988,31 +1010,65 @@ size_t ScopeDsymbol::dim(Array *members)
*/
#if DMDV2
Dsymbol *ScopeDsymbol::getNth(Array *members, size_t nth, size_t *pn)
struct GetNthSymbolCtx
{
if (!members)
return NULL;
size_t nth;
Dsymbol *sym;
};
size_t n = 0;
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
AttribDeclaration *a = s->isAttribDeclaration();
if (a)
{
s = getNth(a->decl, nth - n, &n);
if (s)
return s;
static int getNthSymbolDg(void *ctx, size_t n, Dsymbol *sym)
{
GetNthSymbolCtx *p = (GetNthSymbolCtx *)ctx;
if (n == p->nth)
{ p->sym = sym;
return 1;
}
else if (n == nth)
return s;
return 0;
}
Dsymbol *ScopeDsymbol::getNth(Dsymbols *members, size_t nth, size_t *pn)
{
GetNthSymbolCtx ctx = { nth, NULL };
int res = foreach(members, &getNthSymbolDg, &ctx);
return res ? ctx.sym : NULL;
}
#endif
/***************************************
* Expands attribute declarations in members in depth first
* order. Calls dg(void *ctx, size_t symidx, Dsymbol *sym) for each
* member.
* If dg returns !=0, stops and returns that value else returns 0.
* Use this function to avoid the O(N + N^2/2) complexity of
* calculating dim and calling N times getNth.
*/
#if DMDV2
int ScopeDsymbol::foreach(Dsymbols *members, ScopeDsymbol::ForeachDg dg, void *ctx, size_t *pn)
{
assert(members);
size_t n = pn ? *pn : 0; // take over index
int result = 0;
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
if (AttribDeclaration *a = s->isAttribDeclaration())
result = foreach(a->decl, dg, ctx, &n);
else if (TemplateMixin *tm = s->isTemplateMixin())
result = foreach(tm->members, dg, ctx, &n);
else if (s->isTemplateInstance())
;
else
n++;
result = dg(ctx, n++, s);
if (result)
break;
}
if (pn)
*pn += n;
return NULL;
*pn = n; // update index
return result;
}
#endif
@@ -1161,35 +1217,27 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
* multiple times, it gets set only once.
*/
if (!*pvar) // if not already initialized
{ /* Create variable v and set it to the value of $,
* which will be a constant.
{ /* Create variable v and set it to the value of $
*/
VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
if (ce->op == TOKstring)
{ /* It is for a string literal, so the
* length will be a const.
*/
Expression *e = new IntegerExp(0, ((StringExp *)ce)->len, Type::tsize_t);
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)
if (ce->op == TOKtuple)
{ /* It is for an expression tuple, so the
* length will be a const.
* length will be a compile-time constant.
*/
Expression *e = new IntegerExp(0, ((TupleExp *)ce)->exps->dim, Type::tsize_t);
v->init = new ExpInitializer(0, e);
v->storage_class |= STCconst;
}
else
{ /* For arrays, $ will either be a compile-time constant
* (in which case its value in set during constant-folding),
* or a variable (in which case an expression is created in
* toir.c).
*/
VoidInitializer *e = new VoidInitializer(0);
e->type = Type::tsize_t;
v->init = e;
}
*pvar = v;
}
return (*pvar);
@@ -1202,89 +1250,46 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
DsymbolTable::DsymbolTable()
{
#if STRINGTABLE
tab = new StringTable;
#else
tab = NULL;
#endif
}
DsymbolTable::~DsymbolTable()
{
#if STRINGTABLE
delete tab;
#endif
}
Dsymbol *DsymbolTable::lookup(Identifier *ident)
{
#if STRINGTABLE
#ifdef DEBUG
assert(ident);
assert(tab);
#endif
//printf("DsymbolTable::lookup(%s)\n", (char*)ident->string);
StringValue *sv = tab->lookup((char*)ident->string, ident->len);
return (Dsymbol *)(sv ? sv->ptrvalue : NULL);
#else
//printf("DsymbolTable::lookup(%s)\n", (char*)ident->string);
return (Dsymbol *)_aaGetRvalue(tab, ident);
#endif
}
Dsymbol *DsymbolTable::insert(Dsymbol *s)
{
//printf("DsymbolTable::insert(this = %p, '%s')\n", this, s->ident->toChars());
Identifier *ident = s->ident;
#if STRINGTABLE
#ifdef DEBUG
assert(ident);
assert(tab);
#endif
StringValue *sv = tab->insert(ident->toChars(), ident->len);
if (!sv)
return NULL; // already in table
sv->ptrvalue = s;
return s;
#else
Dsymbol **ps = (Dsymbol **)_aaGet(&tab, ident);
if (*ps)
return NULL; // already in table
*ps = s;
return s;
#endif
}
Dsymbol *DsymbolTable::insert(Identifier *ident, Dsymbol *s)
{
//printf("DsymbolTable::insert()\n");
#if STRINGTABLE
StringValue *sv = tab->insert(ident->toChars(), ident->len);
if (!sv)
return NULL; // already in table
sv->ptrvalue = s;
return s;
#else
Dsymbol **ps = (Dsymbol **)_aaGet(&tab, ident);
if (*ps)
return NULL; // already in table
*ps = s;
return s;
#endif
}
Dsymbol *DsymbolTable::update(Dsymbol *s)
{
Identifier *ident = s->ident;
#if STRINGTABLE
StringValue *sv = tab->update(ident->toChars(), ident->len);
sv->ptrvalue = s;
return s;
#else
Dsymbol **ps = (Dsymbol **)_aaGet(&tab, ident);
*ps = s;
return s;
#endif
}

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -145,6 +145,7 @@ struct Dsymbol : Object
int isAnonymous();
void error(Loc loc, const char *format, ...) IS_PRINTF(3);
void error(const char *format, ...) IS_PRINTF(2);
void verror(Loc loc, const char *format, va_list ap);
void checkDeprecated(Loc loc, Scope *sc);
Module *getModule(); // module where declared
Module *getCompilationModule(); // possibly different for templates
@@ -155,7 +156,7 @@ struct Dsymbol : Object
int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
static Array *arraySyntaxCopy(Array *a);
static Dsymbols *arraySyntaxCopy(Dsymbols *a);
virtual const char *toPrettyChars();
virtual const char *kind();
@@ -172,10 +173,8 @@ struct Dsymbol : Object
Dsymbol *search_correct(Identifier *id);
Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
virtual int overloadInsert(Dsymbol *s);
#ifdef _DH
char *toHChars();
virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
#endif
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
virtual void toDocBuffer(OutBuffer *buf);
virtual void toJsonBuffer(OutBuffer *buf);
@@ -198,8 +197,9 @@ struct Dsymbol : Object
virtual enum PROT prot();
virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
virtual int oneMember(Dsymbol **ps);
static int oneMembers(Array *members, Dsymbol **ps);
static int oneMembers(Dsymbols *members, Dsymbol **ps);
virtual int hasPointers();
virtual bool hasStaticCtorOrDtor();
virtual void addLocalClass(ClassDeclarations *) { }
virtual void checkCtorConstInit() { }
@@ -254,9 +254,8 @@ struct Dsymbol : Object
virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; }
virtual Import *isImport() { return NULL; }
virtual EnumDeclaration *isEnumDeclaration() { return NULL; }
#ifdef _DH
virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
#endif
//virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
virtual StaticStructInitDeclaration *isStaticStructInitDeclaration() { return NULL; }
virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; }
@@ -283,10 +282,10 @@ struct Dsymbol : Object
struct ScopeDsymbol : Dsymbol
{
Array *members; // all Dsymbol's in this scope
Dsymbols *members; // all Dsymbol's in this scope
DsymbolTable *symtab; // members[] sorted into table
Array *imports; // imported ScopeDsymbol's
ScopeDsymbols *imports; // imported ScopeDsymbol's
unsigned char *prots; // array of PROT, one for each import
ScopeDsymbol();
@@ -301,11 +300,15 @@ struct ScopeDsymbol : Dsymbol
const char *kind();
FuncDeclaration *findGetMembers();
virtual Dsymbol *symtabInsert(Dsymbol *s);
bool hasStaticCtorOrDtor();
void emitMemberComments(Scope *sc);
static size_t dim(Array *members);
static Dsymbol *getNth(Array *members, size_t nth, size_t *pn = NULL);
static size_t dim(Dsymbols *members);
static Dsymbol *getNth(Dsymbols *members, size_t nth, size_t *pn = NULL);
typedef int (*ForeachDg)(void *ctx, size_t idx, Dsymbol *s);
static int foreach(Dsymbols *members, ForeachDg dg, void *ctx, size_t *pn=NULL);
ScopeDsymbol *isScopeDsymbol() { return this; }
};
@@ -357,11 +360,7 @@ struct OverloadSet : Dsymbol
struct DsymbolTable : Object
{
#if STRINGTABLE
StringTable *tab;
#else
AA *tab;
#endif
DsymbolTable();
~DsymbolTable();

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -68,7 +68,7 @@ void EnumDeclaration::semantic0(Scope *sc)
return;
if (!isAnonymous() || memtype)
return;
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
if (em && em->value)
@@ -80,7 +80,7 @@ void EnumDeclaration::semantic0(Scope *sc)
}
void EnumDeclaration::semantic(Scope *sc)
{ int i;
{
uinteger_t number;
Type *t;
Scope *sce;
@@ -140,7 +140,7 @@ void EnumDeclaration::semantic(Scope *sc)
if (members->dim == 0)
error("enum %s must have at least one member", toChars());
int first = 1;
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
Expression *e;
@@ -228,13 +228,13 @@ void EnumDeclaration::semantic(Scope *sc)
if (isAnonymous())
{
//sce->enclosing->insert(em);
for (Scope *scx = sce->enclosing; scx; scx = scx->enclosing)
for (Scope *sct = sce->enclosing; sct; sct = sct->enclosing)
{
if (scx->scopesym)
if (sct->scopesym)
{
if (!scx->scopesym->symtab)
scx->scopesym->symtab = new DsymbolTable();
em->addMember(sce, scx->scopesym, 1);
if (!sct->scopesym->symtab)
sct->scopesym->symtab = new DsymbolTable();
em->addMember(sce, sct->scopesym, 1);
break;
}
}
@@ -279,8 +279,7 @@ int EnumDeclaration::oneMember(Dsymbol **ps)
}
void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{ int i;
{
buf->writestring("enum ");
if (ident)
{ buf->writestring(ident->toChars());
@@ -300,7 +299,7 @@ void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
buf->writeByte('{');
buf->writenl();
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
if (!em)

View File

@@ -21,9 +21,7 @@
struct Identifier;
struct Type;
struct Expression;
#ifdef _DH
struct HdrGenState;
#endif
struct EnumDeclaration : ScopeDsymbol

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -44,6 +44,8 @@ struct BinExp;
struct AssignExp;
struct InterState;
struct OverloadSet;
struct Initializer;
struct StringExp;
enum TOK;
@@ -82,6 +84,17 @@ void expandTuples(Expressions *exps);
FuncDeclaration *hasThis(Scope *sc);
Expression *fromConstInitializer(int result, Expression *e);
int arrayExpressionCanThrow(Expressions *exps);
TemplateDeclaration *getFuncTemplateDecl(Dsymbol *s);
/* Interpreter: what form of return value expression is required?
*/
enum CtfeGoal
{ ctfeNeedRvalue, // Must return an Rvalue
ctfeNeedLvalue, // Must return an Lvalue
ctfeNeedAnyValue, // Can return either an Rvalue or an Lvalue
ctfeNeedLvalueRef,// Must return a reference to an Lvalue (for ref types)
ctfeNeedNothing // The return value is not required
};
struct IntRange
{ uinteger_t imin;
@@ -99,6 +112,7 @@ struct Expression : Object
Expression *copy();
virtual Expression *syntaxCopy();
virtual Expression *semantic(Scope *sc);
Expression *trySemantic(Scope *sc);
int dyncast() { return DYNCAST_EXPRESSION; } // kludge for template.isExpression()
@@ -117,6 +131,7 @@ struct Expression : Object
virtual real_t toReal();
virtual real_t toImaginary();
virtual complex_t toComplex();
virtual StringExp *toString();
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
virtual void toMangleBuffer(OutBuffer *buf);
virtual Expression *toLvalue(Scope *sc, Expression *e);
@@ -143,9 +158,12 @@ struct Expression : Object
virtual Expression *optimize(int result);
#define WANTflags 1
#define WANTvalue 2
// A compile-time result is required. Give an error if not possible
#define WANTinterpret 4
// Same as WANTvalue, but also expand variables as far as possible
#define WANTexpand 8
virtual Expression *interpret(InterState *istate);
virtual Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
virtual int isConst();
virtual int isBool(int result);
@@ -194,7 +212,7 @@ struct IntegerExp : Expression
IntegerExp(dinteger_t value);
int equals(Object *o);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
char *toChars();
void dump(int indent);
dinteger_t toInteger();
@@ -221,6 +239,7 @@ struct ErrorExp : IntegerExp
ErrorExp();
Expression *implicitCastTo(Scope *sc, Type *t);
Expression *castTo(Scope *sc, Type *t);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
};
@@ -231,7 +250,7 @@ struct RealExp : Expression
RealExp(Loc loc, real_t value, Type *type);
int equals(Object *o);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
char *toChars();
dinteger_t toInteger();
uinteger_t toUInteger();
@@ -259,7 +278,7 @@ struct ComplexExp : Expression
ComplexExp(Loc loc, complex_t value, Type *type);
int equals(Object *o);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
char *toChars();
dinteger_t toInteger();
uinteger_t toUInteger();
@@ -271,9 +290,7 @@ struct ComplexExp : Expression
int isBool(int result);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toMangleBuffer(OutBuffer *buf);
#ifdef _DH
OutBuffer hexp;
#endif
#if IN_DMD
elem *toElem(IRState *irs);
dt_t **toDt(dt_t **pdt);
@@ -321,7 +338,7 @@ struct ThisExp : Expression
ThisExp(Loc loc);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int isBool(int result);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expression *toLvalue(Scope *sc, Expression *e);
@@ -360,11 +377,12 @@ struct NullExp : Expression
Expression *semantic(Scope *sc);
int isBool(int result);
int isConst();
StringExp *toString();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toMangleBuffer(OutBuffer *buf);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
#if IN_DMD
elem *toElem(IRState *irs);
dt_t **toDt(dt_t **pdt);
@@ -389,7 +407,9 @@ struct StringExp : Expression
int equals(Object *o);
char *toChars();
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
size_t length();
StringExp *toString();
StringExp *toUTF8(Scope *sc);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
@@ -423,7 +443,7 @@ struct TupleExp : Expression
void checkEscape();
int checkSideEffect(int flag);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
Expression *castTo(Scope *sc, Type *t);
#if IN_DMD
elem *toElem(IRState *irs);
@@ -449,11 +469,12 @@ struct ArrayLiteralExp : Expression
Expression *semantic(Scope *sc);
int isBool(int result);
int checkSideEffect(int flag);
StringExp *toString();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toMangleBuffer(OutBuffer *buf);
void scanForNestedRef(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
@@ -488,7 +509,7 @@ struct AssocArrayLiteralExp : Expression
void toMangleBuffer(OutBuffer *buf);
void scanForNestedRef(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
@@ -507,6 +528,7 @@ struct StructLiteralExp : Expression
StructDeclaration *sd; // which aggregate this is for
Expressions *elements; // parallels sd->fields[] with
// NULL entries for fields to skip
Type *stype; // final type of result (can be different from sd's type)
#if IN_DMD
Symbol *sym; // back end symbol to initialize with literal
@@ -514,7 +536,7 @@ struct StructLiteralExp : Expression
size_t soffset; // offset from start of s
int fillHoles; // fill alignment 'holes' with zero
StructLiteralExp(Loc loc, StructDeclaration *sd, Expressions *elements);
StructLiteralExp(Loc loc, StructDeclaration *sd, Expressions *elements, Type *stype = NULL);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
@@ -525,7 +547,7 @@ struct StructLiteralExp : Expression
void toMangleBuffer(OutBuffer *buf);
void scanForNestedRef(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
Expression *toLvalue(Scope *sc, Expression *e);
int inlineCost(InlineCostState *ics);
@@ -609,7 +631,7 @@ struct NewExp : Expression
Type *newtype, Expressions *arguments);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
Expression *optimize(int result);
#if IN_DMD
elem *toElem(IRState *irs);
@@ -666,7 +688,7 @@ struct SymOffExp : Expression
SymOffExp(Loc loc, Declaration *var, unsigned offset);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void checkEscape();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
int isConst();
@@ -696,7 +718,7 @@ struct VarExp : Expression
int equals(Object *o);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void dump(int indent);
char *toChars();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -744,12 +766,13 @@ struct FuncExp : Expression
FuncExp(Loc loc, FuncLiteralDeclaration *fd);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void scanForNestedRef(Scope *sc);
char *toChars();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#if IN_DMD
elem *toElem(IRState *irs);
dt_t **toDt(dt_t **pdt);
#endif
int inlineCost(InlineCostState *ics);
@@ -771,7 +794,7 @@ struct DeclarationExp : Expression
DeclarationExp(Loc loc, Dsymbol *declaration);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int checkSideEffect(int flag);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#if IN_DMD
@@ -857,7 +880,7 @@ struct UnaExp : Expression
Expression *optimize(int result);
void dump(int indent);
void scanForNestedRef(Scope *sc);
Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *));
Expression *interpretCommon(InterState *istate, CtfeGoal goal, Expression *(*fp)(Type *, Expression *));
int inlineCost(InlineCostState *ics);
Expression *doInline(InlineDoState *ids);
@@ -888,9 +911,12 @@ struct BinExp : Expression
void incompatibleTypes();
void dump(int indent);
void scanForNestedRef(Scope *sc);
Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *));
Expression *interpretCommon2(InterState *istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *));
Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *), int post = 0);
Expression *interpretCommon(InterState *istate, CtfeGoal goal,
Expression *(*fp)(Type *, Expression *, Expression *));
Expression *interpretCommon2(InterState *istate, CtfeGoal goal,
Expression *(*fp)(TOK, Type *, Expression *, Expression *));
Expression *interpretAssignCommon(InterState *istate, CtfeGoal goal,
Expression *(*fp)(Type *, Expression *, Expression *), int post = 0);
Expression *arrayOp(Scope *sc);
int inlineCost(InlineCostState *ics);
@@ -933,7 +959,7 @@ struct AssertExp : UnaExp
AssertExp(Loc loc, Expression *e, Expression *msg = NULL);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int checkSideEffect(int flag);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -977,7 +1003,7 @@ struct DotVarExp : UnaExp
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void dump(int indent);
#if IN_DMD
@@ -1008,7 +1034,7 @@ struct DelegateExp : UnaExp
DelegateExp(Loc loc, Expression *e, FuncDeclaration *func);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -1052,7 +1078,7 @@ struct CallExp : UnaExp
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int checkSideEffect(int flag);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void dump(int indent);
@@ -1086,6 +1112,7 @@ struct AddrExp : UnaExp
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
Expression *optimize(int result);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
#if IN_LLVM
DValue* toElem(IRState* irs);
@@ -1105,7 +1132,7 @@ struct PtrExp : UnaExp
elem *toElem(IRState *irs);
#endif
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
#if IN_LLVM
DValue* toElem(IRState* irs);
@@ -1118,7 +1145,7 @@ struct NegExp : UnaExp
NegExp(Loc loc, Expression *e);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1148,7 +1175,7 @@ struct ComExp : UnaExp
ComExp(Loc loc, Expression *e);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1169,7 +1196,7 @@ struct NotExp : UnaExp
NotExp(Loc loc, Expression *e);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int isBit();
#if IN_DMD
elem *toElem(IRState *irs);
@@ -1185,7 +1212,7 @@ struct BoolExp : UnaExp
BoolExp(Loc loc, Expression *e, Type *type);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int isBit();
#if IN_DMD
elem *toElem(IRState *irs);
@@ -1221,7 +1248,7 @@ struct CastExp : UnaExp
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int checkSideEffect(int flag);
void checkEscape();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -1254,9 +1281,10 @@ struct SliceExp : UnaExp
void checkEscapeRef();
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);
int isBool(int result);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void dump(int indent);
#if IN_DMD
elem *toElem(IRState *irs);
@@ -1264,6 +1292,7 @@ struct SliceExp : UnaExp
void scanForNestedRef(Scope *sc);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
int canThrow();
int inlineCost(InlineCostState *ics);
Expression *doInline(InlineDoState *ids);
@@ -1280,7 +1309,7 @@ struct ArrayLengthExp : UnaExp
ArrayLengthExp(Loc loc, Expression *e1);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#if IN_DMD
elem *toElem(IRState *irs);
@@ -1332,7 +1361,7 @@ struct CommaExp : BinExp
int isBool(int result);
int checkSideEffect(int flag);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
#if IN_DMD
elem *toElem(IRState *irs);
#endif
@@ -1354,7 +1383,7 @@ struct IndexExp : BinExp
Expression *modifiableLvalue(Scope *sc, Expression *e);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
Expression *doInline(InlineDoState *ids);
void scanForNestedRef(Scope *sc);
@@ -1373,7 +1402,7 @@ struct PostExp : BinExp
{
PostExp(enum TOK op, Loc loc, Expression *e);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Identifier *opId(); // For operator overloading
#if IN_DMD
@@ -1391,7 +1420,7 @@ struct AssignExp : BinExp
AssignExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *checkToBoolean();
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
Identifier *opId(); // For operator overloading
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1424,7 +1453,7 @@ struct op##AssignExp : BinExp \
{ \
op##AssignExp(Loc loc, Expression *e1, Expression *e2); \
Expression *semantic(Scope *sc); \
Expression *interpret(InterState *istate); \
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue); \
X(void buildArrayIdent(OutBuffer *buf, Expressions *arguments);) \
X(Expression *buildArrayLoop(Parameters *fparams);) \
\
@@ -1460,7 +1489,7 @@ struct AddExp : BinExp
AddExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1484,7 +1513,7 @@ struct MinExp : BinExp
MinExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1507,7 +1536,7 @@ struct CatExp : BinExp
CatExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
// For operator overloading
Identifier *opId();
@@ -1527,7 +1556,7 @@ struct MulExp : BinExp
MulExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1550,7 +1579,7 @@ struct DivExp : BinExp
DivExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1572,7 +1601,7 @@ struct ModExp : BinExp
ModExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1606,7 +1635,7 @@ struct ShlExp : BinExp
ShlExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
// For operator overloading
Identifier *opId();
@@ -1626,7 +1655,7 @@ struct ShrExp : BinExp
ShrExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
// For operator overloading
Identifier *opId();
@@ -1646,7 +1675,7 @@ struct UshrExp : BinExp
UshrExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
// For operator overloading
Identifier *opId();
@@ -1666,7 +1695,7 @@ struct AndExp : BinExp
AndExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1689,7 +1718,7 @@ struct OrExp : BinExp
OrExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1712,7 +1741,7 @@ struct XorExp : BinExp
XorExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
@@ -1737,7 +1766,7 @@ struct OrOrExp : BinExp
Expression *checkToBoolean();
int isBit();
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int checkSideEffect(int flag);
#if IN_DMD
elem *toElem(IRState *irs);
@@ -1755,7 +1784,7 @@ struct AndAndExp : BinExp
Expression *checkToBoolean();
int isBit();
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int checkSideEffect(int flag);
#if IN_DMD
elem *toElem(IRState *irs);
@@ -1771,7 +1800,7 @@ struct CmpExp : BinExp
CmpExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int isBit();
// For operator overloading
@@ -1791,6 +1820,7 @@ struct InExp : BinExp
{
InExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int isBit();
// For operator overloading
@@ -1809,6 +1839,7 @@ struct InExp : BinExp
struct RemoveExp : BinExp
{
RemoveExp(Loc loc, Expression *e1, Expression *e2);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#if IN_DMD
elem *toElem(IRState *irs);
@@ -1826,7 +1857,7 @@ struct EqualExp : BinExp
EqualExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
int isBit();
// For operator overloading
@@ -1850,7 +1881,7 @@ struct IdentityExp : BinExp
Expression *semantic(Scope *sc);
int isBit();
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
#if IN_DMD
elem *toElem(IRState *irs);
#endif
@@ -1870,7 +1901,7 @@ struct CondExp : BinExp
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void checkEscape();
void checkEscapeRef();
Expression *toLvalue(Scope *sc, Expression *e);

View File

@@ -218,6 +218,10 @@ void FuncDeclaration::semantic(Scope *sc)
if (isAbstract() && !isVirtual())
error("non-virtual functions cannot be abstract");
// https://github.com/donc/dmd/commit/9f7b2f8cfe5d7482f2de7f9678c176d54abe237f#commitcomment-321724
//if (isOverride() && !isVirtual())
//error("cannot override a non-virtual function");
if (isAbstract() && isFinal())
error("cannot be both final and abstract");
#if 0
@@ -313,7 +317,7 @@ void FuncDeclaration::semantic(Scope *sc)
// ctor = (CtorDeclaration *)this;
// if (!cd->ctor)
// cd->ctor = ctor;
return;
goto Ldone;
}
#if 0
@@ -414,12 +418,13 @@ void FuncDeclaration::semantic(Scope *sc)
warning(loc, "overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars());
#endif
if (fdv->toParent() == parent)
FuncDeclaration *fdc = ((Dsymbol *)cd->vtbl.data[vi])->isFuncDeclaration();
if (fdc->toParent() == parent)
{
// If both are mixins, then error.
// If either is not, the one that is not overrides
// the other.
if (fdv->parent->isClassDeclaration())
if (fdc->parent->isClassDeclaration())
break;
if (!this->parent->isClassDeclaration()
#if !BREAKABI
@@ -431,7 +436,7 @@ void FuncDeclaration::semantic(Scope *sc)
)
error("multiple overrides of same function");
}
cd->vtbl.data[vi] = (void *)this;
cd->vtbl[vi] = this;
vtblIndex = vi;
/* Remember which functions this overrides
@@ -496,15 +501,12 @@ void FuncDeclaration::semantic(Scope *sc)
/* Only need to have a tintro if the vptr
* offsets differ
*/
unsigned errors = global.errors;
global.gag++; // suppress printing of error messages
unsigned errors = global.startGagging(); // suppress printing of error messages
int offset;
int baseOf = fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset);
global.gag--; // suppress printing of error messages
if (errors != global.errors)
if (global.endGagging(errors))
{
// any error in isBaseOf() is a forward reference error, so we bail out
global.errors = errors;
cd->sizeok = 2; // can't finish due to forward reference
Module::dprogress = dprogress_save;
return;
@@ -640,7 +642,7 @@ void FuncDeclaration::semantic(Scope *sc)
FuncDeclaration *fd = new FuncDeclaration(loc, loc,
Id::require, STCundefined, tf);
fd->fbody = frequire;
Statement *s1 = new DeclarationStatement(loc, fd);
Statement *s1 = new ExpStatement(loc, fd);
Expression *e = new CallExp(loc, new VarExp(loc, fd), (Expressions *)NULL);
Statement *s2 = new ExpStatement(loc, e);
frequire = new CompoundStatement(loc, s1, s2);
@@ -667,7 +669,7 @@ void FuncDeclaration::semantic(Scope *sc)
FuncDeclaration *fd = new FuncDeclaration(loc, loc,
Id::ensure, STCundefined, tf);
fd->fbody = fensure;
Statement *s1 = new DeclarationStatement(loc, fd);
Statement *s1 = new ExpStatement(loc, fd);
Expression *eresult = NULL;
if (outId)
eresult = new IdentifierExp(loc, outId);
@@ -746,6 +748,20 @@ void FuncDeclaration::semantic3(Scope *sc)
}
}
if (frequire)
{
for (int i = 0; i < foverrides.dim; i++)
{
FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
if (fdv->fbody && !fdv->frequire)
{
error("cannot have an in contract when overriden function %s does not have an in contract", fdv->toPrettyChars());
break;
}
}
}
frequire = mergeFrequire(frequire);
fensure = mergeFensure(fensure);
@@ -768,7 +784,10 @@ void FuncDeclaration::semantic3(Scope *sc)
sc2->sw = NULL;
sc2->fes = fes;
sc2->linkage = LINKd;
sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract | STCdeprecated | STCfinal);
sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract |
STCdeprecated | STCoverride |
STC_TYPECTOR | STCfinal | STCtls | STCgshared | STCref |
STCproperty | STCsafe | STCtrusted | STCsystem);
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
sc2->structalign = 8;
@@ -823,6 +842,21 @@ void FuncDeclaration::semantic3(Scope *sc)
#else
Type *t;
if (global.params.is64bit)
{ // Declare save area for varargs registers
Type *t = new TypeIdentifier(loc, Id::va_argsave_t);
t = t->semantic(loc, sc);
if (t == Type::terror)
error("must import std.c.stdarg to use variadic functions");
else
{
v_argsave = new VarDeclaration(loc, t, Id::va_argsave, NULL);
v_argsave->semantic(sc2);
sc2->insert(v_argsave);
v_argsave->parent = this;
}
}
if (f->linkage == LINKd)
{ // Declare _arguments[]
#if BREAKABI
@@ -846,7 +880,7 @@ void FuncDeclaration::semantic3(Scope *sc)
v_arguments->parent = this;
#endif
}
if (f->linkage == LINKd || (parameters && parameters->dim))
if (f->linkage == LINKd || (f->parameters && Parameter::dim(f->parameters)))
{ // Declare _argptr
#if IN_GCC
t = d_gcc_builtin_va_list_d_type;
@@ -911,7 +945,7 @@ void FuncDeclaration::semantic3(Scope *sc)
{ /* parameters[] has all the tuples removed, as the back end
* doesn't know about tuples
*/
parameters = new Dsymbols();
parameters = new VarDeclarations();
parameters->reserve(nparams);
for (size_t i = 0; i < nparams; i++)
{
@@ -1143,7 +1177,7 @@ void FuncDeclaration::semantic3(Scope *sc)
f = (TypeFunction *)type;
}
int offend = fbody ? fbody->blockExit() & BEfallthru : TRUE;
int offend = fbody ? fbody->blockExit(FALSE) & BEfallthru : TRUE;
if (isStaticCtorDeclaration())
{ /* It's a static constructor. Ensure that all
@@ -1190,17 +1224,16 @@ void FuncDeclaration::semantic3(Scope *sc)
Expression *e1 = new SuperExp(0);
Expression *e = new CallExp(0, e1);
unsigned errors = global.errors;
global.gag++;
e = e->semantic(sc2);
global.gag--;
if (errors != global.errors)
e = e->trySemantic(sc2);
if (!e)
error("no match for implicit super() call in constructor");
else
{
Statement *s = new ExpStatement(0, e);
fbody = new CompoundStatement(0, s, fbody);
}
}
}
else if (fes)
{ // For foreach(){} body, append a return 0;
Expression *e = new IntegerExp(0);
@@ -1287,6 +1320,17 @@ void FuncDeclaration::semantic3(Scope *sc)
v_argptr->init = new VoidInitializer(loc);
#else
Type *t = argptr->type;
if (global.params.is64bit)
{ // Initialize _argptr to point to v_argsave
Expression *e1 = new VarExp(0, argptr);
Expression *e = new SymOffExp(0, v_argsave, 6*8 + 8*16);
e->type = argptr->type;
e = new AssignExp(0, e1, e);
e = e->semantic(sc);
a->push(new ExpStatement(0, e));
}
else
{ // Initialize _argptr to point past non-variadic arg
VarDeclaration *p;
unsigned offset = 0;
@@ -1347,15 +1391,10 @@ void FuncDeclaration::semantic3(Scope *sc)
// Merge contracts together with body into one compound statement
#ifdef _DH
if (frequire && global.params.useIn)
{ frequire->incontract = 1;
a->push(frequire);
}
#else
if (frequire && global.params.useIn)
a->push(frequire);
#endif
// Precondition invariant
if (addPreInvariant())
@@ -1483,9 +1522,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (isSynchronized())
{
AggregateDeclaration *ad = isThis();
ClassDeclaration *cd = ad ? ad->isClassDeclaration() : NULL;
if (!cd)
error("synchronized function %s must be a member of a class", toChars());
ClassDeclaration *cd = ad ? ad->isClassDeclaration() : parent->isClassDeclaration();
Expression *sync;
if (isStatic())
@@ -1618,7 +1655,7 @@ Statement *FuncDeclaration::mergeFrequire(Statement *sf)
}
sf = fdv->mergeFrequire(sf);
if (fdv->fdrequire)
if (sf && fdv->fdrequire)
{
//printf("fdv->frequire: %s\n", fdv->frequire->toChars());
/* Make the call:
@@ -1629,15 +1666,13 @@ Statement *FuncDeclaration::mergeFrequire(Statement *sf)
Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdrequire), eresult);
Statement *s2 = new ExpStatement(loc, e);
if (sf)
{ Catch *c = new Catch(loc, NULL, NULL, sf);
Catch *c = new Catch(loc, NULL, NULL, sf);
Array *catches = new Array();
catches->push(c);
sf = new TryCatchStatement(loc, s2, catches);
}
else
sf = s2;
}
return NULL;
}
return sf;
}
@@ -3011,7 +3046,7 @@ void StaticCtorDeclaration::semantic(Scope *sc)
VarDeclaration *v = new VarDeclaration(0, Type::tint32, id, NULL);
v->storage_class = STCstatic;
Statements *sa = new Statements();
Statement *s = new DeclarationStatement(0, v);
Statement *s = new ExpStatement(0, v);
sa->push(s);
Expression *e = new IdentifierExp(0, id);
e = new AddAssignExp(0, e, new IntegerExp(1));
@@ -3053,6 +3088,11 @@ int StaticCtorDeclaration::isVirtual()
return FALSE;
}
bool StaticCtorDeclaration::hasStaticCtorOrDtor()
{
return TRUE;
}
int StaticCtorDeclaration::addPreInvariant()
{
return FALSE;
@@ -3117,7 +3157,7 @@ void StaticDtorDeclaration::semantic(Scope *sc)
VarDeclaration *v = new VarDeclaration(0, Type::tint32, id, NULL);
v->storage_class = STCstatic;
Statements *sa = new Statements();
Statement *s = new DeclarationStatement(0, v);
Statement *s = new ExpStatement(0, v);
sa->push(s);
Expression *e = new IdentifierExp(0, id);
e = new AddAssignExp(0, e, new IntegerExp((uint64_t)-1));
@@ -3160,6 +3200,11 @@ int StaticDtorDeclaration::isVirtual()
return FALSE;
}
bool StaticDtorDeclaration::hasStaticCtorOrDtor()
{
return TRUE;
}
int StaticDtorDeclaration::addPreInvariant()
{
return FALSE;

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2006 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// Initial header generation implementation by Dave Fladebo
// http://www.digitalmars.com
@@ -10,8 +10,6 @@
// Routines to emit header files
#ifdef _DH
#define PRETTY_PRINT
#define TEST_EMIT_ALL 0 // For Testing
@@ -85,7 +83,7 @@ void Module::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
}
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->toHBuffer(buf, hgs);
@@ -100,5 +98,3 @@ void Dsymbol::toHBuffer(OutBuffer *buf, HdrGenState *hgs)
/*************************************/
#endif // #ifdef _DH

View File

@@ -35,9 +35,7 @@ struct Identifier : Object
int compare(Object *o);
void print();
char *toChars();
#ifdef _DH
char *toHChars();
#endif
const char *toHChars2();
int dyncast();

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -60,6 +60,7 @@ Msgtable msgtable[] =
{ "typeinfo" },
{ "outer" },
{ "Exception" },
{ "Error" },
{ "withSym", "__withSym" },
{ "result", "__result" },
{ "returnLabel", "__returnLabel" },
@@ -249,6 +250,31 @@ Msgtable msgtable[] =
{ "main" },
{ "WinMain" },
{ "DllMain" },
// varargs implementation
{ "va_argsave_t", "__va_argsave_t" },
{ "va_argsave", "__va_argsave" },
// Builtin functions
{ "std" },
{ "core" },
{ "math" },
{ "sin" },
{ "cos" },
{ "tan" },
{ "_sqrt", "sqrt" },
{ "_pow", "pow" },
{ "atan2" },
{ "rndtol" },
{ "expm1" },
{ "exp2" },
{ "yl2x" },
{ "yl2xp1" },
{ "fabs" },
{ "bitop" },
{ "bsf" },
{ "bsr" },
{ "bswap" },
};

View File

@@ -25,7 +25,7 @@
/********************************* Import ****************************/
Import::Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId,
Import::Import(Loc loc, Identifiers *packages, Identifier *id, Identifier *aliasId,
int isstatic)
: Dsymbol(id)
{

View File

@@ -24,13 +24,11 @@ struct OutBuffer;
struct Module;
struct Package;
struct AliasDeclaration;
#ifdef _DH
struct HdrGenState;
#endif
struct Import : Dsymbol
{
Array *packages; // array of Identifier's representing packages
Identifiers *packages; // array of Identifier's representing packages
Identifier *id; // module Identifier
Identifier *aliasId;
int isstatic; // !=0 if static import
@@ -45,7 +43,7 @@ struct Import : Dsymbol
Module *mod;
Package *pkg; // leftmost package/module
Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId,
Import(Loc loc, Identifiers *packages, Identifier *id, Identifier *aliasId,
int isstatic);
void addAlias(Identifier *name, Identifier *alias);

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -34,7 +34,7 @@ Initializer *Initializer::syntaxCopy()
return this;
}
Initializer *Initializer::semantic(Scope *sc, Type *t)
Initializer *Initializer::semantic(Scope *sc, Type *t, int needInterpret)
{
return this;
}
@@ -52,7 +52,7 @@ Initializers *Initializer::arraySyntaxCopy(Initializers *ai)
{
a = new Initializers();
a->setDim(ai->dim);
for (int i = 0; i < a->dim; i++)
for (size_t i = 0; i < a->dim; i++)
{ Initializer *e = (Initializer *)ai->data[i];
e = e->syntaxCopy();
@@ -87,7 +87,7 @@ Initializer *VoidInitializer::syntaxCopy()
}
Initializer *VoidInitializer::semantic(Scope *sc, Type *t)
Initializer *VoidInitializer::semantic(Scope *sc, Type *t, int needInterpret)
{
//printf("VoidInitializer::semantic(t = %p)\n", t);
type = t;
@@ -126,7 +126,7 @@ Initializer *StructInitializer::syntaxCopy()
assert(field.dim == value.dim);
ai->field.setDim(field.dim);
ai->value.setDim(value.dim);
for (int i = 0; i < field.dim; i++)
for (size_t i = 0; i < field.dim; i++)
{
ai->field.data[i] = field.data[i];
@@ -144,21 +144,25 @@ void StructInitializer::addInit(Identifier *field, Initializer *value)
this->value.push(value);
}
Initializer *StructInitializer::semantic(Scope *sc, Type *t)
Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
{
TypeStruct *ts;
int errors = 0;
//printf("StructInitializer::semantic(t = %s) %s\n", t->toChars(), toChars());
vars.setDim(field.dim);
t = t->toBasetype();
if (t->ty == Tstruct)
{ unsigned i;
{
unsigned fieldi = 0;
ts = (TypeStruct *)t;
TypeStruct *ts = (TypeStruct *)t;
ad = ts->sym;
for (i = 0; i < field.dim; i++)
size_t nfields = ad->fields.dim;
#if DMDV2
if (((StructDeclaration *)ad)->isnested)
nfields--; // don't count pointer to outer
#endif
for (size_t i = 0; i < field.dim; i++)
{
Identifier *id = (Identifier *)field.data[i];
Initializer *val = (Initializer *)value.data[i];
@@ -167,8 +171,9 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t)
if (id == NULL)
{
if (fieldi >= ad->fields.dim)
if (fieldi >= nfields)
{ error(loc, "too many initializers for %s", ad->toChars());
errors = 1;
field.remove(i);
i--;
continue;
@@ -185,15 +190,18 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t)
if (!s)
{
error(loc, "'%s' is not a member of '%s'", id->toChars(), t->toChars());
errors = 1;
continue;
}
// Find out which field index it is
for (fieldi = 0; 1; fieldi++)
{
if (fieldi >= ad->fields.dim)
if (fieldi >= nfields)
{
s->error("is not a per-instance initializable field");
error(loc, "%s.%s is not a per-instance initializable field",
t->toChars(), s->toChars());
errors = 1;
break;
}
if (s == (Dsymbol *)ad->fields.data[fieldi])
@@ -202,7 +210,7 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t)
}
if (s && (v = s->isVarDeclaration()) != NULL)
{
val = val->semantic(sc, v->type);
val = val->semantic(sc, v->type, needInterpret);
value.data[i] = (void *)val;
vars.data[i] = (void *)v;
}
@@ -223,7 +231,7 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t)
fd->endloc = loc;
Expression *e = new FuncExp(loc, fd);
ExpInitializer *ie = new ExpInitializer(loc, e);
return ie->semantic(sc, t);
return ie->semantic(sc, t, needInterpret);
}
else
{
@@ -239,7 +247,6 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t)
return this;
}
/***************************************
* This works by transforming a struct initializer into
* a struct literal. In the future, the two should be the
@@ -257,17 +264,96 @@ Expression *StructInitializer::toExpression()
if (!sd)
return NULL;
Expressions *elements = new Expressions();
size_t nfields = ad->fields.dim;
#if DMDV2
if (sd->isnested)
nfields--;
#endif
elements->setDim(nfields);
for (size_t i = 0; i < elements->dim; i++)
{
elements->data[i] = NULL;
}
unsigned fieldi = 0;
for (size_t i = 0; i < value.dim; i++)
{
if (field.data[i])
Identifier *id = (Identifier *)field.data[i];
if (id)
{
Dsymbol * s = ad->search(loc, id, 0);
if (!s)
{
error(loc, "'%s' is not a member of '%s'", id->toChars(), sd->toChars());
goto Lno;
}
// Find out which field index it is
for (fieldi = 0; 1; fieldi++)
{
if (fieldi >= nfields)
{
s->error("is not a per-instance initializable field");
goto Lno;
}
if (s == (Dsymbol *)ad->fields.data[fieldi])
break;
}
}
else if (fieldi >= nfields)
{ error(loc, "too many initializers for '%s'", ad->toChars());
goto Lno;
}
Initializer *iz = (Initializer *)value.data[i];
if (!iz)
goto Lno;
Expression *ex = iz->toExpression();
if (!ex)
goto Lno;
elements->push(ex);
if (elements->data[fieldi])
{ error(loc, "duplicate initializer for field '%s'",
((Dsymbol *)ad->fields.data[fieldi])->toChars());
goto Lno;
}
elements->data[fieldi] = ex;
++fieldi;
}
// Now, fill in any missing elements with default initializers.
// We also need to validate any anonymous unions
for (size_t i = 0; i < elements->dim; )
{
VarDeclaration * vd = ((Dsymbol *)ad->fields.data[i])->isVarDeclaration();
int unionSize = ad->numFieldsInUnion(i);
if (unionSize == 1)
{ // Not a union -- default initialize if missing
if (!elements->data[i])
elements->data[i] = vd->type->defaultInit();
}
else
{ // anonymous union -- check for errors
int found = -1; // index of the first field with an initializer
for (int j = i; j < i + unionSize; ++j)
{
if (!elements->data[j])
continue;
if (found >= 0)
{
VarDeclaration * v1 = ((Dsymbol *)ad->fields.data[found])->isVarDeclaration();
VarDeclaration * v = ((Dsymbol *)ad->fields.data[j])->isVarDeclaration();
error(loc, "%s cannot have initializers for fields %s and %s in same union",
ad->toChars(),
v1->toChars(), v->toChars());
goto Lno;
}
found = j;
}
if (found == -1)
{
error(loc, "no initializer for union that contains field %s",
vd->toChars());
goto Lno;
}
}
i += unionSize;
}
e = new StructLiteralExp(loc, sd, elements);
e->type = sd->type;
@@ -275,7 +361,6 @@ Expression *StructInitializer::toExpression()
Lno:
delete elements;
//error(loc, "struct initializers as expressions are not allowed");
return NULL;
}
@@ -284,7 +369,7 @@ void StructInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
//printf("StructInitializer::toCBuffer()\n");
buf->writebyte('{');
for (int i = 0; i < field.dim; i++)
for (size_t i = 0; i < field.dim; i++)
{
if (i > 0)
buf->writebyte(',');
@@ -320,7 +405,7 @@ Initializer *ArrayInitializer::syntaxCopy()
assert(index.dim == value.dim);
ai->index.setDim(index.dim);
ai->value.setDim(value.dim);
for (int i = 0; i < ai->value.dim; i++)
for (size_t i = 0; i < ai->value.dim; i++)
{ Expression *e = (Expression *)index.data[i];
if (e)
e = e->syntaxCopy();
@@ -341,7 +426,7 @@ void ArrayInitializer::addInit(Expression *index, Initializer *value)
type = NULL;
}
Initializer *ArrayInitializer::semantic(Scope *sc, Type *t)
Initializer *ArrayInitializer::semantic(Scope *sc, Type *t, int needInterpret)
{ unsigned i;
unsigned length;
const unsigned amax = 0x80000000;
@@ -367,17 +452,17 @@ Initializer *ArrayInitializer::semantic(Scope *sc, Type *t)
length = 0;
for (i = 0; i < index.dim; i++)
{
Expression *idx = (Expression *)index.data[i];
Expression *idx = index[i];
if (idx)
{ idx = idx->semantic(sc);
idx = idx->optimize(WANTvalue | WANTinterpret);
index.data[i] = (void *)idx;
index[i] = idx;
length = idx->toInteger();
}
Initializer *val = (Initializer *)value.data[i];
val = val->semantic(sc, t->nextOf());
value.data[i] = (void *)val;
Initializer *val = value[i];
val = val->semantic(sc, t->nextOf(), needInterpret);
value[i] = val;
length++;
if (length == 0)
{ error(loc, "array dimension overflow");
@@ -412,7 +497,6 @@ Lerr:
Expression *ArrayInitializer::toExpression()
{ Expressions *elements;
Expression *e;
//printf("ArrayInitializer::toExpression(), dim = %d\n", dim);
//static int i; if (++i == 2) halt();
@@ -445,8 +529,8 @@ Expression *ArrayInitializer::toExpression()
edim = value.dim;
for (size_t i = 0, j = 0; i < value.dim; i++, j++)
{
if (index.data[i])
j = ((Expression *)index.data[i])->toInteger();
if (index[i])
j = (index[i])->toInteger();
if (j >= edim)
edim = j + 1;
}
@@ -456,10 +540,10 @@ Expression *ArrayInitializer::toExpression()
elements->setDim(edim);
for (size_t i = 0, j = 0; i < value.dim; i++, j++)
{
if (index.data[i])
j = ((Expression *)index.data[i])->toInteger();
if (index[i])
j = (index[i])->toInteger();
assert(j < edim);
Initializer *iz = (Initializer *)value.data[i];
Initializer *iz = value[i];
if (!iz)
goto Lno;
Expression *ex = iz->toExpression();
@@ -467,7 +551,7 @@ Expression *ArrayInitializer::toExpression()
{
goto Lno;
}
elements->data[j] = ex;
(*elements)[j] = ex;
}
/* Fill in any missing elements with the default initializer
@@ -476,13 +560,13 @@ Expression *ArrayInitializer::toExpression()
Expression *init = NULL;
for (size_t i = 0; i < edim; i++)
{
if (!elements->data[i])
if (!(*elements)[i])
{
if (!type)
goto Lno;
if (!init)
init = t->next->defaultInit();
elements->data[i] = init;
(*elements)[i] = init;
}
}
@@ -502,31 +586,30 @@ Lno:
*/
Initializer *ArrayInitializer::toAssocArrayInitializer()
{ Expressions *keys;
Expressions *values;
{
Expression *e;
//printf("ArrayInitializer::toAssocArrayInitializer()\n");
//static int i; if (++i == 2) halt();
keys = new Expressions();
Expressions *keys = new Expressions();
keys->setDim(value.dim);
values = new Expressions();
Expressions *values = new Expressions();
values->setDim(value.dim);
for (size_t i = 0; i < value.dim; i++)
{
e = (Expression *)index.data[i];
e = index.tdata()[i];
if (!e)
goto Lno;
keys->data[i] = (void *)e;
keys->tdata()[i] = e;
Initializer *iz = (Initializer *)value.data[i];
Initializer *iz = value.tdata()[i];
if (!iz)
goto Lno;
e = iz->toExpression();
if (!e)
goto Lno;
values->data[i] = (void *)e;
values->tdata()[i] = e;
}
e = new AssocArrayLiteralExp(loc, keys, values);
return new ExpInitializer(loc, e);
@@ -578,17 +661,17 @@ Laa:
void ArrayInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writebyte('[');
for (int i = 0; i < index.dim; i++)
for (size_t i = 0; i < index.dim; i++)
{
if (i > 0)
buf->writebyte(',');
Expression *ex = (Expression *)index.data[i];
Expression *ex = index.tdata()[i];
if (ex)
{
ex->toCBuffer(buf, hgs);
buf->writebyte(':');
}
Initializer *iz = (Initializer *)value.data[i];
Initializer *iz = value.tdata()[i];
if (iz)
iz->toCBuffer(buf, hgs);
}
@@ -609,10 +692,19 @@ Initializer *ExpInitializer::syntaxCopy()
return new ExpInitializer(loc, exp->syntaxCopy());
}
Initializer *ExpInitializer::semantic(Scope *sc, Type *t)
Initializer *ExpInitializer::semantic(Scope *sc, Type *t, int needInterpret)
{
//printf("ExpInitializer::semantic(%s), type = %s\n", exp->toChars(), t->toChars());
exp = exp->semantic(sc);
int wantOptimize = needInterpret ? WANTinterpret|WANTvalue : WANTvalue;
int olderrors = global.errors;
exp = exp->optimize(wantOptimize);
if (!global.gag && olderrors != global.errors)
return this; // Failed, suppress duplicate error messages
if (exp->op == TOKtype)
error("initializer must be an expression, not '%s'", exp->toChars());
Type *tb = t->toBasetype();
/* Look for case of initializing a static array with a too-short
@@ -645,7 +737,7 @@ Initializer *ExpInitializer::semantic(Scope *sc, Type *t)
exp = exp->implicitCastTo(sc, t);
L1:
exp = exp->optimize(WANTvalue | WANTinterpret);
exp = exp->optimize(wantOptimize);
//printf("-ExpInitializer::semantic(): "); exp->print();
return this;
}

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2007 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -26,9 +26,8 @@ struct VoidInitializer;
struct StructInitializer;
struct ArrayInitializer;
struct ExpInitializer;
#ifdef _DH
struct HdrGenState;
#endif
#if IN_LLVM
namespace llvm {
@@ -42,7 +41,8 @@ struct Initializer : Object
Initializer(Loc loc);
virtual Initializer *syntaxCopy();
virtual Initializer *semantic(Scope *sc, Type *t);
// needInterpret is WANTinterpret if must be a manifest constant, 0 if not.
virtual Initializer *semantic(Scope *sc, Type *t, int needInterpret);
virtual Type *inferType(Scope *sc);
virtual Expression *toExpression() = 0;
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0;
@@ -66,7 +66,7 @@ struct VoidInitializer : Initializer
VoidInitializer(Loc loc);
Initializer *syntaxCopy();
Initializer *semantic(Scope *sc, Type *t);
Initializer *semantic(Scope *sc, Type *t, int needInterpret);
Expression *toExpression();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -82,13 +82,13 @@ struct StructInitializer : Initializer
Identifiers field; // of Identifier *'s
Initializers value; // parallel array of Initializer *'s
Array vars; // parallel array of VarDeclaration *'s
VarDeclarations vars; // parallel array of VarDeclaration *'s
AggregateDeclaration *ad; // which aggregate this is for
StructInitializer(Loc loc);
Initializer *syntaxCopy();
void addInit(Identifier *field, Initializer *value);
Initializer *semantic(Scope *sc, Type *t);
Initializer *semantic(Scope *sc, Type *t, int needInterpret);
Expression *toExpression();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -113,7 +113,7 @@ struct ArrayInitializer : Initializer
ArrayInitializer(Loc loc);
Initializer *syntaxCopy();
void addInit(Expression *index, Initializer *value);
Initializer *semantic(Scope *sc, Type *t);
Initializer *semantic(Scope *sc, Type *t, int needInterpret);
Type *inferType(Scope *sc);
Expression *toExpression();
Initializer *toAssocArrayInitializer();
@@ -133,7 +133,7 @@ struct ExpInitializer : Initializer
ExpInitializer(Loc loc, Expression *exp);
Initializer *syntaxCopy();
Initializer *semantic(Scope *sc, Type *t);
Initializer *semantic(Scope *sc, Type *t, int needInterpret);
Type *inferType(Scope *sc);
Expression *toExpression();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -54,7 +54,7 @@ int CompoundStatement::inlineCost(InlineCostState *ics)
{ int cost = 0;
for (size_t i = 0; i < statements->dim; i++)
{ Statement *s = (Statement *) statements->data[i];
{ Statement *s = (*statements)[i];
if (s)
{
cost += s->inlineCost(ics);
@@ -69,7 +69,7 @@ int UnrolledLoopStatement::inlineCost(InlineCostState *ics)
{ int cost = 0;
for (size_t i = 0; i < statements->dim; i++)
{ Statement *s = (Statement *) statements->data[i];
{ Statement *s = (*statements)[i];
if (s)
{
cost += s->inlineCost(ics);
@@ -136,13 +136,13 @@ int ReturnStatement::inlineCost(InlineCostState *ics)
/* -------------------------- */
int arrayInlineCost(InlineCostState *ics, Array *arguments)
int arrayInlineCost(InlineCostState *ics, Expressions *arguments)
{ int cost = 0;
if (arguments)
{
for (int i = 0; i < arguments->dim; i++)
{ Expression *e = (Expression *)arguments->data[i];
for (size_t i = 0; i < arguments->dim; i++)
{ Expression *e = (*arguments)[i];
if (e)
cost += e->inlineCost(ics);
@@ -206,6 +206,10 @@ int AssocArrayLiteralExp::inlineCost(InlineCostState *ics)
int StructLiteralExp::inlineCost(InlineCostState *ics)
{
#if DMDV2
if (sd->isnested)
return COST_MAX;
#endif
return 1 + arrayInlineCost(ics, elements);
}
@@ -240,7 +244,7 @@ int DeclarationExp::inlineCost(InlineCostState *ics)
return COST_MAX; // finish DeclarationExp::doInline
#else
for (size_t i = 0; i < td->objects->dim; i++)
{ Object *o = (Object *)td->objects->data[i];
{ Object *o = (*td->objects)[i];
if (o->dyncast() != DYNCAST_EXPRESSION)
return COST_MAX;
Expression *eo = (Expression *)o;
@@ -369,7 +373,7 @@ Expression *CompoundStatement::doInline(InlineDoState *ids)
//printf("CompoundStatement::doInline() %d\n", statements->dim);
for (size_t i = 0; i < statements->dim; i++)
{ Statement *s = (Statement *) statements->data[i];
{ Statement *s = (*statements)[i];
if (s)
{
Expression *e2 = s->doInline(ids);
@@ -401,7 +405,7 @@ Expression *UnrolledLoopStatement::doInline(InlineDoState *ids)
//printf("UnrolledLoopStatement::doInline() %d\n", statements->dim);
for (size_t i = 0; i < statements->dim; i++)
{ Statement *s = (Statement *) statements->data[i];
{ Statement *s = (*statements)[i];
if (s)
{
Expression *e2 = s->doInline(ids);
@@ -473,7 +477,7 @@ Expressions *arrayExpressiondoInline(Expressions *a, InlineDoState *ids)
newa = new Expressions();
newa->setDim(a->dim);
for (int i = 0; i < a->dim; i++)
for (size_t i = 0; i < a->dim; i++)
{ Expression *e = (Expression *)a->data[i];
if (e)
@@ -492,10 +496,8 @@ Expression *Expression::doInline(InlineDoState *ids)
Expression *SymOffExp::doInline(InlineDoState *ids)
{
int i;
//printf("SymOffExp::doInline(%s)\n", toChars());
for (i = 0; i < ids->from.dim; i++)
for (size_t i = 0; i < ids->from.dim; i++)
{
if (var == (Declaration *)ids->from.data[i])
{
@@ -510,10 +512,8 @@ Expression *SymOffExp::doInline(InlineDoState *ids)
Expression *VarExp::doInline(InlineDoState *ids)
{
int i;
//printf("VarExp::doInline(%s)\n", toChars());
for (i = 0; i < ids->from.dim; i++)
for (size_t i = 0; i < ids->from.dim; i++)
{
if (var == (Declaration *)ids->from.data[i])
{
@@ -683,7 +683,7 @@ Expression *IndexExp::doInline(InlineDoState *ids)
ids->from.push(vd);
ids->to.push(vto);
if (vd->init)
if (vd->init && !vd->init->isVoidInitializer())
{
ie = vd->init->isExpInitializer();
assert(ie);
@@ -722,7 +722,7 @@ Expression *SliceExp::doInline(InlineDoState *ids)
ids->from.push(vd);
ids->to.push(vto);
if (vd->init)
if (vd->init && !vd->init->isVoidInitializer())
{
ie = vd->init->isExpInitializer();
assert(ie);
@@ -927,7 +927,7 @@ Statement *SwitchStatement::inlineScan(InlineScanState *iss)
sdefault = (DefaultStatement *)sdefault->inlineScan(iss);
if (cases)
{
for (int i = 0; i < cases->dim; i++)
for (size_t i = 0; i < cases->dim; i++)
{ Statement *s;
s = (Statement *) cases->data[i];
@@ -993,7 +993,7 @@ Statement *TryCatchStatement::inlineScan(InlineScanState *iss)
body = body->inlineScan(iss);
if (catches)
{
for (int i = 0; i < catches->dim; i++)
for (size_t i = 0; i < catches->dim; i++)
{ Catch *c = (Catch *)catches->data[i];
if (c->handler)
@@ -1043,7 +1043,7 @@ void arrayInlineScan(InlineScanState *iss, Array *arguments)
{
if (arguments)
{
for (int i = 0; i < arguments->dim; i++)
for (size_t i = 0; i < arguments->dim; i++)
{ Expression *e = (Expression *)arguments->data[i];
if (e)
@@ -1380,7 +1380,7 @@ int FuncDeclaration::canInline(int hasthis, int hdrscan)
*/
if (parameters)
{
for (int i = 0; i < parameters->dim; i++)
for (size_t i = 0; i < parameters->dim; i++)
{
VarDeclaration *v = (VarDeclaration *)parameters->data[i];
if (/*v->isOut() || v->isRef() ||*/ v->type->toBasetype()->ty == Tsarray)
@@ -1406,7 +1406,6 @@ int FuncDeclaration::canInline(int hasthis, int hdrscan)
inlineScan();
#endif
Lyes:
if (!hdrscan) // Don't modify inlineStatus for header content scan
inlineStatus = ILSyes;
#if CANINLINE_LOG
@@ -1497,7 +1496,7 @@ Expression *FuncDeclaration::doInline(InlineScanState *iss, Expression *ethis, A
{
assert(parameters->dim == arguments->dim);
for (int i = 0; i < arguments->dim; i++)
for (size_t i = 0; i < arguments->dim; i++)
{
VarDeclaration *vfrom = (VarDeclaration *)parameters->data[i];
VarDeclaration *vto;
@@ -1541,6 +1540,7 @@ Expression *FuncDeclaration::doInline(InlineScanState *iss, Expression *ethis, A
//eb->type->print();
//eb->print();
//eb->dump(0);
e = Expression::combine(e, eb);
/* There's a problem if what the function returns is used subsequently as an

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -43,15 +43,17 @@ const char Pline[] = "line";
const char Ptype[] = "type";
const char Pcomment[] = "comment";
const char Pmembers[] = "members";
const char Pprotection[] = "protection";
const char* Pprotectionnames[] = {NULL, "none", "private", "package", "protected", "public", "export"};
void JsonRemoveComma(OutBuffer *buf);
void json_generate(Array *modules)
void json_generate(Modules *modules)
{ OutBuffer buf;
buf.writestring("[\n");
for (int i = 0; i < modules->dim; i++)
{ Module *m = (Module *)modules->data[i];
for (size_t i = 0; i < modules->dim; i++)
{ Module *m = modules->tdata()[i];
if (global.params.verbose)
printf("json gen %s\n", m->toChars());
m->toJsonBuffer(&buf);
@@ -64,7 +66,7 @@ void json_generate(Array *modules)
char *arg = global.params.xfilename;
if (!arg || !*arg)
{ // Generate lib file name from first obj name
char *n = (char *)global.params.objfiles->data[0];
char *n = global.params.objfiles->tdata()[0];
n = FileName::name(n);
FileName *fn = FileName::forceExt(n, global.json_ext);
@@ -192,8 +194,8 @@ void Module::toJsonBuffer(OutBuffer *buf)
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
if (offset != buf->offset)
{ buf->writestring(",\n");
offset = buf->offset;
@@ -211,13 +213,13 @@ void AttribDeclaration::toJsonBuffer(OutBuffer *buf)
{
//printf("AttribDeclaration::toJsonBuffer()\n");
Array *d = include(NULL, NULL);
Dsymbols *d = include(NULL, NULL);
if (d)
{
size_t offset = buf->offset;
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
//printf("AttribDeclaration::toJsonBuffer %s\n", s->toChars());
if (offset != buf->offset)
{ buf->writestring(",\n");
@@ -259,6 +261,10 @@ void Declaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);
if (type)
JsonProperty(buf, Ptype, type->toChars());
@@ -285,8 +291,13 @@ void AggregateDeclaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);
if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);
if (loc.linnum)
JsonProperty(buf, Pline, loc.linnum);
@@ -302,7 +313,7 @@ void AggregateDeclaration::toJsonBuffer(OutBuffer *buf)
JsonString(buf, "interfaces");
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < cd->interfaces_dim; i++)
for (size_t i = 0; i < cd->interfaces_dim; i++)
{ BaseClass *b = cd->interfaces[i];
if (offset != buf->offset)
{ buf->writestring(",\n");
@@ -320,8 +331,8 @@ void AggregateDeclaration::toJsonBuffer(OutBuffer *buf)
JsonString(buf, Pmembers);
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
if (offset != buf->offset)
{ buf->writestring(",\n");
offset = buf->offset;
@@ -344,6 +355,10 @@ void TemplateDeclaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);
if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);
@@ -353,8 +368,8 @@ void TemplateDeclaration::toJsonBuffer(OutBuffer *buf)
JsonString(buf, Pmembers);
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
if (offset != buf->offset)
{ buf->writestring(",\n");
offset = buf->offset;
@@ -374,9 +389,9 @@ void EnumDeclaration::toJsonBuffer(OutBuffer *buf)
{
if (members)
{
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
Dsymbol *s = members->tdata()[i];
s->toJsonBuffer(buf);
buf->writestring(",\n");
}
@@ -389,6 +404,10 @@ void EnumDeclaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);
if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);
@@ -403,8 +422,8 @@ void EnumDeclaration::toJsonBuffer(OutBuffer *buf)
JsonString(buf, Pmembers);
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
if (offset != buf->offset)
{ buf->writestring(",\n");
offset = buf->offset;
@@ -427,6 +446,9 @@ void EnumMember::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);
if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);

View File

@@ -16,9 +16,9 @@
#pragma once
#endif /* __DMC__ */
struct Array;
#include "arraytypes.h"
void json_generate(Array *);
void json_generate(Modules *);
#endif /* DMD_JSON_H */

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -106,7 +106,7 @@ void Token::print()
const char *Token::toChars()
{ const char *p;
static char buffer[3 + 3 * sizeof(value) + 1];
static char buffer[3 + 3 * sizeof(float80value) + 1];
p = buffer;
switch (value)
@@ -302,29 +302,22 @@ Lexer::Lexer(Module *mod,
void Lexer::error(const char *format, ...)
{
if (mod && !global.gag)
{
char *p = loc.toChars();
if (*p)
fprintf(stdmsg, "%s: ", p);
mem.free(p);
va_list ap;
va_start(ap, format);
vfprintf(stdmsg, format, ap);
verror(loc, format, ap);
va_end(ap);
fprintf(stdmsg, "\n");
fflush(stdmsg);
if (global.errors >= 20) // moderate blizzard of cascading messages
fatal();
}
global.errors++;
}
void Lexer::error(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verror(loc, format, ap);
va_end(ap);
}
void Lexer::verror(Loc loc, const char *format, va_list ap)
{
if (mod && !global.gag)
{
char *p = loc.toChars();
@@ -332,10 +325,7 @@ void Lexer::error(Loc loc, const char *format, ...)
fprintf(stdmsg, "%s: ", p);
mem.free(p);
va_list ap;
va_start(ap, format);
vfprintf(stdmsg, format, ap);
va_end(ap);
fprintf(stdmsg, "\n");
fflush(stdmsg);
@@ -343,6 +333,10 @@ void Lexer::error(Loc loc, const char *format, ...)
if (global.errors >= 20) // moderate blizzard of cascading messages
fatal();
}
else
{
global.gaggedErrors++;
}
global.errors++;
}
@@ -732,7 +726,6 @@ void Lexer::scan(Token *t)
t->ustring = (unsigned char *)timestamp;
Lstr:
t->value = TOKstring;
Llen:
t->postfix = 0;
t->len = strlen((char *)t->ustring);
}
@@ -743,7 +736,7 @@ void Lexer::scan(Token *t)
for (const char *p = global.version + 1; 1; p++)
{
char c = *p;
if (isdigit(c))
if (isdigit((unsigned char)c))
minor = minor * 10 + c - '0';
else if (c == '.')
{ major = minor;
@@ -1985,7 +1978,6 @@ TOK Lexer::number(Token *t)
};
enum FLAGS flags = FLAGS_decimal;
int i;
int base;
unsigned c;
unsigned char *start;
@@ -2230,7 +2222,7 @@ done:
p += 2, r = 16;
else if (p[1] == 'b' || p[1] == 'B')
p += 2, r = 2;
else if (isdigit(p[1]))
else if (isdigit((unsigned char)p[1]))
p += 1, r = 8;
}
@@ -2265,6 +2257,7 @@ done:
}
// Parse trailing 'u', 'U', 'l' or 'L' in any combination
const unsigned char *psuffix = p;
while (1)
{ unsigned char f;
@@ -2291,6 +2284,12 @@ done:
break;
}
#if DMDV2
if (state == STATE_octal && n >= 8 && !global.params.useDeprecated)
error("octal literals 0%llo%.*s are deprecated, use std.conv.octal!%llo%.*s instead",
n, p - psuffix, psuffix, n, p - psuffix, psuffix);
#endif
switch (flags)
{
case 0:
@@ -2571,7 +2570,10 @@ void Lexer::pragma()
scan(&tok);
if (tok.value == TOKint32v || tok.value == TOKint64v)
linnum = tok.uns64value - 1;
{ linnum = tok.uns64value - 1;
if (linnum != tok.uns64value - 1)
error("line number out of range");
}
else
goto Lerr;
@@ -3038,6 +3040,8 @@ void Lexer::initKeywords()
enum TOK v;
unsigned nkeywords = sizeof(keywords) / sizeof(keywords[0]);
stringtable.init();
if (global.params.Dversion == 1)
nkeywords -= 2;

View File

@@ -210,7 +210,6 @@ enum TOK
case TOKcomplex32: t = Type::tcomplex32; goto LabelX; \
case TOKcomplex64: t = Type::tcomplex64; goto LabelX; \
case TOKcomplex80: t = Type::tcomplex80; goto LabelX; \
case TOKbit: t = Type::tbit; goto LabelX; \
case TOKbool: t = Type::tbool; goto LabelX; \
case TOKchar: t = Type::tchar; goto LabelX; \
case TOKwchar: t = Type::twchar; goto LabelX; \
@@ -305,6 +304,7 @@ struct Lexer
TOK inreal(Token *t);
void error(const char *format, ...) IS_PRINTF(2);
void error(Loc loc, const char *format, ...) IS_PRINTF(3);
void verror(Loc loc, const char *format, va_list ap);
void pragma();
unsigned decodeUTF();
void getDocComment(Token *t, unsigned lineComment);

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2006 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -19,8 +19,9 @@
#include "root.h"
class Macro
struct Macro
{
private:
Macro *next; // next in list
unsigned char *name; // macro name

View File

@@ -24,7 +24,7 @@
#include "id.h"
#include "module.h"
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
char *cpp_mangle(Dsymbol *s);
#endif
@@ -34,7 +34,7 @@ char *mangle(Declaration *sthis)
char *id;
Dsymbol *s;
//printf("::mangle(%s)\n", sthis->toChars());
//printf("::mangle(%s), type %s\n", sthis->toChars(), sthis->type->toChars());
s = sthis;
do
{
@@ -122,7 +122,7 @@ char *Declaration::mangle()
return ident->toChars();
case LINKcpp:
#if DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS)
#if DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS)
return cpp_mangle(this);
#else
// Windows C++ mangling is done by C++ back end

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -36,6 +36,21 @@
#include "lexer.h"
#include "json.h"
#if WINDOWS_SEH
#include <windows.h>
long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep);
#endif
int response_expand(int *pargc, char ***pargv);
void browse(const char *url);
void getenv_setargv(const char *envvar, int *pargc, char** *pargv);
void obj_start(char *srcfile);
void obj_end(Library *library, File *objfile);
void printCtfePerformanceStats();
Global global;
Global::Global()
@@ -57,9 +72,9 @@ Global::Global()
obj_ext_alt = "obj";
#endif
copyright = "Copyright (c) 1999-2010 by Digital Mars and Tomas Lindquist Olsen";
copyright = "Copyright (c) 1999-2011 by Digital Mars and Tomas Lindquist Olsen";
written = "written by Walter Bright and Tomas Lindquist Olsen";
version = "v1.067";
version = "v1.072";
ldc_version = "LDC trunk";
llvm_version = "LLVM 3.0";
global.structalign = 8;
@@ -72,6 +87,24 @@ Global::Global()
// may run before this one.
}
unsigned Global::startGagging()
{
++gag;
return gaggedErrors;
}
bool Global::endGagging(unsigned oldGagged)
{
bool anyErrs = (gaggedErrors != oldGagged);
--gag;
// Restore the original state of gagged errors; set total errors
// to be original errors + new ungagged errors.
errors -= (gaggedErrors - oldGagged);
gaggedErrors = oldGagged;
return anyErrs;
}
char *Loc::toChars() const
{
OutBuffer buf;
@@ -132,6 +165,11 @@ void verror(Loc loc, const char *format, va_list ap)
vfprintf(stdmsg, format, ap);
fprintf(stdmsg, "\n");
fflush(stdmsg);
//halt();
}
else
{
global.gaggedErrors++;
}
global.errors++;
}
@@ -187,7 +225,6 @@ void halt()
#endif
}
/***********************************
* Parse and append contents of environment variable envvar
* to argc and argv[].
@@ -209,11 +246,11 @@ void getenv_setargv(const char *envvar, int *pargc, char** *pargv)
env = mem.strdup(env); // create our own writable copy
int argc = *pargc;
Array *argv = new Array();
Strings *argv = new Strings();
argv->setDim(argc);
int argc_left = 0;
for (int i = 0; i < argc; i++) {
size_t argc_left = 0;
for (size_t i = 0; i < argc; i++) {
if (!strcmp((*pargv)[i], "-run") || !strcmp((*pargv)[i], "--run")) {
// HACK: set flag to indicate we saw '-run' here
global.params.run = true;
@@ -231,7 +268,7 @@ void getenv_setargv(const char *envvar, int *pargc, char** *pargv)
argv->push((char*)"");
argc++;
int j = 1; // leave argv[0] alone
size_t j = 1; // leave argv[0] alone
while (1)
{
int wildcard = 1; // do wildcard expansion
@@ -310,5 +347,5 @@ Ldone:
argv->data[argc++] = (void *)(*pargv)[i];
*pargc = argc;
*pargv = (char **)argv->data;
*pargv = argv->tdata();
}

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -29,6 +29,7 @@ Macros defined by the compiler, not the code:
__DMC__ Digital Mars compiler
_MSC_VER Microsoft compiler
__GNUC__ Gnu compiler
__clang__ Clang compiler
Host operating system:
_WIN32 Microsoft NT, Windows 95, Windows 98, Win32s,
@@ -37,6 +38,7 @@ Macros defined by the compiler, not the code:
linux Linux
__APPLE__ Mac OSX
__FreeBSD__ FreeBSD
__OpenBSD__ OpenBSD
__sun&&__SVR4 Solaris, OpenSolaris (yes, both macros are necessary)
For the target systems, there are the target operating system and
@@ -47,6 +49,7 @@ the target object file format:
TARGET_LINUX Covers 32 and 64 bit linux
TARGET_OSX Covers 32 and 64 bit Mac OSX
TARGET_FREEBSD Covers 32 and 64 bit FreeBSD
TARGET_OPENBSD Covers 32 and 64 bit OpenBSD
TARGET_SOLARIS Covers 32 and 64 bit Solaris
TARGET_NET Covers .Net
@@ -55,7 +58,7 @@ the target object file format:
Target object module format:
OMFOBJ Intel Object Module Format, used on Windows
ELFOBJ Elf Object Module Format, used on linux, FreeBSD and Solaris
ELFOBJ Elf Object Module Format, used on linux, FreeBSD, OpenBSD and Solaris
MACHOBJ Mach-O Object Module Format, used on Mac OSX
There are currently no macros for byte endianness order.
@@ -81,12 +84,20 @@ the target object file format:
#ifndef IS_PRINTF
# ifdef __GNUC__
# define IS_PRINTF(FMTARG) __attribute((__format__ (__printf__, (FMTARG), (FMTARG)+1) ))
# define IS_PRINTF(FMTARG) __attribute__((__format__ (__printf__, (FMTARG), (FMTARG)+1) ))
# else
# define IS_PRINTF(FMTARG)
# endif
#endif
#ifndef IS_VPRINTF
# ifdef __GNUC__
# define IS_VPRINTF(FMTARG) __attribute__((__format__ (__printf__, (FMTARG), 0) ))
# else
# define IS_VPRINTF(FMTARG)
# endif
#endif
#ifdef IN_GCC
/* Changes for the GDC compiler by David Friedman */
#endif
@@ -99,19 +110,23 @@ the target object file format:
#define MODULEINFO_IS_STRUCT DMDV2 // if ModuleInfo is a struct rather than a class
// Set if C++ mangling is done by the front end
#define CPP_MANGLE (DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS))
#define CPP_MANGLE (DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS))
/* Other targets are TARGET_LINUX, TARGET_OSX, TARGET_FREEBSD and
/* Other targets are TARGET_LINUX, TARGET_OSX, TARGET_FREEBSD, TARGET_OPENBSD and
* TARGET_SOLARIS, which are
* set on the command line via the compiler makefile.
*/
#if _WIN32
#ifndef TARGET_WINDOS
#define TARGET_WINDOS 1 // Windows dmd generates Windows targets
#define OMFOBJ 1
#endif
#ifndef OMFOBJ
#define OMFOBJ TARGET_WINDOS
#endif
#endif
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
#ifndef ELFOBJ
#define ELFOBJ 1
#endif
@@ -124,7 +139,6 @@ the target object file format:
#endif
struct Array;
struct OutBuffer;
// LDC
@@ -158,6 +172,11 @@ enum OS
typedef unsigned char ubyte;
// Can't include arraytypes.h here, need to declare these directly.
template <typename TYPE> struct ArrayBase;
//typedef ArrayBase<struct Identifier> Identifiers;
typedef ArrayBase<char> Strings;
// Put command line switches in here
struct Param
{
@@ -171,6 +190,7 @@ struct Param
char optimizeLevel; // optimization level
#endif
char vtls; // identify thread local variables
// KN Start merge conflict
ARCH cpu; // target CPU
OS os; // target OS
bool is64bit; // generate 64 bit code
@@ -186,20 +206,51 @@ struct Param
bool useInline; // inline expand functions
ubyte warnings; // enable warnings
ubyte Dversion; // D version number
// KN End merge conflict
#if 0
char symdebug; // insert debug symbolic information
char alwaysframe; // always emit standard stack frame
char optimize; // run optimizer
char map; // generate linker .map file
char cpu; // target CPU
char is64bit; // generate 64 bit code
char isLinux; // generate code for linux
char isOSX; // generate code for Mac OSX
char isWindows; // generate code for Windows
char isFreeBSD; // generate code for FreeBSD
char isOPenBSD; // generate code for OpenBSD
char isSolaris; // generate code for Solaris
char scheduler; // which scheduler to use
char useDeprecated; // allow use of deprecated features
char useAssert; // generate runtime code for assert()'s
char useInvariants; // generate class invariant checks
char useIn; // generate precondition checks
char useOut; // generate postcondition checks
char useArrayBounds; // 0: no array bounds checks
// 1: array bounds checks for safe functions only
// 2: array bounds checks for all functions
char noboundscheck; // no array bounds checking at all
char useSwitchError; // check for switches without a default
char useUnitTests; // generate unittest code
char useInline; // inline expand functions
char release; // build release version
char preservePaths; // !=0 means don't strip path from source file
char warnings; // 0: enable warnings
#endif
// 1: warnings as errors
// 2: informational warnings (no errors)
char safe; // enforce safe memory model
char *argv0; // program name
Array *imppath; // array of char*'s of where to look for import modules
Array *fileImppath; // array of char*'s of where to look for file import modules
char *objdir; // .obj file output directory
Strings *imppath; // array of char*'s of where to look for import modules
Strings *fileImppath; // array of char*'s of where to look for file import modules
char *objdir; // .obj/.lib file output directory
char *objname; // .obj file output name
bool doDocComments; // process embedded documentation comments
char *docdir; // write documentation file to docdir directory
char *docname; // write documentation file to docname
Array *ddocfiles; // macro include files for Ddoc
Strings *ddocfiles; // macro include files for Ddoc
bool doHdrGeneration; // process embedded documentation comments
char *hdrdir; // write 'header' file to docdir directory
@@ -209,15 +260,15 @@ struct Param
char *xfilename; // write JSON file to xfilename
unsigned debuglevel; // debug level
Array *debugids; // debug identifiers
Strings *debugids; // debug identifiers
unsigned versionlevel; // version level
Array *versionids; // version identifiers
Strings *versionids; // version identifiers
bool dump_source;
Array *defaultlibnames; // default libraries for non-debug builds
Array *debuglibnames; // default libraries for debug builds
Strings *defaultlibnames; // default libraries for non-debug builds
Strings *debuglibnames; // default libraries for debug builds
char *moduleDepsFile; // filename for deps output
OutBuffer *moduleDeps; // contents to be written to deps file
@@ -235,9 +286,9 @@ struct Param
bool run; // run resulting executable
// Linker stuff
Array *objfiles;
Array *linkswitches;
Array *libfiles;
Strings *objfiles;
Strings *linkswitches;
Strings *libfiles;
char *deffile;
char *resfile;
char *exefile;
@@ -281,8 +332,8 @@ struct Global
const char *map_ext; // for .map files
const char *copyright;
const char *written;
Array *path; // Array of char*'s which form the import lookup path
Array *filePath; // Array of char*'s which form the file import lookup path
Strings *path; // Array of char*'s which form the import lookup path
Strings *filePath; // Array of char*'s which form the file import lookup path
int structalign;
const char *version;
char *ldc_version;
@@ -292,6 +343,15 @@ struct Global
unsigned errors; // number of errors reported so far
unsigned warnings; // number of warnings reported so far
unsigned gag; // !=0 means gag reporting of errors & warnings
unsigned gaggedErrors; // number of errors reported while gagged
// Start gagging. Return the current number of gagged errors
unsigned startGagging();
/* End gagging, restoring the old gagged state.
* Return true if errors occured while gagged.
*/
bool endGagging(unsigned oldGagged);
Global();
};

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -64,9 +64,9 @@ ClassDeclaration *Module::moduleinfo;
Module *Module::rootModule;
DsymbolTable *Module::modules;
Array Module::amodules;
Modules Module::amodules;
Array Module::deferred; // deferred Dsymbol's needing semantic() run on them
Dsymbols Module::deferred; // deferred Dsymbol's needing semantic() run on them
unsigned Module::dprogress;
void Module::init()
@@ -78,6 +78,8 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
: Package(ident)
{
FileName *srcfilename;
FileName *objfilename;
FileName *symfilename;
// printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars());
this->arg = filename;
@@ -301,7 +303,7 @@ const char *Module::kind()
return "module";
}
Module *Module::load(Loc loc, Array *packages, Identifier *ident)
Module *Module::load(Loc loc, Identifiers *packages, Identifier *ident)
{ Module *m;
char *filename;
@@ -315,10 +317,9 @@ Module *Module::load(Loc loc, Array *packages, Identifier *ident)
if (packages && packages->dim)
{
OutBuffer buf;
int i;
for (i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = packages->tdata()[i];
buf.writestring(pid->toChars());
#if _WIN32
@@ -355,7 +356,7 @@ Module *Module::load(Loc loc, Array *packages, Identifier *ident)
{
for (size_t i = 0; i < global.path->dim; i++)
{
char *p = (char *)global.path->data[i];
char *p = (*global.path)[i];
char *n = FileName::combine(p, sdi);
if (FileName::exists(n))
{ result = n;
@@ -379,7 +380,7 @@ Module *Module::load(Loc loc, Array *packages, Identifier *ident)
if (packages)
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
{ Identifier *pid = packages->tdata()[i];
printf("%s.", pid->toChars());
}
}
@@ -406,10 +407,10 @@ void Module::read(Loc loc)
*/
if (global.path)
{
for (int i = 0; i < global.path->dim; i++)
for (size_t i = 0; i < global.path->dim; i++)
{
char *p = (char *)global.path->data[i];
fprintf(stdmsg, "import path[%d] = %s\n", i, p);
char *p = global.path->tdata()[i];
fprintf(stdmsg, "import path[%zd] = %s\n", i, p);
}
}
else
@@ -421,7 +422,7 @@ void Module::read(Loc loc)
inline unsigned readwordLE(unsigned short *p)
{
#if __I86__
#if LITTLE_ENDIAN
return *p;
#else
return (((unsigned char *)p)[1] << 8) | ((unsigned char *)p)[0];
@@ -435,7 +436,7 @@ inline unsigned readwordBE(unsigned short *p)
inline unsigned readlongLE(unsigned *p)
{
#if __I86__
#if LITTLE_ENDIAN
return *p;
#else
return ((unsigned char *)p)[0] |
@@ -671,6 +672,11 @@ void Module::parse()
#endif
p.nextToken();
members = p.parseModule();
::free(srcfile->buffer);
srcfile->buffer = NULL;
srcfile->len = 0;
md = p.md;
numlines = p.loc.linnum;
@@ -730,7 +736,7 @@ void Module::importAll(Scope *prevsc)
// Add import of "object" if this module isn't "object"
if (ident != Id::object)
{
if (members->dim == 0 || ((Dsymbol *)members->data[0])->ident != Id::object)
if (members->dim == 0 || ((*members)[0])->ident != Id::object)
{
Import *im = new Import(0, NULL, Id::object, NULL, 0);
members->shift(im);
@@ -741,9 +747,9 @@ void Module::importAll(Scope *prevsc)
{
// Add all symbols into module's symbol table
symtab = new DsymbolTable();
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
Dsymbol *s = members->tdata()[i];
s->addMember(NULL, sc->scopesym, 1);
}
}
@@ -755,14 +761,14 @@ void Module::importAll(Scope *prevsc)
* before any semantic() on any of them.
*/
setScope(sc); // remember module scope for semantic
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
s->setScope(sc);
}
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
Dsymbol *s = members->tdata()[i];
s->importAll(sc);
}
@@ -770,7 +776,7 @@ void Module::importAll(Scope *prevsc)
sc->pop(); // 2 pops because Scope::createGlobal() created 2
}
void Module::semantic(Scope *unused_sc)
void Module::semantic()
{
if (semanticstarted)
return;
@@ -799,7 +805,7 @@ void Module::semantic(Scope *unused_sc)
// Add all symbols into module's symbol table
symtab = new DsymbolTable();
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->addMember(NULL, sc->scopesym, 1);
}
@@ -809,23 +815,23 @@ void Module::semantic(Scope *unused_sc)
* If this works out well, it can be extended to all modules
* before any semantic() on any of them.
*/
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->setScope(sc);
}
#endif
// Do semantic() on members that don't depend on others
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
//printf("\tModule('%s'): '%s'.semantic0()\n", toChars(), s->toChars());
s->semantic0(sc);
}
// Pass 1 semantic routines: do public side of the definition
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
//printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars());
s->semantic(sc);
@@ -840,14 +846,13 @@ void Module::semantic(Scope *unused_sc)
//printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
}
void Module::semantic2(Scope* unused_sc)
{ int i;
void Module::semantic2()
{
if (deferred.dim)
{
for (int i = 0; i < deferred.dim; i++)
for (size_t i = 0; i < deferred.dim; i++)
{
Dsymbol *sd = (Dsymbol *)deferred.data[i];
Dsymbol *sd = deferred.tdata()[i];
sd->error("unable to resolve forward reference in definition");
}
@@ -866,10 +871,10 @@ void Module::semantic2(Scope* unused_sc)
//printf("Module = %p\n", sc.scopesym);
// Pass 2 semantic routines: do initializers and function bodies
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s;
s = (Dsymbol *)members->data[i];
s = members->tdata()[i];
s->semantic2(sc);
}
@@ -879,9 +884,8 @@ void Module::semantic2(Scope* unused_sc)
//printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent);
}
void Module::semantic3(Scope* unused_sc)
{ int i;
void Module::semantic3()
{
//printf("Module::semantic3('%s'): parent = %p\n", toChars(), parent);
if (semanticstarted >= 3)
return;
@@ -895,10 +899,10 @@ void Module::semantic3(Scope* unused_sc)
//printf("Module = %p\n", sc.scopesym);
// Pass 3 semantic routines: do initializers and function bodies
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s;
s = (Dsymbol *)members->data[i];
s = members->tdata()[i];
//printf("Module %s: %s.semantic3()\n", toChars(), s->toChars());
s->semantic3(sc);
}
@@ -920,8 +924,8 @@ void Module::inlineScan()
// gets imported, it is unaffected by context.
//printf("Module = %p\n", sc.scopesym);
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
//if (global.params.verbose)
//printf("inline scan symbol %s\n", s->toChars());
@@ -945,8 +949,8 @@ void Module::gensymfile()
buf.printf("// Sym file generated from '%s'", srcfile->toChars());
buf.writenl();
for (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = members->tdata()[i];
s->toCBuffer(&buf, &hgs);
}
@@ -1006,8 +1010,8 @@ Dsymbol *Module::symtabInsert(Dsymbol *s)
void Module::clearCache()
{
for (int i = 0; i < amodules.dim; i++)
{ Module *m = (Module *)amodules.data[i];
for (size_t i = 0; i < amodules.dim; i++)
{ Module *m = amodules.tdata()[i];
m->searchCacheIdent = NULL;
}
}
@@ -1019,9 +1023,9 @@ void Module::clearCache()
void Module::addDeferredSemantic(Dsymbol *s)
{
// Don't add it if it is already there
for (int i = 0; i < deferred.dim; i++)
for (size_t i = 0; i < deferred.dim; i++)
{
Dsymbol *sd = (Dsymbol *)deferred.data[i];
Dsymbol *sd = deferred.tdata()[i];
if (sd == s)
return;
@@ -1066,10 +1070,10 @@ void Module::runDeferredSemantic()
todo = (Dsymbol **)alloca(len * sizeof(Dsymbol *));
assert(todo);
}
memcpy(todo, deferred.data, len * sizeof(Dsymbol *));
memcpy(todo, deferred.tdata(), len * sizeof(Dsymbol *));
deferred.setDim(0);
for (int i = 0; i < len; i++)
for (size_t i = 0; i < len; i++)
{
Dsymbol *s = todo[i];
@@ -1093,13 +1097,13 @@ int Module::imports(Module *m)
//printf("%s Module::imports(%s)\n", toChars(), m->toChars());
int aimports_dim = aimports.dim;
#if 0
for (int i = 0; i < aimports.dim; i++)
for (size_t i = 0; i < aimports.dim; i++)
{ Module *mi = (Module *)aimports.data[i];
printf("\t[%d] %s\n", i, mi->toChars());
}
#endif
for (int i = 0; i < aimports.dim; i++)
{ Module *mi = (Module *)aimports.data[i];
for (size_t i = 0; i < aimports.dim; i++)
{ Module *mi = aimports.tdata()[i];
if (mi == m)
return TRUE;
if (!mi->insearch)
@@ -1122,16 +1126,16 @@ int Module::selfImports()
//printf("Module::selfImports() %s\n", toChars());
if (!selfimports)
{
for (int i = 0; i < amodules.dim; i++)
{ Module *mi = (Module *)amodules.data[i];
for (size_t i = 0; i < amodules.dim; i++)
{ Module *mi = amodules.tdata()[i];
//printf("\t[%d] %s\n", i, mi->toChars());
mi->insearch = 0;
}
selfimports = imports(this) + 1;
for (int i = 0; i < amodules.dim; i++)
{ Module *mi = (Module *)amodules.data[i];
for (size_t i = 0; i < amodules.dim; i++)
{ Module *mi = amodules.tdata()[i];
//printf("\t[%d] %s\n", i, mi->toChars());
mi->insearch = 0;
}
@@ -1142,7 +1146,7 @@ int Module::selfImports()
/* =========================== ModuleDeclaration ===================== */
ModuleDeclaration::ModuleDeclaration(Array *packages, Identifier *id)
ModuleDeclaration::ModuleDeclaration(Identifiers *packages, Identifier *id)
{
this->packages = packages;
this->id = id;
@@ -1151,12 +1155,11 @@ ModuleDeclaration::ModuleDeclaration(Array *packages, Identifier *id)
char *ModuleDeclaration::toChars()
{
OutBuffer buf;
int i;
if (packages && packages->dim)
{
for (i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = packages->tdata()[i];
buf.writestring(pid->toChars());
buf.writeByte('.');
@@ -1181,7 +1184,7 @@ const char *Package::kind()
}
DsymbolTable *Package::resolve(Array *packages, Dsymbol **pparent, Package **ppkg)
DsymbolTable *Package::resolve(Identifiers *packages, Dsymbol **pparent, Package **ppkg)
{
DsymbolTable *dst = Module::modules;
Dsymbol *parent = NULL;
@@ -1191,10 +1194,9 @@ DsymbolTable *Package::resolve(Array *packages, Dsymbol **pparent, Package **ppk
*ppkg = NULL;
if (packages)
{ int i;
for (i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = packages->tdata()[i];
Dsymbol *p;
p = dst->lookup(pid);

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -51,7 +51,7 @@ struct Package : ScopeDsymbol
Package(Identifier *ident);
const char *kind();
static DsymbolTable *resolve(Array *packages, Dsymbol **pparent, Package **ppkg);
static DsymbolTable *resolve(Identifiers *packages, Dsymbol **pparent, Package **ppkg);
Package *isPackage() { return this; }
@@ -62,8 +62,8 @@ struct Module : Package
{
static Module *rootModule;
static DsymbolTable *modules; // symbol table of all modules
static Array amodules; // array of all modules
static Array deferred; // deferred Dsymbol's needing semantic() run on them
static Modules amodules; // array of all modules
static Dsymbols deferred; // deferred Dsymbol's needing semantic() run on them
static unsigned dprogress; // progress resolving the deferred list
static void init();
@@ -104,19 +104,19 @@ struct Module : Package
// i.e. a module that will be taken all the
// way to an object file
Array *decldefs; // top level declarations for this Module
Dsymbols *decldefs; // top level declarations for this Module
Array aimports; // all imported modules
Modules aimports; // all imported modules
ModuleInfoDeclaration *vmoduleinfo;
unsigned debuglevel; // debug level
Array *debugids; // debug identifiers
Array *debugidsNot; // forward referenced debug identifiers
Strings *debugids; // debug identifiers
Strings *debugidsNot; // forward referenced debug identifiers
unsigned versionlevel; // version level
Array *versionids; // version identifiers
Array *versionidsNot; // forward referenced version identifiers
Strings *versionids; // version identifiers
Strings *versionidsNot; // forward referenced version identifiers
Macro *macrotable; // document comment macros
struct Escape *escapetable; // document comment escapes
@@ -129,7 +129,7 @@ struct Module : Package
Module(char *arg, Identifier *ident, int doDocComment, int doHdrGen);
~Module();
static Module *load(Loc loc, Array *packages, Identifier *ident);
static Module *load(Loc loc, Identifiers *packages, Identifier *ident);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toJsonBuffer(OutBuffer *buf);
@@ -143,13 +143,13 @@ struct Module : Package
void parse(); // syntactic parse
#endif
void importAll(Scope *sc);
void semantic(Scope* unused_sc = NULL); // semantic analysis
void semantic2(Scope* unused_sc = NULL); // pass 2 semantic analysis
void semantic3(Scope* unused_sc = NULL); // pass 3 semantic analysis
void semantic(); // semantic analysis
void semantic2(); // pass 2 semantic analysis
void semantic3(); // pass 3 semantic analysis
void inlineScan(); // scan for functions to inline
#ifdef _DH
void setHdrfile(); // set hdrfile member
void genhdrfile(); // generate D import file
#endif
void genobjfile(int multiobj);
// void gensymfile();
void gendocfile();
int needModuleInfo();
@@ -215,10 +215,10 @@ struct Module : Package
struct ModuleDeclaration
{
Identifier *id;
Array *packages; // array of Identifier's representing packages
Identifiers *packages; // array of Identifier's representing packages
bool safe;
ModuleDeclaration(Array *packages, Identifier *id);
ModuleDeclaration(Identifiers *packages, Identifier *id);
char *toChars();
};

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -52,7 +52,6 @@
#include "import.h"
#include "aggregate.h"
#include "hdrgen.h"
#include "doc.h"
#if IN_LLVM
//#include "gen/tollvm.h"
@@ -83,7 +82,7 @@ int PTRSIZE = 4;
int REALSIZE = 16;
int REALPAD = 6;
int REALALIGNSIZE = 16;
#elif TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS
#elif TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
int REALSIZE = 12;
int REALPAD = 2;
int REALALIGNSIZE = 4;
@@ -119,6 +118,7 @@ ClassDeclaration *Type::typeinfodelegate;
ClassDeclaration *Type::typeinfotypelist;
Type *Type::tvoidptr;
Type *Type::tstring;
Type *Type::basic[TMAX];
unsigned char Type::mangleChar[TMAX];
StringTable Type::stringtable;
@@ -189,9 +189,8 @@ void Type::init(Ir* _sir)
#else
void Type::init()
#endif
{ int i;
int j;
{
stringtable.init();
Lexer::initKeywords();
mangleChar[Tarray] = 'A';
@@ -242,9 +241,9 @@ void Type::init()
mangleChar[Tslice] = '@';
mangleChar[Treturn] = '@';
for (i = 0; i < TMAX; i++)
for (size_t i = 0; i < TMAX; i++)
{ if (!mangleChar[i])
fprintf(stdmsg, "ty = %d\n", i);
fprintf(stdmsg, "ty = %zd\n", i);
assert(mangleChar[i]);
}
@@ -257,11 +256,12 @@ void Type::init()
Tbool,
Tascii, Twchar, Tdchar };
for (i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++)
for (size_t i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++)
basic[basetab[i]] = new TypeBasic(basetab[i]);
basic[Terror] = new TypeError();
tvoidptr = tvoid->pointerTo();
tstring = tchar->arrayOf();
// LDC
sir = _sir;
@@ -321,8 +321,22 @@ Type *Type::semantic(Loc loc, Scope *sc)
return merge();
}
Type *Type::trySemantic(Loc loc, Scope *sc)
{
//printf("+trySemantic(%s) %d\n", toChars(), global.errors);
unsigned errors = global.startGagging();
Type *t = semantic(loc, sc);
if (global.endGagging(errors)) // if any errors happened
{
t = NULL;
}
//printf("-trySemantic(%s) %d\n", toChars(), global.errors);
return t;
}
Type *Type::pointerTo()
{
if (ty == Terror)
return this;
if (!pto)
{ Type *t;
@@ -334,6 +348,8 @@ Type *Type::pointerTo()
Type *Type::referenceTo()
{
if (ty == Terror)
return this;
if (!rto)
{ Type *t;
@@ -345,6 +361,8 @@ Type *Type::referenceTo()
Type *Type::arrayOf()
{
if (ty == Terror)
return this;
if (!arrayof)
{ Type *t;
@@ -446,6 +464,7 @@ void Type::toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod)
Type *Type::merge()
{
if (ty == Terror) return this;
//printf("merge(%s)\n", toChars());
Type *t = this;
assert(t);
@@ -664,6 +683,8 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
{
if (ty == Tvoid)
error(loc, "void does not have an initializer");
if (ty == Tfunction)
error(loc, "function does not have an initializer");
e = defaultInit(loc);
}
else if (ident == Id::mangleof)
@@ -1013,12 +1034,6 @@ TypeBasic::TypeBasic(TY ty)
break;
case Tbit: d = Token::toChars(TOKbit);
c = "bit";
flags |= TFLAGSintegral | TFLAGSunsigned;
assert(0);
break;
case Tbool: d = "bool";
c = d;
flags |= TFLAGSintegral | TFLAGSunsigned;
@@ -1104,7 +1119,6 @@ d_uns64 TypeBasic::size(Loc loc)
size = 1;
break;
case Tbit: size = 1; break;
case Tbool: size = 1; break;
case Tascii: size = 1; break;
case Twchar: size = 2; break;
@@ -1120,20 +1134,47 @@ d_uns64 TypeBasic::size(Loc loc)
unsigned TypeBasic::alignsize()
{
#if IN_LLVM
if (ty == Tvoid)
return 1;
return GetTypeAlignment(sir, this);
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
#else
unsigned sz;
switch (ty)
{
case Tfloat80:
case Timaginary80:
case Tcomplex80:
sz = REALALIGNSIZE;
break;
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
case Tint64:
case Tuns64:
sz = global.params.is64bit ? 8 : 4;
break;
case Tfloat64:
case Timaginary64:
sz = global.params.is64bit ? 8 : 4;
break;
case Tcomplex32:
case Tcomplex64:
sz = 4;
break;
case Tcomplex64:
sz = global.params.is64bit ? 8 : 4;
break;
#endif
default:
sz = size(0);
break;
}
return sz;
#endif
}
#if IN_LLVM
@@ -1168,7 +1209,6 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
case Tuns32: ivalue = 0xFFFFFFFFUL; goto Livalue;
case Tint64: ivalue = 0x7FFFFFFFFFFFFFFFLL; goto Livalue;
case Tuns64: ivalue = 0xFFFFFFFFFFFFFFFFULL; goto Livalue;
case Tbit: ivalue = 1; goto Livalue;
case Tbool: ivalue = 1; goto Livalue;
case Tchar: ivalue = 0xFF; goto Livalue;
case Twchar: ivalue = 0xFFFFUL; goto Livalue;
@@ -1197,7 +1237,6 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
case Tuns32: ivalue = 0; goto Livalue;
case Tint64: ivalue = (-9223372036854775807LL-1LL); goto Livalue;
case Tuns64: ivalue = 0; goto Livalue;
case Tbit: ivalue = 0; goto Livalue;
case Tbool: ivalue = 0; goto Livalue;
case Tchar: ivalue = 0; goto Livalue;
case Twchar: ivalue = 0; goto Livalue;
@@ -1378,7 +1417,7 @@ Lfvalue:
cvalue.re = fvalue;
cvalue.im = fvalue;
#endif
//for (int i = 0; i < 20; i++)
//for (size_t i = 0; i < 20; i++)
// printf("%02x ", ((unsigned char *)&cvalue)[i]);
//printf("\n");
e = new ComplexExp(loc, cvalue, this);
@@ -1519,7 +1558,7 @@ int TypeBasic::isZeroInit(Loc loc)
int TypeBasic::isbit()
{
return (ty == Tbit);
return 0;
}
int TypeBasic::isintegral()
@@ -1816,13 +1855,6 @@ d_uns64 TypeSArray::size(Loc loc)
if (!dim)
return Type::size(loc);
sz = dim->toInteger();
if (next->toBasetype()->ty == Tbit) // if array of bits
{
if (sz + 31 < sz)
goto Loverflow;
sz = ((sz + 31) & ~31) / 8; // size in bytes, rounded up to 32 bit dwords
}
else
{ dinteger_t n, n2;
n = next->size();
@@ -1902,7 +1934,7 @@ void TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
sc = sc->pop();
if (d >= td->objects->dim)
{ error(loc, "tuple index %ju exceeds %u", d, td->objects->dim);
{ error(loc, "tuple index %ju exceeds length %u", d, td->objects->dim);
goto Ldefault;
}
Object *o = (Object *)td->objects->data[(size_t)d];
@@ -1974,7 +2006,10 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
if (dim)
{ dinteger_t n, n2;
int errors = global.errors;
dim = semanticLength(sc, tbn, dim);
if (errors != global.errors)
goto Lerror;
dim = dim->optimize(WANTvalue | WANTinterpret);
if (sc && sc->parameterSpecialization && dim->op == TOKvar &&
@@ -1990,6 +2025,9 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
dim = dim->optimize(WANTvalue);
dinteger_t d2 = dim->toInteger();
if (dim->op == TOKerror)
goto Lerror;
if (d1 != d2)
goto Loverflow;
@@ -2014,7 +2052,7 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
{
Loverflow:
error(loc, "index %jd overflow for static array", d1);
dim = new IntegerExp(0, 1, tsize_t);
goto Lerror;
}
}
}
@@ -2028,20 +2066,24 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
if (d >= tt->arguments->dim)
{ error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim);
return Type::terror;
goto Lerror;
}
Parameter *arg = (Parameter *)tt->arguments->data[(size_t)d];
Parameter *arg = tt->arguments->tdata()[(size_t)d];
return arg->type;
}
case Tfunction:
case Tnone:
error(loc, "can't have array of %s", tbn->toChars());
tbn = next = tint32;
break;
goto Lerror;
}
if (tbn->isscope())
error(loc, "cannot have array of scope %s", tbn->toChars());
{ error(loc, "cannot have array of auto %s", tbn->toChars());
goto Lerror;
}
return merge();
Lerror:
return Type::terror;
}
void TypeSArray::toDecoBuffer(OutBuffer *buf, bool mangle)
@@ -2169,6 +2211,17 @@ Expression *TypeSArray::toExpression()
int TypeSArray::hasPointers()
{
/* Don't want to do this, because:
* struct S { T* array[0]; }
* may be a variable length struct.
*/
//if (dim->toInteger() == 0)
//return FALSE;
if (next->ty == Tvoid)
// Arrays of void contain arbitrary data, which may include pointers
return TRUE;
else
return next->hasPointers();
}
@@ -2254,6 +2307,8 @@ Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
return new IntegerExp(se->loc, se->len, Type::tindex);
}
if (e->op == TOKnull)
return new IntegerExp(e->loc, 0, Type::tindex);
e = new ArrayLengthExp(e->loc, e);
e->type = Type::tsize_t;
return e;
@@ -2397,7 +2452,6 @@ Type *TypeAArray::semantic(Loc loc, Scope *sc)
key = key->next->arrayOf();
#endif
break;
case Tbit:
case Tbool:
case Tfunction:
case Tvoid:
@@ -2516,6 +2570,9 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
arguments = new Expressions();
arguments->push(e);
size_t keysize = key->size(e->loc);
if (global.params.is64bit)
keysize = (keysize + 15) & ~15;
else
keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
arguments->push(new IntegerExp(0, keysize, Type::tsize_t));
arguments->push(new IntegerExp(0, next->size(e->loc), Type::tsize_t));
@@ -2706,8 +2763,6 @@ int TypePointer::hasPointers()
TypeReference::TypeReference(Type *t)
: Type(Treference, t)
{
if (t->ty == Tbit)
error(0,"cannot make reference to a bit");
// BUG: what about references to static arrays?
}
@@ -2833,7 +2888,12 @@ int Type::covariant(Type *t)
}
}
else if (t1->parameters != t2->parameters)
{
size_t dim1 = !t1->parameters ? 0 : t1->parameters->dim;
size_t dim2 = !t2->parameters ? 0 : t2->parameters->dim;
if (dim1 || dim2)
goto Ldistinct;
}
// The argument lists match
if (inoutmismatch)
@@ -2841,6 +2901,7 @@ int Type::covariant(Type *t)
if (t1->linkage != t2->linkage)
goto Lnotcovariant;
// Return types
Type *t1n = t1->next;
Type *t2n = t2->next;
@@ -2863,7 +2924,7 @@ int Type::covariant(Type *t)
if (!cd->isBaseInfoComplete())
#endif
{
return 3;
return 3; // forward references
}
}
if (t1n->implicitConvTo(t2n))
@@ -2946,6 +3007,11 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf, bool mangle)
void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
{
toCBufferWithAttributes(buf, ident, hgs, this, NULL);
}
void TypeFunction::toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td)
{
const char *p = NULL;
if (inuse)
@@ -2979,6 +3045,17 @@ void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs
{ buf->writeByte(' ');
buf->writestring(ident->toHChars2());
}
if (td)
{ buf->writeByte('(');
for (size_t i = 0; i < td->origParameters->dim; i++)
{
TemplateParameter *tp = td->origParameters->tdata()[i];
if (i)
buf->writestring(", ");
tp->toCBuffer(buf, hgs);
}
buf->writeByte(')');
}
Parameter::argsToCBuffer(buf, hgs, parameters, varargs);
inuse--;
}
@@ -3038,10 +3115,10 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
if (parameters)
{ tf->parameters = (Parameters *)parameters->copy();
for (size_t i = 0; i < parameters->dim; i++)
{ Parameter *arg = (Parameter *)parameters->data[i];
{ Parameter *arg = parameters->tdata()[i];
Parameter *cpy = (Parameter *)mem.malloc(sizeof(Parameter));
memcpy(cpy, arg, sizeof(Parameter));
tf->parameters->data[i] = (void *)cpy;
tf->parameters->tdata()[i] = cpy;
}
}
@@ -3195,12 +3272,18 @@ int TypeFunction::callMatch(Expressions *args)
goto L1;
goto Nomatch; // not enough arguments
}
arg = (Expression *)args->data[u];
arg = (*args)[u];
assert(arg);
if (p->storageClass & STClazy && p->type->ty == Tvoid && arg->type->ty != Tvoid)
m = MATCHconvert;
else
m = arg->implicitConvTo(p->type);
/* prefer matching the element type rather than the array
* type when more arguments are present with T[]...
*/
if (varargs == 2 && u + 1 == nparams && nargs > nparams)
goto L1;
//printf("\tm = %d\n", m);
if (m == MATCHnomatch) // if no match
{
@@ -3220,7 +3303,7 @@ int TypeFunction::callMatch(Expressions *args)
case Tarray:
for (; u < nargs; u++)
{
arg = (Expression *)args->data[u];
arg = (*args)[u];
assert(arg);
#if 1
/* If lazy array of delegates,
@@ -3292,6 +3375,12 @@ Type *TypeFunction::reliesOnTident()
return next->reliesOnTident();
}
Expression *TypeFunction::defaultInit(Loc loc)
{
error(loc, "function does not have a default initializer");
return new ErrorExp();
}
/***************************** TypeDelegate *****************************/
TypeDelegate::TypeDelegate(Type *t)
@@ -3331,6 +3420,11 @@ unsigned TypeDelegate::alignsize()
{
// A Delegate consists of two ptr values, so align it on pointer size
// boundary
#if DMDV1
// See Bugzilla 942 for discussion
if (!global.params.is64bit)
return PTRSIZE * 2;
#endif
return PTRSIZE;
}
@@ -3408,7 +3502,7 @@ void TypeQualified::syntaxCopyHelper(TypeQualified *t)
{
//printf("TypeQualified::syntaxCopyHelper(%s) %s\n", t->toChars(), toChars());
idents.setDim(t->idents.dim);
for (int i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = (Identifier *)t->idents.data[i];
if (id->dyncast() == DYNCAST_DSYMBOL)
@@ -3430,9 +3524,7 @@ void TypeQualified::addIdent(Identifier *ident)
void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs)
{
int i;
for (i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{ Identifier *id = (Identifier *)idents.data[i];
buf->writeByte('.');
@@ -3465,8 +3557,6 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
Dsymbol *s, Dsymbol *scopesym,
Expression **pe, Type **pt, Dsymbol **ps)
{
Identifier *id = NULL;
int i;
VarDeclaration *v;
EnumMember *em;
TupleDeclaration *td;
@@ -3487,11 +3577,10 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
s->checkDeprecated(loc, sc); // check for deprecated aliases
s = s->toAlias();
//printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
for (i = 0; i < idents.dim; i++)
{ Dsymbol *sm;
id = (Identifier *)idents.data[i];
sm = s->searchX(loc, sc, id);
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Dsymbol *sm = s->searchX(loc, sc, id);
//printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
//printf("getType = '%s'\n", s->getType()->toChars());
if (!sm)
@@ -3509,12 +3598,12 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
goto Lerror;
goto L3;
}
else if (v && id == Id::stringof)
else if (v && (id == Id::stringof || id == Id::offsetof))
{
e = new DsymbolExp(loc, s);
do
{
id = (Identifier *)idents.data[i];
id = idents.tdata()[i];
e = new DotIdExp(loc, e, id);
} while (++i < idents.dim);
e = e->semantic(sc);
@@ -3524,7 +3613,14 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
t = s->getType();
if (!t && s->isDeclaration())
t = s->isDeclaration()->type;
{ t = s->isDeclaration()->type;
if (!t && s->isTupleDeclaration())
{
e = new TupleExp(loc, s->isTupleDeclaration());
e = e->semantic(sc);
t = e->type;
}
}
if (t)
{
sm = t->toDsymbol(sc);
@@ -3540,15 +3636,21 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
L3:
for (; i < idents.dim; i++)
{
id = (Identifier *)idents.data[i];
id = idents.tdata()[i];
//printf("e: '%s', id: '%s', type = %p\n", e->toChars(), id->toChars(), e->type);
e = e->type->dotExp(sc, e, id);
}
if (e->op == TOKtype)
*pt = e->type;
else
*pe = e;
}
else
{
Lerror:
error(loc, "identifier '%s' of '%s' is not defined", id->toChars(), toChars());
*pe = new ErrorExp();
}
return;
}
L2:
@@ -3664,6 +3766,7 @@ L1:
else
error(loc, "undefined identifier %s", p);
}
*pt = Type::terror;
}
}
@@ -3738,7 +3841,7 @@ Dsymbol *TypeIdentifier::toDsymbol(Scope *sc)
Dsymbol *s = sc->search(loc, ident, &scopesym);
if (s)
{
for (int i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = (Identifier *)idents.data[i];
s = s->searchX(loc, sc, id);
@@ -3796,7 +3899,7 @@ Type *TypeIdentifier::reliesOnTident()
Expression *TypeIdentifier::toExpression()
{
Expression *e = new IdentifierExp(loc, ident);
for (int i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = (Identifier *)idents.data[i];
e = new DotIdExp(loc, e, id);
@@ -3870,15 +3973,12 @@ Type *TypeInstance::semantic(Loc loc, Scope *sc)
if (sc->parameterSpecialization)
{
unsigned errors = global.errors;
global.gag++;
unsigned errors = global.startGagging();
resolve(loc, sc, &e, &t, &s);
global.gag--;
if (errors != global.errors)
{ if (global.gag == 0)
global.errors = errors;
if (global.endGagging(errors))
{
return this;
}
}
@@ -3892,7 +3992,7 @@ Type *TypeInstance::semantic(Loc loc, Scope *sc)
printf("2: e:%p s:%p ", e, s);
#endif
error(loc, "%s is used as a type", toChars());
t = tvoid;
t = terror;
}
return t;
}
@@ -3907,18 +4007,13 @@ Dsymbol *TypeInstance::toDsymbol(Scope *sc)
if (sc->parameterSpecialization)
{
unsigned errors = global.errors;
global.gag++;
unsigned errors = global.startGagging();
resolve(loc, sc, &e, &t, &s);
global.gag--;
if (errors != global.errors)
{ if (global.gag == 0)
global.errors = errors;
if (global.endGagging(errors))
return NULL;
}
}
else
resolve(loc, sc, &e, &t, &s);
@@ -4361,7 +4456,10 @@ char *TypeTypedef::toChars()
Type *TypeTypedef::semantic(Loc loc, Scope *sc)
{
//printf("TypeTypedef::semantic(%s), sem = %d\n", toChars(), sym->sem);
int errors = global.errors;
sym->semantic(sc);
if (errors != global.errors)
return terror;
return merge();
}
@@ -4632,8 +4730,7 @@ void TypeStruct::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
}
Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
{ unsigned offset;
{
Expression *b;
VarDeclaration *v;
Dsymbol *s;
@@ -4771,7 +4868,8 @@ L1:
if (e->op == TOKtype)
{ FuncDeclaration *fd = sc->func;
if (d->needThis() && fd && fd->vthis)
if (d->needThis() && fd && fd->vthis &&
fd->toParent2()->isStructDeclaration() == sym)
{
e = new DotVarExp(e->loc, new ThisExp(e->loc), d);
e = e->semantic(sc);
@@ -4794,7 +4892,7 @@ L1:
accessCheck(e->loc, sc, e, d);
ve = new VarExp(e->loc, d);
e = new CommaExp(e->loc, e, ve);
e->type = d->type;
e = e->semantic(sc);
return e;
}
@@ -4853,7 +4951,11 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]);
Expression *e;
if (vd->init)
{ if (vd->init->isVoidInitializer())
e = NULL;
else
e = vd->init->toExpression();
}
else
e = vd->type->defaultInitLiteral();
structelems->data[j] = e;
@@ -4953,9 +5055,7 @@ void TypeClass::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
}
Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
{ unsigned offset;
Expression *b;
{
VarDeclaration *v;
Dsymbol *s;
DotVarExp *de;
@@ -5263,7 +5363,7 @@ L1:
accessCheck(e->loc, sc, e, d);
ve = new VarExp(e->loc, d);
e = new CommaExp(e->loc, e, ve);
e->type = d->type;
e = e->semantic(sc);
return e;
}
@@ -5660,23 +5760,20 @@ char *Parameter::argsTypesToChars(Parameters *args, int varargs)
buf->writeByte('(');
if (args)
{ int i;
OutBuffer argbuf;
{ OutBuffer argbuf;
HdrGenState hgs;
for (i = 0; i < args->dim; i++)
{ Parameter *arg;
if (i)
for (size_t i = 0; i < args->dim; i++)
{ if (i)
buf->writeByte(',');
arg = (Parameter *)args->data[i];
Parameter *arg = (Parameter *)args->data[i];
argbuf.reset();
arg->type->toCBuffer2(&argbuf, &hgs, 0);
buf->write(&argbuf);
}
if (varargs)
{
if (i && varargs == 1)
if (args->dim && varargs == 1)
buf->writeByte(',');
buf->writestring("...");
}
@@ -5690,15 +5787,14 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
{
buf->writeByte('(');
if (arguments)
{ int i;
{
OutBuffer argbuf;
for (i = 0; i < arguments->dim; i++)
{ Parameter *arg;
for (size_t i = 0; i < arguments->dim; i++)
{
if (i)
buf->writestring(", ");
arg = (Parameter *)arguments->data[i];
Parameter *arg = (Parameter *)arguments->data[i];
if (arg->storageClass & STCout)
buf->writestring("out ");
else if (arg->storageClass & STCref)
@@ -5711,18 +5807,13 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
if (arg->defaultArg)
{
argbuf.writestring(" = ");
unsigned o = argbuf.offset;
arg->defaultArg->toCBuffer(&argbuf, hgs);
if(hgs->ddoc)
{
escapeDdocString(&argbuf, o);
}
}
buf->write(&argbuf);
}
if (varargs)
{
if (i && varargs == 1)
if (arguments->dim && varargs == 1)
buf->writeByte(',');
buf->writestring("...");
}
@@ -5730,21 +5821,40 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
buf->writeByte(')');
}
static const int mangleFlag = 0x01;
static int argsToDecoBufferDg(void *ctx, size_t n, Parameter *arg, int flags)
{
arg->toDecoBuffer((OutBuffer *)ctx, flags & mangleFlag);
return 0;
}
void Parameter::argsToDecoBuffer(OutBuffer *buf, Parameters *arguments, bool mangle)
{
//printf("Parameter::argsToDecoBuffer()\n");
// Write argument types
if (arguments)
{
size_t dim = Parameter::dim(arguments);
for (size_t i = 0; i < dim; i++)
{
Parameter *arg = Parameter::getNth(arguments, i);
arg->toDecoBuffer(buf, mangle);
}
}
foreach(arguments, &argsToDecoBufferDg, buf, 0, mangle ? mangleFlag : 0);
}
/****************************************
* Determine if parameter list is really a template parameter list
* (i.e. it has auto or alias parameters)
*/
static int isTPLDg(void *ctx, size_t n, Parameter *arg, int)
{
if (arg->storageClass & (STCalias | STCauto | STCstatic))
return 1;
return 0;
}
int Parameter::isTPL(Parameters *arguments)
{
//printf("Parameter::isTPL()\n");
if (arguments)
return foreach(arguments, &isTPLDg, NULL);
return 0;
}
/****************************************************
@@ -5804,23 +5914,17 @@ void Parameter::toDecoBuffer(OutBuffer *buf, bool mangle)
* Determine number of arguments, folding in tuples.
*/
static int dimDg(void *ctx, size_t n, Parameter *, int)
{
++*(size_t *)ctx;
return 0;
}
size_t Parameter::dim(Parameters *args)
{
size_t n = 0;
if (args)
{
for (size_t i = 0; i < args->dim; i++)
{ Parameter *arg = (Parameter *)args->data[i];
Type *t = arg->type->toBasetype();
if (t->ty == Ttuple)
{ TypeTuple *tu = (TypeTuple *)t;
n += dim(tu->arguments);
}
else
n++;
}
}
foreach(args, &dimDg, &n);
return n;
}
@@ -5832,29 +5936,59 @@ size_t Parameter::dim(Parameters *args)
* of Parameters
*/
struct GetNthParamCtx
{
size_t nth;
Parameter *arg;
};
static int getNthParamDg(void *ctx, size_t n, Parameter *arg, int)
{
GetNthParamCtx *p = (GetNthParamCtx *)ctx;
if (n == p->nth)
{ p->arg = arg;
return 1;
}
return 0;
}
Parameter *Parameter::getNth(Parameters *args, size_t nth, size_t *pn)
{
if (!args)
return NULL;
GetNthParamCtx ctx = { nth, NULL };
int res = foreach(args, &getNthParamDg, &ctx);
return res ? ctx.arg : NULL;
}
size_t n = 0;
/***************************************
* Expands tuples in args in depth first order. Calls
* dg(void *ctx, size_t argidx, Parameter *arg) for each Parameter.
* If dg returns !=0, stops and returns that value else returns 0.
* Use this function to avoid the O(N + N^2/2) complexity of
* calculating dim and calling N times getNth.
*/
int Parameter::foreach(Parameters *args, Parameter::ForeachDg dg, void *ctx, size_t *pn, int flags)
{
assert(args && dg);
size_t n = pn ? *pn : 0; // take over index
int result = 0;
for (size_t i = 0; i < args->dim; i++)
{ Parameter *arg = (Parameter *)args->data[i];
{ Parameter *arg = args->tdata()[i];
Type *t = arg->type->toBasetype();
if (t->ty == Ttuple)
{ TypeTuple *tu = (TypeTuple *)t;
arg = getNth(tu->arguments, nth - n, &n);
if (arg)
return arg;
result = foreach(tu->arguments, dg, ctx, &n, flags);
}
else if (n == nth)
return arg;
else
n++;
result = dg(ctx, n++, arg, flags);
if (result)
break;
}
if (pn)
*pn += n;
return NULL;
*pn = n; // update index
return result;
}

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -170,6 +170,7 @@ struct Type : Object
#define tboolean tbool // result of boolean expression
#define tindex tsize_t // array/ptr index
static Type *tvoidptr; // void*
static Type *tstring; // immutable(char)[]
#define terror basic[Terror] // for error recovery
#define tsize_t basic[Tsize_t] // matches size_t alias
@@ -222,6 +223,7 @@ struct Type : Object
virtual d_uns64 size(Loc loc);
virtual unsigned alignsize();
virtual Type *semantic(Loc loc, Scope *sc);
Type *trySemantic(Loc loc, Scope *sc);
// append the mangleof or a string uniquely identifying this type to buf
virtual void toDecoBuffer(OutBuffer *buf, bool mangle);
Type *merge();
@@ -508,6 +510,7 @@ struct TypeFunction : Type
Type *semantic(Loc loc, Scope *sc);
void toDecoBuffer(OutBuffer *buf, bool mangle);
void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs);
void toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td);
void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
TypeInfoDeclaration *getTypeInfoDeclaration();
@@ -528,6 +531,8 @@ struct TypeFunction : Type
FuncDeclaration* funcdecl;
#endif
Expression *defaultInit(Loc loc);
};
struct TypeDelegate : Type
@@ -553,7 +558,7 @@ struct TypeDelegate : Type
struct TypeQualified : Type
{
Loc loc;
Array idents; // array of Identifier's representing ident.ident.ident etc.
Identifiers idents; // array of Identifier's representing ident.ident.ident etc.
TypeQualified(TY ty, Loc loc);
void syntaxCopyHelper(TypeQualified *t);
@@ -815,6 +820,9 @@ struct Parameter : Object
static int isTPL(Parameters *arguments);
static size_t dim(Parameters *arguments);
static Parameter *getNth(Parameters *arguments, size_t nth, size_t *pn = NULL);
typedef int (*ForeachDg)(void *ctx, size_t paramidx, Parameter *param, int flags);
static int foreach(Parameters *args, ForeachDg dg, void *ctx, size_t *pn=NULL, int flags = 0);
};
extern int PTRSIZE;

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -40,7 +40,7 @@ static real_t zero; // work around DMC bug for now
* return that initializer.
*/
Expression *fromConstInitializer(Expression *e1)
Expression *fromConstInitializer(int result, Expression *e1)
{
//printf("fromConstInitializer(%s)\n", e1->toChars());
if (e1->op == TOKvar)
@@ -48,7 +48,13 @@ Expression *fromConstInitializer(Expression *e1)
VarDeclaration *v = ve->var->isVarDeclaration();
if (v && !v->originalType && v->scope) // semantic() not yet run
v->semantic (v->scope);
if (v && v->isConst() && v->init)
if (!v || !v->type)
return e1;
Type * tb = v->type->toBasetype();
if (v->isConst() && v->init
&& (result & WANTinterpret || (tb->isscalar() ||
((result & WANTexpand) && (tb->ty != Tsarray && tb->ty != Tstruct))))
)
{ Expression *ei = v->init->toExpression();
if (ei && ei->type)
e1 = ei;
@@ -66,10 +72,7 @@ Expression *Expression::optimize(int result)
Expression *VarExp::optimize(int result)
{
if (result & WANTinterpret)
{
return fromConstInitializer(this);
}
return fromConstInitializer(result, this);
return this;
}
@@ -388,7 +391,7 @@ Expression *CastExp::optimize(int result)
e1 = e1->optimize(result);
if (result & WANTinterpret)
e1 = fromConstInitializer(e1);
e1 = fromConstInitializer(result, e1);
if ((e1->op == TOKstring || e1->op == TOKarrayliteral) &&
(type->ty == Tpointer || type->ty == Tarray) &&
@@ -660,7 +663,7 @@ Expression *ArrayLengthExp::optimize(int result)
{ Expression *e;
//printf("ArrayLengthExp::optimize(result = %d) %s\n", result, toChars());
e1 = e1->optimize(WANTvalue | (result & WANTinterpret));
e1 = e1->optimize(WANTvalue | WANTexpand | (result & WANTinterpret));
e = this;
if (e1->op == TOKstring || e1->op == TOKarrayliteral || e1->op == TOKassocarrayliteral)
{
@@ -677,8 +680,8 @@ Expression *EqualExp::optimize(int result)
e2 = e2->optimize(WANTvalue | (result & WANTinterpret));
e = this;
Expression *e1 = fromConstInitializer(this->e1);
Expression *e2 = fromConstInitializer(this->e2);
Expression *e1 = fromConstInitializer(result, this->e1);
Expression *e2 = fromConstInitializer(result, this->e2);
e = Equal(op, type, e1, e2);
if (e == EXP_CANT_INTERPRET)
@@ -703,13 +706,40 @@ Expression *IdentityExp::optimize(int result)
return e;
}
/* It is possible for constant folding to change an array expression of
* unknown length, into one where the length is known.
* If the expression 'arr' is a literal, set lengthVar to be its length.
*/
void setLengthVarIfKnown(VarDeclaration *lengthVar, Expression *arr)
{
if (!lengthVar)
return;
if (lengthVar->init && !lengthVar->init->isVoidInitializer())
return; // we have previously calculated the length
size_t len;
if (arr->op == TOKstring)
len = ((StringExp *)arr)->len;
else if (arr->op == TOKarrayliteral)
len = ((ArrayLiteralExp *)arr)->elements->dim;
else
return; // we don't know the length yet
Expression *dollar = new IntegerExp(0, len, Type::tsize_t);
lengthVar->init = new ExpInitializer(0, dollar);
lengthVar->storage_class |= STCstatic | STCconst;
}
Expression *IndexExp::optimize(int result)
{ Expression *e;
//printf("IndexExp::optimize(result = %d) %s\n", result, toChars());
Expression *e1 = this->e1->optimize(WANTvalue | (result & WANTinterpret));
if (result & WANTinterpret)
e1 = fromConstInitializer(e1);
e1 = fromConstInitializer(result, e1);
// We might know $ now
setLengthVarIfKnown(lengthVar, e1);
e2 = e2->optimize(WANTvalue | (result & WANTinterpret));
e = Index(type, e1, e2);
if (e == EXP_CANT_INTERPRET)
@@ -717,6 +747,7 @@ Expression *IndexExp::optimize(int result)
return e;
}
Expression *SliceExp::optimize(int result)
{ Expression *e;
@@ -733,12 +764,15 @@ Expression *SliceExp::optimize(int result)
return e;
}
if (result & WANTinterpret)
e1 = fromConstInitializer(e1);
e1 = fromConstInitializer(result, e1);
// We might know $ now
setLengthVarIfKnown(lengthVar, e1);
lwr = lwr->optimize(WANTvalue | (result & WANTinterpret));
upr = upr->optimize(WANTvalue | (result & WANTinterpret));
e = Slice(type, e1, lwr, upr);
if (e == EXP_CANT_INTERPRET)
e = this;
//printf("-SliceExp::optimize() %s\n", e->toChars());
return e;
}

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -68,9 +68,9 @@ Parser::Parser(Module *module, unsigned char *base, unsigned length, int doDocCo
//nextToken(); // start up the scanner
}
Array *Parser::parseModule()
Dsymbols *Parser::parseModule()
{
Array *decldefs;
Dsymbols *decldefs;
// ModuleDeclation leads off
if (token.value == TOKmodule)
@@ -103,14 +103,14 @@ Array *Parser::parseModule()
}
else
{
Array *a = NULL;
Identifiers *a = NULL;
Identifier *id;
id = token.ident;
while (nextToken() == TOKdot)
{
if (!a)
a = new Array();
a = new Identifiers();
a->push(id);
nextToken();
if (token.value != TOKidentifier)
@@ -138,21 +138,21 @@ Lerr:
while (token.value != TOKsemicolon && token.value != TOKeof)
nextToken();
nextToken();
return new Array();
return new Dsymbols();
}
Array *Parser::parseDeclDefs(int once)
Dsymbols *Parser::parseDeclDefs(int once)
{ Dsymbol *s;
Array *decldefs;
Array *a;
Array *aelse;
Dsymbols *decldefs;
Dsymbols *a;
Dsymbols *aelse;
enum PROT prot;
StorageClass stc;
Condition *condition;
unsigned char *comment;
//printf("Parser::parseDeclDefs()\n");
decldefs = new Array();
decldefs = new Dsymbols();
do
{
comment = token.blockComment;
@@ -396,10 +396,10 @@ Array *Parser::parseDeclDefs(int once)
if (token.value == TOKlparen)
{
nextToken();
if (token.value == TOKint32v)
if (token.value == TOKint32v && token.uns64value > 0)
n = (unsigned)token.uns64value;
else
{ error("integer expected, not %s", token.toChars());
{ error("positive integer expected, not %s", token.toChars());
n = 1;
}
nextToken();
@@ -445,7 +445,7 @@ Array *Parser::parseDeclDefs(int once)
nextToken();
if (token.value == TOKidentifier)
s = new DebugSymbol(loc, token.ident);
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
s = new DebugSymbol(loc, (unsigned)token.uns64value);
else
{ error("identifier or integer expected, not %s", token.toChars());
@@ -466,7 +466,7 @@ Array *Parser::parseDeclDefs(int once)
nextToken();
if (token.value == TOKidentifier)
s = new VersionSymbol(loc, token.ident);
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
s = new VersionSymbol(loc, (unsigned)token.uns64value);
else
{ error("identifier or integer expected, not %s", token.toChars());
@@ -528,14 +528,43 @@ void Parser::composeStorageClass(StorageClass stc)
}
#endif
/***********************************************
* Parse storage class, lexer is on '@'
*/
#if DMDV2
StorageClass Parser::parseAttribute()
{
nextToken();
StorageClass stc = 0;
if (token.value != TOKidentifier)
{
error("identifier expected after @, not %s", token.toChars());
}
else if (token.ident == Id::property)
stc = STCproperty;
else if (token.ident == Id::safe)
stc = STCsafe;
else if (token.ident == Id::trusted)
stc = STCtrusted;
else if (token.ident == Id::system)
stc = STCsystem;
else if (token.ident == Id::disable)
stc = STCdisable;
else
error("valid attribute identifiers are @property, @safe, @trusted, @system, @disable not @%s", token.toChars());
return stc;
}
#endif
/********************************************
* Parse declarations after an align, protection, or extern decl.
*/
Array *Parser::parseBlock()
Dsymbols *Parser::parseBlock()
{
Array *a = NULL;
Dsymbol *s;
Dsymbols *a = NULL;
//printf("parseBlock()\n");
switch (token.value)
@@ -692,7 +721,7 @@ Condition *Parser::parseDebugCondition()
if (token.value == TOKidentifier)
id = token.ident;
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
level = (unsigned)token.uns64value;
else
error("identifier or integer expected, not %s", token.toChars());
@@ -721,7 +750,7 @@ Condition *Parser::parseVersionCondition()
nextToken();
if (token.value == TOKidentifier)
id = token.ident;
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
level = (unsigned)token.uns64value;
#if DMDV2
/* Allow:
@@ -754,8 +783,6 @@ Condition *Parser::parseVersionCondition()
Condition *Parser::parseStaticIfCondition()
{ Expression *exp;
Condition *condition;
Array *aif;
Array *aelse;
Loc loc = this->loc;
nextToken();
@@ -1110,7 +1137,7 @@ EnumDeclaration *Parser::parseEnum()
else if (token.value == TOKlcurly)
{
//printf("enum definition\n");
e->members = new Array();
e->members = new Dsymbols();
nextToken();
unsigned char *comment = token.blockComment;
while (token.value != TOKrcurly)
@@ -1237,7 +1264,7 @@ Dsymbol *Parser::parseAggregate()
{
//printf("aggregate definition\n");
nextToken();
Array *decl = parseDeclDefs(0);
Dsymbols *decl = parseDeclDefs(0);
if (token.value != TOKrcurly)
error("} expected following member declarations in aggregate");
nextToken();
@@ -1259,7 +1286,7 @@ Dsymbol *Parser::parseAggregate()
if (tpl)
{ // Wrap a template around the aggregate declaration
Array *decldefs = new Array();
Dsymbols *decldefs = new Dsymbols();
decldefs->push(a);
TemplateDeclaration *tempdecl =
new TemplateDeclaration(loc, id, tpl, constraint, decldefs);
@@ -1338,7 +1365,7 @@ TemplateDeclaration *Parser::parseTemplateDeclaration()
TemplateDeclaration *tempdecl;
Identifier *id;
TemplateParameters *tpl;
Array *decldefs;
Dsymbols *decldefs;
Loc loc = this->loc;
nextToken();
@@ -1535,7 +1562,7 @@ Dsymbol *Parser::parseMixin()
Identifier *id;
Type *tqual;
Objects *tiargs;
Array *idents;
Identifiers *idents;
//printf("parseMixin()\n");
nextToken();
@@ -1566,7 +1593,7 @@ Dsymbol *Parser::parseMixin()
nextToken();
}
idents = new Array();
idents = new Identifiers();
while (1)
{
tiargs = NULL;
@@ -1659,7 +1686,7 @@ Import *Parser::parseImport(Array *decldefs, int isstatic)
{ Import *s;
Identifier *id;
Identifier *aliasid = NULL;
Array *a;
Identifiers *a;
Loc loc;
//printf("Parser::parseImport()\n");
@@ -1684,7 +1711,7 @@ Import *Parser::parseImport(Array *decldefs, int isstatic)
while (token.value == TOKdot)
{
if (!a)
a = new Array();
a = new Identifiers();
a->push(id);
nextToken();
if (token.value != TOKidentifier)
@@ -2143,7 +2170,7 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
* Return array of Declaration *'s.
*/
Array *Parser::parseDeclarations()
Dsymbols *Parser::parseDeclarations()
{
StorageClass storage_class;
StorageClass stc;
@@ -2151,7 +2178,7 @@ Array *Parser::parseDeclarations()
Type *t;
Type *tfirst;
Identifier *ident;
Array *a;
Dsymbols *a;
enum TOK tok = TOKreserved;
unsigned char *comment = token.blockComment;
enum LINK link = linkage;
@@ -2213,7 +2240,7 @@ Array *Parser::parseDeclarations()
break;
}
a = new Array();
a = new Dsymbols();
/* Look for auto initializers:
* storage_class identifier = initializer;
@@ -2300,7 +2327,7 @@ Array *Parser::parseDeclarations()
a->push(v);
else
{
Array *ax = new Array();
Dsymbols *ax = new Dsymbols();
ax->push(v);
Dsymbol *s = new LinkDeclaration(link, ax);
a->push(s);
@@ -2334,14 +2361,14 @@ Array *Parser::parseDeclarations()
}
else
{
Array *ax = new Array();
Dsymbols *ax = new Dsymbols();
ax->push(f);
s = new LinkDeclaration(link, ax);
}
if (tpl) // it's a function template
{
// Wrap a template around the aggregate declaration
Array *decldefs = new Array();
Dsymbols *decldefs = new Dsymbols();
decldefs->push(s);
TemplateDeclaration *tempdecl =
new TemplateDeclaration(loc, s->ident, tpl, NULL, decldefs);
@@ -2365,7 +2392,7 @@ Array *Parser::parseDeclarations()
a->push(v);
else
{
Array *ax = new Array();
Dsymbols *ax = new Dsymbols();
ax->push(v);
Dsymbol *s = new LinkDeclaration(link, ax);
a->push(s);
@@ -2585,7 +2612,7 @@ Initializer *Parser::parseInitializer()
is = new StructInitializer(loc);
nextToken();
comma = 0;
comma = 2;
while (1)
{
switch (token.value)
@@ -2609,6 +2636,8 @@ Initializer *Parser::parseInitializer()
continue;
case TOKcomma:
if (comma == 2)
error("expression expected, not ','");
nextToken();
comma = 2;
continue;
@@ -2622,6 +2651,8 @@ Initializer *Parser::parseInitializer()
break;
default:
if (comma == 1)
error("comma expected separating field initializers");
value = parseInitializer();
is->addInit(NULL, value);
comma = 1;
@@ -2670,7 +2701,7 @@ Initializer *Parser::parseInitializer()
ia = new ArrayInitializer(loc);
nextToken();
comma = 0;
comma = 2;
while (1)
{
switch (token.value)
@@ -2707,6 +2738,8 @@ Initializer *Parser::parseInitializer()
continue;
case TOKcomma:
if (comma == 2)
error("expression expected, not ','");
nextToken();
comma = 2;
continue;
@@ -2909,10 +2942,10 @@ Statement *Parser::parseStatement(int flags)
{
Statements *as = new Statements();
as->reserve(a->dim);
for (int i = 0; i < a->dim; i++)
for (size_t i = 0; i < a->dim; i++)
{
Dsymbol *d = (Dsymbol *)a->data[i];
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
as->push(s);
}
s = new CompoundDeclarationStatement(loc, as);
@@ -2920,7 +2953,7 @@ Statement *Parser::parseStatement(int flags)
else if (a->dim == 1)
{
Dsymbol *d = (Dsymbol *)a->data[0];
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
}
else
assert(0);
@@ -2936,7 +2969,7 @@ Statement *Parser::parseStatement(int flags)
{ Dsymbol *d;
d = parseAggregate();
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
break;
}
@@ -2944,7 +2977,7 @@ Statement *Parser::parseStatement(int flags)
{ Dsymbol *d;
d = parseEnum();
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
break;
}
@@ -2952,16 +2985,21 @@ Statement *Parser::parseStatement(int flags)
{ t = peek(&token);
if (t->value == TOKlparen)
{ // mixin(string)
nextToken();
check(TOKlparen, "mixin");
Expression *e = parseAssignExp();
check(TOKrparen);
check(TOKsemicolon, "mixin (string)");
s = new CompileStatement(loc, e);
check(TOKsemicolon);
if (e->op == TOKmixin)
{
CompileExp *cpe = (CompileExp *)e;
s = new CompileStatement(loc, cpe->e1);
}
else
{
s = new ExpStatement(loc, e);
}
break;
}
Dsymbol *d = parseMixin();
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
break;
}
@@ -2998,7 +3036,7 @@ Statement *Parser::parseStatement(int flags)
if (!(flags & PSsemi))
error("use '{ }' for an empty statement, not a ';'");
nextToken();
s = new ExpStatement(loc, NULL);
s = new ExpStatement(loc, (Expression *)NULL);
break;
case TOKdo:
@@ -3316,7 +3354,7 @@ Statement *Parser::parseStatement(int flags)
s = new ScopeStatement(loc, s);
// Keep cases in order by building the case statements backwards
for (int i = cases.dim; i; i--)
for (size_t i = cases.dim; i; i--)
{
exp = (Expression *)cases.data[i - 1];
s = new CaseStatement(loc, exp, s);
@@ -3707,8 +3745,6 @@ int Parser::isBasicType(Token **pt)
{
// This code parallels parseBasicType()
Token *t = *pt;
Token *t2;
int parens;
switch (t->value)
{
@@ -4157,7 +4193,6 @@ int Parser::skipParens(Token *t, Token **pt)
break;
case TOKeof:
case TOKsemicolon:
goto Lfalse;
default:
@@ -4359,7 +4394,6 @@ Expression *Parser::parsePrimaryExp()
case BASIC_TYPES_X(t):
nextToken();
L1:
check(TOKdot, t->toChars());
if (token.value != TOKidentifier)
{ error("found '%s' when expecting identifier following '%s.'", token.toChars(), t->toChars());
@@ -4676,6 +4710,7 @@ Expression *Parser::parsePostExp(Expression *e)
nextToken();
if (token.value == TOKrbracket)
{ // array[]
inBrackets--;
e = new SliceExp(loc, e, NULL, NULL);
nextToken();
}
@@ -5386,7 +5421,7 @@ Expression *Parser::parseNewExp(Expression *thisexp)
else
{
nextToken();
Array *decl = parseDeclDefs(0);
Dsymbols *decl = parseDeclDefs(0);
if (token.value != TOKrcurly)
error("class member expected");
nextToken();
@@ -5472,7 +5507,7 @@ enum PREC precedence[TOKMAX];
void initPrecedence()
{
for (int i = 0; i < TOKMAX; i++)
for (size_t i = 0; i < TOKMAX; i++)
precedence[i] = PREC_zero;
precedence[TOKtype] = PREC_expr;

View File

@@ -66,10 +66,10 @@ struct Parser : Lexer
Parser(Module *module, unsigned char *base, unsigned length, int doDocComment);
Array *parseModule();
Array *parseDeclDefs(int once);
Dsymbols *parseModule();
Dsymbols *parseDeclDefs(int once);
Array *parseAutoDeclarations(StorageClass storageClass, unsigned char *comment);
Array *parseBlock();
Dsymbols *parseBlock();
void composeStorageClass(StorageClass stc);
Expression *parseConstraint();
TemplateDeclaration *parseTemplateDeclaration();
@@ -102,7 +102,7 @@ struct Parser : Lexer
Type *parseBasicType();
Type *parseBasicType2(Type *t);
Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL);
Array *parseDeclarations();
Dsymbols *parseDeclarations();
void parseContracts(FuncDeclaration *f);
Statement *parseStatement(int flags);
Initializer *parseInitializer();

View File

@@ -190,7 +190,8 @@ char *Array::toChars()
char *str;
char *p;
buf = (char **)alloca(dim * sizeof(char *));
buf = (char **)malloc(dim * sizeof(char *));
assert(buf);
len = 2;
for (u = 0; u < dim; u++)
{
@@ -211,6 +212,7 @@ char *Array::toChars()
}
*p++ = ']';
*p = 0;
free(buf);
return str;
}

View File

@@ -12,7 +12,6 @@
#include <process.h>
#include "root.h"
#include "rmem.h"
static unsigned __stdcall startthread(void *p);
@@ -41,7 +40,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
AsyncRead *aw = (AsyncRead *)calloc(1, sizeof(AsyncRead) +
(nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
@@ -92,7 +91,7 @@ int AsyncRead::read(size_t i)
void AsyncRead::dispose(AsyncRead *aw)
{
delete aw;
free(aw);
}
@@ -119,7 +118,6 @@ unsigned __stdcall startthread(void *p)
#include <time.h>
#include "root.h"
#include "rmem.h"
void *startthread(void *arg);
@@ -155,7 +153,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
AsyncRead *aw = (AsyncRead *)calloc(1, sizeof(AsyncRead) +
(nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
@@ -228,7 +226,7 @@ void AsyncRead::dispose(AsyncRead *aw)
if (status != 0)
err_abort(status, "mutex destroy");
}
delete aw;
free(aw);
}
@@ -265,7 +263,6 @@ void *startthread(void *p)
#include <errno.h>
#include "root.h"
#include "rmem.h"
struct FileData
{
@@ -292,7 +289,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
AsyncRead *aw = (AsyncRead *)calloc(1, sizeof(AsyncRead) +
(nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
@@ -322,7 +319,7 @@ int AsyncRead::read(size_t i)
void AsyncRead::dispose(AsyncRead *aw)
{
delete aw;
free(aw);
}
#endif

View File

@@ -327,7 +327,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 2:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint16_t *)str;
#else
hash += str[0] * 256 + str[1];
@@ -336,7 +336,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 3:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += (*(const uint16_t *)str << 8) +
((const uint8_t *)str)[2];
#else
@@ -346,7 +346,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
default:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint32_t *)str;
#else
hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
@@ -379,7 +379,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 2:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint16_t *)str;
#else
hash += str[0] * 256 + str[1];
@@ -388,7 +388,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 3:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += (*(const uint16_t *)str << 8) +
((const uint8_t *)str)[2];
#else
@@ -398,7 +398,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
default:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint32_t *)str;
#else
hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2006 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// www.digitalmars.com
@@ -161,14 +161,14 @@ struct Dchar
static int memcmp(const dchar *s1, const dchar *s2, int nchars) { return ::memcmp(s1, s2, nchars); }
static int isDigit(dchar c) { return '0' <= c && c <= '9'; }
#ifndef GCC_SAFE_DMD
static int isAlpha(dchar c) { return isalpha(c); }
static int isUpper(dchar c) { return isupper(c); }
static int isLower(dchar c) { return islower(c); }
static int isLocaleUpper(dchar c) { return isupper(c); }
static int isLocaleLower(dchar c) { return islower(c); }
static int toLower(dchar c) { return isupper(c) ? tolower(c) : c; }
static int isAlpha(dchar c) { return isalpha((unsigned char)c); }
static int isUpper(dchar c) { return isupper((unsigned char)c); }
static int isLower(dchar c) { return islower((unsigned char)c); }
static int isLocaleUpper(dchar c) { return isupper((unsigned char)c); }
static int isLocaleLower(dchar c) { return islower((unsigned char)c); }
static int toLower(dchar c) { return isupper((unsigned char)c) ? tolower(c) : c; }
static int toLower(dchar *p) { return toLower(*p); }
static int toUpper(dchar c) { return islower(c) ? toupper(c) : c; }
static int toUpper(dchar c) { return islower((unsigned char)c) ? toupper(c) : c; }
static dchar *dup(dchar *p) { return ::strdup(p); } // BUG: out of memory?
#endif
static dchar *chr(dchar *p, int c) { return strchr(p, c); }

View File

@@ -26,7 +26,7 @@ void browse(const char *url)
#endif
#if linux || __FreeBSD__ || __sun&&__SVR4
#if linux || __FreeBSD__ || __OpenBSD__ || __sun&&__SVR4
#include <sys/types.h>
#include <sys/wait.h>

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -70,6 +70,11 @@ double Port::pow(double x, double y)
return ::pow(x, y);
}
long double Port::fmodl(long double x, long double y)
{
return ::fmodl(x, y);
}
unsigned long long Port::strtoull(const char *p, char **pend, int base)
{
return ::strtoull(p, pend, base);
@@ -201,14 +206,21 @@ double Port::pow(double x, double y)
return ::pow(x, y);
}
long double Port::fmodl(long double x, long double y)
{
return ::fmodl(x, y);
}
unsigned _int64 Port::strtoull(const char *p, char **pend, int base)
{
unsigned _int64 number = 0;
int c;
int error;
#ifndef ULLONG_MAX
#define ULLONG_MAX ((unsigned _int64)~0I64)
#endif
while (isspace(*p)) /* skip leading white space */
while (isspace((unsigned char)*p)) /* skip leading white space */
p++;
if (*p == '+')
p++;
@@ -315,7 +327,7 @@ char *Port::strupr(char *s)
#endif
#if linux || __APPLE__ || __FreeBSD__ || __MINGW32__ || __HAIKU__
#if linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __MINGW32__ || __HAIKU__
#include <math.h>
#if linux
@@ -332,6 +344,7 @@ char *Port::strupr(char *s)
#include <stdlib.h>
#include <ctype.h>
#include <float.h>
#include <assert.h>
static double zero = 0;
double Port::nan = NAN;
@@ -368,18 +381,14 @@ PortInitializer::PortInitializer()
#endif
}
#if !defined __MINGW32__ && !defined __HAIKU__
#undef isnan
#endif
int Port::isNan(double r)
{
#if __APPLE__
return __inline_isnan(r);
#elif defined __MINGW32__
return isnan(r);
#elif defined __HAIKU__
#elif __OpenBSD__ || __MINGW32__ || __HAIKU__
return isnan(r);
#else
#undef isnan
return ::isnan(r);
#endif
}
@@ -388,11 +397,10 @@ int Port::isNan(long double r)
{
#if __APPLE__
return __inline_isnan(r);
#elif defined __MINGW32__
return isnan(r);
#elif defined __HAIKU__
#elif __OpenBSD__ || __MINGW32__ || __HAIKU__
return isnan(r);
#else
#undef isnan
return ::isnan(r);
#endif
}
@@ -419,18 +427,14 @@ int Port::isFinite(double r)
return ::finite(r);
}
#if !defined __MINGW32__ && !defined __HAIKU__
#undef isinf
#endif
int Port::isInfinity(double r)
{
#if __APPLE__
return fpclassify(r) == FP_INFINITE;
#elif defined __MINGW32__
return isinf(r);
#elif defined __HAIKU__
#elif __OpenBSD__ || __MINGW32__ || __HAIKU__
return isinf(r);
#else
#undef isinf
return ::isinf(r);
#endif
}
@@ -453,6 +457,15 @@ double Port::pow(double x, double y)
return ::pow(x, y);
}
long double Port::fmodl(long double x, long double y)
{
#if __FreeBSD__ || __OpenBSD__
return ::fmod(x, y); // hack for now, fix later
#else
return ::fmodl(x, y);
#endif
}
unsigned long long Port::strtoull(const char *p, char **pend, int base)
{
return ::strtoull(p, pend, base);
@@ -466,10 +479,14 @@ char *Port::ull_to_string(char *buffer, ulonglong ull)
wchar_t *Port::ull_to_string(wchar_t *buffer, ulonglong ull)
{
#if __OpenBSD__
assert(0);
#else
#ifndef __MINGW32__
swprintf(buffer, sizeof(ulonglong) * 3 + 1, L"%llu", ull);
#else
_snwprintf(buffer, sizeof(ulonglong) * 3 + 1, L"%llu", ull);
#endif
#endif
return buffer;
}

View File

@@ -40,7 +40,8 @@ struct Port
static double dbl_min;
static long double ldbl_max;
#if __GNUC__ && !defined __HAIKU__
#if __OpenBSD__
#elif __GNUC__ && !defined __HAIKU__
// These conflict with macros in math.h, should rename them
#undef isnan
#undef isfinite
@@ -60,6 +61,8 @@ struct Port
static double floor(double);
static double pow(double x, double y);
static long double fmodl(long double x, long double y);
static ulonglong strtoull(const char *p, char **pend, int base);
static char *ull_to_string(char *buffer, ulonglong ull);

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -8,7 +8,7 @@
// See the included readme.txt for details.
#ifndef POSIX
#define POSIX (linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4)
#define POSIX (linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun&&__SVR4)
#endif
#include <stdio.h>
@@ -364,21 +364,21 @@ FileName::FileName(char *path, char *name)
}
// Split a path into an Array of paths
Array *FileName::splitPath(const char *path)
Strings *FileName::splitPath(const char *path)
{
char c = 0; // unnecessary initializer is for VC /W4
const char *p;
OutBuffer buf;
Array *array;
Strings *array;
array = new Array();
array = new Strings();
if (path)
{
p = path;
do
{ char instring = 0;
while (isspace(*p)) // skip leading whitespace
while (isspace((unsigned char)*p)) // skip leading whitespace
p++;
buf.reserve(strlen(p) + 1); // guess size of path
// LDC remember first character
@@ -799,7 +799,7 @@ void FileName::CopyTo(FileName *to)
* cwd if !=0, search current directory before searching path
*/
char *FileName::searchPath(Array *path, const char *name, int cwd)
char *FileName::searchPath(Strings *path, const char *name, int cwd)
{
if (absolute(name))
{
@@ -815,7 +815,7 @@ char *FileName::searchPath(Array *path, const char *name, int cwd)
for (i = 0; i < path->dim; i++)
{
char *p = (char *)path->data[i];
char *p = path->tdata()[i];
char *n = combine(p, name);
if (exists(n))
@@ -839,7 +839,7 @@ char *FileName::searchPath(Array *path, const char *name, int cwd)
* !=NULL mem.malloc'd file name
*/
char *FileName::safeSearchPath(Array *path, const char *name)
char *FileName::safeSearchPath(Strings *path, const char *name)
{
#if _WIN32
/* Disallow % / \ : and .. in name characters
@@ -876,7 +876,7 @@ char *FileName::safeSearchPath(Array *path, const char *name)
for (i = 0; i < path->dim; i++)
{
char *cname = NULL;
char *cpath = canonicalName((char *)path->data[i]);
char *cpath = canonicalName(path->tdata()[i]);
//printf("FileName::safeSearchPath(): name=%s; path=%s; cpath=%s\n",
// name, (char *)path->data[i], cpath);
if (cpath == NULL)
@@ -966,7 +966,7 @@ void FileName::ensurePathExists(const char *path)
{
//printf("mkdir(%s)\n", path);
#if _WIN32
if (mkdir(path))
if (_mkdir(path))
#endif
#if POSIX
if (mkdir(path, 0777))
@@ -1088,13 +1088,13 @@ int File::read()
//printf("File::read('%s')\n",name);
fd = open(name, O_RDONLY);
if (fd == -1)
{ result = errno;
{
//printf("\topen error, errno = %d\n",errno);
goto err1;
}
if (!ref)
mem.free(buffer);
::free(buffer);
ref = 0; // we own the buffer now
//printf("\tfile opened\n");
@@ -1104,7 +1104,7 @@ int File::read()
goto err2;
}
size = buf.st_size;
buffer = (unsigned char *) mem.malloc(size + 2);
buffer = (unsigned char *) ::malloc(size + 2);
if (!buffer)
{
printf("\tmalloc error, errno = %d\n",errno);
@@ -1137,7 +1137,7 @@ int File::read()
err2:
close(fd);
err:
mem.free(buffer);
::free(buffer);
buffer = NULL;
len = 0;
@@ -1158,11 +1158,11 @@ err1:
goto err1;
if (!ref)
mem.free(buffer);
::free(buffer);
ref = 0;
size = GetFileSize(h,NULL);
buffer = (unsigned char *) mem.malloc(size + 2);
buffer = (unsigned char *) ::malloc(size + 2);
if (!buffer)
goto err2;
@@ -1191,7 +1191,7 @@ err1:
err2:
CloseHandle(h);
err:
mem.free(buffer);
::free(buffer);
buffer = NULL;
len = 0;
@@ -1454,23 +1454,23 @@ void File::remove()
#endif
}
Array *File::match(char *n)
Files *File::match(char *n)
{
return match(new FileName(n, 0));
}
Array *File::match(FileName *n)
Files *File::match(FileName *n)
{
#if POSIX
return NULL;
#elif _WIN32
HANDLE h;
WIN32_FIND_DATAA fileinfo;
Array *a;
Files *a;
char *c;
char *name;
a = new Array();
a = new Files();
c = n->toChars();
name = n->name();
h = FindFirstFileA(c,&fileinfo);
@@ -1563,11 +1563,11 @@ OutBuffer::~OutBuffer()
mem.free(data);
}
void *OutBuffer::extractData()
char *OutBuffer::extractData()
{
void *p;
char *p;
p = (void *)data;
p = (char *)data;
data = NULL;
offset = 0;
size = 0;

View File

@@ -1,6 +1,6 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -13,6 +13,9 @@
#include <stdlib.h>
#include <stdarg.h>
#ifdef DEBUG
#include <assert.h>
#endif
#if __DMC__
#pragma once
@@ -68,7 +71,12 @@ longlong randomx();
*/
struct OutBuffer;
struct Array;
// Can't include arraytypes.h here, need to declare these directly.
template <typename TYPE> struct ArrayBase;
typedef ArrayBase<struct File> Files;
typedef ArrayBase<char> Strings;
struct Object
{
@@ -149,14 +157,14 @@ struct FileName : String
static const char *replaceName(const char *path, const char *name);
static char *combine(const char *path, const char *name);
static Array *splitPath(const char *path);
static Strings *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, const char *name, int cwd);
static char *safeSearchPath(Array *path, const char *name);
static char *searchPath(Strings *path, const char *name, int cwd);
static char *safeSearchPath(Strings *path, const char *name);
static int exists(const char *name);
static void ensurePathExists(const char *path);
static char *canonicalName(const char *name);
@@ -241,8 +249,8 @@ struct File : Object
* matching File's.
*/
static Array *match(char *);
static Array *match(FileName *);
static Files *match(char *);
static Files *match(FileName *);
// Compare file times.
// Return <0 this < f
@@ -275,7 +283,7 @@ struct OutBuffer : Object
OutBuffer();
~OutBuffer();
void *extractData();
char *extractData();
void mark();
void reserve(unsigned nbytes);
@@ -348,6 +356,48 @@ struct Array : Object
Array *copy();
};
template <typename TYPE>
struct ArrayBase : Array
{
TYPE **tdata()
{
return (TYPE **)data;
}
TYPE*& operator[] (size_t index)
{
#ifdef DEBUG
assert(index < dim);
#endif
return ((TYPE **)data)[index];
}
void insert(size_t index, TYPE *v)
{
Array::insert(index, (void *)v);
}
void insert(size_t index, ArrayBase *a)
{
Array::insert(index, (Array *)a);
}
void append(ArrayBase *a)
{
Array::append((Array *)a);
}
void push(TYPE *a)
{
Array::push((void *)a);
}
ArrayBase *copy()
{
return (ArrayBase *)Array::copy();
}
};
struct Bits : Object
{
unsigned bitdim;

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -18,7 +18,7 @@
#include "lstring.h"
#include "stringtable.h"
StringTable::StringTable(unsigned size)
void StringTable::init(unsigned size)
{
table = (void **)mem.calloc(size, sizeof(void *));
tabledim = size;

View File

@@ -1,4 +1,4 @@
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -28,13 +28,13 @@ struct StringValue
Lstring lstring;
};
struct StringTable : Object
struct StringTable
{
void **table;
unsigned count;
unsigned tabledim;
StringTable(unsigned size = 37);
void init(unsigned size = 37);
~StringTable();
StringValue *lookup(const dchar *s, unsigned len);

View File

@@ -111,7 +111,7 @@ void *spellerX(const char *seed, size_t seedlen, fp_speller_t fp, void *fparg,
/* Deletions */
memcpy(buf, seed + 1, seedlen);
for (int i = 0; i < seedlen; i++)
for (size_t i = 0; i < seedlen; i++)
{
//printf("del buf = '%s'\n", buf);
void *p;
@@ -129,7 +129,7 @@ void *spellerX(const char *seed, size_t seedlen, fp_speller_t fp, void *fparg,
if (!flag)
{
memcpy(buf, seed, seedlen + 1);
for (int i = 0; i + 1 < seedlen; i++)
for (size_t i = 0; i + 1 < seedlen; i++)
{
// swap [i] and [i + 1]
buf[i] = seed[i + 1];
@@ -148,7 +148,7 @@ void *spellerX(const char *seed, size_t seedlen, fp_speller_t fp, void *fparg,
{
/* Substitutions */
memcpy(buf, seed, seedlen + 1);
for (int i = 0; i < seedlen; i++)
for (size_t i = 0; i < seedlen; i++)
{
for (const char *s = charset; *s; s++)
{
@@ -168,7 +168,7 @@ void *spellerX(const char *seed, size_t seedlen, fp_speller_t fp, void *fparg,
/* Insertions */
memcpy(buf + 1, seed, seedlen + 1);
for (int i = 0; i <= seedlen; i++) // yes, do seedlen+1 iterations
for (size_t i = 0; i <= seedlen; i++) // yes, do seedlen+1 iterations
{
for (const char *s = charset; *s; s++)
{

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -27,7 +27,7 @@ struct Expression;
struct LabelDsymbol;
struct Identifier;
struct IfStatement;
struct DeclarationStatement;
struct ExpStatement;
struct DefaultStatement;
struct VarDeclaration;
struct Condition;
@@ -46,6 +46,9 @@ struct GotoStatement;
struct ScopeStatement;
struct TryCatchStatement;
struct TryFinallyStatement;
struct CaseStatement;
struct DefaultStatement;
struct LabelStatement;
struct HdrGenState;
struct InterState;
struct CaseStatement;
@@ -112,9 +115,7 @@ struct Statement : Object
virtual GotoStatement *isGotoStatement() { return NULL; }
virtual AsmStatement *isAsmStatement() { return NULL; }
virtual AsmBlockStatement *isAsmBlockStatement() { return NULL; }
#ifdef _DH
int incontract;
#endif
virtual ScopeStatement *isScopeStatement() { return NULL; }
virtual Statement *semantic(Scope *sc);
Statement *semanticScope(Scope *sc, Statement *sbreak, Statement *scontinue);
@@ -122,7 +123,7 @@ struct Statement : Object
virtual int hasBreak();
virtual int hasContinue();
virtual int usesEH();
virtual int blockExit();
virtual int blockExit(bool mustNotThrow);
virtual int comeFrom();
virtual int isEmpty();
virtual void scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally);
@@ -137,11 +138,12 @@ struct Statement : Object
virtual void toIR(IRState *irs);
// Avoid dynamic_cast
virtual DeclarationStatement *isDeclarationStatement() { return NULL; }
virtual ExpStatement *isExpStatement() { return NULL; }
virtual CompoundStatement *isCompoundStatement() { return NULL; }
virtual ReturnStatement *isReturnStatement() { return NULL; }
virtual IfStatement *isIfStatement() { return NULL; }
virtual CaseStatement* isCaseStatement() { return NULL; }
virtual DefaultStatement *isDefaultStatement() { return NULL; }
virtual LabelStatement* isLabelStatement() { return NULL; }
#if IN_LLVM
@@ -163,12 +165,14 @@ struct ExpStatement : Statement
Expression *exp;
ExpStatement(Loc loc, Expression *exp);
ExpStatement(Loc loc, Dsymbol *s);
Statement *syntaxCopy();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Statement *semantic(Scope *sc);
Expression *interpret(InterState *istate);
int blockExit();
int blockExit(bool mustNotThrow);
int isEmpty();
void scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally);
int inlineCost(InlineCostState *ics);
Expression *doInline(InlineDoState *ids);
@@ -179,6 +183,8 @@ struct ExpStatement : Statement
#if IN_LLVM
void toNakedIR(IRState *irs);
#endif
ExpStatement *isExpStatement() { return this; }
};
struct CompileStatement : Statement
@@ -192,20 +198,6 @@ struct CompileStatement : Statement
Statement *semantic(Scope *sc);
};
struct DeclarationStatement : ExpStatement
{
// Doing declarations as an expression, rather than a statement,
// makes inlining functions much easier.
DeclarationStatement(Loc loc, Dsymbol *s);
DeclarationStatement(Loc loc, Expression *exp);
Statement *syntaxCopy();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally);
DeclarationStatement *isDeclarationStatement() { return this; }
};
struct CompoundStatement : Statement
{
Statements *statements;
@@ -217,7 +209,7 @@ struct CompoundStatement : Statement
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
virtual Statement *semantic(Scope *sc);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
int isEmpty();
virtual Statements *flatten(Scope *sc);
@@ -257,7 +249,7 @@ struct UnrolledLoopStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -281,7 +273,7 @@ struct ScopeStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
int isEmpty();
Expression *interpret(InterState *istate);
@@ -302,7 +294,7 @@ struct WhileStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -323,7 +315,7 @@ struct DoStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -347,7 +339,7 @@ struct ForStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -369,7 +361,7 @@ struct ForeachStatement : Statement
FuncDeclaration *func; // function we're lexically in
Array *cases; // put breaks, continues, gotos and returns here
Statements *cases; // put breaks, continues, gotos and returns here
Array *gotos; // forward referenced goto's go here
ForeachStatement(Loc loc, enum TOK op, Parameters *arguments, Expression *aggr, Statement *body);
@@ -379,7 +371,7 @@ struct ForeachStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -407,7 +399,7 @@ struct ForeachRangeStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -433,7 +425,7 @@ struct IfStatement : Statement
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
IfStatement *isIfStatement() { return this; }
int inlineCost(InlineCostState *ics);
@@ -454,7 +446,7 @@ struct ConditionalStatement : Statement
Statement *semantic(Scope *sc);
Statements *flatten(Scope *sc);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
};
@@ -469,7 +461,7 @@ struct PragmaStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
};
@@ -481,7 +473,7 @@ struct StaticAssertStatement : Statement
StaticAssertStatement(StaticAssert *sa);
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
};
@@ -494,7 +486,7 @@ struct SwitchStatement : Statement
DefaultStatement *sdefault;
Array gotoCases; // array of unresolved GotoCaseStatement's
Array *cases; // array of CaseStatement's
CaseStatements *cases; // array of CaseStatement's
int hasNoDefault; // !=0 if no default statement
// LDC
@@ -505,7 +497,7 @@ struct SwitchStatement : Statement
Statement *semantic(Scope *sc);
int hasBreak();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -530,17 +522,16 @@ struct CaseStatement : Statement
Statement *semantic(Scope *sc);
int compare(Object *obj);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
CaseStatement *isCaseStatement() { return this; }
Statement *inlineScan(InlineScanState *iss);
void toIR(IRState *irs);
CaseStatement* isCaseStatement() { return this; }
#if IN_LLVM
llvm::BasicBlock* bodyBB;
llvm::Value* llvmIdx;
@@ -577,10 +568,11 @@ struct DefaultStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
DefaultStatement *isDefaultStatement() { return this; }
Statement *inlineScan(InlineScanState *iss);
@@ -598,7 +590,7 @@ struct GotoDefaultStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
Expression *interpret(InterState *istate);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toIR(IRState *irs);
@@ -614,7 +606,7 @@ struct GotoCaseStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
Expression *interpret(InterState *istate);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toIR(IRState *irs);
@@ -623,7 +615,7 @@ struct GotoCaseStatement : Statement
struct SwitchErrorStatement : Statement
{
SwitchErrorStatement(Loc loc);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toIR(IRState *irs);
@@ -637,7 +629,7 @@ struct ReturnStatement : Statement
Statement *syntaxCopy();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Statement *semantic(Scope *sc);
int blockExit();
int blockExit(bool mustNotThrow);
Expression *interpret(InterState *istate);
int inlineCost(InlineCostState *ics);
@@ -657,7 +649,7 @@ struct BreakStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
Expression *interpret(InterState *istate);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toIR(IRState *irs);
@@ -674,7 +666,7 @@ struct ContinueStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
Expression *interpret(InterState *istate);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toIR(IRState *irs);
@@ -694,7 +686,7 @@ struct SynchronizedStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Statement *inlineScan(InlineScanState *iss);
@@ -717,7 +709,7 @@ struct WithStatement : Statement
Statement *semantic(Scope *sc);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
Expression *interpret(InterState *istate);
Statement *inlineScan(InlineScanState *iss);
@@ -735,7 +727,7 @@ struct TryCatchStatement : Statement
Statement *semantic(Scope *sc);
int hasBreak();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
Expression *interpret(InterState *istate);
Statement *inlineScan(InlineScanState *iss);
@@ -756,7 +748,7 @@ struct Catch : Object
Catch(Loc loc, Type *t, Identifier *id, Statement *handler);
Catch *syntaxCopy();
void semantic(Scope *sc);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
};
@@ -772,7 +764,7 @@ struct TryFinallyStatement : Statement
int hasBreak();
int hasContinue();
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
Expression *interpret(InterState *istate);
Statement *inlineScan(InlineScanState *iss);
@@ -787,7 +779,7 @@ struct OnScopeStatement : Statement
OnScopeStatement(Loc loc, TOK tok, Statement *statement);
Statement *syntaxCopy();
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Statement *semantic(Scope *sc);
int usesEH();
@@ -805,7 +797,7 @@ struct ThrowStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
int blockExit();
int blockExit(bool mustNotThrow);
Expression *interpret(InterState *istate);
Statement *inlineScan(InlineScanState *iss);
@@ -821,7 +813,7 @@ struct VolatileStatement : Statement
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
Statements *flatten(Scope *sc);
int blockExit();
int blockExit(bool mustNotThrow);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Statement *inlineScan(InlineScanState *iss);
@@ -839,7 +831,7 @@ struct GotoStatement : Statement
GotoStatement(Loc loc, Identifier *ident);
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
int blockExit();
int blockExit(bool mustNotThrow);
Expression *interpret(InterState *istate);
void toIR(IRState *irs);
@@ -862,20 +854,19 @@ struct LabelStatement : Statement
Statement *semantic(Scope *sc);
Statements *flatten(Scope *sc);
int usesEH();
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Statement *inlineScan(InlineScanState *iss);
LabelStatement *isLabelStatement() { return this; }
void toIR(IRState *irs);
// LDC
bool asmLabel; // for labels inside inline assembler
void toNakedIR(IRState *irs);
LabelStatement* isLabelStatement() { return this; }
};
struct LabelDsymbol : Dsymbol
@@ -897,7 +888,7 @@ struct AsmStatement : Statement
AsmStatement(Loc loc, Token *tokens);
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
int blockExit();
int blockExit(bool mustNotThrow);
int comeFrom();
Expression *interpret(InterState *istate);

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -52,10 +52,8 @@ void StaticAssert::semantic(Scope *sc)
void StaticAssert::semantic2(Scope *sc)
{
Expression *e;
//printf("StaticAssert::semantic2() %s\n", toChars());
e = exp->semantic(sc);
Expression *e = exp->semantic(sc);
if (e->op == TOKerror)
return;
e = e->optimize(WANTvalue | WANTinterpret);

View File

@@ -18,9 +18,7 @@
#include "dsymbol.h"
struct Expression;
#ifdef _DH
struct HdrGenState;
#endif
struct StaticAssert : Dsymbol
{

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -51,6 +51,8 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
ctor = NULL;
defaultCtor = NULL;
aliasthis = NULL;
noDefaultCtor = FALSE;
#endif
#if IN_LLVM
@@ -83,8 +85,7 @@ void AggregateDeclaration::semantic2(Scope *sc)
}
void AggregateDeclaration::semantic3(Scope *sc)
{ int i;
{
// LDC
if (!global.params.useAvailableExternally)
availableExternally = false;
@@ -93,7 +94,7 @@ void AggregateDeclaration::semantic3(Scope *sc)
if (members)
{
sc = sc->push(this);
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->semantic3(sc);
@@ -103,12 +104,11 @@ void AggregateDeclaration::semantic3(Scope *sc)
}
void AggregateDeclaration::inlineScan()
{ int i;
{
//printf("AggregateDeclaration::inlineScan(%s)\n", toChars());
if (members)
{
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
//printf("inline scan aggregate symbol '%s'\n", s->toChars());
@@ -155,7 +155,7 @@ void AggregateDeclaration::alignmember(
if (salign > 1)
{
assert(size != 3);
int sa = size;
unsigned sa = size;
if (sa == 0 || salign < sa)
sa = salign;
*poffset = (*poffset + sa - 1) & ~(sa - 1);
@@ -216,7 +216,10 @@ void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v)
if (!isUnionDeclaration())
sc->offset = ofs;
#endif
if (sc->structalign < memalignsize)
if (global.params.is64bit && sc->structalign == 8 && memalignsize == 16)
/* Not sure how to handle this */
;
else if (sc->structalign < memalignsize)
memalignsize = sc->structalign;
if (alignsize < memalignsize)
alignsize = memalignsize;
@@ -227,6 +230,57 @@ void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v)
fields.push(v);
}
/****************************************
* If field[indx] is not part of a union, return indx.
* Otherwise, return the lowest field index of the union.
*/
int AggregateDeclaration::firstFieldInUnion(int indx)
{
if (isUnionDeclaration())
return 0;
VarDeclaration * vd = (VarDeclaration *)fields.data[indx];
int firstNonZero = indx; // first index in the union with non-zero size
for (; ;)
{
if (indx == 0)
return firstNonZero;
VarDeclaration * v = (VarDeclaration *)fields.data[indx - 1];
if (v->offset != vd->offset)
return firstNonZero;
--indx;
/* If it is a zero-length field, it's ambiguous: we don't know if it is
* in the union unless we find an earlier non-zero sized field with the
* same offset.
*/
if (v->size(loc) != 0)
firstNonZero = indx;
}
}
/****************************************
* Count the number of fields starting at firstIndex which are part of the
* same union as field[firstIndex]. If not a union, return 1.
*/
int AggregateDeclaration::numFieldsInUnion(int firstIndex)
{
VarDeclaration * vd = (VarDeclaration *)fields.data[firstIndex];
/* If it is a zero-length field, AND we can't find an earlier non-zero
* sized field with the same offset, we assume it's not part of a union.
*/
if (vd->size(loc) == 0 && !isUnionDeclaration() &&
firstFieldInUnion(firstIndex) == firstIndex)
return 1;
int count = 1;
for (size_t i = firstIndex+1; i < fields.dim; ++i)
{
VarDeclaration * v = (VarDeclaration *)fields.data[i];
// If offsets are different, they are not in the same union
if (v->offset != vd->offset)
break;
++count;
}
return count;
}
/********************************* StructDeclaration ****************************/
@@ -257,7 +311,7 @@ Dsymbol *StructDeclaration::syntaxCopy(Dsymbol *s)
}
void StructDeclaration::semantic(Scope *sc)
{ int i;
{
Scope *sc2;
//printf("+StructDeclaration::semantic(this=%p, '%s')\n", this, toChars());
@@ -310,7 +364,7 @@ void StructDeclaration::semantic(Scope *sc)
if (sizeok == 0) // if not already done the addMember step
{
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
//printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
@@ -327,12 +381,12 @@ void StructDeclaration::semantic(Scope *sc)
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
int members_dim = members->dim;
size_t members_dim = members->dim;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (int i = 0; i < members_dim; i++)
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
@@ -344,7 +398,7 @@ void StructDeclaration::semantic(Scope *sc)
}
}
for (i = 0; i < members_dim; i++)
for (size_t i = 0; i < members_dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->semantic(sc2);
@@ -356,6 +410,10 @@ void StructDeclaration::semantic(Scope *sc)
#endif
}
#if DMDV1
/* This doesn't work for DMDV2 because (ref S) and (S) parameter
* lists will overload the same.
*/
/* The TypeInfo_Struct is expecting an opEquals and opCmp with
* a parameter that is a pointer to the struct. But if there
* isn't one, but is an opEquals or opCmp with a value, write
@@ -413,6 +471,7 @@ void StructDeclaration::semantic(Scope *sc)
id = Id::cmp;
}
#endif
#if DMDV2
dtor = buildDtor(sc2);
postblit = buildPostBlit(sc2);
@@ -458,7 +517,7 @@ void StructDeclaration::semantic(Scope *sc)
// Determine if struct is all zeros or not
zeroInit = 1;
for (i = 0; i < fields.dim; i++)
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
VarDeclaration *vd = s->isVarDeclaration();
@@ -501,7 +560,7 @@ Dsymbol *StructDeclaration::search(Loc loc, Identifier *ident, int flags)
{
//printf("%s.StructDeclaration::search('%s')\n", toChars(), ident->toChars());
if (scope)
if (scope && !symtab)
semantic(scope);
if (!members || !symtab)
@@ -514,8 +573,7 @@ Dsymbol *StructDeclaration::search(Loc loc, Identifier *ident, int flags)
}
void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{ int i;
{
buf->printf("%s ", kind());
if (!isAnonymous())
buf->writestring(toChars());
@@ -528,7 +586,7 @@ void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
buf->writeByte('{');
buf->writenl();
for (i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -55,7 +55,7 @@ struct TemplateDeclaration : ScopeDsymbol
TemplateParameters *origParameters; // originals for Ddoc
Expression *constraint;
Array instances; // array of TemplateInstance's
TemplateInstances instances; // array of TemplateInstance's
TemplateDeclaration *overnext; // next overloaded TemplateDeclaration
TemplateDeclaration *overroot; // first in overnext list
@@ -65,11 +65,12 @@ struct TemplateDeclaration : ScopeDsymbol
Dsymbol *onemember; // if !=NULL then one member of this template
TemplateDeclaration(Loc loc, Identifier *id, TemplateParameters *parameters,
Expression *constraint, Array *decldefs);
Expression *constraint, Dsymbols *decldefs);
Dsymbol *syntaxCopy(Dsymbol *);
void semantic(Scope *sc);
int overloadInsert(Dsymbol *s);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
bool hasStaticCtorOrDtor();
const char *kind();
char *toChars();
@@ -140,7 +141,7 @@ struct TemplateParameter
/* Match actual argument against parameter.
*/
virtual MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags = 0) = 0;
virtual MATCH matchArg(Scope *sc, Objects *tiargs, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags = 0) = 0;
/* Create dummy argument based on parameter.
*/
@@ -166,7 +167,7 @@ struct TemplateTypeParameter : TemplateParameter
Object *specialization();
Object *defaultArg(Loc loc, Scope *sc);
int overloadMatch(TemplateParameter *);
MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
MATCH matchArg(Scope *sc, Objects *tiargs, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
void *dummyArg();
};
@@ -210,7 +211,7 @@ struct TemplateValueParameter : TemplateParameter
Object *specialization();
Object *defaultArg(Loc loc, Scope *sc);
int overloadMatch(TemplateParameter *);
MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
MATCH matchArg(Scope *sc, Objects *tiargs, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
void *dummyArg();
};
@@ -238,7 +239,7 @@ struct TemplateAliasParameter : TemplateParameter
Object *specialization();
Object *defaultArg(Loc loc, Scope *sc);
int overloadMatch(TemplateParameter *);
MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
MATCH matchArg(Scope *sc, Objects *tiargs, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
void *dummyArg();
};
@@ -259,7 +260,7 @@ struct TemplateTupleParameter : TemplateParameter
Object *specialization();
Object *defaultArg(Loc loc, Scope *sc);
int overloadMatch(TemplateParameter *);
MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
MATCH matchArg(Scope *sc, Objects *tiargs, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam, int flags);
void *dummyArg();
};
@@ -271,7 +272,7 @@ struct TemplateInstance : ScopeDsymbol
* tiargs = args
*/
Identifier *name;
//Array idents;
//Identifiers idents;
Objects *tiargs; // Array of Types/Expressions of template
// instance arguments [int*, char, 10*10]
@@ -292,6 +293,7 @@ struct TemplateInstance : ScopeDsymbol
int havetempdecl; // 1 if used second constructor
Dsymbol *isnested; // if referencing local symbols, this is the context
int errors; // 1 if compiled with errors
int speculative; // 1 if only instantiated with errors gagged
#ifdef IN_GCC
/* On some targets, it is necessary to know whether a symbol
will be emitted in the output or not before the symbol
@@ -343,10 +345,10 @@ struct TemplateInstance : ScopeDsymbol
struct TemplateMixin : TemplateInstance
{
Array *idents;
Identifiers *idents;
Type *tqual;
TemplateMixin(Loc loc, Identifier *ident, Type *tqual, Array *idents, Objects *tiargs);
TemplateMixin(Loc loc, Identifier *ident, Type *tqual, Identifiers *idents, Objects *tiargs);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
void semantic2(Scope *sc);

View File

@@ -63,7 +63,7 @@ int DebugSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
if (findCondition(m->debugidsNot, ident))
error("defined after use");
if (!m->debugids)
m->debugids = new Array();
m->debugids = new Strings();
m->debugids->push(ident->toChars());
}
}
@@ -144,7 +144,7 @@ int VersionSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
if (findCondition(m->versionidsNot, ident))
error("defined after use");
if (!m->versionids)
m->versionids = new Array();
m->versionids = new Strings();
m->versionids->push(ident->toChars());
}
}

View File

@@ -183,11 +183,7 @@ Statement *AsmStatement::semantic(Scope *sc)
return this;
}
#if DMDV2
int AsmStatement::blockExit(bool mustNotThrow)
#else
int AsmStatement::blockExit()
#endif
{
//printf("AsmStatement::blockExit(%p)\n", this);
#if DMDV2

View File

@@ -6,13 +6,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#if DMDV1
struct Array;
typedef Array Strings;
#else
template <typename TYPE> struct ArrayBase;
typedef ArrayBase<char> Strings;
#endif
namespace opts {
namespace cl = llvm::cl;

View File

@@ -49,10 +49,6 @@ using namespace opts;
#include <windows.h>
#endif
#if DMDV1
typedef Array Modules;
#endif
extern void getenv_setargv(const char *envvar, int *pargc, char** *pargv);
extern void backend_init();
extern void backend_term();

View File

@@ -837,7 +837,7 @@ static LLValue* call_string_switch_runtime(llvm::Value* table, Expression* e)
fname = "_d_switch_dstring";
}
else {
assert(0 && "not char/wchar/dchar");
llvm_unreachable("not char/wchar/dchar");
}
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
@@ -1587,11 +1587,7 @@ void VolatileStatement::toIR(IRState* p)
p->func()->gen->targetScopes.pop_back();
// no point in a unreachable barrier, terminating statements must insert this themselves.
#if DMDV2
if (statement->blockExit(false) & BEfallthru)
#else
if (statement->blockExit() & BEfallthru)
#endif
{
// store-load
DtoMemoryBarrier(false, false, true, false);