Added missing initialization.

This commit is contained in:
kai
2012-02-03 16:51:11 +01:00
parent f9201e8352
commit 37ed7cdbae

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2011 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -82,7 +82,7 @@ int PTRSIZE = 4;
int REALSIZE = 16;
int REALPAD = 6;
int REALALIGNSIZE = 16;
#elif TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
#elif TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
int REALSIZE = 12;
int REALPAD = 2;
int REALALIGNSIZE = 4;
@@ -118,7 +118,7 @@ ClassDeclaration *Type::typeinfodelegate;
ClassDeclaration *Type::typeinfotypelist;
Type *Type::tvoidptr;
Type *Type::tstring;
Type *Type::tstring;
Type *Type::basic[TMAX];
unsigned char Type::mangleChar[TMAX];
StringTable Type::stringtable;
@@ -189,8 +189,9 @@ void Type::init(Ir* _sir)
#else
void Type::init()
#endif
{
stringtable.init();
{
stringtable.init();
deco_stringtable.init();
Lexer::initKeywords();
mangleChar[Tarray] = 'A';
@@ -241,9 +242,9 @@ void Type::init()
mangleChar[Tslice] = '@';
mangleChar[Treturn] = '@';
for (size_t i = 0; i < TMAX; i++)
for (size_t i = 0; i < TMAX; i++)
{ if (!mangleChar[i])
fprintf(stdmsg, "ty = %zd\n", i);
fprintf(stdmsg, "ty = %zd\n", i);
assert(mangleChar[i]);
}
@@ -256,12 +257,12 @@ void Type::init()
Tbool,
Tascii, Twchar, Tdchar };
for (size_t i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++)
for (size_t i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++)
basic[basetab[i]] = new TypeBasic(basetab[i]);
basic[Terror] = new TypeError();
tvoidptr = tvoid->pointerTo();
tstring = tchar->arrayOf();
tstring = tchar->arrayOf();
// LDC
sir = _sir;
@@ -321,22 +322,22 @@ Type *Type::semantic(Loc loc, Scope *sc)
return merge();
}
Type *Type::trySemantic(Loc loc, Scope *sc)
{
//printf("+trySemantic(%s) %d\n", toChars(), global.errors);
unsigned errors = global.startGagging();
Type *t = semantic(loc, sc);
if (global.endGagging(errors)) // if any errors happened
{
t = NULL;
}
//printf("-trySemantic(%s) %d\n", toChars(), global.errors);
return t;
}
Type *Type::trySemantic(Loc loc, Scope *sc)
{
//printf("+trySemantic(%s) %d\n", toChars(), global.errors);
unsigned errors = global.startGagging();
Type *t = semantic(loc, sc);
if (global.endGagging(errors)) // if any errors happened
{
t = NULL;
}
//printf("-trySemantic(%s) %d\n", toChars(), global.errors);
return t;
}
Type *Type::pointerTo()
{
if (ty == Terror)
return this;
if (ty == Terror)
return this;
if (!pto)
{ Type *t;
@@ -348,8 +349,8 @@ Type *Type::pointerTo()
Type *Type::referenceTo()
{
if (ty == Terror)
return this;
if (ty == Terror)
return this;
if (!rto)
{ Type *t;
@@ -361,8 +362,8 @@ Type *Type::referenceTo()
Type *Type::arrayOf()
{
if (ty == Terror)
return this;
if (ty == Terror)
return this;
if (!arrayof)
{ Type *t;
@@ -464,7 +465,7 @@ void Type::toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod)
Type *Type::merge()
{
if (ty == Terror) return this;
if (ty == Terror) return this;
//printf("merge(%s)\n", toChars());
Type *t = this;
assert(t);
@@ -683,8 +684,8 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
{
if (ty == Tvoid)
error(loc, "void does not have an initializer");
if (ty == Tfunction)
error(loc, "function does not have an initializer");
if (ty == Tfunction)
error(loc, "function does not have an initializer");
e = defaultInit(loc);
}
else if (ident == Id::mangleof)
@@ -1134,47 +1135,47 @@ d_uns64 TypeBasic::size(Loc loc)
unsigned TypeBasic::alignsize()
{
#if IN_LLVM
#if IN_LLVM
if (ty == Tvoid)
return 1;
return GetTypeAlignment(sir, this);
#else
unsigned sz;
switch (ty)
{
case Tfloat80:
case Timaginary80:
case Tcomplex80:
sz = REALALIGNSIZE;
break;
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
#else
unsigned sz;
switch (ty)
{
case Tfloat80:
case Timaginary80:
case Tcomplex80:
sz = REALALIGNSIZE;
break;
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
case Tint64:
case Tuns64:
sz = global.params.is64bit ? 8 : 4;
break;
sz = global.params.is64bit ? 8 : 4;
break;
case Tfloat64:
case Timaginary64:
sz = global.params.is64bit ? 8 : 4;
break;
sz = global.params.is64bit ? 8 : 4;
break;
case Tcomplex32:
sz = 4;
break;
case Tcomplex64:
sz = global.params.is64bit ? 8 : 4;
break;
case Tcomplex64:
sz = global.params.is64bit ? 8 : 4;
break;
#endif
default:
sz = size(0);
break;
}
return sz;
#endif
default:
sz = size(0);
break;
}
return sz;
#endif
}
#if IN_LLVM
@@ -1417,7 +1418,7 @@ Lfvalue:
cvalue.re = fvalue;
cvalue.im = fvalue;
#endif
//for (size_t i = 0; i < 20; i++)
//for (size_t i = 0; i < 20; i++)
// printf("%02x ", ((unsigned char *)&cvalue)[i]);
//printf("\n");
e = new ComplexExp(loc, cvalue, this);
@@ -1558,7 +1559,7 @@ int TypeBasic::isZeroInit(Loc loc)
int TypeBasic::isbit()
{
return 0;
return 0;
}
int TypeBasic::isintegral()
@@ -1934,7 +1935,7 @@ void TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
sc = sc->pop();
if (d >= td->objects->dim)
{ error(loc, "tuple index %ju exceeds length %u", d, td->objects->dim);
{ error(loc, "tuple index %ju exceeds length %u", d, td->objects->dim);
goto Ldefault;
}
Object *o = (Object *)td->objects->data[(size_t)d];
@@ -2006,10 +2007,10 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
if (dim)
{ dinteger_t n, n2;
int errors = global.errors;
int errors = global.errors;
dim = semanticLength(sc, tbn, dim);
if (errors != global.errors)
goto Lerror;
if (errors != global.errors)
goto Lerror;
dim = dim->optimize(WANTvalue | WANTinterpret);
if (sc && sc->parameterSpecialization && dim->op == TOKvar &&
@@ -2025,9 +2026,9 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
dim = dim->optimize(WANTvalue);
dinteger_t d2 = dim->toInteger();
if (dim->op == TOKerror)
goto Lerror;
if (dim->op == TOKerror)
goto Lerror;
if (d1 != d2)
goto Loverflow;
@@ -2052,7 +2053,7 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
{
Loverflow:
error(loc, "index %jd overflow for static array", d1);
goto Lerror;
goto Lerror;
}
}
}
@@ -2066,24 +2067,24 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
if (d >= tt->arguments->dim)
{ error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim);
goto Lerror;
goto Lerror;
}
Parameter *arg = tt->arguments->tdata()[(size_t)d];
Parameter *arg = tt->arguments->tdata()[(size_t)d];
return arg->type;
}
case Tfunction:
case Tnone:
error(loc, "can't have array of %s", tbn->toChars());
goto Lerror;
goto Lerror;
}
if (tbn->isscope())
{ error(loc, "cannot have array of auto %s", tbn->toChars());
goto Lerror;
}
{ error(loc, "cannot have array of auto %s", tbn->toChars());
goto Lerror;
}
return merge();
Lerror:
return Type::terror;
Lerror:
return Type::terror;
}
void TypeSArray::toDecoBuffer(OutBuffer *buf, bool mangle)
@@ -2211,17 +2212,17 @@ Expression *TypeSArray::toExpression()
int TypeSArray::hasPointers()
{
/* Don't want to do this, because:
* struct S { T* array[0]; }
* may be a variable length struct.
*/
//if (dim->toInteger() == 0)
//return FALSE;
if (next->ty == Tvoid)
// Arrays of void contain arbitrary data, which may include pointers
return TRUE;
else
/* Don't want to do this, because:
* struct S { T* array[0]; }
* may be a variable length struct.
*/
//if (dim->toInteger() == 0)
//return FALSE;
if (next->ty == Tvoid)
// Arrays of void contain arbitrary data, which may include pointers
return TRUE;
else
return next->hasPointers();
}
@@ -2307,8 +2308,8 @@ Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
return new IntegerExp(se->loc, se->len, Type::tindex);
}
if (e->op == TOKnull)
return new IntegerExp(e->loc, 0, Type::tindex);
if (e->op == TOKnull)
return new IntegerExp(e->loc, 0, Type::tindex);
e = new ArrayLengthExp(e->loc, e);
e->type = Type::tsize_t;
return e;
@@ -2570,9 +2571,9 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
arguments = new Expressions();
arguments->push(e);
size_t keysize = key->size(e->loc);
if (global.params.is64bit)
keysize = (keysize + 15) & ~15;
else
if (global.params.is64bit)
keysize = (keysize + 15) & ~15;
else
keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
arguments->push(new IntegerExp(0, keysize, Type::tsize_t));
arguments->push(new IntegerExp(0, next->size(e->loc), Type::tsize_t));
@@ -2888,12 +2889,12 @@ int Type::covariant(Type *t)
}
}
else if (t1->parameters != t2->parameters)
{
size_t dim1 = !t1->parameters ? 0 : t1->parameters->dim;
size_t dim2 = !t2->parameters ? 0 : t2->parameters->dim;
if (dim1 || dim2)
{
size_t dim1 = !t1->parameters ? 0 : t1->parameters->dim;
size_t dim2 = !t2->parameters ? 0 : t2->parameters->dim;
if (dim1 || dim2)
goto Ldistinct;
}
}
// The argument lists match
if (inoutmismatch)
@@ -2901,7 +2902,7 @@ int Type::covariant(Type *t)
if (t1->linkage != t2->linkage)
goto Lnotcovariant;
// Return types
// Return types
Type *t1n = t1->next;
Type *t2n = t2->next;
@@ -2924,7 +2925,7 @@ int Type::covariant(Type *t)
if (!cd->isBaseInfoComplete())
#endif
{
return 3; // forward references
return 3; // forward references
}
}
if (t1n->implicitConvTo(t2n))
@@ -3007,11 +3008,11 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf, bool mangle)
void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
{
toCBufferWithAttributes(buf, ident, hgs, this, NULL);
}
void TypeFunction::toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td)
{
toCBufferWithAttributes(buf, ident, hgs, this, NULL);
}
void TypeFunction::toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td)
{
const char *p = NULL;
if (inuse)
@@ -3045,17 +3046,17 @@ void TypeFunction::toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, Hd
{ buf->writeByte(' ');
buf->writestring(ident->toHChars2());
}
if (td)
{ buf->writeByte('(');
for (size_t i = 0; i < td->origParameters->dim; i++)
{
TemplateParameter *tp = td->origParameters->tdata()[i];
if (i)
buf->writestring(", ");
tp->toCBuffer(buf, hgs);
}
buf->writeByte(')');
}
if (td)
{ buf->writeByte('(');
for (size_t i = 0; i < td->origParameters->dim; i++)
{
TemplateParameter *tp = td->origParameters->tdata()[i];
if (i)
buf->writestring(", ");
tp->toCBuffer(buf, hgs);
}
buf->writeByte(')');
}
Parameter::argsToCBuffer(buf, hgs, parameters, varargs);
inuse--;
}
@@ -3115,10 +3116,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 = parameters->tdata()[i];
{ Parameter *arg = parameters->tdata()[i];
Parameter *cpy = (Parameter *)mem.malloc(sizeof(Parameter));
memcpy(cpy, arg, sizeof(Parameter));
tf->parameters->tdata()[i] = cpy;
tf->parameters->tdata()[i] = cpy;
}
}
@@ -3272,18 +3273,18 @@ int TypeFunction::callMatch(Expressions *args)
goto L1;
goto Nomatch; // not enough arguments
}
arg = (*args)[u];
arg = (*args)[u];
assert(arg);
if (p->storageClass & STClazy && p->type->ty == Tvoid && arg->type->ty != Tvoid)
m = MATCHconvert;
else
m = arg->implicitConvTo(p->type);
/* prefer matching the element type rather than the array
* type when more arguments are present with T[]...
*/
if (varargs == 2 && u + 1 == nparams && nargs > nparams)
goto L1;
/* prefer matching the element type rather than the array
* type when more arguments are present with T[]...
*/
if (varargs == 2 && u + 1 == nparams && nargs > nparams)
goto L1;
//printf("\tm = %d\n", m);
if (m == MATCHnomatch) // if no match
{
@@ -3303,7 +3304,7 @@ int TypeFunction::callMatch(Expressions *args)
case Tarray:
for (; u < nargs; u++)
{
arg = (*args)[u];
arg = (*args)[u];
assert(arg);
#if 1
/* If lazy array of delegates,
@@ -3375,12 +3376,12 @@ Type *TypeFunction::reliesOnTident()
return next->reliesOnTident();
}
Expression *TypeFunction::defaultInit(Loc loc)
{
error(loc, "function does not have a default initializer");
return new ErrorExp();
}
Expression *TypeFunction::defaultInit(Loc loc)
{
error(loc, "function does not have a default initializer");
return new ErrorExp();
}
/***************************** TypeDelegate *****************************/
TypeDelegate::TypeDelegate(Type *t)
@@ -3420,11 +3421,11 @@ unsigned TypeDelegate::alignsize()
{
// A Delegate consists of two ptr values, so align it on pointer size
// boundary
#if DMDV1
// See Bugzilla 942 for discussion
if (!global.params.is64bit)
return PTRSIZE * 2;
#endif
#if DMDV1
// See Bugzilla 942 for discussion
if (!global.params.is64bit)
return PTRSIZE * 2;
#endif
return PTRSIZE;
}
@@ -3502,7 +3503,7 @@ void TypeQualified::syntaxCopyHelper(TypeQualified *t)
{
//printf("TypeQualified::syntaxCopyHelper(%s) %s\n", t->toChars(), toChars());
idents.setDim(t->idents.dim);
for (size_t i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = (Identifier *)t->idents.data[i];
if (id->dyncast() == DYNCAST_DSYMBOL)
@@ -3524,7 +3525,7 @@ void TypeQualified::addIdent(Identifier *ident)
void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs)
{
for (size_t i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{ Identifier *id = (Identifier *)idents.data[i];
buf->writeByte('.');
@@ -3577,10 +3578,10 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
s->checkDeprecated(loc, sc); // check for deprecated aliases
s = s->toAlias();
//printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Dsymbol *sm = s->searchX(loc, sc, id);
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Dsymbol *sm = s->searchX(loc, sc, id);
//printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
//printf("getType = '%s'\n", s->getType()->toChars());
if (!sm)
@@ -3598,12 +3599,12 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
goto Lerror;
goto L3;
}
else if (v && (id == Id::stringof || id == Id::offsetof))
else if (v && (id == Id::stringof || id == Id::offsetof))
{
e = new DsymbolExp(loc, s);
do
{
id = idents.tdata()[i];
id = idents.tdata()[i];
e = new DotIdExp(loc, e, id);
} while (++i < idents.dim);
e = e->semantic(sc);
@@ -3613,14 +3614,14 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
t = s->getType();
if (!t && s->isDeclaration())
{ t = s->isDeclaration()->type;
if (!t && s->isTupleDeclaration())
{
e = new TupleExp(loc, s->isTupleDeclaration());
e = e->semantic(sc);
t = e->type;
}
}
{ t = s->isDeclaration()->type;
if (!t && s->isTupleDeclaration())
{
e = new TupleExp(loc, s->isTupleDeclaration());
e = e->semantic(sc);
t = e->type;
}
}
if (t)
{
sm = t->toDsymbol(sc);
@@ -3636,21 +3637,21 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
L3:
for (; i < idents.dim; i++)
{
id = idents.tdata()[i];
id = idents.tdata()[i];
//printf("e: '%s', id: '%s', type = %p\n", e->toChars(), id->toChars(), e->type);
e = e->type->dotExp(sc, e, id);
}
if (e->op == TOKtype)
*pt = e->type;
else
if (e->op == TOKtype)
*pt = e->type;
else
*pe = e;
}
else
{
{
Lerror:
error(loc, "identifier '%s' of '%s' is not defined", id->toChars(), toChars());
*pe = new ErrorExp();
}
*pe = new ErrorExp();
}
return;
}
L2:
@@ -3766,7 +3767,7 @@ L1:
else
error(loc, "undefined identifier %s", p);
}
*pt = Type::terror;
*pt = Type::terror;
}
}
@@ -3841,7 +3842,7 @@ Dsymbol *TypeIdentifier::toDsymbol(Scope *sc)
Dsymbol *s = sc->search(loc, ident, &scopesym);
if (s)
{
for (size_t i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = (Identifier *)idents.data[i];
s = s->searchX(loc, sc, id);
@@ -3899,7 +3900,7 @@ Type *TypeIdentifier::reliesOnTident()
Expression *TypeIdentifier::toExpression()
{
Expression *e = new IdentifierExp(loc, ident);
for (size_t i = 0; i < idents.dim; i++)
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = (Identifier *)idents.data[i];
e = new DotIdExp(loc, e, id);
@@ -3973,12 +3974,12 @@ Type *TypeInstance::semantic(Loc loc, Scope *sc)
if (sc->parameterSpecialization)
{
unsigned errors = global.startGagging();
unsigned errors = global.startGagging();
resolve(loc, sc, &e, &t, &s);
if (global.endGagging(errors))
{
if (global.endGagging(errors))
{
return this;
}
}
@@ -3992,7 +3993,7 @@ Type *TypeInstance::semantic(Loc loc, Scope *sc)
printf("2: e:%p s:%p ", e, s);
#endif
error(loc, "%s is used as a type", toChars());
t = terror;
t = terror;
}
return t;
}
@@ -4007,11 +4008,11 @@ Dsymbol *TypeInstance::toDsymbol(Scope *sc)
if (sc->parameterSpecialization)
{
unsigned errors = global.startGagging();
unsigned errors = global.startGagging();
resolve(loc, sc, &e, &t, &s);
if (global.endGagging(errors))
if (global.endGagging(errors))
return NULL;
}
else
@@ -4456,10 +4457,10 @@ char *TypeTypedef::toChars()
Type *TypeTypedef::semantic(Loc loc, Scope *sc)
{
//printf("TypeTypedef::semantic(%s), sem = %d\n", toChars(), sym->sem);
int errors = global.errors;
int errors = global.errors;
sym->semantic(sc);
if (errors != global.errors)
return terror;
if (errors != global.errors)
return terror;
return merge();
}
@@ -4730,7 +4731,7 @@ void TypeStruct::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
}
Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
{
{
Expression *b;
VarDeclaration *v;
Dsymbol *s;
@@ -4868,8 +4869,8 @@ L1:
if (e->op == TOKtype)
{ FuncDeclaration *fd = sc->func;
if (d->needThis() && fd && fd->vthis &&
fd->toParent2()->isStructDeclaration() == sym)
if (d->needThis() && fd && fd->vthis &&
fd->toParent2()->isStructDeclaration() == sym)
{
e = new DotVarExp(e->loc, new ThisExp(e->loc), d);
e = e->semantic(sc);
@@ -4892,7 +4893,7 @@ L1:
accessCheck(e->loc, sc, e, d);
ve = new VarExp(e->loc, d);
e = new CommaExp(e->loc, e, ve);
e = e->semantic(sc);
e = e->semantic(sc);
return e;
}
@@ -4951,11 +4952,11 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]);
Expression *e;
if (vd->init)
{ if (vd->init->isVoidInitializer())
e = NULL;
else
{ if (vd->init->isVoidInitializer())
e = NULL;
else
e = vd->init->toExpression();
}
}
else
e = vd->type->defaultInitLiteral();
structelems->data[j] = e;
@@ -5055,7 +5056,7 @@ void TypeClass::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
}
Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
{
{
VarDeclaration *v;
Dsymbol *s;
DotVarExp *de;
@@ -5363,7 +5364,7 @@ L1:
accessCheck(e->loc, sc, e, d);
ve = new VarExp(e->loc, d);
e = new CommaExp(e->loc, e, ve);
e = e->semantic(sc);
e = e->semantic(sc);
return e;
}
@@ -5760,20 +5761,20 @@ char *Parameter::argsTypesToChars(Parameters *args, int varargs)
buf->writeByte('(');
if (args)
{ OutBuffer argbuf;
{ OutBuffer argbuf;
HdrGenState hgs;
for (size_t i = 0; i < args->dim; i++)
{ if (i)
for (size_t i = 0; i < args->dim; i++)
{ if (i)
buf->writeByte(',');
Parameter *arg = (Parameter *)args->data[i];
Parameter *arg = (Parameter *)args->data[i];
argbuf.reset();
arg->type->toCBuffer2(&argbuf, &hgs, 0);
buf->write(&argbuf);
}
if (varargs)
{
if (args->dim && varargs == 1)
if (args->dim && varargs == 1)
buf->writeByte(',');
buf->writestring("...");
}
@@ -5787,14 +5788,14 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
{
buf->writeByte('(');
if (arguments)
{
{
OutBuffer argbuf;
for (size_t 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 = (Parameter *)arguments->data[i];
if (arg->storageClass & STCout)
buf->writestring("out ");
else if (arg->storageClass & STCref)
@@ -5813,7 +5814,7 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
}
if (varargs)
{
if (arguments->dim && varargs == 1)
if (arguments->dim && varargs == 1)
buf->writeByte(',');
buf->writestring("...");
}
@@ -5821,40 +5822,40 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
buf->writeByte(')');
}
static const int mangleFlag = 0x01;
static int argsToDecoBufferDg(void *ctx, size_t n, Parameter *arg, int flags)
{
arg->toDecoBuffer((OutBuffer *)ctx, flags & mangleFlag);
return 0;
}
static const int mangleFlag = 0x01;
static int argsToDecoBufferDg(void *ctx, size_t n, Parameter *arg, int flags)
{
arg->toDecoBuffer((OutBuffer *)ctx, flags & mangleFlag);
return 0;
}
void Parameter::argsToDecoBuffer(OutBuffer *buf, Parameters *arguments, bool mangle)
{
//printf("Parameter::argsToDecoBuffer()\n");
// Write argument types
if (arguments)
foreach(arguments, &argsToDecoBufferDg, buf, 0, mangle ? mangleFlag : 0);
}
/****************************************
* Determine if parameter list is really a template parameter list
* (i.e. it has auto or alias parameters)
*/
static int isTPLDg(void *ctx, size_t n, Parameter *arg, int)
{
if (arg->storageClass & (STCalias | STCauto | STCstatic))
return 1;
return 0;
}
int Parameter::isTPL(Parameters *arguments)
{
//printf("Parameter::isTPL()\n");
if (arguments)
return foreach(arguments, &isTPLDg, NULL);
return 0;
foreach(arguments, &argsToDecoBufferDg, buf, 0, mangle ? mangleFlag : 0);
}
/****************************************
* Determine if parameter list is really a template parameter list
* (i.e. it has auto or alias parameters)
*/
static int isTPLDg(void *ctx, size_t n, Parameter *arg, int)
{
if (arg->storageClass & (STCalias | STCauto | STCstatic))
return 1;
return 0;
}
int Parameter::isTPL(Parameters *arguments)
{
//printf("Parameter::isTPL()\n");
if (arguments)
return foreach(arguments, &isTPLDg, NULL);
return 0;
}
/****************************************************
@@ -5914,17 +5915,17 @@ void Parameter::toDecoBuffer(OutBuffer *buf, bool mangle)
* Determine number of arguments, folding in tuples.
*/
static int dimDg(void *ctx, size_t n, Parameter *, int)
{
++*(size_t *)ctx;
return 0;
}
static int dimDg(void *ctx, size_t n, Parameter *, int)
{
++*(size_t *)ctx;
return 0;
}
size_t Parameter::dim(Parameters *args)
{
size_t n = 0;
if (args)
foreach(args, &dimDg, &n);
foreach(args, &dimDg, &n);
return n;
}
@@ -5936,59 +5937,59 @@ size_t Parameter::dim(Parameters *args)
* of Parameters
*/
struct GetNthParamCtx
{
size_t nth;
Parameter *arg;
};
static int getNthParamDg(void *ctx, size_t n, Parameter *arg, int)
{
GetNthParamCtx *p = (GetNthParamCtx *)ctx;
if (n == p->nth)
{ p->arg = arg;
return 1;
}
return 0;
}
struct GetNthParamCtx
{
size_t nth;
Parameter *arg;
};
static int getNthParamDg(void *ctx, size_t n, Parameter *arg, int)
{
GetNthParamCtx *p = (GetNthParamCtx *)ctx;
if (n == p->nth)
{ p->arg = arg;
return 1;
}
return 0;
}
Parameter *Parameter::getNth(Parameters *args, size_t nth, size_t *pn)
{
GetNthParamCtx ctx = { nth, NULL };
int res = foreach(args, &getNthParamDg, &ctx);
return res ? ctx.arg : NULL;
}
GetNthParamCtx ctx = { nth, NULL };
int res = foreach(args, &getNthParamDg, &ctx);
return res ? ctx.arg : NULL;
}
/***************************************
* Expands tuples in args in depth first order. Calls
* dg(void *ctx, size_t argidx, Parameter *arg) for each Parameter.
* If dg returns !=0, stops and returns that value else returns 0.
* Use this function to avoid the O(N + N^2/2) complexity of
* calculating dim and calling N times getNth.
*/
int Parameter::foreach(Parameters *args, Parameter::ForeachDg dg, void *ctx, size_t *pn, int flags)
{
assert(args && dg);
size_t n = pn ? *pn : 0; // take over index
int result = 0;
/***************************************
* Expands tuples in args in depth first order. Calls
* dg(void *ctx, size_t argidx, Parameter *arg) for each Parameter.
* If dg returns !=0, stops and returns that value else returns 0.
* Use this function to avoid the O(N + N^2/2) complexity of
* calculating dim and calling N times getNth.
*/
int Parameter::foreach(Parameters *args, Parameter::ForeachDg dg, void *ctx, size_t *pn, int flags)
{
assert(args && dg);
size_t n = pn ? *pn : 0; // take over index
int result = 0;
for (size_t i = 0; i < args->dim; i++)
{ Parameter *arg = args->tdata()[i];
{ Parameter *arg = args->tdata()[i];
Type *t = arg->type->toBasetype();
if (t->ty == Ttuple)
{ TypeTuple *tu = (TypeTuple *)t;
result = foreach(tu->arguments, dg, ctx, &n, flags);
result = foreach(tu->arguments, dg, ctx, &n, flags);
}
else
result = dg(ctx, n++, arg, flags);
if (result)
break;
result = dg(ctx, n++, arg, flags);
if (result)
break;
}
if (pn)
*pn = n; // update index
return result;
*pn = n; // update index
return result;
}