Merge dmd v2.055

This commit is contained in:
Alexey Prokhin
2011-09-13 21:01:32 +04:00
parent 8f4a15c868
commit 0e754b5acd
74 changed files with 3809 additions and 2240 deletions
+12 -17
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
+9 -8
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
@@ -62,7 +62,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
@@ -84,6 +84,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
@@ -209,17 +210,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 *);
};
@@ -244,13 +245,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)
+2
View File
@@ -51,6 +51,8 @@ void AliasThis::semantic(Scope *sc)
error("there can be only one alias this");
assert(ad->members);
Dsymbol *s = ad->search(loc, ident, 0);
if (!s)
::error(loc, "undefined identifier %s", ident->toChars());
ad->aliasthis = s;
}
else
+4 -3
View File
@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 2010-2010 by Digital Mars
// Copyright (c) 2010-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -155,8 +155,9 @@ TypeTuple *TypeDelegate::toArgTypes()
TypeTuple *TypeStruct::toArgTypes()
{
int sz = size(0);
switch (sz)
d_uns64 sz = size(0);
assert(sz < 0xFFFFFFFF);
switch ((unsigned)sz)
{
case 1:
return new TypeTuple(Type::tint8);
+15 -3
View File
@@ -326,7 +326,7 @@ 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->tdata()[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));
@@ -443,6 +443,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X
@@ -476,6 +479,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X
@@ -531,7 +537,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->tdata()[0];
param->storageClass = 0;
Expression *e = new AssignExp(0, ex1, ex2);
return e;
@@ -544,7 +550,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->tdata()[0]; \
param->storageClass = 0; \
Expression *e = new Str##AssignExp(0, ex1, ex2); \
return e; \
@@ -558,6 +564,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X
@@ -594,6 +603,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
#if DMDV2
X(Pow)
#endif
#undef X
+44 -18
View File
@@ -18,34 +18,60 @@
#include "root.h"
struct Expression;
struct Statement;
struct BaseClass;
struct TemplateParameter;
struct FuncDeclaration;
struct Identifier;
struct Initializer;
typedef ArrayBase<struct TemplateParameter> TemplateParameters;
struct TemplateParameters : Array { };
typedef ArrayBase<struct Expression> Expressions;
struct Expressions : Array { };
typedef ArrayBase<struct Statement> Statements;
struct Statements : Array { };
typedef ArrayBase<struct BaseClass> BaseClasses;
struct BaseClasses : Array { };
typedef ArrayBase<struct ClassDeclaration> ClassDeclarations;
struct ClassDeclarations : Array { };
typedef ArrayBase<struct Dsymbol> Dsymbols;
struct Dsymbols : Array { };
typedef ArrayBase<struct Object> Objects;
struct Objects : Array { };
typedef ArrayBase<struct FuncDeclaration> FuncDeclarations;
struct FuncDeclarations : Array { };
typedef ArrayBase<struct Parameter> Parameters;
struct Parameters : Array { };
typedef ArrayBase<struct Identifier> Identifiers;
struct Identifiers : Array { };
typedef ArrayBase<struct Initializer> Initializers;
struct Initializers : Array { };
typedef ArrayBase<struct VarDeclaration> VarDeclarations;
typedef ArrayBase<struct Type> Types;
typedef ArrayBase<struct ScopeDsymbol> ScopeDsymbols;
typedef ArrayBase<struct Catch> Catches;
typedef ArrayBase<struct StaticDtorDeclaration> StaticDtorDeclarations;
typedef ArrayBase<struct SharedStaticDtorDeclaration> SharedStaticDtorDeclarations;
typedef ArrayBase<struct AliasDeclaration> AliasDeclarations;
typedef ArrayBase<struct Module> Modules;
typedef ArrayBase<struct File> Files;
typedef ArrayBase<struct CaseStatement> CaseStatements;
typedef ArrayBase<struct CompoundStatement> CompoundStatements;
typedef ArrayBase<struct GotoCaseStatement> GotoCaseStatements;
typedef ArrayBase<struct TemplateInstance> TemplateInstances;
//typedef ArrayBase<char> Strings;
typedef ArrayBase<void> Voids;
typedef ArrayBase<struct block> Blocks;
typedef ArrayBase<struct Symbol> Symbols;
#endif
+56 -54
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
@@ -70,7 +70,7 @@ int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
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);
}
@@ -101,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()
}
@@ -136,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);
}
@@ -157,7 +157,7 @@ void AttribDeclaration::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);
}
@@ -171,7 +171,7 @@ void AttribDeclaration::semantic2(Scope *sc)
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->semantic2(sc);
}
}
@@ -184,7 +184,7 @@ void AttribDeclaration::semantic3(Scope *sc)
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->semantic3(sc);
}
}
@@ -197,7 +197,7 @@ void AttribDeclaration::inlineScan()
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();
}
@@ -214,7 +214,7 @@ void AttribDeclaration::addComment(unsigned char *comment)
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);
}
@@ -239,7 +239,7 @@ void AttribDeclaration::emitComment(Scope *sc)
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);
}
@@ -255,7 +255,7 @@ void AttribDeclaration::toObjFile(int multiobj)
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->toObjFile(multiobj);
}
}
@@ -270,7 +270,7 @@ int AttribDeclaration::cvMember(unsigned char *p)
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;
@@ -289,7 +289,7 @@ int AttribDeclaration::hasPointers()
{
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;
}
@@ -316,7 +316,7 @@ void AttribDeclaration::checkCtorConstInit()
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->checkCtorConstInit();
}
}
@@ -332,7 +332,7 @@ void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses)
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
{ Dsymbol *s = d->tdata()[i];
s->addLocalClass(aclasses);
}
}
@@ -346,7 +346,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();
@@ -354,7 +354,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);
@@ -546,7 +546,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);
}
@@ -626,9 +626,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);
}
@@ -790,7 +790,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)
@@ -842,7 +842,7 @@ void AnonDeclaration::semantic(Scope *sc)
//printf("\tadding members of aad to '%s'\n", ad->toChars());
for (unsigned i = 0; i < aad.fields.dim; i++)
{
VarDeclaration *v = (VarDeclaration *)aad.fields.data[i];
VarDeclaration *v = aad.fields.tdata()[i];
#if IN_LLVM
v->offset2 = sc->offset;
@@ -883,7 +883,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);
@@ -943,15 +943,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 +981,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,18 +1003,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;
args->tdata()[0] = e;
if (e->op == TOKerror)
goto Lnodecl;
if (e->op != TOKstring)
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;
@@ -1034,7 +1035,7 @@ void PragmaDeclaration::semantic(Scope *sc)
Declaration *d = NULL;
StringExp *s = NULL;
e = (Expression *)args->data[0];
e = args->tdata()[0];
e = e->semantic(sc);
if (e->op == TOKvar)
{
@@ -1045,10 +1046,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->optimize(WANTvalue | WANTinterpret);
e = e->toString();
if (e && ((StringExp *)e)->sz == 1)
s = ((StringExp *)e);
else
error("second argument of GNU_asm must be a char string");
@@ -1066,10 +1068,10 @@ void PragmaDeclaration::semantic(Scope *sc)
error("function name expected for start address");
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;
args->tdata()[0] = e;
Dsymbol *sa = getDsymbol(e);
if (!sa || !sa->isFuncDeclaration())
error("function name expected for start address, not '%s'", e->toChars());
@@ -1220,11 +1222,11 @@ void PragmaDeclaration::semantic(Scope *sc)
{
for (size_t i = 0; i < args->dim; i++)
{
Expression *e = args->tdata()[i];
// ignore errors in ignored pragmas.
global.gag++;
unsigned errors_save = global.errors;
Expression *e = (Expression *)args->data[i];
e = e->semantic(sc);
e = e->optimize(WANTvalue | WANTinterpret);
if (i == 0)
@@ -1250,7 +1252,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);
@@ -1399,7 +1401,7 @@ void PragmaDeclaration::toObjFile(int multiobj)
{
assert(args && args->dim == 1);
Expression *e = (Expression *)args->data[0];
Expression *e = args->tdata()[0];
assert(e->op == TOKstring);
@@ -1418,7 +1420,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
@@ -1427,7 +1429,7 @@ void PragmaDeclaration::toObjFile(int multiobj)
else if (ident == Id::startaddress)
{
assert(args && args->dim == 1);
Expression *e = (Expression *)args->data[0];
Expression *e = args->tdata()[0];
Dsymbol *sa = getDsymbol(e);
FuncDeclaration *f = sa->isFuncDeclaration();
assert(f);
@@ -1500,7 +1502,7 @@ void ConditionalDeclaration::emitComment(Scope *sc)
*/
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);
}
}
@@ -1524,7 +1526,7 @@ void ConditionalDeclaration::setScope(Scope *sc)
{
for (unsigned i = 0; i < d->dim; i++)
{
Dsymbol *s = (Dsymbol *)d->data[i];
Dsymbol *s = d->tdata()[i];
s->setScope(sc);
}
@@ -1540,7 +1542,7 @@ void ConditionalDeclaration::importAll(Scope *sc)
{
for (unsigned i = 0; i < d->dim; i++)
{
Dsymbol *s = (Dsymbol *)d->data[i];
Dsymbol *s = d->tdata()[i];
s->importAll(sc);
}
@@ -1566,7 +1568,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);
}
@@ -1588,7 +1590,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);
@@ -1604,7 +1606,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);
@@ -1690,7 +1692,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);
}
@@ -1742,12 +1744,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;
+1 -1
View File
@@ -92,7 +92,7 @@ enum BUILTIN FuncDeclaration::isBuiltin()
Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments)
{
assert(arguments && arguments->dim);
Expression *arg0 = (Expression *)arguments->data[0];
Expression *arg0 = arguments->tdata()[0];
Expression *e = NULL;
switch (builtin)
{
+156 -40
View File
@@ -427,8 +427,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;
te = te->castMod(t->mod);
MATCH m2 = e->implicitConvTo(te);
@@ -442,8 +442,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());
@@ -536,8 +535,8 @@ 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
@@ -558,13 +557,13 @@ MATCH AssocArrayLiteralExp::implicitConvTo(Type *t)
if (tb->ty == Taarray && typeb->ty == Taarray)
{
for (size_t i = 0; i < keys->dim; i++)
{ Expression *e = (Expression *)keys->data[i];
{ Expression *e = keys->tdata()[i];
MATCH m = (MATCH)e->implicitConvTo(((TypeAArray *)tb)->index);
if (m < result)
result = m; // remember worst match
if (result == MATCHnomatch)
break; // no need to check for worse
e = (Expression *)values->data[i];
e = values->tdata()[i];
m = (MATCH)e->implicitConvTo(tb->nextOf());
if (m < result)
result = m; // remember worst match
@@ -577,6 +576,26 @@ MATCH AssocArrayLiteralExp::implicitConvTo(Type *t)
return Expression::implicitConvTo(t);
}
MATCH CallExp::implicitConvTo(Type *t)
{
#if 0
printf("CalLExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
toChars(), type->toChars(), t->toChars());
#endif
MATCH m = Expression::implicitConvTo(t);
if (m)
return m;
/* Allow the result of strongly pure functions to
* convert to immutable
*/
if (f && f->isPure() == PUREstrong)
return type->invariantOf()->implicitConvTo(t);
return MATCHnomatch;
}
MATCH AddrExp::implicitConvTo(Type *t)
{
#if 0
@@ -598,8 +617,8 @@ MATCH AddrExp::implicitConvTo(Type *t)
(t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction)
{ OverExp *eo = (OverExp *)e1;
FuncDeclaration *f = NULL;
for (int i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = (Dsymbol *)eo->vars->a.data[i];
for (size_t i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = eo->vars->a[i];
FuncDeclaration *f2 = s->isFuncDeclaration();
assert(f2);
if (f2->overloadExactMatch(t->nextOf(), m))
@@ -686,11 +705,10 @@ MATCH DelegateExp::implicitConvTo(Type *t)
if (result == MATCHnomatch)
{
// Look for pointers to functions where the functions are overloaded.
FuncDeclaration *f;
t = t->toBasetype();
if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction &&
t->ty == Tdelegate && t->nextOf()->ty == Tfunction)
if (type->ty == Tdelegate &&
t->ty == Tdelegate)
{
if (func && func->overloadExactMatch(t->nextOf(), m))
result = MATCHexact;
@@ -819,9 +837,9 @@ Expression *Expression::castTo(Scope *sc, Type *t)
* cast(to)e1.aliasthis
*/
Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident);
Expression *e = new CastExp(loc, e1, tb);
e = e->semantic(sc);
return e;
Expression *e2 = new CastExp(loc, e1, tb);
e2 = e2->semantic(sc);
return e2;
}
}
else if (typeb->ty == Tclass)
@@ -840,9 +858,9 @@ Expression *Expression::castTo(Scope *sc, Type *t)
* cast(to)e1.aliasthis
*/
Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident);
Expression *e = new CastExp(loc, e1, tb);
e = e->semantic(sc);
return e;
Expression *e2 = new CastExp(loc, e1, tb);
e2 = e2->semantic(sc);
return e2;
}
L1: ;
}
@@ -989,7 +1007,9 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
if (committed && tb->ty == Tsarray && typeb->ty == Tarray)
{
se = (StringExp *)copy();
se->sz = tb->nextOf()->size();
d_uns64 szx = tb->nextOf()->size();
assert(szx <= 255);
se->sz = (unsigned char)szx;
se->len = (len * sz) / se->sz;
se->committed = 1;
se->type = t;
@@ -1124,7 +1144,12 @@ 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:
@@ -1139,9 +1164,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)
@@ -1189,8 +1214,8 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
(t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction)
{ OverExp *eo = (OverExp *)e1;
FuncDeclaration *f = NULL;
for (int i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = (Dsymbol *)eo->vars->a.data[i];
for (size_t i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = eo->vars->a[i];
FuncDeclaration *f2 = s->isFuncDeclaration();
assert(f2);
if (f2->overloadExactMatch(t->nextOf(), m))
@@ -1297,9 +1322,9 @@ Expression *TupleExp::castTo(Scope *sc, Type *t)
{ TupleExp *e = (TupleExp *)copy();
e->exps = (Expressions *)exps->copy();
for (size_t i = 0; i < e->exps->dim; i++)
{ Expression *ex = (Expression *)e->exps->data[i];
{ Expression *ex = e->exps->tdata()[i];
ex = ex->castTo(sc, t);
e->exps->data[i] = (void *)ex;
e->exps->tdata()[i] = ex;
}
return e;
}
@@ -1329,10 +1354,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;
@@ -1364,18 +1389,17 @@ Expression *AssocArrayLiteralExp::castTo(Scope *sc, Type *t)
e->values = (Expressions *)values->copy();
assert(keys->dim == values->dim);
for (size_t i = 0; i < keys->dim; i++)
{ Expression *ex = (Expression *)values->data[i];
{ Expression *ex = values->tdata()[i];
ex = ex->castTo(sc, tb->nextOf());
e->values->data[i] = (void *)ex;
e->values->tdata()[i] = ex;
ex = (Expression *)keys->data[i];
ex = keys->tdata()[i];
ex = ex->castTo(sc, ((TypeAArray *)tb)->index);
e->keys->data[i] = (void *)ex;
e->keys->tdata()[i] = ex;
}
e->type = t;
return e;
}
L1:
return e->Expression::castTo(sc, t);
}
@@ -1464,8 +1488,8 @@ Expression *DelegateExp::castTo(Scope *sc, Type *t)
// Look for delegates to functions where the functions are overloaded.
FuncDeclaration *f;
if (typeb->ty == Tdelegate && typeb->nextOf()->ty == Tfunction &&
tb->ty == Tdelegate && tb->nextOf()->ty == Tfunction)
if (typeb->ty == Tdelegate &&
tb->ty == Tdelegate)
{
if (func)
{
@@ -1600,7 +1624,7 @@ bool isVoidArrayLiteral(Expression *e, Type *other)
while (e->op == TOKarrayliteral && e->type->ty == Tarray
&& (((ArrayLiteralExp *)e)->elements->dim == 1))
{
e = (Expression *)((ArrayLiteralExp *)e)->elements->data[0];
e = ((ArrayLiteralExp *)e)->elements->tdata()[0];
if (other->ty == Tsarray || other->ty == Tarray)
other = other->nextOf();
else
@@ -1712,6 +1736,41 @@ Lagain:
t = t2;
else if (t2n->ty == Tvoid)
;
else if (t1n->ty == Tfunction && t2n->ty == Tfunction)
{
if (t1->implicitConvTo(t2))
goto Lt2;
if (t2->implicitConvTo(t1))
goto Lt1;
TypeFunction *tf1 = (TypeFunction *)t1n;
TypeFunction *tf2 = (TypeFunction *)t2n;
TypeFunction *d = (TypeFunction *)tf1->syntaxCopy();
if (tf1->purity != tf2->purity)
d->purity = PUREimpure;
assert(d->purity != PUREfwdref);
d->isnothrow = (tf1->isnothrow && tf2->isnothrow);
if (tf1->trust == tf2->trust)
d->trust = tf1->trust;
else if (tf1->trust <= TRUSTsystem || tf2->trust <= TRUSTsystem)
d->trust = TRUSTsystem;
else
d->trust = TRUSTtrusted;
Type *tx = d->pointerTo();
if (t1->implicitConvTo(tx) && t2->implicitConvTo(tx))
{
t = tx;
e1 = e1->castTo(sc, t);
e2 = e2->castTo(sc, t);
goto Lret;
}
goto Lincompatible;
}
else if (t1n->mod != t2n->mod)
{
t1 = t1n->mutableOf()->constOf()->pointerTo();
@@ -1851,14 +1910,71 @@ Lagain:
else
goto Lincompatible;
}
else if (t1->ty == Tstruct && ((TypeStruct *)t1)->sym->aliasthis)
{
e1 = new DotIdExp(e1->loc, e1, ((TypeStruct *)t1)->sym->aliasthis->ident);
e1 = e1->semantic(sc);
e1 = resolveProperties(sc, e1);
t1 = e1->type;
continue;
}
else if (t2->ty == Tstruct && ((TypeStruct *)t2)->sym->aliasthis)
{
e2 = new DotIdExp(e2->loc, e2, ((TypeStruct *)t2)->sym->aliasthis->ident);
e2 = e2->semantic(sc);
e2 = resolveProperties(sc, e2);
t2 = e2->type;
continue;
}
else
goto Lincompatible;
}
}
else if (t1->ty == Tstruct && t2->ty == Tstruct)
{
if (((TypeStruct *)t1)->sym != ((TypeStruct *)t2)->sym)
goto Lincompatible;
TypeStruct *ts1 = (TypeStruct *)t1;
TypeStruct *ts2 = (TypeStruct *)t2;
if (ts1->sym != ts2->sym)
{
if (!ts1->sym->aliasthis && !ts2->sym->aliasthis)
goto Lincompatible;
int i1 = 0;
int i2 = 0;
Expression *e1b = NULL;
Expression *e2b = NULL;
if (ts2->sym->aliasthis)
{
e2b = new DotIdExp(e2->loc, e2, ts2->sym->aliasthis->ident);
e2b = e2b->semantic(sc);
e2b = resolveProperties(sc, e2b);
i1 = e2b->implicitConvTo(t1);
}
if (ts1->sym->aliasthis)
{
e1b = new DotIdExp(e1->loc, e1, ts1->sym->aliasthis->ident);
e1b = e1b->semantic(sc);
e1b = resolveProperties(sc, e1b);
i2 = e1b->implicitConvTo(t2);
}
assert(!(i1 && i2));
if (i1)
goto Lt1;
else if (i2)
goto Lt2;
if (e1b)
{ e1 = e1b;
t1 = e1b->type->toBasetype();
}
if (e2b)
{ e2 = e2b;
t2 = e2b->type->toBasetype();
}
goto Lagain;
}
}
else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2))
{
+61 -67
View File
@@ -232,11 +232,11 @@ 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 *b = this->baseclasses->tdata()[i];
BaseClass *b2 = new BaseClass(b->type->syntaxCopy(), b->protection);
cd->baseclasses->data[i] = b2;
cd->baseclasses->tdata()[i] = b2;
}
ScopeDsymbol::syntaxCopy(cd);
@@ -244,9 +244,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);
@@ -300,8 +298,8 @@ void ClassDeclaration::semantic(Scope *sc)
error("cannot create C++ classes");
// Expand any tuples in baseclasses[]
for (i = 0; i < baseclasses->dim; )
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
for (size_t i = 0; i < baseclasses->dim; )
{ BaseClass *b = baseclasses->tdata()[i];
//printf("test1 %s %s\n", toChars(), b->type->toChars());
b->type = b->type->semantic(loc, sc);
//printf("test2\n");
@@ -328,7 +326,7 @@ void ClassDeclaration::semantic(Scope *sc)
BaseClass *b;
Type *tb;
b = (BaseClass *)baseclasses->data[0];
b = baseclasses->tdata()[0];
//b->type = b->type->semantic(loc, sc);
tb = b->type->toBasetype();
if (tb->ty != Tclass)
@@ -392,12 +390,12 @@ 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;
b = (BaseClass *)baseclasses->data[i];
b = baseclasses->tdata()[i];
b->type = b->type->semantic(loc, sc);
tb = b->type->toBasetype();
if (tb->ty == Tclass)
@@ -426,7 +424,7 @@ void ClassDeclaration::semantic(Scope *sc)
// Check for duplicate interfaces
for (size_t j = (baseClass ? 1 : 0); j < i; j++)
{
BaseClass *b2 = (BaseClass *)baseclasses->data[j];
BaseClass *b2 = baseclasses->tdata()[j];
if (b2->base == tc->sym)
error("inherits from duplicate interface %s", b2->base->toChars());
}
@@ -480,7 +478,7 @@ void ClassDeclaration::semantic(Scope *sc)
}
interfaces_dim = baseclasses->dim;
interfaces = (BaseClass **)baseclasses->data;
interfaces = baseclasses->tdata();
if (baseClass)
@@ -493,7 +491,7 @@ void ClassDeclaration::semantic(Scope *sc)
// Copy vtbl[] from base class
vtbl.setDim(baseClass->vtbl.dim);
memcpy(vtbl.data, baseClass->vtbl.data, sizeof(void *) * vtbl.dim);
memcpy(vtbl.tdata(), baseClass->vtbl.tdata(), sizeof(void *) * vtbl.dim);
// Inherit properties from base class
com = baseClass->isCOMclass();
@@ -515,9 +513,9 @@ 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];
Dsymbol *s = members->tdata()[i];
s->addMember(sc, this, 1);
}
@@ -561,9 +559,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 = Type::tvoidptr;
@@ -629,14 +627,14 @@ 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++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = members->tdata()[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
*/
@@ -647,8 +645,8 @@ void ClassDeclaration::semantic(Scope *sc)
}
}
for (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->semantic(sc);
}
@@ -724,9 +722,9 @@ 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];
BaseClass *b = vtblInterfaces->tdata()[i];
unsigned thissize = PTRSIZE;
alignmember(structalign, thissize, &sc->offset);
@@ -760,7 +758,7 @@ void ClassDeclaration::semantic(Scope *sc)
// Fill in base class vtbl[]s
for (i = 0; i < vtblInterfaces->dim; i++)
{
BaseClass *b = (BaseClass *)vtblInterfaces->data[i];
BaseClass *b = vtblInterfaces->tdata()[i];
//b->fillVtbl(this, &b->vtbl, 1);
}
@@ -783,9 +781,9 @@ 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];
BaseClass *b = baseclasses->tdata()[i];
if (i)
buf->writeByte(',');
@@ -797,9 +795,9 @@ 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];
Dsymbol *s = members->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -833,8 +831,8 @@ 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++)
{ BaseClass *b = (BaseClass *)cd->baseclasses->data[i];
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{ BaseClass *b = cd->baseclasses->tdata()[i];
if (b->base == this || isBaseOf2(b->base))
return 1;
@@ -879,8 +877,8 @@ int ClassDeclaration::isBaseInfoComplete()
{
if (!baseClass)
return ident == Id::Object;
for (int i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = baseclasses->tdata()[i];
if (!b->base || !b->base->isBaseInfoComplete())
return 0;
}
@@ -911,11 +909,9 @@ 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];
BaseClass *b = baseclasses->tdata()[i];
if (b->base)
{
@@ -962,9 +958,9 @@ int ClassDeclaration::isFuncHidden(FuncDeclaration *fd)
OverloadSet *os = s->isOverloadSet();
if (os)
{
for (int i = 0; i < os->a.dim; i++)
{ Dsymbol *s = (Dsymbol *)os->a.data[i];
FuncDeclaration *f2 = s->isFuncDeclaration();
for (size_t i = 0; i < os->a.dim; i++)
{ Dsymbol *s2 = os->a.tdata()[i];
FuncDeclaration *f2 = s2->isFuncDeclaration();
if (f2 && overloadApply(getModule(), f2, &isf, fd))
return 0;
}
@@ -989,12 +985,12 @@ FuncDeclaration *ClassDeclaration::findFunc(Identifier *ident, TypeFunction *tf)
//printf("ClassDeclaration::findFunc(%s, %s) %s\n", ident->toChars(), tf->toChars(), toChars());
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->tdata()[i]->isFuncDeclaration();
if (!fd)
continue; // the first entry might be a ClassInfo
@@ -1069,9 +1065,9 @@ 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();
FuncDeclaration *fd = vtbl.tdata()[i]->isFuncDeclaration();
//printf("\tvtbl[%d] = %p\n", i, fd);
if (!fd || fd->isAbstract())
@@ -1139,8 +1135,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;
@@ -1177,8 +1172,8 @@ void InterfaceDeclaration::semantic(Scope *sc)
}
// Expand any tuples in baseclasses[]
for (i = 0; i < baseclasses->dim; )
{ BaseClass *b = (BaseClass *)baseclasses->data[0];
for (size_t i = 0; i < baseclasses->dim; )
{ BaseClass *b = baseclasses->tdata()[0];
b->type = b->type->semantic(loc, sc);
Type *tb = b->type->toBasetype();
@@ -1201,12 +1196,12 @@ void InterfaceDeclaration::semantic(Scope *sc)
cpp = 1;
// 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;
b = (BaseClass *)baseclasses->data[i];
b = baseclasses->tdata()[i];
b->type = b->type->semantic(loc, sc);
tb = b->type->toBasetype();
if (tb->ty == Tclass)
@@ -1224,7 +1219,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
// Check for duplicate interfaces
for (size_t j = 0; j < i; j++)
{
BaseClass *b2 = (BaseClass *)baseclasses->data[j];
BaseClass *b2 = baseclasses->tdata()[j];
if (b2->base == tc->sym)
error("inherits from duplicate interface %s", b2->base->toChars());
}
@@ -1260,7 +1255,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
}
interfaces_dim = baseclasses->dim;
interfaces = (BaseClass **)baseclasses->data;
interfaces = baseclasses->tdata();
interfaceSemantic(sc);
@@ -1268,7 +1263,7 @@ 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
@@ -1285,7 +1280,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
{
vtbl.reserve(d - 1);
for (int j = 1; j < d; j++)
vtbl.push(b->base->vtbl.data[j]);
vtbl.push(b->base->vtbl.tdata()[j]);
}
}
else
@@ -1300,9 +1295,9 @@ void InterfaceDeclaration::semantic(Scope *sc)
protection = sc->protection;
storage_class |= sc->stc & STC_TYPECTOR;
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->tdata()[i];
s->addMember(sc, this, 1);
}
@@ -1319,9 +1314,9 @@ void InterfaceDeclaration::semantic(Scope *sc)
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->tdata()[i];
s->semantic(sc);
}
inuse--;
@@ -1414,8 +1409,8 @@ int InterfaceDeclaration::isBaseOf(BaseClass *bc, int *poffset)
int InterfaceDeclaration::isBaseInfoComplete()
{
assert(!baseClass);
for (int i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = baseclasses->tdata()[i];
if (!b->base || !b->base->isBaseInfoComplete ())
return 0;
}
@@ -1487,10 +1482,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());
@@ -1498,9 +1492,9 @@ 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 *ifd = base->vtbl.tdata()[j]->isFuncDeclaration();
FuncDeclaration *fd;
TypeFunction *tf;
@@ -1537,7 +1531,7 @@ int BaseClass::fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance)
fd = NULL;
}
if (vtbl)
vtbl->data[j] = fd;
vtbl->tdata()[j] = fd;
}
return result;
+16 -17
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,7 +44,7 @@ int StructDeclaration::needOpAssign()
*/
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
Dsymbol *s = fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
if (v->storage_class & STCref)
@@ -87,7 +87,7 @@ int StructDeclaration::needOpEquals()
*/
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
Dsymbol *s = fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
if (v->storage_class & STCref)
@@ -104,7 +104,6 @@ int StructDeclaration::needOpEquals()
goto Lneed;
}
}
Ldontneed:
if (X) printf("\tdontneed\n");
return 0;
@@ -185,9 +184,9 @@ FuncDeclaration *StructDeclaration::buildOpAssign(Scope *sc)
/* Instead of running the destructor on s, run it
* on tmp. This avoids needing to copy tmp back in to s.
*/
Expression *ec = new DotVarExp(0, new VarExp(0, tmp), dtor, 0);
ec = new CallExp(0, ec);
e = Expression::combine(e, ec);
Expression *ec2 = new DotVarExp(0, new VarExp(0, tmp), dtor, 0);
ec2 = new CallExp(0, ec2);
e = Expression::combine(e, ec2);
}
}
else
@@ -196,7 +195,7 @@ FuncDeclaration *StructDeclaration::buildOpAssign(Scope *sc)
//printf("\tmemberwise copy\n");
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
Dsymbol *s = fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
// this.v = s.v;
@@ -267,7 +266,7 @@ FuncDeclaration *StructDeclaration::buildOpEquals(Scope *sc)
//printf("\tmemberwise compare\n");
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
Dsymbol *s = fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
if (v->storage_class & STCref)
@@ -390,13 +389,13 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
Dsymbol *s = fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
size_t dim = (tv->ty == Tsarray ? 1 : 0);
dinteger_t dim = (tv->ty == Tsarray ? 1 : 0);
while (tv->ty == Tsarray)
{ TypeSArray *ta = (TypeSArray *)tv;
dim *= ((TypeSArray *)tv)->dim->toInteger();
@@ -458,12 +457,12 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)
return NULL;
case 1:
return (FuncDeclaration *)postblits.data[0];
return postblits.tdata()[0];
default:
e = NULL;
for (size_t i = 0; i < postblits.dim; i++)
{ FuncDeclaration *fd = (FuncDeclaration *)postblits.data[i];
{ FuncDeclaration *fd = postblits.tdata()[i];
stc |= fd->storage_class & STCdisable;
if (stc & STCdisable)
{
@@ -502,13 +501,13 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
#if DMDV2
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
Dsymbol *s = fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
size_t dim = (tv->ty == Tsarray ? 1 : 0);
dinteger_t dim = (tv->ty == Tsarray ? 1 : 0);
while (tv->ty == Tsarray)
{ TypeSArray *ta = (TypeSArray *)tv;
dim *= ((TypeSArray *)tv)->dim->toInteger();
@@ -563,12 +562,12 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
return NULL;
case 1:
return (FuncDeclaration *)dtors.data[0];
return dtors.tdata()[0];
default:
e = NULL;
for (size_t i = 0; i < dtors.dim; i++)
{ FuncDeclaration *fd = (FuncDeclaration *)dtors.data[i];
{ FuncDeclaration *fd = dtors.tdata()[i];
Expression *ex = new ThisExp(0);
ex = new DotVarExp(0, ex, fd, 0);
ex = new CallExp(0, ex);
+13 -13
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
@@ -23,13 +23,13 @@
#include "mtype.h"
#include "scope.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->tdata()[i];
if (strcmp(id, ident->toChars()) == 0)
return TRUE;
@@ -72,8 +72,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);
}
@@ -96,7 +96,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());
}
}
@@ -173,8 +173,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 +199,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());
}
}
@@ -327,19 +327,19 @@ int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
TemplateParameters parameters;
parameters.setDim(1);
parameters.data[0] = (void *)&tp;
parameters.tdata()[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.tdata()[0];
if (!tded)
tded = targ;
Dsymbol *s = new AliasDeclaration(loc, id, tded);
+1 -1
View File
@@ -22,7 +22,7 @@ struct DebugCondition;
enum TOK;
struct HdrGenState;
int findCondition(Array *ids, Identifier *ident);
int findCondition(Strings *ids, Identifier *ident);
struct Condition
{
+46 -35
View File
@@ -534,6 +534,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
@@ -556,7 +571,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:
@@ -606,18 +623,20 @@ 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
// Possible only with >>>=. >>> always gets promoted to int.
value = (value & 0xFF) >> count;
break;
case Tint16:
case Tuns16:
assert(0); // no way to trigger this
// Possible only with >>>=. >>> always gets promoted to int.
value = (value & 0xFFFF) >> count;
break;
@@ -730,8 +749,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)
@@ -744,9 +763,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)
@@ -760,10 +779,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());
@@ -789,8 +809,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;
@@ -1187,7 +1207,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);
@@ -1252,8 +1272,8 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
if (i >= es1->len)
e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len);
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)
@@ -1266,7 +1286,7 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
}
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;
@@ -1282,7 +1302,7 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
{ e1->error("array index %ju is out of bounds %s[0 .. %u]", i, e1->toChars(), ale->elements->dim);
}
else
{ e = (Expression *)ale->elements->data[i];
{ e = ale->elements->tdata()[i];
e->type = type;
if (e->checkSideEffect(2))
e = EXP_CANT_INTERPRET;
@@ -1297,12 +1317,12 @@ 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;
@@ -1335,7 +1355,7 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
if (iupr > es1->len || ilwr > iupr)
e1->error("string slice [%ju .. %ju] is out of bounds", ilwr, iupr);
else
{ dinteger_t value;
{
void *s;
size_t len = iupr - ilwr;
int sz = es1->sz;
@@ -1365,9 +1385,9 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
{
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;
}
@@ -1447,7 +1467,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;
@@ -1469,10 +1488,6 @@ 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;
}
@@ -1487,8 +1502,8 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
void *s = mem.malloc((len + 1) * sz);
memcpy((char *)s + sz * es2->elements->dim, es1->string, es1->len * sz);
for (int i = 0; i < es2->elements->dim; i++)
{ Expression *es2e = (Expression *)es2->elements->data[i];
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();
@@ -1515,8 +1530,8 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
void *s = mem.malloc((len + 1) * sz);
memcpy(s, es1->string, es1->len * sz);
for (int i = 0; i < es2->elements->dim; i++)
{ Expression *es2e = (Expression *)es2->elements->data[i];
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();
@@ -1538,7 +1553,6 @@ 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();
@@ -1561,7 +1575,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;
}
@@ -1571,7 +1584,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();
@@ -1586,7 +1598,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;
}
+5 -5
View File
@@ -40,14 +40,14 @@
struct CppMangleState
{
static Array components;
static Voids components;
int substitute(OutBuffer *buf, void *p);
int exist(void *p);
void store(void *p);
};
Array CppMangleState::components;
Voids CppMangleState::components;
void writeBase36(OutBuffer *buf, unsigned i)
@@ -69,7 +69,7 @@ int CppMangleState::substitute(OutBuffer *buf, void *p)
{
for (size_t i = 0; i < components.dim; i++)
{
if (p == components.data[i])
if (p == components.tdata()[i])
{
/* Sequence is S_, S0_, .., S9_, SA_, ..., SZ_, S10_, ...
*/
@@ -88,7 +88,7 @@ int CppMangleState::exist(void *p)
{
for (size_t i = 0; i < components.dim; i++)
{
if (p == components.data[i])
if (p == components.tdata()[i])
{
return 1;
}
@@ -409,7 +409,7 @@ void Parameter::argsCppMangle(OutBuffer *buf, CppMangleState *cms, Parameters *a
if (arguments)
{
for (size_t i = 0; i < arguments->dim; i++)
{ Parameter *arg = (Parameter *)arguments->data[i];
{ Parameter *arg = arguments->tdata()[i];
Type *t = arg->type;
if (arg->storageClass & (STCout | STCref))
t = t->referenceTo();
+221 -58
View File
@@ -83,6 +83,7 @@ enum PROT Declaration::prot()
*/
#if DMDV2
void Declaration::checkModify(Loc loc, Scope *sc, Type *t)
{
if (sc->incontract && isParameter())
@@ -91,40 +92,10 @@ void Declaration::checkModify(Loc loc, Scope *sc, Type *t)
if (sc->incontract && isResult())
error(loc, "cannot modify result '%s' in contract", toChars());
if (isCtorinit() && !t->isMutable())
if (isCtorinit() && !t->isMutable() ||
(storage_class & STCnodefaultctor))
{ // It's only modifiable if inside the right constructor
Dsymbol *s = sc->func;
while (1)
{
FuncDeclaration *fd = NULL;
if (s)
fd = s->isFuncDeclaration();
if (fd &&
((fd->isCtorDeclaration() && storage_class & STCfield) ||
(fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) &&
fd->toParent() == toParent()
)
{
VarDeclaration *v = isVarDeclaration();
assert(v);
v->ctorinit = 1;
//printf("setting ctorinit\n");
}
else
{
if (s)
{ s = s->toParent2();
continue;
}
else
{
const char *p = isStatic() ? "static " : "";
error(loc, "can only initialize %sconst %s inside %sconstructor",
p, toChars(), p);
}
}
break;
}
modifyFieldVar(loc, sc, isVarDeclaration(), NULL);
}
else
{
@@ -185,7 +156,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->tdata()[i];
if (o->dyncast() != DYNCAST_TYPE)
{
@@ -196,12 +167,13 @@ Type *TupleDeclaration::getType()
/* We know it's a type tuple, so build the TypeTuple
*/
Types *types = (Types *)objects;
Parameters *args = new Parameters();
args->setDim(objects->dim);
OutBuffer buf;
int hasdeco = 1;
for (size_t i = 0; i < objects->dim; i++)
{ Type *t = (Type *)objects->data[i];
for (size_t i = 0; i < types->dim; i++)
{ Type *t = types->tdata()[i];
//printf("type = %s\n", t->toChars());
#if 0
@@ -212,7 +184,7 @@ Type *TupleDeclaration::getType()
#else
Parameter *arg = new Parameter(0, t, NULL, NULL);
#endif
args->data[i] = (void *)arg;
args->tdata()[i] = arg;
if (!t->deco)
hasdeco = 0;
}
@@ -229,7 +201,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->tdata()[i];
if (o->dyncast() == DYNCAST_EXPRESSION)
{ Expression *e = (Expression *)o;
if (e->op == TOKdsymbol)
@@ -753,7 +725,7 @@ void VarDeclaration::semantic(Scope *sc)
printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars());
printf(" type = %s\n", type ? type->toChars() : "null");
printf(" stc = x%x\n", sc->stc);
printf(" storage_class = x%x\n", storage_class);
printf(" storage_class = x%llx\n", storage_class);
printf("linkage = %d\n", sc->linkage);
//if (strcmp(toChars(), "mul") == 0) halt();
#endif
@@ -854,8 +826,8 @@ void VarDeclaration::semantic(Scope *sc)
Dsymbol *s = type->toDsymbol(sc);
if (s)
{
AggregateDeclaration *ad = s->isAggregateDeclaration();
if (ad && ad->hasUnions)
AggregateDeclaration *ad2 = s->isAggregateDeclaration();
if (ad2 && ad2->hasUnions)
{
if (sc->func->setUnsafe())
error("unions containing pointers are not allowed in @safe functions");
@@ -899,6 +871,103 @@ void VarDeclaration::semantic(Scope *sc)
Objects *exps = new Objects();
exps->setDim(nelems);
Expression *ie = init ? init->toExpression() : NULL;
if (ie) ie = ie->semantic(sc);
if (nelems > 0 && ie)
{
Expressions *iexps = new Expressions();
iexps->push(ie);
Expressions *exps = new Expressions();
for (size_t pos = 0; pos < iexps->dim; pos++)
{
Lexpand1:
Expression *e = iexps->tdata()[pos];
Parameter *arg = Parameter::getNth(tt->arguments, pos);
arg->type = arg->type->semantic(loc, sc);
//printf("[%d] iexps->dim = %d, ", pos, iexps->dim);
//printf("e = (%s %s, %s), ", Token::tochars[e->op], e->toChars(), e->type->toChars());
//printf("arg = (%s, %s)\n", arg->toChars(), arg->type->toChars());
if (e != ie)
{
if (iexps->dim > nelems)
goto Lnomatch;
if (e->type->implicitConvTo(arg->type))
continue;
}
if (e->op == TOKtuple)
{
TupleExp *te = (TupleExp *)e;
if (iexps->dim - 1 + te->exps->dim > nelems)
goto Lnomatch;
iexps->remove(pos);
iexps->insert(pos, te->exps);
goto Lexpand1;
}
else if (isAliasThisTuple(e))
{
Identifier *id = Lexer::uniqueId("__tup");
ExpInitializer *ei = new ExpInitializer(e->loc, e);
VarDeclaration *v = new VarDeclaration(loc, NULL, id, ei);
v->storage_class = STCctfe | STCref | STCforeach;
VarExp *ve = new VarExp(loc, v);
ve->type = e->type;
exps->setDim(1);
(*exps)[0] = ve;
expandAliasThisTuples(exps, 0);
for (size_t u = 0; u < exps->dim ; u++)
{
Lexpand2:
Expression *ee = (*exps)[u];
Parameter *arg = Parameter::getNth(tt->arguments, pos + u);
arg->type = arg->type->semantic(loc, sc);
//printf("[%d+%d] exps->dim = %d, ", pos, u, exps->dim);
//printf("ee = (%s %s, %s), ", Token::tochars[ee->op], ee->toChars(), ee->type->toChars());
//printf("arg = (%s, %s)\n", arg->toChars(), arg->type->toChars());
size_t iexps_dim = iexps->dim - 1 + exps->dim;
if (iexps_dim > nelems)
goto Lnomatch;
if (ee->type->implicitConvTo(arg->type))
continue;
if (expandAliasThisTuples(exps, u) != -1)
goto Lexpand2;
}
if ((*exps)[0] != ve)
{
Expression *e0 = (*exps)[0];
(*exps)[0] = new CommaExp(loc, new DeclarationExp(loc, v), e0);
(*exps)[0]->type = e0->type;
iexps->remove(pos);
iexps->insert(pos, exps);
goto Lexpand1;
}
}
}
if (iexps->dim < nelems)
goto Lnomatch;
ie = new TupleExp(init->loc, iexps);
}
Lnomatch:
if (ie && ie->op == TOKtuple)
{ size_t tedim = ((TupleExp *)ie)->exps->dim;
if (tedim != nelems)
{ ::error(loc, "tuple of %d elements cannot be assigned to tuple of %d elements", (int)tedim, (int)nelems);
for (size_t u = tedim; u < nelems; u++) // fill dummy expression
((TupleExp *)ie)->exps->push(new ErrorExp());
}
}
for (size_t i = 0; i < nelems; i++)
{ Parameter *arg = Parameter::getNth(tt->arguments, i);
@@ -911,7 +980,7 @@ void VarDeclaration::semantic(Scope *sc)
Expression *einit = ie;
if (ie && ie->op == TOKtuple)
{ einit = (Expression *)((TupleExp *)ie)->exps->data[i];
{ einit = ((TupleExp *)ie)->exps->tdata()[i];
}
Initializer *ti = init;
if (einit)
@@ -932,7 +1001,7 @@ void VarDeclaration::semantic(Scope *sc)
}
#endif
Expression *e = new DsymbolExp(loc, v);
exps->data[i] = e;
exps->tdata()[i] = e;
}
TupleDeclaration *v2 = new TupleDeclaration(loc, ident, exps);
v2->isexp = 1;
@@ -940,7 +1009,6 @@ void VarDeclaration::semantic(Scope *sc)
return;
}
Lagain:
/* Storage class can modify the type
*/
type = type->addStorageClass(storage_class);
@@ -991,12 +1059,19 @@ Lagain:
if (storage_class & (STCconst | STCimmutable) && init)
{
if (!type->toBasetype()->isTypeBasic())
if (!tb->isTypeBasic())
storage_class |= STCstatic;
}
else
#endif
{
aad->addField(sc, this);
if (tb->ty == Tstruct && ((TypeStruct *)tb)->sym->noDefaultCtor ||
tb->ty == Tclass && ((TypeClass *)tb)->sym->noDefaultCtor)
aad->noDefaultCtor = TRUE;
}
#else
aad->addField(sc, this);
#endif
}
InterfaceDeclaration *id = parent->isInterfaceDeclaration();
@@ -1020,10 +1095,10 @@ Lagain:
}
// 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());
}
}
}
@@ -1041,6 +1116,21 @@ Lagain:
{
error("only fields, parameters or stack based variables can be inout");
}
if (!(storage_class & (STCctfe | STCref)) && tb->ty == Tstruct &&
((TypeStruct *)tb)->sym->noDefaultCtor)
{
if (!init)
{ if (storage_class & STCfield)
/* For fields, we'll check the constructor later to make sure it is initialized
*/
storage_class |= STCnodefaultctor;
else if (storage_class & STCparameter)
;
else
error("initializer required for type %s", type->toChars());
}
}
#endif
if (type->isscope() && !noscope)
@@ -1173,7 +1263,7 @@ Lagain:
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)
{
@@ -1335,15 +1425,15 @@ Lagain:
* because the postblit doesn't get run on the initialization of w.
*/
Type *tb = e->type->toBasetype();
if (tb->ty == Tstruct)
{ StructDeclaration *sd = ((TypeStruct *)tb)->sym;
Type *tb2 = e->type->toBasetype();
if (tb2->ty == Tstruct)
{ StructDeclaration *sd = ((TypeStruct *)tb2)->sym;
Type *typeb = type->toBasetype();
/* Look to see if initializer involves a copy constructor
* (which implies a postblit)
*/
if (sd->cpctor && // there is a copy constructor
typeb->equals(tb)) // rvalue is the same struct
typeb->equals(tb2)) // rvalue is the same struct
{
// The only allowable initializer is a (non-copy) constructor
if (e->op == TOKcall)
@@ -1571,8 +1661,8 @@ void VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
if (loc.filename)
fdthis->getLevel(loc, fdv);
for (int i = 0; i < nestedrefs.dim; i++)
{ FuncDeclaration *f = (FuncDeclaration *)nestedrefs.data[i];
for (size_t i = 0; i < nestedrefs.dim; i++)
{ FuncDeclaration *f = nestedrefs.tdata()[i];
if (f == fdthis)
goto L1;
}
@@ -1580,8 +1670,8 @@ void VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
L1: ;
for (int i = 0; i < fdv->closureVars.dim; i++)
{ Dsymbol *s = (Dsymbol *)fdv->closureVars.data[i];
for (size_t i = 0; i < fdv->closureVars.dim; i++)
{ Dsymbol *s = fdv->closureVars.tdata()[i];
if (s == this)
goto L2;
}
@@ -1834,6 +1924,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 ****************************/
@@ -1905,6 +2004,10 @@ void TypeInfoDeclaration::semantic(Scope *sc)
TypeInfoConstDeclaration::TypeInfoConstDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoconst)
{
ObjectNotFound(Id::TypeInfo_Const);
}
type = Type::typeinfoconst->type;
}
#endif
@@ -1915,6 +2018,10 @@ TypeInfoConstDeclaration::TypeInfoConstDeclaration(Type *tinfo)
TypeInfoInvariantDeclaration::TypeInfoInvariantDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoinvariant)
{
ObjectNotFound(Id::TypeInfo_Invariant);
}
type = Type::typeinfoinvariant->type;
}
#endif
@@ -1925,6 +2032,10 @@ TypeInfoInvariantDeclaration::TypeInfoInvariantDeclaration(Type *tinfo)
TypeInfoSharedDeclaration::TypeInfoSharedDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoshared)
{
ObjectNotFound(Id::TypeInfo_Shared);
}
type = Type::typeinfoshared->type;
}
#endif
@@ -1935,6 +2046,10 @@ TypeInfoSharedDeclaration::TypeInfoSharedDeclaration(Type *tinfo)
TypeInfoWildDeclaration::TypeInfoWildDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfowild)
{
ObjectNotFound(Id::TypeInfo_Wild);
}
type = Type::typeinfowild->type;
}
#endif
@@ -1944,6 +2059,10 @@ TypeInfoWildDeclaration::TypeInfoWildDeclaration(Type *tinfo)
TypeInfoStructDeclaration::TypeInfoStructDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfostruct)
{
ObjectNotFound(Id::TypeInfo_Struct);
}
type = Type::typeinfostruct->type;
}
@@ -1952,6 +2071,10 @@ TypeInfoStructDeclaration::TypeInfoStructDeclaration(Type *tinfo)
TypeInfoClassDeclaration::TypeInfoClassDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoclass)
{
ObjectNotFound(Id::TypeInfo_Class);
}
type = Type::typeinfoclass->type;
}
@@ -1960,6 +2083,10 @@ TypeInfoClassDeclaration::TypeInfoClassDeclaration(Type *tinfo)
TypeInfoInterfaceDeclaration::TypeInfoInterfaceDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfointerface)
{
ObjectNotFound(Id::TypeInfo_Interface);
}
type = Type::typeinfointerface->type;
}
@@ -1968,6 +2095,10 @@ TypeInfoInterfaceDeclaration::TypeInfoInterfaceDeclaration(Type *tinfo)
TypeInfoTypedefDeclaration::TypeInfoTypedefDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfotypedef)
{
ObjectNotFound(Id::TypeInfo_Typedef);
}
type = Type::typeinfotypedef->type;
}
@@ -1976,6 +2107,10 @@ TypeInfoTypedefDeclaration::TypeInfoTypedefDeclaration(Type *tinfo)
TypeInfoPointerDeclaration::TypeInfoPointerDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfopointer)
{
ObjectNotFound(Id::TypeInfo_Pointer);
}
type = Type::typeinfopointer->type;
}
@@ -1984,6 +2119,10 @@ TypeInfoPointerDeclaration::TypeInfoPointerDeclaration(Type *tinfo)
TypeInfoArrayDeclaration::TypeInfoArrayDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoarray)
{
ObjectNotFound(Id::TypeInfo_Array);
}
type = Type::typeinfoarray->type;
}
@@ -1992,6 +2131,10 @@ TypeInfoArrayDeclaration::TypeInfoArrayDeclaration(Type *tinfo)
TypeInfoStaticArrayDeclaration::TypeInfoStaticArrayDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfostaticarray)
{
ObjectNotFound(Id::TypeInfo_StaticArray);
}
type = Type::typeinfostaticarray->type;
}
@@ -2000,6 +2143,10 @@ TypeInfoStaticArrayDeclaration::TypeInfoStaticArrayDeclaration(Type *tinfo)
TypeInfoAssociativeArrayDeclaration::TypeInfoAssociativeArrayDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoassociativearray)
{
ObjectNotFound(Id::TypeInfo_AssociativeArray);
}
type = Type::typeinfoassociativearray->type;
}
@@ -2008,6 +2155,10 @@ TypeInfoAssociativeArrayDeclaration::TypeInfoAssociativeArrayDeclaration(Type *t
TypeInfoEnumDeclaration::TypeInfoEnumDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoenum)
{
ObjectNotFound(Id::TypeInfo_Enum);
}
type = Type::typeinfoenum->type;
}
@@ -2016,6 +2167,10 @@ TypeInfoEnumDeclaration::TypeInfoEnumDeclaration(Type *tinfo)
TypeInfoFunctionDeclaration::TypeInfoFunctionDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfofunction)
{
ObjectNotFound(Id::TypeInfo_Function);
}
type = Type::typeinfofunction->type;
}
@@ -2024,6 +2179,10 @@ TypeInfoFunctionDeclaration::TypeInfoFunctionDeclaration(Type *tinfo)
TypeInfoDelegateDeclaration::TypeInfoDelegateDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfodelegate)
{
ObjectNotFound(Id::TypeInfo_Delegate);
}
type = Type::typeinfodelegate->type;
}
@@ -2032,6 +2191,10 @@ TypeInfoDelegateDeclaration::TypeInfoDelegateDeclaration(Type *tinfo)
TypeInfoTupleDeclaration::TypeInfoTupleDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfotypelist)
{
ObjectNotFound(Id::TypeInfo_Tuple);
}
type = Type::typeinfotypelist->type;
}
+8 -6
View File
@@ -95,6 +95,7 @@ enum PURE;
#define STCctfe 0x1000000000LL // can be used in CTFE, even if it is static
#define STCdisable 0x2000000000LL // for functions that are not callable
#define STCresult 0x4000000000LL // for result variables passed to out contracts
#define STCnodefaultctor 0x8000000000LL // must be set inside constructor
struct Match
{
@@ -159,7 +160,7 @@ struct Declaration : Dsymbol
int isParameter() { return storage_class & STCparameter; }
int isDeprecated() { return storage_class & STCdeprecated; }
int isOverride() { return storage_class & STCoverride; }
int isResult() { return storage_class & STCresult; }
StorageClass isResult() { return storage_class & STCresult; }
int isIn() { return storage_class & STCin; }
int isOut() { return storage_class & STCout; }
@@ -689,7 +690,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;
@@ -710,7 +711,7 @@ struct FuncDeclaration : Declaration
VarDeclaration *v_argptr; // '_argptr' variable
#endif
VarDeclaration *v_argsave; // save area for args passed in registers for variadic functions
Dsymbols *parameters; // Array of VarDeclaration's for parameters
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
@@ -749,7 +750,7 @@ 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
@@ -773,7 +774,7 @@ struct FuncDeclaration : Declaration
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs);
int overrides(FuncDeclaration *fd);
int findVtblIndex(Array *vtbl, int dim);
int findVtblIndex(Dsymbols *vtbl, int dim);
int overloadInsert(Dsymbol *s);
FuncDeclaration *overloadExactMatch(Type *t, Module* from);
FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, int flags = 0, Module* from=NULL);
@@ -796,6 +797,7 @@ struct FuncDeclaration : Declaration
int isCodeseg();
int isOverloadable();
enum PURE isPure();
enum PURE isPureBypassingInference();
bool setImpure();
int isSafe();
int isTrusted();
@@ -809,7 +811,7 @@ struct FuncDeclaration : Declaration
Expression *interpret(InterState *istate, Expressions *arguments, Expression *thisexp = NULL);
void inlineScan();
int canInline(int hasthis, int hdrscan = 0);
Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments);
Expression *doInline(InlineScanState *iss, Expression *ethis, Expressions *arguments);
const char *kind();
void toDocBuffer(OutBuffer *buf);
FuncDeclaration *isUnique();
+3 -3
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)
{
+29 -27
View File
@@ -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;
@@ -223,9 +225,9 @@ 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);
FileName f(global.params.ddocfiles->tdata()[i], 0);
File file(&f);
file.readv();
// BUG: convert file contents to UTF-8 before use
@@ -250,12 +252,14 @@ void Module::gendocfile()
Macro::define(&macrotable, (unsigned char *)"TITLE", 5, (unsigned char *)p, strlen(p));
}
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);
// 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));
@@ -526,9 +530,9 @@ 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];
Dsymbol *s = (*members)[i];
//printf("\ts = '%s'\n", s->toChars());
s->emitComment(sc);
}
@@ -698,9 +702,9 @@ 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];
Dsymbol *s = (*members)[i];
s->emitComment(sc);
}
return;
@@ -957,8 +961,8 @@ void ClassDeclaration::toDocBuffer(OutBuffer *buf)
buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
}
int any = 0;
for (int i = 0; i < baseclasses->dim; i++)
{ BaseClass *bc = (BaseClass *)baseclasses->data[i];
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *bc = (*baseclasses)[i];
if (bc->protection == PROTprivate)
continue;
@@ -1013,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;
@@ -1025,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;
}
}
@@ -1170,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;
@@ -1748,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)
{
@@ -2007,7 +2010,6 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
break;
}
}
Ldone:
if (inCode)
s->error("unmatched --- in DDoc comment");
;
+45 -28
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
@@ -123,15 +123,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);
@@ -216,7 +216,6 @@ const char *Dsymbol::toPrettyChars()
char *Dsymbol::locToChars()
{
OutBuffer buf;
char *p;
if (!loc.filename) // avoid bug 5861.
{
@@ -459,14 +458,20 @@ AggregateDeclaration *Dsymbol::isThis()
return NULL;
}
ClassDeclaration *Dsymbol::isClassMember() // are we a member of a class?
AggregateDeclaration *Dsymbol::isAggregateMember() // are we a member of an aggregate?
{
Dsymbol *parent = toParent();
if (parent && parent->isClassDeclaration())
return (ClassDeclaration *)parent;
if (parent && parent->isAggregateDeclaration())
return (AggregateDeclaration *)parent;
return NULL;
}
ClassDeclaration *Dsymbol::isClassMember() // are we a member of a class?
{
AggregateDeclaration *ad = isAggregateMember();
return ad ? ad->isClassDeclaration() : NULL;
}
void Dsymbol::defineRef(Dsymbol *s)
{
assert(0);
@@ -616,13 +621,13 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
goto L1;
}
for (; sc; sc = sc->enclosing)
for (Scope *sc2 = sc; sc2; sc2 = sc2->enclosing)
{
if (sc->scopesym && sc->scopesym->isDeprecated())
if (sc2->scopesym && sc2->scopesym->isDeprecated())
goto L1;
// If inside a StorageClassDeclaration that is deprecated
if (sc->stc & STCdeprecated)
if (sc2->stc & STCdeprecated)
goto L1;
}
@@ -653,6 +658,10 @@ Module *Dsymbol::getModule()
Dsymbol *s;
//printf("Dsymbol::getModule()\n");
TemplateDeclaration *td = getFuncTemplateDecl(this);
if (td)
return td->getModule();
s = this;
while (s)
{
@@ -713,12 +722,12 @@ Dsymbols *Dsymbol::arraySyntaxCopy(Dsymbols *a)
if (a)
{
b = (Dsymbols *)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;
@@ -823,8 +832,8 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
OverloadSet *a = NULL;
// 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
@@ -871,12 +880,12 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
a = new OverloadSet();
/* Don't add to a[] if s2 is alias of previous sym
*/
for (int j = 0; j < a->a.dim; j++)
{ Dsymbol *s3 = (Dsymbol *)a->a.data[j];
for (size_t j = 0; j < a->a.dim; j++)
{ Dsymbol *s3 = a->a[j];
if (s2->toAlias() == s3->toAlias())
{
if (s3->isDeprecated())
a->a.data[j] = (void *)s2;
a->a[j] = s2;
goto Lcontinue;
}
}
@@ -922,13 +931,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])
@@ -1017,13 +1024,13 @@ Dsymbol *ScopeDsymbol::symtabInsert(Dsymbol *s)
*/
#if DMDV2
size_t ScopeDsymbol::dim(Array *members)
size_t ScopeDsymbol::dim(Dsymbols *members)
{
size_t n = 0;
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
{ Dsymbol *s = (*members)[i];
AttribDeclaration *a = s->isAttribDeclaration();
if (a)
@@ -1047,15 +1054,17 @@ size_t ScopeDsymbol::dim(Array *members)
*/
#if DMDV2
Dsymbol *ScopeDsymbol::getNth(Array *members, size_t nth, size_t *pn)
Dsymbol *ScopeDsymbol::getNth(Dsymbols *members, size_t nth, size_t *pn)
{
if (!members)
return NULL;
size_t n = 0;
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
{ Dsymbol *s = (*members)[i];
AttribDeclaration *a = s->isAttribDeclaration();
TemplateMixin *tm = s->isTemplateMixin();
TemplateInstance *ti = s->isTemplateInstance();
if (a)
{
@@ -1063,6 +1072,14 @@ Dsymbol *ScopeDsymbol::getNth(Array *members, size_t nth, size_t *pn)
if (s)
return s;
}
else if (tm)
{
s = getNth(tm->members, nth - n, &n);
if (s)
return s;
}
else if (ti)
;
else if (n == nth)
return s;
else
+6 -5
View File
@@ -187,7 +187,8 @@ struct Dsymbol : Object
virtual int isforwardRef();
virtual void defineRef(Dsymbol *s);
virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member
virtual ClassDeclaration *isClassMember(); // are we a member of a class?
AggregateDeclaration *isAggregateMember(); // are we a member of an aggregate?
ClassDeclaration *isClassMember(); // are we a member of a class?
virtual int isExport(); // is Dsymbol exported?
virtual int isImportedSymbol(); // is Dsymbol imported?
virtual int isDeprecated(); // is Dsymbol deprecated?
@@ -202,7 +203,7 @@ 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 void addLocalClass(ClassDeclarations *) { }
virtual void checkCtorConstInit() { }
@@ -288,7 +289,7 @@ struct ScopeDsymbol : Dsymbol
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();
@@ -306,8 +307,8 @@ struct ScopeDsymbol : Dsymbol
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);
ScopeDsymbol *isScopeDsymbol() { return this; }
};
+1 -1
View File
@@ -36,7 +36,7 @@ void dumpExpressions(int i, Expressions *exps)
if (exps)
{
for (size_t j = 0; j < exps->dim; j++)
{ Expression *e = (Expression *)exps->data[j];
{ Expression *e = exps->tdata()[j];
indent(i);
printf("(\n");
e->dump(i + 2);
+13 -14
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
@@ -71,9 +71,9 @@ 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();
EnumMember *em = (*members)[i]->isEnumMember();
if (em && (em->type || em->value))
return;
}
@@ -165,9 +165,9 @@ void EnumDeclaration::semantic(Scope *sc)
error("enum %s must have at least one member", toChars());
int first = 1;
Expression *elast = NULL;
for (int i = 0; i < members->dim; i++)
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
EnumMember *em = (*members)[i]->isEnumMember();
Expression *e;
if (!em)
@@ -242,13 +242,13 @@ void EnumDeclaration::semantic(Scope *sc)
{
/* Anonymous enum members get added to enclosing scope.
*/
for (Scope *scx = sce; scx; scx = scx->enclosing)
for (Scope *sct = sce; 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;
}
}
@@ -308,8 +308,7 @@ int EnumDeclaration::oneMember(Dsymbol **ps)
}
void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{ int i;
{
buf->writestring("enum ");
if (ident)
{ buf->writestring(ident->toChars());
@@ -329,9 +328,9 @@ 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();
EnumMember *em = (*members)[i]->isEnumMember();
if (!em)
continue;
//buf->writestring(" ");
+585 -273
View File
File diff suppressed because it is too large Load Diff
+18
View File
@@ -48,6 +48,7 @@ struct Symbol; // back end symbol
#endif
struct OverloadSet;
struct Initializer;
struct StringExp;
#if IN_LLVM
struct AssignExp;
#endif
@@ -86,10 +87,15 @@ void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr, Mo
void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs);
void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs);
void expandTuples(Expressions *exps);
TupleDeclaration *isAliasThisTuple(Expression *e);
int expandAliasThisTuples(Expressions *exps, int starti = 0);
FuncDeclaration *hasThis(Scope *sc);
Expression *fromConstInitializer(int result, Expression *e);
int arrayExpressionCanThrow(Expressions *exps, bool mustNotThrow);
TemplateDeclaration *getFuncTemplateDecl(Dsymbol *s);
void valueNoDtor(Expression *e);
void modifyFieldVar(Loc loc, Scope *sc, VarDeclaration *var, Expression *e1);
/* Interpreter: what form of return value expression is required?
*/
@@ -132,6 +138,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 int isLvalue();
@@ -391,6 +398,7 @@ 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);
@@ -422,6 +430,7 @@ struct StringExp : Expression
Expression *semantic(Scope *sc);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
size_t length();
StringExp *toString();
StringExp *toUTF8(Scope *sc);
Expression *implicitCastTo(Scope *sc, Type *t);
MATCH implicitConvTo(Type *t);
@@ -485,6 +494,7 @@ 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);
@@ -795,6 +805,7 @@ struct FuncExp : Expression
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#if IN_DMD
elem *toElem(IRState *irs);
dt_t **toDt(dt_t **pdt);
#endif
int inlineCost(InlineCostState *ics);
@@ -1114,6 +1125,7 @@ struct DotTypeExp : UnaExp
struct CallExp : UnaExp
{
Expressions *arguments; // function arguments
FuncDeclaration *f; // symbol to call
CallExp(Loc loc, Expression *e, Expressions *exps);
CallExp(Loc loc, Expression *e);
@@ -1135,6 +1147,7 @@ struct CallExp : UnaExp
Expression *toLvalue(Scope *sc, Expression *e);
int canThrow(bool mustNotThrow);
Expression *addDtorHook(Scope *sc);
MATCH implicitConvTo(Type *t);
int inlineCost(InlineCostState *ics);
Expression *doInline(InlineDoState *ids);
@@ -1341,6 +1354,7 @@ struct SliceExp : UnaExp
int isLvalue();
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, CtfeGoal goal = ctfeNeedRvalue);
@@ -1566,6 +1580,8 @@ struct PowAssignExp : BinAssignExp
{
PowAssignExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
// For operator overloading
Identifier *opId();
@@ -1715,6 +1731,8 @@ struct PowExp : BinExp
{
PowExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
// For operator overloading
Identifier *opId();
+76 -42
View File
@@ -306,6 +306,9 @@ void FuncDeclaration::semantic(Scope *sc)
if (isAbstract() && !isVirtual())
error("non-virtual functions cannot be abstract");
if (isOverride() && !isVirtual())
error("cannot override a non-virtual function");
if ((f->isConst() || f->isImmutable()) && !isThis())
error("without 'this' cannot be const/immutable");
@@ -458,7 +461,7 @@ void FuncDeclaration::semantic(Scope *sc)
/* Find index of existing function in base class's vtbl[] to override
* (the index will be the same as in cd's current vtbl[])
*/
vi = cd->baseClass ? findVtblIndex(&cd->baseClass->vtbl, cd->baseClass->vtbl.dim)
vi = cd->baseClass ? findVtblIndex((Dsymbols*)&cd->baseClass->vtbl, cd->baseClass->vtbl.dim)
: -1;
switch (vi)
@@ -504,7 +507,7 @@ void FuncDeclaration::semantic(Scope *sc)
return;
default:
{ FuncDeclaration *fdv = (FuncDeclaration *)cd->baseClass->vtbl.data[vi];
{ FuncDeclaration *fdv = (FuncDeclaration *)cd->baseClass->vtbl.tdata()[vi];
// This function is covariant with fdv
if (fdv->isFinal())
error("cannot override final function %s", fdv->toPrettyChars());
@@ -531,7 +534,7 @@ void FuncDeclaration::semantic(Scope *sc)
)
error("multiple overrides of same function");
}
cd->vtbl.data[vi] = (void *)this;
cd->vtbl.tdata()[vi] = this;
vtblIndex = vi;
/* Remember which functions this overrides
@@ -570,7 +573,7 @@ void FuncDeclaration::semantic(Scope *sc)
for (int i = 0; i < cd->interfaces_dim; i++)
{
BaseClass *b = cd->interfaces[i];
vi = findVtblIndex(&b->base->vtbl, b->base->vtbl.dim);
vi = findVtblIndex((Dsymbols *)&b->base->vtbl, b->base->vtbl.dim);
switch (vi)
{
case -1:
@@ -582,7 +585,7 @@ void FuncDeclaration::semantic(Scope *sc)
return;
default:
{ FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl.data[vi];
{ FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl.tdata()[vi];
Type *ti = NULL;
/* Remember which functions this overrides
@@ -867,7 +870,7 @@ void FuncDeclaration::semantic3(Scope *sc)
{
for (int i = 0; i < fthrows->dim; i++)
{
Type *t = (Type *)fthrows->data[i];
Type *t = fthrows->tdata()[i];
t = t->semantic(loc, sc);
if (!t->isClassHandle())
@@ -880,7 +883,7 @@ void FuncDeclaration::semantic3(Scope *sc)
{
for (int i = 0; i < foverrides.dim; i++)
{
FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
FuncDeclaration *fdv = foverrides.tdata()[i];
if (fdv->fbody && !fdv->frequire)
{
@@ -1094,7 +1097,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (f->parameters)
{
for (size_t i = 0; i < f->parameters->dim; i++)
{ Parameter *arg = (Parameter *)f->parameters->data[i];
{ Parameter *arg = f->parameters->tdata()[i];
//printf("[%d] arg->type->ty = %d %s\n", i, arg->type->ty, arg->type->toChars());
if (arg->type->ty == Ttuple)
@@ -1117,7 +1120,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++)
{
@@ -1154,7 +1157,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (f->parameters)
{
for (size_t i = 0; i < f->parameters->dim; i++)
{ Parameter *arg = (Parameter *)f->parameters->data[i];
{ Parameter *arg = f->parameters->tdata()[i];
if (!arg->ident)
continue; // never used, so ignore
@@ -1169,7 +1172,7 @@ void FuncDeclaration::semantic3(Scope *sc)
VarDeclaration *v = sc2->search(0, narg->ident, NULL)->isVarDeclaration();
assert(v);
Expression *e = new VarExp(v->loc, v);
exps->data[j] = (void *)e;
exps->tdata()[j] = e;
}
assert(arg->ident);
TupleDeclaration *v = new TupleDeclaration(loc, arg->ident, exps);
@@ -1327,14 +1330,14 @@ void FuncDeclaration::semantic3(Scope *sc)
sc2->incontract--;
if (fbody)
{ ClassDeclaration *cd = isClassMember();
{ AggregateDeclaration *ad = isAggregateMember();
/* If this is a class constructor
*/
if (isCtorDeclaration() && cd)
if (ad && isCtorDeclaration())
{
for (int i = 0; i < cd->fields.dim; i++)
{ VarDeclaration *v = (VarDeclaration *)cd->fields.data[i];
for (size_t i = 0; i < ad->fields.dim; i++)
{ VarDeclaration *v = ad->fields[i];
v->ctorinit = 0;
}
@@ -1363,37 +1366,51 @@ void FuncDeclaration::semantic3(Scope *sc)
*/
Dsymbol *p = toParent();
ScopeDsymbol *ad = p->isScopeDsymbol();
if (!ad)
ScopeDsymbol *pd = p->isScopeDsymbol();
if (!pd)
{
error("static constructor can only be member of struct/class/module, not %s %s", p->kind(), p->toChars());
}
else
{
for (int i = 0; i < ad->members->dim; i++)
{ Dsymbol *s = (Dsymbol *)ad->members->data[i];
for (size_t i = 0; i < pd->members->dim; i++)
{ Dsymbol *s = pd->members->tdata()[i];
s->checkCtorConstInit();
}
}
}
if (isCtorDeclaration() && cd)
if (isCtorDeclaration() && ad)
{
//printf("callSuper = x%x\n", sc2->callSuper);
ClassDeclaration *cd = ad->isClassDeclaration();
// Verify that all the ctorinit fields got initialized
if (!(sc2->callSuper & CSXthis_ctor))
{
for (int i = 0; i < cd->fields.dim; i++)
{ VarDeclaration *v = (VarDeclaration *)cd->fields.data[i];
for (size_t i = 0; i < ad->fields.dim; i++)
{ VarDeclaration *v = ad->fields[i];
if (v->ctorinit == 0 && v->isCtorinit() && !v->type->isMutable())
error("missing initializer for final field %s", v->toChars());
if (v->ctorinit == 0)
{
/* Current bugs in the flow analysis:
* 1. union members should not produce error messages even if
* not assigned to
* 2. structs should recognize delegating opAssign calls as well
* as delegating calls to other constructors
*/
if (v->isCtorinit() && !v->type->isMutable() && cd)
error("missing initializer for final field %s", v->toChars());
else if (v->storage_class & STCnodefaultctor)
error("field %s must be initialized in constructor", v->toChars());
}
}
}
if (!(sc2->callSuper & CSXany_ctor) &&
if (cd &&
!(sc2->callSuper & CSXany_ctor) &&
cd->baseClass && cd->baseClass->ctor)
{
sc2->callSuper = 0;
@@ -1488,7 +1505,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (parameters)
{ for (size_t i = 0; i < parameters->dim; i++)
{
VarDeclaration *v = (VarDeclaration *)parameters->data[i];
VarDeclaration *v = parameters->tdata()[i];
if (v->storage_class & STCout)
{
assert(v->init);
@@ -1511,7 +1528,7 @@ void FuncDeclaration::semantic3(Scope *sc)
v_argptr->init = new VoidInitializer(loc);
#else
Type *t = argptr->type;
if (global.params.isX86_64)
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);
@@ -1530,7 +1547,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (parameters && parameters->dim)
{
int lastNonref = parameters->dim -1;
p = (VarDeclaration *)parameters->data[lastNonref];
p = parameters->tdata()[lastNonref];
/* The trouble with out and ref parameters is that taking
* the address of it doesn't work, because later processing
* adds in an extra level of indirection. So we skip over them.
@@ -1544,7 +1561,7 @@ void FuncDeclaration::semantic3(Scope *sc)
p = v_arguments;
break;
}
p = (VarDeclaration *)parameters->data[lastNonref];
p = parameters->tdata()[lastNonref];
}
}
else
@@ -1738,7 +1755,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (parameters)
{ for (size_t i = 0; i < parameters->dim; i++)
{
VarDeclaration *v = (VarDeclaration *)parameters->data[i];
VarDeclaration *v = parameters->tdata()[i];
if (v->storage_class & (STCref | STCout))
continue;
@@ -1929,7 +1946,7 @@ Statement *FuncDeclaration::mergeFrequire(Statement *sf)
*/
for (int i = 0; i < foverrides.dim; i++)
{
FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
FuncDeclaration *fdv = foverrides.tdata()[i];
/* The semantic pass on the contracts of the overridden functions must
* be completed before code generation occurs (bug 3602).
@@ -1956,7 +1973,7 @@ Statement *FuncDeclaration::mergeFrequire(Statement *sf)
Statement *s2 = new ExpStatement(loc, e);
Catch *c = new Catch(loc, NULL, NULL, sf);
Array *catches = new Array();
Catches *catches = new Catches();
catches->push(c);
sf = new TryCatchStatement(loc, s2, catches);
}
@@ -1984,7 +2001,7 @@ Statement *FuncDeclaration::mergeFensure(Statement *sf)
*/
for (int i = 0; i < foverrides.dim; i++)
{
FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
FuncDeclaration *fdv = foverrides.tdata()[i];
/* The semantic pass on the contracts of the overridden functions must
* be completed before code generation occurs (bug 3602 and 5230).
@@ -2051,13 +2068,13 @@ int FuncDeclaration::overrides(FuncDeclaration *fd)
* -2 can't determine because of forward references
*/
int FuncDeclaration::findVtblIndex(Array *vtbl, int dim)
int FuncDeclaration::findVtblIndex(Dsymbols *vtbl, int dim)
{
FuncDeclaration *mismatch = NULL;
int bestvi = -1;
for (int vi = 0; vi < dim; vi++)
{
FuncDeclaration *fdv = ((Dsymbol *)vtbl->data[vi])->isFuncDeclaration();
FuncDeclaration *fdv = vtbl->tdata()[vi]->isFuncDeclaration();
if (fdv && fdv->ident == ident)
{
if (type->equals(fdv->type)) // if exact match
@@ -2406,7 +2423,7 @@ if (arguments)
for (i = 0; i < arguments->dim; i++)
{ Expression *arg;
arg = (Expression *)arguments->data[i];
arg = arguments->tdata()[i];
assert(arg->type);
printf("\t%s: ", arg->toChars());
arg->type->print();
@@ -2449,7 +2466,7 @@ if (arguments)
OutBuffer buf2;
tf->modToBuffer(&buf2);
//printf("tf = %s, args = %s\n", tf->deco, ((Expression *)arguments->data[0])->type->deco);
//printf("tf = %s, args = %s\n", tf->deco, arguments->tdata()[0]->type->deco);
error(loc, "%s%s is not callable using argument types %s",
Parameter::argsTypesToChars(tf->parameters, tf->varargs),
buf2.toChars(),
@@ -2535,7 +2552,7 @@ MATCH FuncDeclaration::leastAsSpecialized(FuncDeclaration *g)
}
else
e = p->type->defaultInit();
args.data[u] = e;
args.tdata()[u] = e;
}
MATCH m = (MATCH) tg->callMatch(NULL, &args, 1);
@@ -2855,6 +2872,14 @@ enum PURE FuncDeclaration::isPure()
return purity;
}
enum PURE FuncDeclaration::isPureBypassingInference()
{
if (flags & FUNCFLAGpurityInprocess)
return PUREfwdref;
else
return isPure();
}
/**************************************
* The function is doing something impure,
* so mark it as impure.
@@ -3026,12 +3051,12 @@ int FuncDeclaration::needsClosure()
//printf("FuncDeclaration::needsClosure() %s\n", toChars());
for (int i = 0; i < closureVars.dim; i++)
{ VarDeclaration *v = (VarDeclaration *)closureVars.data[i];
{ VarDeclaration *v = closureVars.tdata()[i];
assert(v->isVarDeclaration());
//printf("\tv = %s\n", v->toChars());
for (int j = 0; j < v->nestedrefs.dim; j++)
{ FuncDeclaration *f = (FuncDeclaration *)v->nestedrefs.data[j];
{ FuncDeclaration *f = v->nestedrefs.tdata()[j];
assert(f != this);
//printf("\t\tf = %s, %d, %p, %d\n", f->toChars(), f->isVirtual(), f->isThis(), f->tookAddressOf);
@@ -3258,8 +3283,17 @@ void CtorDeclaration::semantic(Scope *sc)
// See if it's the default constructor
if (ad && tf->varargs == 0 && Parameter::dim(tf->parameters) == 0)
{ if (ad->isStructDeclaration())
error("default constructor not allowed for structs");
{
StructDeclaration *sd = ad->isStructDeclaration();
if (sd)
{
if (fbody || !(storage_class & STCdisable))
{ error("default constructor for structs only allowed with @disable and no body");
storage_class |= STCdisable;
fbody = NULL;
}
sd->noDefaultCtor = TRUE;
}
else
ad->defaultCtor = this;
}
+4 -4
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
@@ -46,7 +46,7 @@
#include "mtype.h"
#include "hdrgen.h"
void argsToCBuffer(OutBuffer *buf, Array *arguments, HdrGenState *hgs);
void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs);
void Module::genhdrfile()
{
@@ -83,8 +83,8 @@ void Module::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
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->toHBuffer(buf, hgs);
}
+1
View File
@@ -34,6 +34,7 @@ Msgtable msgtable[] =
{ "max" },
{ "min" },
{ "This", "this" },
{ "super" },
{ "ctor", "__ctor" },
{ "dtor", "__dtor" },
{ "cpctor", "__cpctor" },
+20 -13
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)
{
@@ -42,7 +42,7 @@ Import::Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId,
this->ident = aliasId;
// Kludge to change Import identifier to first package
else if (packages && packages->dim)
this->ident = (Identifier *)packages->data[0];
this->ident = packages->tdata()[0];
}
void Import::addAlias(Identifier *name, Identifier *alias)
@@ -73,7 +73,7 @@ Dsymbol *Import::syntaxCopy(Dsymbol *s)
for (size_t i = 0; i < names.dim; i++)
{
si->addAlias((Identifier *)names.data[i], (Identifier *)aliases.data[i]);
si->addAlias(names.tdata()[i], aliases.tdata()[i]);
}
return si;
@@ -186,7 +186,14 @@ void Import::semantic(Scope *sc)
enum PROT prot = sc->protection;
if (!sc->explicitProtection)
prot = PROTprivate;
sc->scopesym->importScope(mod, prot);
for (Scope *scd = sc; scd; scd = scd->enclosing)
{
if (scd->scopesym)
{
scd->scopesym->importScope(mod, prot);
break;
}
}
}
mod->semantic();
@@ -198,11 +205,11 @@ void Import::semantic(Scope *sc)
sc = sc->push(mod);
for (size_t i = 0; i < aliasdecls.dim; i++)
{ Dsymbol *s = (Dsymbol *)aliasdecls.data[i];
{ Dsymbol *s = aliasdecls.tdata()[i];
//printf("\tImport alias semantic('%s')\n", s->toChars());
if (!mod->search(loc, (Identifier *)names.data[i], 0))
error("%s not found", ((Identifier *)names.data[i])->toChars());
if (!mod->search(loc, names.tdata()[i], 0))
error("%s not found", (names.tdata()[i])->toChars());
s->semantic(sc);
}
@@ -240,7 +247,7 @@ void Import::semantic(Scope *sc)
{
for (size_t i = 0; i < packages->dim; i++)
{
Identifier *pid = (Identifier *)packages->data[i];
Identifier *pid = packages->tdata()[i];
ob->printf("%s.", pid->toChars());
}
}
@@ -260,8 +267,8 @@ void Import::semantic(Scope *sc)
else
ob->writebyte(',');
Identifier *name = (Identifier *)names.data[i];
Identifier *alias = (Identifier *)aliases.data[i];
Identifier *name = names.tdata()[i];
Identifier *alias = aliases.tdata()[i];
if (!alias)
{
@@ -317,8 +324,8 @@ int Import::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
*/
for (size_t i = 0; i < names.dim; i++)
{
Identifier *name = (Identifier *)names.data[i];
Identifier *alias = (Identifier *)aliases.data[i];
Identifier *name = names.tdata()[i];
Identifier *alias = aliases.tdata()[i];
if (!alias)
alias = name;
@@ -367,7 +374,7 @@ void Import::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
if (packages && packages->dim)
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
{ Identifier *pid = packages->tdata()[i];
buf->printf("%s.", pid->toChars());
}
+5 -5
View File
@@ -28,21 +28,21 @@ struct HdrGenState;
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
// Pairs of alias=name to bind into current namespace
Array names;
Array aliases;
Identifiers names;
Identifiers aliases;
Array aliasdecls; // AliasDeclarations for names/aliases
AliasDeclarations aliasdecls; // AliasDeclarations for names/aliases
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);
+18 -23
View File
@@ -70,8 +70,6 @@ const char *inifile(const char *argv0x, const char *inifilex)
char *path; // need path for @P macro
char *filename;
OutBuffer buf;
int i;
int k;
int envsection = 0;
#if LOG
@@ -137,7 +135,7 @@ const char *inifile(const char *argv0x, const char *inifilex)
if (1){
// Search PATH for argv0
const char *p = getenv("PATH");
Array *paths = FileName::splitPath(p);
Strings *paths = FileName::splitPath(p);
filename = FileName::searchPath(paths, argv0, 0);
if (!filename)
goto Letc; // argv0 not found on path
@@ -145,10 +143,9 @@ const char *inifile(const char *argv0x, const char *inifilex)
if (FileName::exists(filename))
goto Ldone;
}
#endif
// Search /etc/ for inifile
Letc:
#endif
filename = FileName::combine((char *)"/etc/", inifile);
Ldone:
@@ -169,9 +166,9 @@ const char *inifile(const char *argv0x, const char *inifilex)
// Parse into lines
int eof = 0;
for (i = 0; i < file.len && !eof; i++)
for (size_t i = 0; i < file.len && !eof; i++)
{
int linestart = i;
size_t linestart = i;
for (; i < file.len; i++)
{
@@ -199,7 +196,7 @@ const char *inifile(const char *argv0x, const char *inifilex)
// The line is file.buffer[linestart..i]
char *line;
int len;
size_t len;
char *p;
char *pn;
@@ -211,13 +208,11 @@ const char *inifile(const char *argv0x, const char *inifilex)
// First, expand the macros.
// Macros are bracketed by % characters.
for (k = 0; k < len; k++)
for (size_t k = 0; k < len; k++)
{
if (line[k] == '%')
{
int j;
for (j = k + 1; j < len; j++)
for (size_t j = k + 1; j < len; j++)
{
if (line[j] == '%')
{
@@ -229,16 +224,16 @@ const char *inifile(const char *argv0x, const char *inifilex)
p = (char *)".";
}
else
{ int len = j - k;
{ size_t len2 = j - k;
char tmp[10]; // big enough most of the time
if (len <= sizeof(tmp))
if (len2 <= sizeof(tmp))
p = tmp;
else
p = (char *)alloca(len);
len--;
memcpy(p, &line[k + 1], len);
p[len] = 0;
p = (char *)alloca(len2);
len2--;
memcpy(p, &line[k + 1], len2);
p[len2] = 0;
strupr(p);
p = getenv(p);
if (!p)
@@ -273,7 +268,7 @@ const char *inifile(const char *argv0x, const char *inifilex)
case '[': // look for [Environment]
p = skipspace(p + 1);
for (pn = p; isalnum(*pn); pn++)
for (pn = p; isalnum((unsigned char)*pn); pn++)
;
if (pn - p == 11 &&
memicmp(p, "Environment", 11) == 0 &&
@@ -292,14 +287,14 @@ const char *inifile(const char *argv0x, const char *inifilex)
// Convert name to upper case;
// remove spaces bracketing =
for (p = pn; *p; p++)
{ if (islower(*p))
{ if (islower((unsigned char)*p))
*p &= ~0x20;
else if (isspace(*p))
else if (isspace((unsigned char)*p))
memmove(p, p + 1, strlen(p));
else if (*p == '=')
{
p++;
while (isspace(*p))
while (isspace((unsigned char)*p))
memmove(p, p + 1, strlen(p));
break;
}
@@ -326,7 +321,7 @@ const char *inifile(const char *argv0x, const char *inifilex)
char *skipspace(const char *p)
{
while (isspace(*p))
while (isspace((unsigned char)*p))
p++;
return (char *)p;
}
+74 -68
View File
@@ -52,11 +52,11 @@ Initializers *Initializer::arraySyntaxCopy(Initializers *ai)
{
a = new Initializers();
a->setDim(ai->dim);
for (int i = 0; i < a->dim; i++)
{ Initializer *e = (Initializer *)ai->data[i];
for (size_t i = 0; i < a->dim; i++)
{ Initializer *e = ai->tdata()[i];
e = e->syntaxCopy();
a->data[i] = e;
a->tdata()[i] = e;
}
}
return a;
@@ -123,13 +123,13 @@ 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];
ai->field.tdata()[i] = field.tdata()[i];
Initializer *init = (Initializer *)value.data[i];
Initializer *init = value.tdata()[i];
init = init->syntaxCopy();
ai->value.data[i] = init;
ai->value.tdata()[i] = init;
}
return ai;
}
@@ -157,16 +157,18 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
if (ad->ctor)
error(loc, "%s %s has constructors, cannot use { initializers }, use %s( initializers ) instead",
ad->kind(), ad->toChars(), ad->toChars());
size_t nfields = ad->fields.dim;
if (((StructDeclaration *)ad)->isnested) nfields--;
for (size_t i = 0; i < field.dim; i++)
{
Identifier *id = (Identifier *)field.data[i];
Initializer *val = (Initializer *)value.data[i];
Identifier *id = field.tdata()[i];
Initializer *val = value.tdata()[i];
Dsymbol *s;
VarDeclaration *v;
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);
@@ -175,7 +177,7 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
}
else
{
s = (Dsymbol *)ad->fields.data[fieldi];
s = ad->fields.tdata()[fieldi];
}
}
else
@@ -192,22 +194,22 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
// Find out which field index it is
for (fieldi = 0; 1; fieldi++)
{
if (fieldi >= ad->fields.dim)
if (fieldi >= nfields)
{
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])
if (s == ad->fields.tdata()[fieldi])
break;
}
}
if (s && (v = s->isVarDeclaration()) != NULL)
{
val = val->semantic(sc, v->type, needInterpret);
value.data[i] = (void *)val;
vars.data[i] = (void *)v;
value.tdata()[i] = val;
vars.tdata()[i] = v;
}
else
{ error(loc, "%s is not a field of %s", id ? id->toChars() : s->toChars(), ad->toChars());
@@ -260,15 +262,20 @@ Expression *StructInitializer::toExpression()
if (!sd)
return NULL;
Expressions *elements = new Expressions();
elements->setDim(ad->fields.dim);
for (int i = 0; i < elements->dim; i++)
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;
elements->tdata()[i] = NULL;
}
unsigned fieldi = 0;
for (int i = 0; i < value.dim; i++)
for (size_t i = 0; i < value.dim; i++)
{
Identifier *id = (Identifier *)field.data[i];
Identifier *id = field.tdata()[i];
if (id)
{
Dsymbol * s = ad->search(loc, id, 0);
@@ -281,52 +288,52 @@ Expression *StructInitializer::toExpression()
// 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");
goto Lno;
}
if (s == (Dsymbol *)ad->fields.data[fieldi])
if (s == ad->fields.tdata()[fieldi])
break;
}
}
else if (fieldi >= ad->fields.dim)
else if (fieldi >= nfields)
{ error(loc, "too many initializers for '%s'", ad->toChars());
goto Lno;
}
Initializer *iz = (Initializer *)value.data[i];
Initializer *iz = value.tdata()[i];
if (!iz)
goto Lno;
Expression *ex = iz->toExpression();
if (!ex)
goto Lno;
if (elements->data[fieldi])
if (elements->tdata()[fieldi])
{ error(loc, "duplicate initializer for field '%s'",
((Dsymbol *)ad->fields.data[fieldi])->toChars());
ad->fields.tdata()[fieldi]->toChars());
goto Lno;
}
elements->data[fieldi] = ex;
elements->tdata()[fieldi] = ex;
++fieldi;
}
// Now, fill in any missing elements with default initializers.
// We also need to validate any anonymous unions
offset = 0;
for (int i = 0; i < elements->dim; )
for (size_t i = 0; i < elements->dim; )
{
VarDeclaration * vd = ((Dsymbol *)ad->fields.data[i])->isVarDeclaration();
VarDeclaration * vd = ad->fields.tdata()[i]->isVarDeclaration();
//printf("test2 [%d] : %s %d %d\n", i, vd->toChars(), (int)offset, (int)vd->offset);
if (vd->offset < offset)
{
// Only the first field of a union can have an initializer
if (elements->data[i])
if (elements->tdata()[i])
goto Lno;
}
else
{
if (!elements->data[i])
if (!elements->tdata()[i])
// Default initialize
elements->data[i] = vd->type->defaultInit();
elements->tdata()[i] = vd->type->defaultInit();
}
offset = vd->offset + vd->type->size();
i++;
@@ -334,15 +341,15 @@ Expression *StructInitializer::toExpression()
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();
if (!elements->tdata()[i])
elements->tdata()[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])
if (!elements->tdata()[j])
continue;
if (found >= 0)
{
@@ -379,17 +386,17 @@ 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(',');
Identifier *id = (Identifier *)field.data[i];
Identifier *id = field.tdata()[i];
if (id)
{
buf->writestring(id->toChars());
buf->writebyte(':');
}
Initializer *iz = (Initializer *)value.data[i];
Initializer *iz = value.tdata()[i];
if (iz)
iz->toCBuffer(buf, hgs);
}
@@ -415,15 +422,15 @@ 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++)
{ Expression *e = (Expression *)index.data[i];
for (size_t i = 0; i < ai->value.dim; i++)
{ Expression *e = index.tdata()[i];
if (e)
e = e->syntaxCopy();
ai->index.data[i] = e;
ai->index.tdata()[i] = e;
Initializer *init = (Initializer *)value.data[i];
Initializer *init = value.tdata()[i];
init = init->syntaxCopy();
ai->value.data[i] = init;
ai->value.tdata()[i] = init;
}
return ai;
}
@@ -462,17 +469,17 @@ Initializer *ArrayInitializer::semantic(Scope *sc, Type *t, int needInterpret)
length = 0;
for (i = 0; i < index.dim; i++)
{
Expression *idx = (Expression *)index.data[i];
Expression *idx = index.tdata()[i];
if (idx)
{ idx = idx->semantic(sc);
idx = idx->optimize(WANTvalue | WANTinterpret);
index.data[i] = (void *)idx;
index.tdata()[i] = idx;
length = idx->toInteger();
}
Initializer *val = (Initializer *)value.data[i];
Initializer *val = value.tdata()[i];
val = val->semantic(sc, t->nextOf(), needInterpret);
value.data[i] = (void *)val;
value.tdata()[i] = val;
length++;
if (length == 0)
{ error(loc, "array dimension overflow");
@@ -508,7 +515,6 @@ Lerr:
Expression *ArrayInitializer::toExpression()
{ Expressions *elements;
Expression *e;
//printf("ArrayInitializer::toExpression(), dim = %d\n", dim);
//static int i; if (++i == 2) halt();
@@ -529,8 +535,8 @@ Expression *ArrayInitializer::toExpression()
case Tpointer:
case Tarray:
edim = dim;
break;
edim = dim;
break;
default:
assert(0);
@@ -541,8 +547,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.tdata()[i])
j = index.tdata()[i]->toInteger();
if (j >= edim)
edim = j + 1;
}
@@ -553,10 +559,10 @@ Expression *ArrayInitializer::toExpression()
elements->zero();
for (size_t i = 0, j = 0; i < value.dim; i++, j++)
{
if (index.data[i])
j = ((Expression *)index.data[i])->toInteger();
if (index.tdata()[i])
j = (index.tdata()[i])->toInteger();
assert(j < edim);
Initializer *iz = (Initializer *)value.data[i];
Initializer *iz = value.tdata()[i];
if (!iz)
goto Lno;
Expression *ex = iz->toExpression();
@@ -564,7 +570,7 @@ Expression *ArrayInitializer::toExpression()
{
goto Lno;
}
elements->data[j] = ex;
elements->tdata()[j] = ex;
}
/* Fill in any missing elements with the default initializer
@@ -573,13 +579,13 @@ Expression *ArrayInitializer::toExpression()
Expression *init = NULL;
for (size_t i = 0; i < edim; i++)
{
if (!elements->data[i])
if (!elements->tdata()[i])
{
if (!type)
goto Lno;
if (!init)
init = ((TypeNext *)t)->next->defaultInit();
elements->data[i] = init;
elements->tdata()[i] = init;
}
}
@@ -610,18 +616,18 @@ Expression *ArrayInitializer::toAssocArrayLiteral()
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 e;
@@ -637,7 +643,7 @@ int ArrayInitializer::isAssociativeArray()
{
for (size_t i = 0; i < value.dim; i++)
{
if (index.data[i])
if (index.tdata()[i])
return 1;
}
return 0;
@@ -695,17 +701,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);
}
@@ -782,9 +788,9 @@ bool arrayHasNonConstPointers(Expressions *elems)
{
for (size_t i = 0; i < elems->dim; i++)
{
if (!(Expression *)elems->data[i])
if (!elems->tdata()[i])
continue;
if (hasNonConstPointers((Expression *)elems->data[i]))
if (hasNonConstPointers(elems->tdata()[i]))
return true;
}
return false;
+1 -1
View File
@@ -76,7 +76,7 @@ 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);
+41 -46
View File
@@ -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->tdata()[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->tdata()[i];
if (s)
{
cost += s->inlineCost(ics);
@@ -141,13 +141,13 @@ int ImportStatement::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->tdata()[i];
if (e)
cost += e->inlineCost(ics);
@@ -246,7 +246,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->tdata()[i];
if (o->dyncast() != DYNCAST_EXPRESSION)
return COST_MAX;
Expression *eo = (Expression *)o;
@@ -354,8 +354,8 @@ int CondExp::inlineCost(InlineCostState *ics)
struct InlineDoState
{
VarDeclaration *vthis;
Array from; // old Dsymbols
Array to; // parallel array of new Dsymbols
Dsymbols from; // old Dsymbols
Dsymbols to; // parallel array of new Dsymbols
Dsymbol *parent; // new parent
};
@@ -379,7 +379,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->tdata()[i];
if (s)
{
Expression *e2 = s->doInline(ids);
@@ -411,7 +411,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->tdata()[i];
if (s)
{
Expression *e2 = s->doInline(ids);
@@ -488,12 +488,12 @@ Expressions *arrayExpressiondoInline(Expressions *a, InlineDoState *ids)
newa = new Expressions();
newa->setDim(a->dim);
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->tdata()[i];
if (e)
e = e->doInline(ids);
newa->data[i] = (void *)e;
newa->tdata()[i] = e;
}
}
return newa;
@@ -507,16 +507,14 @@ 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])
if (var == ids->from.tdata()[i])
{
SymOffExp *se = (SymOffExp *)copy();
se->var = (Declaration *)ids->to.data[i];
se->var = (Declaration *)ids->to.tdata()[i];
return se;
}
}
@@ -525,16 +523,14 @@ 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])
if (var == ids->from.tdata()[i])
{
VarExp *ve = (VarExp *)copy();
ve->var = (Declaration *)ids->to.data[i];
ve->var = (Declaration *)ids->to.tdata()[i];
return ve;
}
}
@@ -578,7 +574,7 @@ Expression *DeclarationExp::doInline(InlineDoState *ids)
if (td)
{
for (size_t i = 0; i < td->objects->dim; i++)
{ DsymbolExp *se = (DsymbolExp *)td->objects->data[i];
{ DsymbolExp *se = td->objects->tdata()[i];
assert(se->op == TOKdsymbol);
se->s;
}
@@ -847,9 +843,9 @@ Statement *ExpStatement::inlineScan(InlineScanState *iss)
Statement *CompoundStatement::inlineScan(InlineScanState *iss)
{
for (size_t i = 0; i < statements->dim; i++)
{ Statement *s = (Statement *) statements->data[i];
{ Statement *s = statements->tdata()[i];
if (s)
statements->data[i] = (void *)s->inlineScan(iss);
statements->tdata()[i] = s->inlineScan(iss);
}
return this;
}
@@ -857,9 +853,9 @@ Statement *CompoundStatement::inlineScan(InlineScanState *iss)
Statement *UnrolledLoopStatement::inlineScan(InlineScanState *iss)
{
for (size_t i = 0; i < statements->dim; i++)
{ Statement *s = (Statement *) statements->data[i];
{ Statement *s = statements->tdata()[i];
if (s)
statements->data[i] = (void *)s->inlineScan(iss);
statements->tdata()[i] = s->inlineScan(iss);
}
return this;
}
@@ -942,11 +938,11 @@ Statement *SwitchStatement::inlineScan(InlineScanState *iss)
sdefault = (DefaultStatement *)sdefault->inlineScan(iss);
if (cases)
{
for (int i = 0; i < cases->dim; i++)
{ Statement *s;
for (size_t i = 0; i < cases->dim; i++)
{ CaseStatement *s;
s = (Statement *) cases->data[i];
cases->data[i] = (void *)s->inlineScan(iss);
s = cases->tdata()[i];
cases->tdata()[i] = (CaseStatement *)s->inlineScan(iss);
}
}
return this;
@@ -1008,8 +1004,8 @@ Statement *TryCatchStatement::inlineScan(InlineScanState *iss)
body = body->inlineScan(iss);
if (catches)
{
for (int i = 0; i < catches->dim; i++)
{ Catch *c = (Catch *)catches->data[i];
for (size_t i = 0; i < catches->dim; i++)
{ Catch *c = catches->tdata()[i];
if (c->handler)
c->handler = c->handler->inlineScan(iss);
@@ -1054,17 +1050,17 @@ Statement *LabelStatement::inlineScan(InlineScanState *iss)
/* -------------------------- */
void arrayInlineScan(InlineScanState *iss, Array *arguments)
void arrayInlineScan(InlineScanState *iss, Expressions *arguments)
{
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->tdata()[i];
if (e)
{
e = e->inlineScan(iss);
arguments->data[i] = (void *)e;
arguments->tdata()[i] = e;
}
}
}
@@ -1084,7 +1080,7 @@ void scanVar(Dsymbol *s, InlineScanState *iss)
if (td)
{
for (size_t i = 0; i < td->objects->dim; i++)
{ DsymbolExp *se = (DsymbolExp *)td->objects->data[i];
{ DsymbolExp *se = (DsymbolExp *)td->objects->tdata()[i];
assert(se->op == TOKdsymbol);
scanVar(se->s, iss);
}
@@ -1389,9 +1385,9 @@ int FuncDeclaration::canInline(int hasthis, int hdrscan)
#if 0
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];
VarDeclaration *v = parameters->tdata()[i];
if (
#if DMDV1
v->isOut() || v->isRef() ||
@@ -1419,7 +1415,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
@@ -1436,7 +1431,7 @@ Lno:
return 0;
}
Expression *FuncDeclaration::doInline(InlineScanState *iss, Expression *ethis, Array *arguments)
Expression *FuncDeclaration::doInline(InlineScanState *iss, Expression *ethis, Expressions *arguments)
{
InlineDoState ids;
DeclarationExp *de;
@@ -1510,11 +1505,11 @@ 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 *vfrom = parameters->tdata()[i];
VarDeclaration *vto;
Expression *arg = (Expression *)arguments->data[i];
Expression *arg = arguments->tdata()[i];
ExpInitializer *ei;
VarExp *ve;
+851 -277
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -458,8 +458,8 @@ void IntRange::splitBySign(IntRange& negRange, bool& hasNegRange,
const IntRange& IntRange::dump(const char* funcName, Expression *e) const
{
printf("[(%c)%#018llx, (%c)%#018llx] @ %s ::: %s\n",
imin.negative?'-':'+', imin.value,
imax.negative?'-':'+', imax.value,
imin.negative?'-':'+', (unsigned long long)imin.value,
imax.negative?'-':'+', (unsigned long long)imax.value,
funcName, e->toChars());
return *this;
}
+3 -5
View File
@@ -20,8 +20,8 @@ struct Identifier;
struct Symbol;
struct FuncDeclaration;
struct Blockx;
struct Array;
struct elem;
#include "arraytypes.h"
struct IRState
{
@@ -34,12 +34,10 @@ struct IRState
Symbol *sthis; // 'this' parameter to function (member and nested)
Symbol *sclosure; // pointer to closure instance
Blockx *blx;
Array *deferToObj; // array of Dsymbol's to run toObjFile(int multiobj) on later
Dsymbols *deferToObj; // array of Dsymbol's to run toObjFile(int multiobj) on later
elem *ehidden; // transmit hidden pointer to CallExp::toElem()
Symbol *startaddress;
#if DMDV2
Array *varsInScope; // variables that are in scope that will need destruction later
#endif
VarDeclarations *varsInScope; // variables that are in scope that will need destruction later
block *breakBlock;
block *contBlock;
+40 -18
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);
+2 -2
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 */
+6 -5
View File
@@ -728,7 +728,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);
}
@@ -739,7 +738,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;
@@ -1981,7 +1980,6 @@ TOK Lexer::number(Token *t)
};
enum FLAGS flags = FLAGS_decimal;
int i;
int base;
unsigned c;
unsigned char *start;
@@ -2226,7 +2224,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;
}
@@ -2572,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;
+7 -2
View File
@@ -23,11 +23,16 @@ struct ObjSymbol
ObjModule *om;
};
#include "arraytypes.h"
typedef ArrayBase<ObjModule> ObjModules;
typedef ArrayBase<ObjSymbol> ObjSymbols;
struct Library
{
File *libfile;
Array objmodules; // ObjModule[]
Array objsymbols; // ObjSymbol[]
ObjModules objmodules; // ObjModule[]
ObjSymbols objsymbols; // ObjSymbol[]
StringTable tab;
+3 -2
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
+4 -7
View File
@@ -100,7 +100,7 @@ Global::Global()
"\nMSIL back-end (alpha release) by Cristian L. Vlasceanu and associates.";
#endif
;
version = "v2.054";
version = "v2.055";
#if IN_LLVM
ldc_version = "LDC trunk";
llvm_version = "LLVM 2.9";
@@ -238,8 +238,6 @@ void halt()
#endif
}
extern signed char tyalignsize[];
/***********************************
* Parse and append contents of environment variable envvar
* to argc and argv[].
@@ -261,7 +259,7 @@ 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;
@@ -276,14 +274,13 @@ void getenv_setargv(const char *envvar, int *pargc, char** *pargv)
argv->setDim(i);
break;
} else {
argv->data[i] = (void *)(*pargv)[i];
}
}
// HACK to stop required values from command line being drawn from DFLAGS
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
@@ -362,5 +359,5 @@ Ldone:
argv->data[argc++] = (void *)(*pargv)[i];
*pargc = argc;
*pargv = (char **)argv->data;
*pargv = argv->tdata();
}
+25 -16
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,
@@ -113,8 +114,12 @@ void unittests();
*/
#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_OPENBSD || TARGET_SOLARIS
@@ -130,9 +135,13 @@ void unittests();
#endif
struct Array;
struct OutBuffer;
// 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;
#if IN_LLVM
enum ARCH
{
@@ -180,9 +189,9 @@ struct Param
#endif
ARCH cpu; // target CPU
OS os;
bool is64bit; // generate X86_64 bit code
char map; // generate linker .map file
bool isLE; // generate little endian code
bool is64bit; // generate 64 bit code
bool useDeprecated; // allow use of deprecated features
bool useAssert; // generate runtime code for assert()'s
bool useInvariants; // generate class invariant checks
@@ -197,15 +206,15 @@ struct Param
char enforcePropertySyntax;
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
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 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
@@ -215,15 +224,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
@@ -241,9 +250,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;
@@ -288,8 +297,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;
#if IN_LLVM
+55 -62
View File
@@ -64,9 +64,9 @@ AggregateDeclaration *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()
@@ -79,8 +79,6 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
{
FileName *srcfilename;
#if IN_DMD
FileName *cfilename;
FileName *hfilename;
FileName *objfilename;
FileName *symfilename;
#endif
@@ -424,7 +422,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;
@@ -438,10 +436,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
@@ -478,7 +475,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->tdata()[i];
char *n = FileName::combine(p, sdi);
if (FileName::exists(n))
{ result = n;
@@ -502,7 +499,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());
}
}
@@ -529,10 +526,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
@@ -858,7 +855,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->tdata()[0]->ident != Id::object)
{
Import *im = new Import(0, NULL, Id::object, NULL, 0);
members->shift(im);
@@ -869,9 +866,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);
}
}
@@ -883,14 +880,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);
}
@@ -927,7 +924,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);
}
@@ -937,23 +934,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);
@@ -969,13 +966,12 @@ void Module::semantic(Scope* unused_sc)
}
void Module::semantic2(Scope* unused_sc)
{ int i;
{
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");
}
@@ -994,10 +990,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);
}
@@ -1008,8 +1004,7 @@ void Module::semantic2(Scope* unused_sc)
}
void Module::semantic3(Scope* unused_sc)
{ int i;
{
//printf("Module::semantic3('%s'): parent = %p\n", toChars(), parent);
if (semanticstarted >= 3)
return;
@@ -1023,10 +1018,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);
}
@@ -1048,8 +1043,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());
@@ -1073,8 +1068,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);
}
@@ -1134,8 +1129,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;
}
}
@@ -1147,9 +1142,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;
@@ -1194,10 +1189,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];
@@ -1221,13 +1216,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)
@@ -1250,16 +1245,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;
}
@@ -1270,7 +1265,7 @@ int Module::selfImports()
/* =========================== ModuleDeclaration ===================== */
ModuleDeclaration::ModuleDeclaration(Array *packages, Identifier *id, bool safe)
ModuleDeclaration::ModuleDeclaration(Identifiers *packages, Identifier *id, bool safe)
{
this->packages = packages;
this->id = id;
@@ -1280,12 +1275,11 @@ ModuleDeclaration::ModuleDeclaration(Array *packages, Identifier *id, bool safe)
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('.');
@@ -1310,7 +1304,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;
@@ -1320,10 +1314,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);
+12 -12
View File
@@ -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();
@@ -103,19 +103,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
Escape *escapetable; // document comment escapes
@@ -130,7 +130,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);
@@ -221,10 +221,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, bool safe);
ModuleDeclaration(Identifiers *packages, Identifier *id, bool safe);
char *toChars();
};
+171 -228
View File
@@ -60,6 +60,7 @@ unsigned GetTypeAlignment(Ir* ir, Type* t);
#endif
FuncDeclaration *hasThis(Scope *sc);
void ObjectNotFound(Identifier *id);
#define LOGDOTEXP 0 // log ::dotExp()
@@ -196,16 +197,13 @@ void Type::init(Ir* _sir)
#else
void Type::init()
#endif
{ int i;
int j;
{
Lexer::initKeywords();
for (i = 0; i < TMAX; i++)
for (size_t i = 0; i < TMAX; i++)
sizeTy[i] = sizeof(TypeBasic);
sizeTy[Tsarray] = sizeof(TypeSArray);
sizeTy[Tarray] = sizeof(TypeDArray);
//sizeTy[Tnarray] = sizeof(TypeNArray);
sizeTy[Taarray] = sizeof(TypeAArray);
sizeTy[Tpointer] = sizeof(TypePointer);
sizeTy[Treference] = sizeof(TypeReference);
@@ -224,7 +222,6 @@ void Type::init()
mangleChar[Tarray] = 'A';
mangleChar[Tsarray] = 'G';
mangleChar[Tnarray] = '@';
mangleChar[Taarray] = 'H';
mangleChar[Tpointer] = 'P';
mangleChar[Treference] = 'R';
@@ -270,9 +267,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]);
}
@@ -285,7 +282,7 @@ 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++)
{ Type *t = new TypeBasic(basetab[i]);
t = t->merge();
basic[basetab[i]] = t;
@@ -382,7 +379,7 @@ Type *Type::trySemantic(Loc loc, Scope *sc)
* Determine if converting 'this' to 'to' is an identity operation,
* a conversion to const operation, or the types aren't the same.
* Returns:
* MATCHequal 'this' == 'to'
* MATCHexact 'this' == 'to'
* MATCHconst 'to' is const
* MATCHnomatch conversion to mutable or invariant
*/
@@ -909,7 +906,7 @@ void Type::check()
}
Type *tn = nextOf();
if (tn && ty != Tfunction && ty != Tdelegate)
if (tn && ty != Tfunction && tn->ty != Tfunction)
{ // Verify transitivity
switch (mod)
{
@@ -1915,17 +1912,6 @@ Expression *Type::noMember(Scope *sc, Expression *e, Identifier *ident)
ident != Id::stringof &&
ident != Id::offsetof)
{
/* See if we should forward to the alias this.
*/
if (sym->aliasthis)
{ /* Rewrite e.ident as:
* e.aliasthis.ident
*/
e = new DotIdExp(e->loc, e, sym->aliasthis->ident);
e = new DotIdExp(e->loc, e, ident);
return e->semantic(sc);
}
/* Look for overloaded opDot() to see if we should forward request
* to it.
*/
@@ -1962,6 +1948,17 @@ Expression *Type::noMember(Scope *sc, Expression *e, Identifier *ident)
return e;
//return e->semantic(sc);
}
/* See if we should forward to the alias this.
*/
if (sym->aliasthis)
{ /* Rewrite e.ident as:
* e.aliasthis.ident
*/
e = new DotIdExp(e->loc, e, sym->aliasthis->ident);
e = new DotIdExp(e->loc, e, ident);
return e->semantic(sc);
}
}
return Type::dotExp(sc, e, ident);
@@ -2217,7 +2214,7 @@ Type *TypeNext::makeConst()
return cto;
}
TypeNext *t = (TypeNext *)Type::makeConst();
if (ty != Tfunction && ty != Tdelegate &&
if (ty != Tfunction && next->ty != Tfunction &&
//(next->deco || next->ty == Tfunction) &&
!next->isImmutable() && !next->isConst())
{ if (next->isShared())
@@ -2241,7 +2238,7 @@ Type *TypeNext::makeInvariant()
return ito;
}
TypeNext *t = (TypeNext *)Type::makeInvariant();
if (ty != Tfunction && ty != Tdelegate &&
if (ty != Tfunction && next->ty != Tfunction &&
//(next->deco || next->ty == Tfunction) &&
!next->isImmutable())
{ t->next = next->invariantOf();
@@ -2261,7 +2258,7 @@ Type *TypeNext::makeShared()
return sto;
}
TypeNext *t = (TypeNext *)Type::makeShared();
if (ty != Tfunction && ty != Tdelegate &&
if (ty != Tfunction && next->ty != Tfunction &&
//(next->deco || next->ty == Tfunction) &&
!next->isImmutable() && !next->isShared())
{
@@ -2286,7 +2283,7 @@ Type *TypeNext::makeSharedConst()
return scto;
}
TypeNext *t = (TypeNext *)Type::makeSharedConst();
if (ty != Tfunction && ty != Tdelegate &&
if (ty != Tfunction && next->ty != Tfunction &&
//(next->deco || next->ty == Tfunction) &&
!next->isImmutable() && !next->isSharedConst())
{
@@ -2308,7 +2305,7 @@ Type *TypeNext::makeWild()
return wto;
}
TypeNext *t = (TypeNext *)Type::makeWild();
if (ty != Tfunction && ty != Tdelegate &&
if (ty != Tfunction && next->ty != Tfunction &&
//(next->deco || next->ty == Tfunction) &&
!next->isImmutable() && !next->isConst() && !next->isWild())
{
@@ -2333,7 +2330,7 @@ Type *TypeNext::makeSharedWild()
return swto;
}
TypeNext *t = (TypeNext *)Type::makeSharedWild();
if (ty != Tfunction && ty != Tdelegate &&
if (ty != Tfunction && next->ty != Tfunction &&
//(next->deco || next->ty == Tfunction) &&
!next->isImmutable() && !next->isSharedConst())
{
@@ -2351,7 +2348,7 @@ Type *TypeNext::makeMutable()
{
//printf("TypeNext::makeMutable() %p, %s\n", this, toChars());
TypeNext *t = (TypeNext *)Type::makeMutable();
if ((ty != Tfunction && ty != Tdelegate &&
if ((ty != Tfunction && next->ty != Tfunction &&
//(next->deco || next->ty == Tfunction) &&
next->isWild()) || ty == Tsarray)
{
@@ -2571,12 +2568,12 @@ unsigned TypeBasic::alignsize()
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
case Tint64:
case Tuns64:
sz = global.params.isX86_64 ? 8 : 4;
sz = global.params.is64bit ? 8 : 4;
break;
case Tfloat64:
case Timaginary64:
sz = global.params.isX86_64 ? 8 : 4;
sz = global.params.is64bit ? 8 : 4;
break;
case Tcomplex32:
@@ -2584,7 +2581,7 @@ unsigned TypeBasic::alignsize()
break;
case Tcomplex64:
sz = global.params.isX86_64 ? 8 : 4;
sz = global.params.is64bit ? 8 : 4;
break;
#endif
#if IN_DMD
@@ -2832,7 +2829,6 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
}
}
Ldefault:
return Type::getProperty(loc, ident);
Livalue:
@@ -3420,7 +3416,7 @@ void TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
{ error(loc, "tuple index %ju exceeds length %u", d, td->objects->dim);
goto Ldefault;
}
Object *o = (Object *)td->objects->data[(size_t)d];
Object *o = td->objects->tdata()[(size_t)d];
if (o->dyncast() == DYNCAST_DSYMBOL)
{
*ps = (Dsymbol *)o;
@@ -3440,7 +3436,7 @@ void TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
*/
Objects *objects = new Objects;
objects->setDim(1);
objects->data[0] = o;
objects->tdata()[0] = o;
TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects);
*ps = tds;
@@ -3474,7 +3470,7 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
{ error(loc, "tuple index %ju exceeds %u", d, sd->objects->dim);
return Type::terror;
}
Object *o = (Object *)sd->objects->data[(size_t)d];
Object *o = sd->objects->tdata()[(size_t)d];
if (o->dyncast() != DYNCAST_TYPE)
{ error(loc, "%s is not a type", toChars());
return Type::terror;
@@ -3551,7 +3547,7 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
{ error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim);
goto Lerror;
}
Parameter *arg = (Parameter *)tt->arguments->data[(size_t)d];
Parameter *arg = tt->arguments->tdata()[(size_t)d];
return arg->type;
}
case Tstruct:
@@ -3737,7 +3733,7 @@ Expression *TypeSArray::defaultInitLiteral(Loc loc)
Expressions *elements = new Expressions();
elements->setDim(d);
for (size_t i = 0; i < d; i++)
elements->data[i] = elementinit;
elements->tdata()[i] = elementinit;
ArrayLiteralExp *ae = new ArrayLiteralExp(0, elements);
ae->type = this;
return ae;
@@ -3973,87 +3969,6 @@ int TypeDArray::hasPointers()
}
/***************************** TypeNewArray *****************************/
#if 0
TypeNewArray::TypeNewArray(Type *telement)
: TypeArray(Tnewarray, telement)
{
sym = NULL;
}
Type *TypeNewArray::syntaxCopy()
{
Type *t = next->syntaxCopy();
if (t == next)
t = this;
else
{ t = new TypeNewArray(t);
t->mod = mod;
}
return t;
}
d_uns64 TypeNewArray::size(Loc loc)
{
//printf("TypeNewArray::size()\n");
return PTRSIZE;
}
unsigned TypeNewArray::alignsize()
{
return PTRSIZE;
}
Type *TypeNewArray::semantic(Loc loc, Scope *sc)
{ Type *tn = next;
tn = next->semantic(loc,sc);
Type *tbn = tn->toBasetype();
switch (tbn->ty)
{
case Tfunction:
case Tnone:
case Ttuple:
error(loc, "can't have array of %s", tbn->toChars());
tn = next = tint32;
break;
case Tstruct:
{ TypeStruct *ts = (TypeStruct *)tbn;
if (0 && ts->sym->isnested)
error(loc, "cannot have array of inner structs %s", ts->toChars());
break;
}
}
if (tn->isscope())
error(loc, "cannot have array of scope %s", tn->toChars());
next = tn;
transitive();
return merge();
}
void TypeNewArray::toDecoBuffer(OutBuffer *buf, int flag)
{
Type::toDecoBuffer(buf, flag);
buf->writeByte('e');
if (next)
next->toDecoBuffer(buf, (flag & 0x100) ? 0 : mod);
}
void TypeNewArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
{ toCBuffer3(buf, hgs, mod);
return;
}
next->toCBuffer2(buf, hgs, this->mod);
buf->writestring("[new]");
}
#endif
/***************************** TypeAArray *****************************/
TypeAArray::TypeAArray(Type *t, Type *index)
@@ -4190,6 +4105,10 @@ StructDeclaration *TypeAArray::getImpl()
// Create AssociativeArray!(index, next)
#if 1
if (! Type::associativearray)
{
ObjectNotFound(Id::AssociativeArray);
}
TemplateInstance *ti = new TemplateInstance(loc, Type::associativearray, tiargs);
#else
//Expression *e = new IdentifierExp(loc, Id::object);
@@ -4343,11 +4262,18 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
}
else
#endif
if (ident != Id::__sizeof &&
ident != Id::__xalignof &&
ident != Id::init &&
ident != Id::mangleof &&
ident != Id::stringof &&
ident != Id::offsetof)
{
e->type = getImpl()->type;
e = e->type->dotExp(sc, e, ident);
//e = Type::dotExp(sc, e, ident);
}
else
e = Type::dotExp(sc, e, ident);
return e;
}
@@ -4501,14 +4427,35 @@ MATCH TypePointer::implicitConvTo(Type *to)
if (equals(to))
return MATCHexact;
if (to->ty == Tpointer)
if (next->ty == Tfunction)
{
if (to->ty == Tpointer)
{
TypePointer *tp = (TypePointer*)to;
if (tp->next->ty == Tfunction)
{
if (next->equals(tp->next))
return MATCHconst;
if (next->covariant(tp->next) == 1)
return MATCHconvert;
}
else if (tp->next->ty == Tvoid)
{
// Allow conversions to void*
return MATCHconvert;
}
}
return MATCHnomatch;
}
else if (to->ty == Tpointer)
{ TypePointer *tp = (TypePointer *)to;
assert(tp->next);
if (!MODimplicitConv(next->mod, tp->next->mod))
return MATCHnomatch; // not const-compatible
/* Alloc conversion to void[]
/* Alloc conversion to void*
*/
if (next->ty != Tvoid && tp->next->ty == Tvoid)
{
@@ -4532,6 +4479,18 @@ MATCH TypePointer::implicitConvTo(Type *to)
return MATCHnomatch;
}
MATCH TypePointer::constConv(Type *to)
{
if (next->ty == Tfunction)
{
if (to->nextOf() && next->equals(((TypeNext*)to)->next))
return Type::constConv(to);
else
return MATCHnomatch;
}
return TypeNext::constConv(to);
}
int TypePointer::isscalar()
{
return TRUE;
@@ -4990,9 +4949,9 @@ void TypeFunction::toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, Hd
}
if (td)
{ buf->writeByte('(');
for (int i = 0; i < td->origParameters->dim; i++)
for (size_t i = 0; i < td->origParameters->dim; i++)
{
TemplateParameter *tp = (TemplateParameter *)td->origParameters->data[i];
TemplateParameter *tp = td->origParameters->tdata()[i];
if (i)
buf->writestring(", ");
tp->toCBuffer(buf, hgs);
@@ -5093,10 +5052,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;
}
}
@@ -5220,7 +5179,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
{
size_t tdim = tt->arguments->dim;
for (size_t j = 0; j < tdim; j++)
{ Parameter *narg = (Parameter *)tt->arguments->data[j];
{ Parameter *narg = tt->arguments->tdata()[j];
narg->storageClass |= fparam->storageClass;
}
fparam->storageClass = 0;
@@ -5240,7 +5199,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
if (fparam->storageClass & STCauto)
{
if (fargs && i < fargs->dim)
{ Expression *farg = (Expression *)fargs->data[i];
{ Expression *farg = fargs->tdata()[i];
if (farg->isLvalue())
; // ref parameter
else
@@ -5297,10 +5256,8 @@ void TypeFunction::purityLevel()
{ Parameter *fparam = Parameter::getNth(tf->parameters, i);
if (fparam->storageClass & STClazy)
{
/* We could possibly allow this by doing further analysis on the
* lazy parameter to see if it's pure.
*/
error(0, "cannot have lazy parameters to a pure function");
tf->purity = PUREweak;
break;
}
if (fparam->storageClass & STCout)
{
@@ -5413,7 +5370,7 @@ int TypeFunction::callMatch(Expression *ethis, Expressions *args, int flag)
goto L1;
goto Nomatch; // not enough arguments
}
arg = (Expression *)args->data[u];
arg = args->tdata()[u];
assert(arg);
//printf("arg: %s, type: %s\n", arg->toChars(), arg->type->toChars());
@@ -5490,7 +5447,7 @@ int TypeFunction::callMatch(Expression *ethis, Expressions *args, int flag)
{ TypeArray *ta = (TypeArray *)tb;
for (; u < nargs; u++)
{
arg = (Expression *)args->data[u];
arg = args->tdata()[u];
assert(arg);
#if 1
/* If lazy array of delegates,
@@ -5758,9 +5715,9 @@ 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];
Identifier *id = t->idents.tdata()[i];
if (id->dyncast() == DYNCAST_DSYMBOL)
{
TemplateInstance *ti = (TemplateInstance *)id;
@@ -5768,7 +5725,7 @@ void TypeQualified::syntaxCopyHelper(TypeQualified *t)
ti = (TemplateInstance *)ti->syntaxCopy(NULL);
id = (Identifier *)ti;
}
idents.data[i] = id;
idents.tdata()[i] = id;
}
}
@@ -5780,10 +5737,8 @@ void TypeQualified::addIdent(Identifier *ident)
void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs)
{
int i;
for (i = 0; i < idents.dim; i++)
{ Identifier *id = (Identifier *)idents.data[i];
for (size_t i = 0; i < idents.dim; i++)
{ Identifier *id = idents.tdata()[i];
buf->writeByte('.');
@@ -5816,9 +5771,7 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
Expression **pe, Type **pt, Dsymbol **ps)
{
VarDeclaration *v;
FuncDeclaration *fd;
EnumMember *em;
TupleDeclaration *td;
Expression *e;
#if 0
@@ -5835,9 +5788,9 @@ 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 (int i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = (Identifier *)idents.data[i];
Identifier *id = idents.tdata()[i];
Dsymbol *sm = s->searchX(loc, sc, id);
//printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
//printf("\tgetType = '%s'\n", s->getType()->toChars());
@@ -5855,12 +5808,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, 0);
do
{
id = (Identifier *)idents.data[i];
id = idents.tdata()[i];
e = new DotIdExp(loc, e, id);
} while (++i < idents.dim);
e = e->semantic(sc);
@@ -5886,7 +5839,7 @@ 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);
if (id == Id::offsetof || !e->type)
{ e = new DotIdExp(e->loc, e, id);
@@ -6057,6 +6010,29 @@ void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsy
Dsymbol *scopesym;
//printf("TypeIdentifier::resolve(sc = %p, idents = '%s')\n", sc, toChars());
if ((ident->equals(Id::super) || ident->equals(Id::This)) && !hasThis(sc))
{
AggregateDeclaration *ad = sc->getStructClassScope();
if (ad)
{
ClassDeclaration *cd = ad->isClassDeclaration();
if (cd)
{
if (ident->equals(Id::This))
ident = cd->ident;
else if (cd->baseClass && ident->equals(Id::super))
ident = cd->baseClass->ident;
}
else
{
StructDeclaration *sd = ad->isStructDeclaration();
if (sd && ident->equals(Id::This))
ident = sd->ident;
}
}
}
Dsymbol *s = sc->search(loc, ident, &scopesym);
resolveHelper(loc, sc, s, scopesym, pe, pt, ps);
if (*pt)
@@ -6079,9 +6055,9 @@ 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];
Identifier *id = idents.tdata()[i];
s = s->searchX(loc, sc, id);
if (!s) // failed to find a symbol
{ //printf("\tdidn't find a symbol\n");
@@ -6139,9 +6115,9 @@ 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];
Identifier *id = idents.tdata()[i];
e = new DotIdExp(loc, e, id);
}
@@ -6311,7 +6287,7 @@ void TypeTypeof::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
}
Type *TypeTypeof::semantic(Loc loc, Scope *sc)
{ Expression *e;
{
Type *t;
//printf("TypeTypeof::semantic() %s\n", toChars());
@@ -6409,7 +6385,7 @@ Type *TypeTypeof::semantic(Loc loc, Scope *sc)
{
if (!s)
break;
Identifier *id = (Identifier *)idents.data[i];
Identifier *id = idents.tdata()[i];
s = s->searchX(loc, sc, id);
}
@@ -6489,7 +6465,7 @@ Type *TypeReturn::semantic(Loc loc, Scope *sc)
{
if (!s)
break;
Identifier *id = (Identifier *)idents.data[i];
Identifier *id = idents.tdata()[i];
s = s->searchX(loc, sc, id);
}
if (s)
@@ -7134,8 +7110,7 @@ void TypeStruct::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
}
Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
{ unsigned offset;
{
VarDeclaration *v;
Dsymbol *s;
DotVarExp *de;
@@ -7161,7 +7136,7 @@ Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
Expressions *exps = new Expressions;
exps->reserve(sym->fields.dim);
for (size_t i = 0; i < sym->fields.dim; i++)
{ VarDeclaration *v = (VarDeclaration *)sym->fields.data[i];
{ VarDeclaration *v = sym->fields.tdata()[i];
Expression *fe = new DotVarExp(e->loc, e, v);
exps->push(fe);
}
@@ -7264,21 +7239,11 @@ L1:
OverloadSet *o = s->isOverloadSet();
if (o)
{ /* We really should allow this, triggered by:
* template c()
* {
* void a();
* void b () { this.a(); }
* }
* struct S
* {
* mixin c;
* mixin c;
* }
* alias S e;
*/
error(e->loc, "overload set for %s.%s not allowed in struct declaration", e->toChars(), ident->toChars());
return new ErrorExp();
{
OverExp *oe = new OverExp(o);
if (e->op == TOKtype)
return oe;
return new DotExp(e->loc, e, oe);
}
d = s->isDeclaration();
@@ -7372,7 +7337,7 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
structelems->setDim(sym->fields.dim);
for (size_t j = 0; j < structelems->dim; j++)
{
VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]);
VarDeclaration *vd = sym->fields.tdata()[j];
Expression *e;
if (vd->init)
{ if (vd->init->isVoidInitializer())
@@ -7382,7 +7347,7 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
}
else
e = vd->type->defaultInitLiteral();
structelems->data[j] = e;
structelems->tdata()[j] = e;
}
StructLiteralExp *structinit = new StructLiteralExp(loc, (StructDeclaration *)sym, structelems);
// Why doesn't the StructLiteralExp constructor do this, when
@@ -7416,7 +7381,7 @@ int TypeStruct::isAssignable()
* then one cannot assign this struct.
*/
for (size_t i = 0; i < sym->fields.dim; i++)
{ VarDeclaration *v = (VarDeclaration *)sym->fields.data[i];
{ VarDeclaration *v = sym->fields.tdata()[i];
//printf("%s [%d] v = (%s) %s, v->offset = %d, v->parent = %s", sym->toChars(), i, v->kind(), v->toChars(), v->offset, v->parent->kind());
if (i == 0)
;
@@ -7450,7 +7415,7 @@ int TypeStruct::hasPointers()
sym->size(0); // give error for forward references
for (size_t i = 0; i < s->fields.dim; i++)
{
Dsymbol *sm = (Dsymbol *)s->fields.data[i];
Dsymbol *sm = s->fields.tdata()[i];
Declaration *d = sm->isDeclaration();
if (d->storage_class & STCref || d->hasPointers())
return TRUE;
@@ -7515,8 +7480,8 @@ MATCH TypeStruct::implicitConvTo(Type *to)
{ /* Check all the fields. If they can all be converted,
* allow the conversion.
*/
for (int i = 0; i < sym->fields.dim; i++)
{ Dsymbol *s = (Dsymbol *)sym->fields.data[i];
for (size_t i = 0; i < sym->fields.dim; i++)
{ Dsymbol *s = sym->fields.tdata()[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
@@ -7614,9 +7579,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;
@@ -7645,7 +7608,7 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
Expressions *exps = new Expressions;
exps->reserve(sym->fields.dim);
for (size_t i = 0; i < sym->fields.dim; i++)
{ VarDeclaration *v = (VarDeclaration *)sym->fields.data[i];
{ VarDeclaration *v = sym->fields.tdata()[i];
// Don't include hidden 'this' pointer
if (v->isThisDeclaration())
continue;
@@ -7867,10 +7830,11 @@ L1:
OverloadSet *o = s->isOverloadSet();
if (o)
{ /* We really should allow this
*/
error(e->loc, "overload set for %s.%s not allowed in struct declaration", e->toChars(), ident->toChars());
return new ErrorExp();
{
OverExp *oe = new OverExp(o);
if (e->op == TOKtype)
return oe;
return new DotExp(e->loc, e, oe);
}
Declaration *d = s->isDeclaration();
@@ -8056,7 +8020,7 @@ TypeTuple::TypeTuple(Parameters *arguments)
{
for (size_t i = 0; i < arguments->dim; i++)
{
Parameter *arg = (Parameter *)arguments->data[i];
Parameter *arg = arguments->tdata()[i];
assert(arg && arg->type);
}
}
@@ -8076,11 +8040,11 @@ TypeTuple::TypeTuple(Expressions *exps)
{
arguments->setDim(exps->dim);
for (size_t i = 0; i < exps->dim; i++)
{ Expression *e = (Expression *)exps->data[i];
{ Expression *e = exps->tdata()[i];
if (e->type->ty == Ttuple)
e->error("cannot form tuple of tuples");
Parameter *arg = new Parameter(STCundefined, e->type, NULL, NULL);
arguments->data[i] = (void *)arg;
arguments->tdata()[i] = arg;
}
}
this->arguments = arguments;
@@ -8147,8 +8111,8 @@ int TypeTuple::equals(Object *o)
if (arguments->dim == tt->arguments->dim)
{
for (size_t i = 0; i < tt->arguments->dim; i++)
{ Parameter *arg1 = (Parameter *)arguments->data[i];
Parameter *arg2 = (Parameter *)tt->arguments->data[i];
{ Parameter *arg1 = arguments->tdata()[i];
Parameter *arg2 = tt->arguments->tdata()[i];
if (!arg1->type->equals(arg2->type))
return 0;
@@ -8165,7 +8129,7 @@ Type *TypeTuple::reliesOnTident()
{
for (size_t i = 0; i < arguments->dim; i++)
{
Parameter *arg = (Parameter *)arguments->data[i];
Parameter *arg = arguments->tdata()[i];
Type *t = arg->type->reliesOnTident();
if (t)
return t;
@@ -8184,9 +8148,9 @@ Type *TypeTuple::makeConst()
t->arguments = new Parameters();
t->arguments->setDim(arguments->dim);
for (size_t i = 0; i < arguments->dim; i++)
{ Parameter *arg = (Parameter *)arguments->data[i];
{ Parameter *arg = arguments->tdata()[i];
Parameter *narg = new Parameter(arg->storageClass, arg->type->constOf(), arg->ident, arg->defaultArg);
t->arguments->data[i] = (Parameter *)narg;
t->arguments->tdata()[i] = (Parameter *)narg;
}
return t;
}
@@ -8274,7 +8238,7 @@ Type *TypeSlice::semantic(Loc loc, Scope *sc)
Parameters *args = new Parameters;
args->reserve(i2 - i1);
for (size_t i = i1; i < i2; i++)
{ Parameter *arg = (Parameter *)tt->arguments->data[i];
{ Parameter *arg = tt->arguments->tdata()[i];
args->push(arg);
}
@@ -8330,7 +8294,7 @@ void TypeSlice::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
objects->setDim(i2 - i1);
for (size_t i = 0; i < objects->dim; i++)
{
objects->data[i] = td->objects->data[(size_t)i1 + i];
objects->tdata()[i] = td->objects->tdata()[(size_t)i1 + i];
}
TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects);
@@ -8358,27 +8322,6 @@ void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
buf->printf("%s]", upr->toChars());
}
/***************************** TypeNewArray *****************************/
/* T[new]
*/
TypeNewArray::TypeNewArray(Type *next)
: TypeNext(Tnarray, next)
{
//printf("TypeNewArray\n");
}
void TypeNewArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
{ toCBuffer3(buf, hgs, mod);
return;
}
next->toCBuffer2(buf, hgs, this->mod);
buf->writestring("[new]");
}
/***************************** Parameter *****************************/
Parameter::Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg)
@@ -8406,10 +8349,10 @@ Parameters *Parameter::arraySyntaxCopy(Parameters *args)
a = new Parameters();
a->setDim(args->dim);
for (size_t i = 0; i < a->dim; i++)
{ Parameter *arg = (Parameter *)args->data[i];
{ Parameter *arg = args->tdata()[i];
arg = arg->syntaxCopy();
a->data[i] = (void *)arg;
a->tdata()[i] = arg;
}
}
return a;
@@ -8428,10 +8371,10 @@ char *Parameter::argsTypesToChars(Parameters *args, int varargs)
{ OutBuffer argbuf;
HdrGenState hgs;
for (int i = 0; i < args->dim; i++)
for (size_t i = 0; i < args->dim; i++)
{ if (i)
buf->writeByte(',');
Parameter *arg = (Parameter *)args->data[i];
Parameter *arg = args->tdata()[i];
argbuf.reset();
arg->type->toCBuffer2(&argbuf, &hgs, 0);
buf->write(&argbuf);
@@ -8452,14 +8395,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++)
for (size_t i = 0; i < arguments->dim; i++)
{
if (i)
buf->writestring(", ");
Parameter *arg = (Parameter *)arguments->data[i];
Parameter *arg = arguments->tdata()[i];
if (arg->storageClass & STCauto)
buf->writestring("auto ");
@@ -8499,7 +8442,7 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
}
if (varargs)
{
if (i && varargs == 1)
if (arguments->dim && varargs == 1)
buf->writeByte(',');
buf->writestring("...");
}
@@ -8620,7 +8563,7 @@ size_t Parameter::dim(Parameters *args)
if (args)
{
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)
@@ -8649,7 +8592,7 @@ Parameter *Parameter::getNth(Parameters *args, size_t nth, size_t *pn)
size_t n = 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)
+2 -8
View File
@@ -63,7 +63,6 @@ enum ENUMTY
{
Tarray, // slice array, aka T[]
Tsarray, // static array, aka T[dimension]
Tnarray, // resizable array, aka T[new]
Taarray, // associative array, aka T[type]
Tpointer,
Treference,
@@ -549,6 +548,7 @@ struct TypePointer : TypeNext
d_uns64 size(Loc loc);
void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
MATCH implicitConvTo(Type *to);
MATCH constConv(Type *to);
int isscalar();
// LDC: pointers are unsigned
int isunsigned() { return TRUE; };
@@ -690,7 +690,7 @@ struct TypeDelegate : TypeNext
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);
@@ -966,12 +966,6 @@ struct TypeSlice : TypeNext
void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
};
struct TypeNewArray : TypeNext
{
TypeNewArray(Type *next);
void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
};
/**************************************************************/
//enum InOut { None, In, Out, InOut, Lazy };
+28 -18
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
@@ -475,6 +475,11 @@ Expression *BinExp::op_overload(Scope *sc)
Objects *targsi = NULL;
#if DMDV2
if (op == TOKplusplus || op == TOKminusminus)
{ // Bug4099 fix
if (ad1 && search_function(ad1, Id::opUnary))
return NULL;
}
if (!s && !s_r && op != TOKequal && op != TOKnotequal && op != TOKassign &&
op != TOKplusplus && op != TOKminusminus)
{
@@ -504,9 +509,9 @@ Expression *BinExp::op_overload(Scope *sc)
*/
args1.setDim(1);
args1.data[0] = (void*) e1;
args1.tdata()[0] = e1;
args2.setDim(1);
args2.data[0] = (void*) e2;
args2.tdata()[0] = e2;
argsset = 1;
Match m;
@@ -597,9 +602,9 @@ L1:
if (!argsset)
{ args1.setDim(1);
args1.data[0] = (void*) e1;
args1.tdata()[0] = e1;
args2.setDim(1);
args2.data[0] = (void*) e2;
args2.tdata()[0] = e2;
}
Match m;
@@ -755,9 +760,9 @@ Expression *BinExp::compare_overload(Scope *sc, Identifier *id)
Expressions args2;
args1.setDim(1);
args1.data[0] = (void*) e1;
args1.tdata()[0] = e1;
args2.setDim(1);
args2.data[0] = (void*) e2;
args2.tdata()[0] = e2;
Match m;
memset(&m, 0, sizeof(m));
@@ -895,12 +900,17 @@ Expression *EqualExp::op_overload(Scope *sc)
if (t1->ty == Tclass && t2->ty == Tclass)
{
/* Rewrite as:
* .object.opEquals(e1, e2)
* .object.opEquals(cast(Object)e1, cast(Object)e2)
* The explicit cast is necessary for interfaces,
* see http://d.puremagic.com/issues/show_bug.cgi?id=4088
*/
Expression *e1x = e1; //new CastExp(loc, e1, ClassDeclaration::object->getType());
Expression *e2x = e2; //new CastExp(loc, e2, ClassDeclaration::object->getType());
Expression *e = new IdentifierExp(loc, Id::empty);
e = new DotIdExp(loc, e, Id::object);
e = new DotIdExp(loc, e, Id::eq);
e = new CallExp(loc, e, e1, e2);
e = new CallExp(loc, e, e1x, e2x);
e = e->semantic(sc);
return e;
}
@@ -940,8 +950,8 @@ Expression *BinAssignExp::op_overload(Scope *sc)
{
Expressions *a = new Expressions();
a->push(e2);
for (int i = 0; i < ae->arguments->dim; i++)
a->push(ae->arguments->data[i]);
for (size_t i = 0; i < ae->arguments->dim; i++)
a->push(ae->arguments->tdata()[i]);
Objects *targsi = opToArg(sc, op);
Expression *e = new DotTemplateInstanceExp(loc, ae->e1, fd->ident, targsi);
@@ -1054,7 +1064,7 @@ Expression *BinAssignExp::op_overload(Scope *sc)
*/
args2.setDim(1);
args2.data[0] = (void*) e2;
args2.tdata()[0] = e2;
Match m;
memset(&m, 0, sizeof(m));
@@ -1194,7 +1204,7 @@ void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr, Mo
for (size_t u = 0; 1; u++)
{ if (u == arguments->dim)
return;
Parameter *arg = (Parameter *)arguments->data[u];
Parameter *arg = arguments->tdata()[u];
if (!arg->type)
break;
}
@@ -1202,7 +1212,7 @@ void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr, Mo
Dsymbol *s;
AggregateDeclaration *ad;
Parameter *arg = (Parameter *)arguments->data[0];
Parameter *arg = arguments->tdata()[0];
Type *taggr = aggr->type;
if (!taggr)
return;
@@ -1216,7 +1226,7 @@ void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr, Mo
{
if (!arg->type)
arg->type = Type::tsize_t; // key type
arg = (Parameter *)arguments->data[1];
arg = arguments->tdata()[1];
}
if (!arg->type && tab->ty != Ttuple)
arg->type = tab->nextOf(); // value type
@@ -1229,7 +1239,7 @@ void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr, Mo
{
if (!arg->type)
arg->type = taa->index; // key type
arg = (Parameter *)arguments->data[1];
arg = arguments->tdata()[1];
}
if (!arg->type)
arg->type = taa->next; // value type
@@ -1365,7 +1375,7 @@ static int inferApplyArgTypesY(TypeFunction *tf, Parameters *arguments)
for (size_t u = 0; u < nparams; u++)
{
Parameter *arg = (Parameter *)arguments->data[u];
Parameter *arg = arguments->tdata()[u];
Parameter *param = Parameter::getNth(tf->parameters, u);
if (arg->type)
{ if (!arg->type->equals(param->type))
@@ -1409,7 +1419,7 @@ void inferApplyArgTypesZ(TemplateDeclaration *tstart, Parameters *arguments)
}
if (!td->parameters || td->parameters->dim != 1)
continue;
TemplateParameter *tp = (TemplateParameter *)td->parameters->data[0];
TemplateParameter *tp = td->parameters->tdata()[0];
TemplateAliasParameter *tap = tp->isTemplateAliasParameter();
if (!tap || !tap->specType || tap->specType->ty != Tfunction)
continue;
+16 -16
View File
@@ -202,10 +202,10 @@ Expression *VarExp::optimize(int result)
Expression *TupleExp::optimize(int result)
{
for (size_t i = 0; i < exps->dim; i++)
{ Expression *e = (Expression *)exps->data[i];
{ Expression *e = exps->tdata()[i];
e = e->optimize(WANTvalue | (result & WANTinterpret));
exps->data[i] = (void *)e;
exps->tdata()[i] = e;
}
return this;
}
@@ -215,10 +215,10 @@ Expression *ArrayLiteralExp::optimize(int result)
if (elements)
{
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (Expression *)elements->data[i];
{ Expression *e = elements->tdata()[i];
e = e->optimize(WANTvalue | (result & (WANTinterpret | WANTexpand)));
elements->data[i] = (void *)e;
elements->tdata()[i] = e;
}
}
return this;
@@ -228,14 +228,14 @@ Expression *AssocArrayLiteralExp::optimize(int result)
{
assert(keys->dim == values->dim);
for (size_t i = 0; i < keys->dim; i++)
{ Expression *e = (Expression *)keys->data[i];
{ Expression *e = keys->tdata()[i];
e = e->optimize(WANTvalue | (result & (WANTinterpret | WANTexpand)));
keys->data[i] = (void *)e;
keys->tdata()[i] = e;
e = (Expression *)values->data[i];
e = values->tdata()[i];
e = e->optimize(WANTvalue | (result & (WANTinterpret | WANTexpand)));
values->data[i] = (void *)e;
values->tdata()[i] = e;
}
return this;
}
@@ -245,11 +245,11 @@ Expression *StructLiteralExp::optimize(int result)
if (elements)
{
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (Expression *)elements->data[i];
{ Expression *e = elements->tdata()[i];
if (!e)
continue;
e = e->optimize(WANTvalue | (result & (WANTinterpret | WANTexpand)));
elements->data[i] = (void *)e;
elements->tdata()[i] = e;
}
}
return this;
@@ -494,20 +494,20 @@ Expression *NewExp::optimize(int result)
if (newargs)
{
for (size_t i = 0; i < newargs->dim; i++)
{ Expression *e = (Expression *)newargs->data[i];
{ Expression *e = newargs->tdata()[i];
e = e->optimize(WANTvalue);
newargs->data[i] = (void *)e;
newargs->tdata()[i] = e;
}
}
if (arguments)
{
for (size_t i = 0; i < arguments->dim; i++)
{ Expression *e = (Expression *)arguments->data[i];
{ Expression *e = arguments->tdata()[i];
e = e->optimize(WANTvalue);
arguments->data[i] = (void *)e;
arguments->tdata()[i] = e;
}
}
if (result & WANTinterpret)
@@ -526,10 +526,10 @@ Expression *CallExp::optimize(int result)
if (arguments)
{
for (size_t i = 0; i < arguments->dim; i++)
{ Expression *e = (Expression *)arguments->data[i];
{ Expression *e = arguments->tdata()[i];
e = e->optimize(WANTvalue);
arguments->data[i] = (void *)e;
arguments->tdata()[i] = e;
}
}
+105 -39
View File
@@ -62,6 +62,7 @@ Parser::Parser(Module *module, unsigned char *base, unsigned length, int doDocCo
linkage = LINKd;
endloc = 0;
inBrackets = 0;
lookingForElse = 0;
//nextToken(); // start up the scanner
}
@@ -101,14 +102,14 @@ Dsymbols *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)
@@ -227,6 +228,7 @@ Dsymbols *Parser::parseDeclDefs(int once)
case TOKalias:
case TOKtypedef:
case TOKidentifier:
case TOKsuper:
case TOKtypeof:
case TOKdot:
Ldeclaration:
@@ -235,7 +237,10 @@ Dsymbols *Parser::parseDeclDefs(int once)
continue;
case TOKthis:
s = parseCtor();
if (peekNext() == TOKdot)
goto Ldeclaration;
else
s = parseCtor();
break;
#if 0 // dead end, use this(this){} instead
@@ -293,11 +298,17 @@ Dsymbols *Parser::parseDeclDefs(int once)
s = parseStaticAssert();
else if (token.value == TOKif)
{ condition = parseStaticIfCondition();
Loc lookingForElseSave = lookingForElse;
lookingForElse = loc;
a = parseBlock();
lookingForElse = lookingForElseSave;
aelse = NULL;
if (token.value == TOKelse)
{ nextToken();
{
Loc elseloc = this->loc;
nextToken();
aelse = parseBlock();
checkDanglingElse(elseloc);
}
s = new StaticIfDeclaration(condition, a, aelse);
break;
@@ -575,11 +586,19 @@ Dsymbols *Parser::parseDeclDefs(int once)
goto Lcondition;
Lcondition:
a = parseBlock();
{
Loc lookingForElseSave = lookingForElse;
lookingForElse = loc;
a = parseBlock();
lookingForElse = lookingForElseSave;
}
aelse = NULL;
if (token.value == TOKelse)
{ nextToken();
{
Loc elseloc = this->loc;
nextToken();
aelse = parseBlock();
checkDanglingElse(elseloc);
}
s = new ConditionalDeclaration(condition, a, aelse);
break;
@@ -695,7 +714,6 @@ StorageClass Parser::parsePostfix()
Dsymbols *Parser::parseBlock()
{
Dsymbols *a = NULL;
Dsymbol *s;
//printf("parseBlock()\n");
switch (token.value)
@@ -710,6 +728,10 @@ Dsymbols *Parser::parseBlock()
break;
case TOKlcurly:
{
Loc lookingForElseSave = lookingForElse;
lookingForElse = 0;
nextToken();
a = parseDeclDefs(0);
if (token.value != TOKrcurly)
@@ -718,7 +740,9 @@ Dsymbols *Parser::parseBlock()
}
else
nextToken();
lookingForElse = lookingForElseSave;
break;
}
case TOKcolon:
nextToken();
@@ -914,8 +938,6 @@ Condition *Parser::parseVersionCondition()
Condition *Parser::parseStaticIfCondition()
{ Expression *exp;
Condition *condition;
Array *aif;
Array *aelse;
Loc loc = this->loc;
nextToken();
@@ -1217,7 +1239,7 @@ Parameters *Parser::parseParameters(int *pvarargs)
check(TOKlparen);
while (1)
{ Type *tb;
{
Identifier *ai = NULL;
Type *at;
Parameter *a;
@@ -1346,7 +1368,7 @@ Parameters *Parser::parseParameters(int *pvarargs)
nextToken();
break;
}
L3:
L3:
a = new Parameter(storageClass, at, ai, ae);
arguments->push(a);
if (token.value == TOKcomma)
@@ -1864,7 +1886,7 @@ Dsymbol *Parser::parseMixin()
Identifier *id;
Type *tqual;
Objects *tiargs;
Array *idents;
Identifiers *idents;
//printf("parseMixin()\n");
nextToken();
@@ -1890,7 +1912,7 @@ Dsymbol *Parser::parseMixin()
nextToken();
}
idents = new Array();
idents = new Identifiers();
while (1)
{
tiargs = NULL;
@@ -1990,8 +2012,8 @@ Objects *Parser::parseTemplateArgumentList2()
* a deduced type.
*/
TemplateParameters *tpl = NULL;
for (int i = 0; i < tf->parameters->dim; i++)
{ Parameter *param = (Parameter *)tf->parameters->data[i];
for (size_t i = 0; i < tf->parameters->dim; i++)
{ Parameter *param = tf->parameters->tdata()[i];
if (param->ident == NULL &&
param->type &&
param->type->ty == Tident &&
@@ -2098,7 +2120,7 @@ Import *Parser::parseImport(Dsymbols *decldefs, int isstatic)
{ Import *s;
Identifier *id;
Identifier *aliasid = NULL;
Array *a;
Identifiers *a;
Loc loc;
//printf("Parser::parseImport()\n");
@@ -2123,7 +2145,7 @@ Import *Parser::parseImport(Dsymbols *decldefs, int isstatic)
while (token.value == TOKdot)
{
if (!a)
a = new Array();
a = new Identifiers();
a->push(id);
nextToken();
if (token.value != TOKidentifier)
@@ -2272,6 +2294,8 @@ Type *Parser::parseBasicType()
nextToken();
break;
case TOKthis:
case TOKsuper:
case TOKidentifier:
id = token.ident;
nextToken();
@@ -3052,7 +3076,7 @@ L1:
#if 0 // Dumped feature
case TOKthrow:
if (!f->fthrows)
f->fthrows = new Array();
f->fthrows = new Types();
nextToken();
check(TOKlparen);
while (1)
@@ -3156,7 +3180,7 @@ Initializer *Parser::parseInitializer()
is = new StructInitializer(loc);
nextToken();
comma = 0;
comma = 2;
while (1)
{
switch (token.value)
@@ -3180,6 +3204,8 @@ Initializer *Parser::parseInitializer()
continue;
case TOKcomma:
if (comma == 2)
error("expression expected, not ','");
nextToken();
comma = 2;
continue;
@@ -3243,7 +3269,7 @@ Initializer *Parser::parseInitializer()
ia = new ArrayInitializer(loc);
nextToken();
comma = 0;
comma = 2;
while (1)
{
switch (token.value)
@@ -3280,6 +3306,8 @@ Initializer *Parser::parseInitializer()
continue;
case TOKcomma:
if (comma == 2)
error("expression expected, not ','");
nextToken();
comma = 2;
continue;
@@ -3342,6 +3370,20 @@ Expression *Parser::parseDefaultInitExp()
}
#endif
/*****************************************
*/
void Parser::checkDanglingElse(Loc elseloc)
{
if (token.value != TOKelse &&
token.value != TOKcatch &&
token.value != TOKfinally &&
lookingForElse.linnum != 0)
{
warning(elseloc, "else is dangling, add { } after condition at %s", lookingForElse.toChars());
}
}
/*****************************************
* Input:
* flags PSxxxx
@@ -3501,16 +3543,16 @@ Statement *Parser::parseStatement(int flags)
#endif
// case TOKtypeof:
Ldeclaration:
{ Array *a;
{ Dsymbols *a;
a = parseDeclarations(STCundefined, NULL);
if (a->dim > 1)
{
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];
Dsymbol *d = a->tdata()[i];
s = new ExpStatement(loc, d);
as->push(s);
}
@@ -3518,7 +3560,7 @@ Statement *Parser::parseStatement(int flags)
}
else if (a->dim == 1)
{
Dsymbol *d = (Dsymbol *)a->data[0];
Dsymbol *d = a->tdata()[0];
s = new ExpStatement(loc, d);
}
else
@@ -3586,6 +3628,9 @@ Statement *Parser::parseStatement(int flags)
case TOKlcurly:
{
Loc lookingForElseSave = lookingForElse;
lookingForElse = 0;
nextToken();
//if (token.value == TOKsemicolon)
//error("use '{ }' for an empty statement, not a ';'");
@@ -3599,6 +3644,7 @@ Statement *Parser::parseStatement(int flags)
if (flags & (PSscope | PScurlyscope))
s = new ScopeStatement(loc, s);
check(TOKrcurly, "compound statement");
lookingForElse = lookingForElseSave;
break;
}
@@ -3627,7 +3673,10 @@ Statement *Parser::parseStatement(int flags)
Expression *condition;
nextToken();
Loc lookingForElseSave = lookingForElse;
lookingForElse = 0;
body = parseStatement(PSscope);
lookingForElse = lookingForElseSave;
check(TOKwhile);
check(TOKlparen);
condition = parseExpression();
@@ -3650,7 +3699,11 @@ Statement *Parser::parseStatement(int flags)
nextToken();
}
else
{ init = parseStatement(0);
{
Loc lookingForElseSave = lookingForElse;
lookingForElse = 0;
init = parseStatement(0);
lookingForElse = lookingForElseSave;
}
if (token.value == TOKsemicolon)
{
@@ -3728,7 +3781,7 @@ Statement *Parser::parseStatement(int flags)
Expression *aggr = parseExpression();
if (token.value == TOKslice && arguments->dim == 1)
{
Parameter *a = (Parameter *)arguments->data[0];
Parameter *a = arguments->tdata()[0];
delete arguments;
nextToken();
Expression *upr = parseExpression();
@@ -3802,11 +3855,18 @@ Statement *Parser::parseStatement(int flags)
condition = parseExpression();
check(TOKrparen);
ifbody = parseStatement(PSscope);
{
Loc lookingForElseSave = lookingForElse;
lookingForElse = loc;
ifbody = parseStatement(PSscope);
lookingForElse = lookingForElseSave;
}
if (token.value == TOKelse)
{
Loc elseloc = this->loc;
nextToken();
elsebody = parseStatement(PSscope);
checkDanglingElse(elseloc);
}
else
elsebody = NULL;
@@ -3856,12 +3916,19 @@ Statement *Parser::parseStatement(int flags)
goto Lcondition;
Lcondition:
ifbody = parseStatement(0 /*PSsemi*/);
{
Loc lookingForElseSave = lookingForElse;
lookingForElse = loc;
ifbody = parseStatement(0 /*PSsemi*/);
lookingForElse = lookingForElseSave;
}
elsebody = NULL;
if (token.value == TOKelse)
{
Loc elseloc = this->loc;
nextToken();
elsebody = parseStatement(0 /*PSsemi*/);
checkDanglingElse(elseloc);
}
s = new ConditionalStatement(loc, condition, ifbody, elsebody);
break;
@@ -3911,7 +3978,7 @@ Statement *Parser::parseStatement(int flags)
case TOKcase:
{ Expression *exp;
Statements *statements;
Array cases; // array of Expression's
Expressions cases; // array of Expression's
Expression *last = NULL;
while (1)
@@ -3958,9 +4025,9 @@ Statement *Parser::parseStatement(int flags)
#endif
{
// 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];
exp = cases.tdata()[i - 1];
s = new CaseStatement(loc, exp, s);
}
}
@@ -4098,11 +4165,14 @@ Statement *Parser::parseStatement(int flags)
case TOKtry:
{ Statement *body;
Array *catches = NULL;
Catches *catches = NULL;
Statement *finalbody = NULL;
nextToken();
Loc lookingForElseSave = lookingForElse;
lookingForElse = 0;
body = parseStatement(PSscope);
lookingForElse = lookingForElseSave;
while (token.value == TOKcatch)
{
Statement *handler;
@@ -4127,7 +4197,7 @@ Statement *Parser::parseStatement(int flags)
handler = parseStatement(0);
c = new Catch(loc, t, id, handler);
if (!catches)
catches = new Array();
catches = new Catches();
catches->push(c);
}
@@ -4362,8 +4432,6 @@ int Parser::isBasicType(Token **pt)
{
// This code parallels parseBasicType()
Token *t = *pt;
Token *t2;
int parens;
int haveId = 0;
switch (t->value)
@@ -4731,7 +4799,6 @@ int Parser::isParameters(Token **pt)
break;
}
}
L3:
if (t->value == TOKcomma)
{
continue;
@@ -5178,7 +5245,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());
@@ -5469,7 +5535,7 @@ Expression *Parser::parsePostExp(Expression *e)
{ Identifier *id = token.ident;
nextToken();
if (token.value == TOKnot && peekNext() != TOKis)
if (token.value == TOKnot && peekNext() != TOKis && peekNext() != TOKin)
{ // identifier!(template-argument-list)
TemplateInstance *tempinst = new TemplateInstance(loc, id);
Objects *tiargs;
@@ -6356,7 +6422,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;
+3 -1
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
@@ -65,6 +65,7 @@ struct Parser : Lexer
enum LINK linkage;
Loc endloc; // set to location of last right curly
int inBrackets; // inside [] of array index or slice
Loc lookingForElse; // location of lonely if looking for an else
Parser(Module *module, unsigned char *base, unsigned length, int doDocComment);
@@ -110,6 +111,7 @@ struct Parser : Lexer
Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL, StorageClass storage_class = 0);
Dsymbols *parseDeclarations(StorageClass storage_class, unsigned char *comment);
void parseContracts(FuncDeclaration *f);
void checkDanglingElse(Loc elseloc);
Statement *parseStatement(int flags);
Initializer *parseInitializer();
Expression *parseDefaultInitExp();
+3 -1
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;
}
+8 -8
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); }
+3 -1
View File
@@ -216,9 +216,11 @@ 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++;
+21 -6
View File
@@ -1,5 +1,5 @@
// Copyright (C) 1990-1998 by Symantec
// Copyright (C) 2000-2009 by Digital Mars
// Copyright (C) 2000-2011 by Digital Mars
// All Rights Reserved
// http://www.digitalmars.com
// Written by Walter Bright
@@ -13,6 +13,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#if _WIN32
#include <tchar.h>
@@ -66,12 +67,18 @@ struct Narg
static int addargp(struct Narg *n, char *p)
{
/* The 2 is to always allow room for a NULL argp at the end */
if (n->argc + 2 >= n->argvmax)
if (n->argc + 2 > n->argvmax)
{
n->argvmax = n->argc + 2;
n->argv = (char **) realloc(n->argv,n->argvmax * sizeof(char *));
if (!n->argv)
char **ap = n->argv;
ap = (char **) realloc(ap,n->argvmax * sizeof(char *));
if (!ap)
{ if (n->argv)
free(n->argv);
memset(n, 0, sizeof(*n));
return 1;
}
n->argv = ap;
}
n->argv[n->argc++] = p;
return 0;
@@ -129,7 +136,7 @@ int response_expand(int *pargc, char ***pargv)
bufend = &buffer[len];
/* Read file into buffer */
#if _WIN32
fd = open(cp,O_RDONLY|O_BINARY);
fd = _open(cp,O_RDONLY|O_BINARY);
#else
fd = open(cp,O_RDONLY);
#endif
@@ -257,7 +264,15 @@ int response_expand(int *pargc, char ***pargv)
else if (addargp(&n,(*pargv)[i]))
goto noexpand;
}
n.argv[n.argc] = NULL;
if (n.argvmax == 0)
{
n.argvmax = 1;
n.argv = (char **) calloc(n.argvmax, sizeof(char *));
if (!n.argv)
return 1;
}
else
n.argv[n.argc] = NULL;
if (recurse)
{
/* Recursively expand @filename */
+18 -18
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
@@ -363,21 +363,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
for (; ; p++)
@@ -792,7 +792,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))
{
@@ -808,7 +808,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))
@@ -832,7 +832,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
@@ -869,7 +869,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)
@@ -959,7 +959,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))
@@ -1081,7 +1081,7 @@ 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;
}
@@ -1447,23 +1447,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);
@@ -1556,11 +1556,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;
+58 -8
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
@@ -60,7 +63,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
{
@@ -141,14 +149,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);
@@ -233,8 +241,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
@@ -267,7 +275,7 @@ struct OutBuffer : Object
OutBuffer();
~OutBuffer();
void *extractData();
char *extractData();
void mark();
void reserve(unsigned nbytes);
@@ -340,6 +348,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;
+4 -4
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++)
{
-1
View File
@@ -16,7 +16,6 @@
struct Dsymbol;
struct ScopeDsymbol;
struct Array;
struct Identifier;
struct Module;
struct Statement;
+285 -168
View File
File diff suppressed because it is too large Load Diff
+19 -7
View File
@@ -189,6 +189,18 @@ struct ExpStatement : Statement
#endif
};
struct DtorExpStatement : ExpStatement
{
/* Wraps an expression that is the destruction of 'var'
*/
VarDeclaration *var;
DtorExpStatement(Loc loc, Expression *exp, VarDeclaration *v);
Statement *syntaxCopy();
void toIR(IRState *irs);
};
struct CompileStatement : Statement
{
Expression *exp;
@@ -365,8 +377,8 @@ struct ForeachStatement : Statement
FuncDeclaration *func; // function we're lexically in
Array *cases; // put breaks, continues, gotos and returns here
Array *gotos; // forward referenced goto's go here
Statements *cases; // put breaks, continues, gotos and returns here
CompoundStatements *gotos; // forward referenced goto's go here
ForeachStatement(Loc loc, enum TOK op, Parameters *arguments, Expression *aggr, Statement *body);
Statement *syntaxCopy();
@@ -492,8 +504,8 @@ struct SwitchStatement : Statement
DefaultStatement *sdefault;
Array gotoCases; // array of unresolved GotoCaseStatement's
Array *cases; // array of CaseStatement's
GotoCaseStatements gotoCases; // array of unresolved GotoCaseStatement's
CaseStatements *cases; // array of CaseStatement's
int hasNoDefault; // !=0 if no default statement
int hasVars; // !=0 if has variable case values
@@ -738,9 +750,9 @@ struct WithStatement : Statement
struct TryCatchStatement : Statement
{
Statement *body;
Array *catches;
Catches *catches;
TryCatchStatement(Loc loc, Statement *body, Array *catches);
TryCatchStatement(Loc loc, Statement *body, Catches *catches);
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
int hasBreak();
@@ -874,7 +886,7 @@ struct LabelStatement : Statement
Statement* enclosingScopeExit;
block *lblock; // back end
Array *fwdrefs; // forward references to this LabelStatement
Blocks *fwdrefs; // forward references to this LabelStatement
LabelStatement(Loc loc, Identifier *ident, Statement *statement);
Statement *syntaxCopy();
+26 -28
View File
@@ -55,6 +55,7 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
ctor = NULL;
defaultCtor = NULL;
aliasthis = NULL;
noDefaultCtor = FALSE;
#endif
dtor = NULL;
@@ -80,7 +81,7 @@ void AggregateDeclaration::semantic2(Scope *sc)
sc = sc->push(this);
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
Dsymbol *s = members->tdata()[i];
s->semantic2(sc);
}
sc->pop();
@@ -88,8 +89,7 @@ void AggregateDeclaration::semantic2(Scope *sc)
}
void AggregateDeclaration::semantic3(Scope *sc)
{ int i;
{
#if IN_LLVM
if (!global.params.useAvailableExternally)
availableExternally = false;
@@ -99,9 +99,9 @@ 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];
Dsymbol *s = members->tdata()[i];
s->semantic3(sc);
}
sc->pop();
@@ -109,14 +109,13 @@ 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];
Dsymbol *s = members->tdata()[i];
//printf("inline scan aggregate symbol '%s'\n", s->toChars());
s->inlineScan();
}
@@ -161,7 +160,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);
@@ -263,13 +262,13 @@ int AggregateDeclaration::firstFieldInUnion(int indx)
{
if (isUnionDeclaration())
return 0;
VarDeclaration * vd = (VarDeclaration *)fields.data[indx];
VarDeclaration * vd = fields.tdata()[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];
VarDeclaration * v = fields.tdata()[indx - 1];
if (v->offset != vd->offset)
return firstNonZero;
--indx;
@@ -288,7 +287,7 @@ int AggregateDeclaration::firstFieldInUnion(int indx)
*/
int AggregateDeclaration::numFieldsInUnion(int firstIndex)
{
VarDeclaration * vd = (VarDeclaration *)fields.data[firstIndex];
VarDeclaration * vd = fields.tdata()[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.
*/
@@ -296,9 +295,9 @@ int AggregateDeclaration::numFieldsInUnion(int firstIndex)
firstFieldInUnion(firstIndex) == firstIndex)
return 1;
int count = 1;
for (int i = firstIndex+1; i < fields.dim; ++i)
for (size_t i = firstIndex+1; i < fields.dim; ++i)
{
VarDeclaration * v = (VarDeclaration *)fields.data[i];
VarDeclaration * v = fields.tdata()[i];
// If offsets are different, they are not in the same union
if (v->offset != vd->offset)
break;
@@ -403,9 +402,9 @@ void StructDeclaration::semantic(Scope *sc)
if (sizeok == 0) // if not already done the addMember step
{
int hasfunctions = 0;
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];
//printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
s->addMember(sc, this, 1);
if (s->isFuncDeclaration())
@@ -455,13 +454,13 @@ 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++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = members->tdata()[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
*/
@@ -472,9 +471,9 @@ void StructDeclaration::semantic(Scope *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->semantic(sc2);
#if 0
if (sizeok == 2)
@@ -639,9 +638,9 @@ void StructDeclaration::semantic(Scope *sc)
// Determine if struct is all zeros or not
zeroInit = 1;
for (int i = 0; i < fields.dim; i++)
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = (Dsymbol *)fields.data[i];
Dsymbol *s = fields.tdata()[i];
VarDeclaration *vd = s->isVarDeclaration();
if (vd && !vd->isDataseg())
{
@@ -700,8 +699,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());
@@ -714,9 +712,9 @@ 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];
Dsymbol *s = members->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
+318 -303
View File
File diff suppressed because it is too large Load Diff
+13 -13
View File
@@ -56,7 +56,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
@@ -88,8 +88,8 @@ struct TemplateDeclaration : ScopeDsymbol
void toJsonBuffer(OutBuffer *buf);
// void toDocBuffer(OutBuffer *buf);
MATCH matchWithInstance(TemplateInstance *ti, Objects *atypes, int flag);
MATCH leastAsSpecialized(TemplateDeclaration *td2);
MATCH matchWithInstance(TemplateInstance *ti, Objects *atypes, Expressions *fargs, int flag);
MATCH leastAsSpecialized(TemplateDeclaration *td2, Expressions *fargs);
MATCH deduceFunctionTemplateMatch(Scope *sc, Loc loc, Objects *targsi, Expression *ethis, Expressions *fargs, Objects *dedargs);
FuncDeclaration *deduceFunctionTemplate(Scope *sc, Loc loc, Objects *targsi, Expression *ethis, Expressions *fargs, int flags = 0);
@@ -100,7 +100,7 @@ struct TemplateDeclaration : ScopeDsymbol
TemplateTupleParameter *isVariadic();
int isOverloadable();
void makeParamNamesVisibleInConstraint(Scope *paramscope);
void makeParamNamesVisibleInConstraint(Scope *paramscope, Expressions *fargs);
#if IN_LLVM
// LDC
std::string intrinsicName;
@@ -150,7 +150,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.
*/
@@ -176,7 +176,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();
};
@@ -220,7 +220,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();
};
@@ -247,7 +247,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();
};
@@ -268,7 +268,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();
};
@@ -280,7 +280,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]
@@ -334,7 +334,7 @@ struct TemplateInstance : ScopeDsymbol
static void semanticTiargs(Loc loc, Scope *sc, Objects *tiargs, int flags);
void semanticTiargs(Scope *sc);
TemplateDeclaration *findTemplateDeclaration(Scope *sc);
TemplateDeclaration *findBestMatch(Scope *sc);
TemplateDeclaration *findBestMatch(Scope *sc, Expressions *fargs);
void declareParameters(Scope *sc);
int hasNestedArgs(Objects *tiargs);
Identifier *genIdent(Objects *args);
@@ -353,10 +353,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);
+22 -22
View File
@@ -82,13 +82,11 @@ Expression *TraitsExp::semantic(Scope *sc)
TemplateInstance::semanticTiargs(loc, sc, args, 1);
}
size_t dim = args ? args->dim : 0;
Object *o;
Declaration *d;
FuncDeclaration *f;
#define ISTYPE(cond) \
for (size_t i = 0; i < dim; i++) \
{ Type *t = getType((Object *)args->data[i]); \
{ Type *t = getType(args->tdata()[i]); \
if (!t) \
goto Lfalse; \
if (!(cond)) \
@@ -100,7 +98,7 @@ Expression *TraitsExp::semantic(Scope *sc)
#define ISDSYMBOL(cond) \
for (size_t i = 0; i < dim; i++) \
{ Dsymbol *s = getDsymbol((Object *)args->data[i]); \
{ Dsymbol *s = getDsymbol(args->tdata()[i]); \
if (!s) \
goto Lfalse; \
if (!(cond)) \
@@ -150,19 +148,23 @@ Expression *TraitsExp::semantic(Scope *sc)
}
else if (ident == Id::isAbstractFunction)
{
FuncDeclaration *f;
ISDSYMBOL((f = s->isFuncDeclaration()) != NULL && f->isAbstract())
}
else if (ident == Id::isVirtualFunction)
{
FuncDeclaration *f;
ISDSYMBOL((f = s->isFuncDeclaration()) != NULL && f->isVirtual())
}
else if (ident == Id::isFinalFunction)
{
FuncDeclaration *f;
ISDSYMBOL((f = s->isFuncDeclaration()) != NULL && f->isFinal())
}
#if DMDV2
else if (ident == Id::isStaticFunction)
{
FuncDeclaration *f;
ISDSYMBOL((f = s->isFuncDeclaration()) != NULL && !f->needThis() && !f->isNested())
}
else if (ident == Id::isRef)
@@ -186,7 +188,7 @@ Expression *TraitsExp::semantic(Scope *sc)
if (dim != 1)
goto Ldimerror;
Object *o = (Object *)args->data[0];
Object *o = args->tdata()[0];
Dsymbol *s = getDsymbol(o);
if (!s || !s->ident)
{
@@ -200,7 +202,7 @@ Expression *TraitsExp::semantic(Scope *sc)
{
if (dim != 1)
goto Ldimerror;
Object *o = (Object *)args->data[0];
Object *o = args->tdata()[0];
Dsymbol *s = getDsymbol(o);
if (s)
s = s->toParent();
@@ -220,18 +222,18 @@ Expression *TraitsExp::semantic(Scope *sc)
{
if (dim != 2)
goto Ldimerror;
Object *o = (Object *)args->data[0];
Expression *e = isExpression((Object *)args->data[1]);
Object *o = args->tdata()[0];
Expression *e = isExpression(args->tdata()[1]);
if (!e)
{ error("expression expected as second argument of __traits %s", ident->toChars());
goto Lfalse;
}
e = e->optimize(WANTvalue | WANTinterpret);
if (e->op != TOKstring)
StringExp *se = e->toString();
if (!se || se->length() == 0)
{ error("string expected as second argument of __traits %s instead of %s", ident->toChars(), e->toChars());
goto Lfalse;
}
StringExp *se = (StringExp *)e;
se = se->toUTF8(sc);
if (se->sz != 1)
{ error("string must be chars");
@@ -312,7 +314,7 @@ Expression *TraitsExp::semantic(Scope *sc)
{
if (dim != 1)
goto Ldimerror;
Object *o = (Object *)args->data[0];
Object *o = args->tdata()[0];
Dsymbol *s = getDsymbol(o);
ClassDeclaration *cd;
if (!s || (cd = s->isClassDeclaration()) == NULL)
@@ -326,7 +328,7 @@ Expression *TraitsExp::semantic(Scope *sc)
{
if (dim != 1)
goto Ldimerror;
Object *o = (Object *)args->data[0];
Object *o = args->tdata()[0];
Dsymbol *s = getDsymbol(o);
ScopeDsymbol *sd;
if (!s)
@@ -341,10 +343,12 @@ Expression *TraitsExp::semantic(Scope *sc)
}
Expressions *exps = new Expressions;
while (1)
{ size_t dim = ScopeDsymbol::dim(sd->members);
for (size_t i = 0; i < dim; i++)
{ size_t sddim = ScopeDsymbol::dim(sd->members);
for (size_t i = 0; i < sddim; i++)
{
Dsymbol *sm = ScopeDsymbol::getNth(sd->members, i);
if (!sm)
break;
//printf("\t[%i] %s %s\n", i, sm->kind(), sm->toChars());
if (sm->ident)
{
@@ -354,7 +358,7 @@ Expression *TraitsExp::semantic(Scope *sc)
/* Skip if already present in exps[]
*/
for (size_t j = 0; j < exps->dim; j++)
{ StringExp *se2 = (StringExp *)exps->data[j];
{ StringExp *se2 = (StringExp *)exps->tdata()[j];
if (strcmp(str, (char *)se2->string) == 0)
goto Lnext;
}
@@ -393,7 +397,7 @@ Expression *TraitsExp::semantic(Scope *sc)
goto Lfalse;
for (size_t i = 0; i < dim; i++)
{ Object *o = (Object *)args->data[i];
{ Object *o = args->tdata()[i];
Expression *e;
unsigned errors = global.errors;
@@ -433,8 +437,8 @@ Expression *TraitsExp::semantic(Scope *sc)
if (dim != 2)
goto Ldimerror;
TemplateInstance::semanticTiargs(loc, sc, args, 0);
Object *o1 = (Object *)args->data[0];
Object *o2 = (Object *)args->data[1];
Object *o1 = args->tdata()[0];
Object *o2 = args->tdata()[1];
Dsymbol *s1 = getDsymbol(o1);
Dsymbol *s2 = getDsymbol(o2);
@@ -482,10 +486,6 @@ Expression *TraitsExp::semantic(Scope *sc)
return NULL;
Lnottype:
error("%s is not a type", o->toChars());
goto Lfalse;
Ldimerror:
error("wrong number of arguments %d", (int)dim);
goto Lfalse;
+2 -2
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());
}
}