Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/arrayop.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ FuncDeclaration *buildArrayOp(Identifier *ident, BinExp *exp, Scope *sc, Loc loc
Parameter *p = (*fparams)[0];
// foreach (i; 0 .. p.length)
Statement *s1 = new ForeachRangeStatement(Loc(), TOKforeach,
new Parameter(0, NULL, Id::p, NULL),
new Parameter(0, NULL, Id::p, NULL, NULL),
new IntegerExp(Loc(), 0, Type::tsize_t),
new ArrayLengthExp(Loc(), new IdentifierExp(Loc(), p->ident)),
new ExpStatement(Loc(), loopbody),
Expand Down Expand Up @@ -425,7 +425,7 @@ Expression *buildArrayLoop(Expression *e, Parameters *fparams)
void visit(Expression *e)
{
Identifier *id = Identifier::generateId("c", fparams->dim);
Parameter *param = new Parameter(0, e->type, id, NULL);
Parameter *param = new Parameter(0, e->type, id, NULL, NULL);
fparams->shift(param);
result = new IdentifierExp(Loc(), id);
}
Expand All @@ -444,7 +444,7 @@ Expression *buildArrayLoop(Expression *e, Parameters *fparams)
void visit(ArrayLiteralExp *e)
{
Identifier *id = Identifier::generateId("p", fparams->dim);
Parameter *param = new Parameter(STCconst, e->type, id, NULL);
Parameter *param = new Parameter(STCconst, e->type, id, NULL, NULL);
fparams->shift(param);
Expression *ie = new IdentifierExp(Loc(), id);
Expressions *arguments = new Expressions();
Expand All @@ -456,7 +456,7 @@ Expression *buildArrayLoop(Expression *e, Parameters *fparams)
void visit(SliceExp *e)
{
Identifier *id = Identifier::generateId("p", fparams->dim);
Parameter *param = new Parameter(STCconst, e->type, id, NULL);
Parameter *param = new Parameter(STCconst, e->type, id, NULL, NULL);
fparams->shift(param);
Expression *ie = new IdentifierExp(Loc(), id);
Expressions *arguments = new Expressions();
Expand Down
16 changes: 8 additions & 8 deletions src/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ FuncDeclaration *buildOpAssign(StructDeclaration *sd, Scope *sc)
}

Parameters *fparams = new Parameters;
fparams->push(new Parameter(STCnodtor, sd->type, Id::p, NULL));
fparams->push(new Parameter(STCnodtor, sd->type, Id::p, NULL, NULL));
TypeFunction *tf = new TypeFunction(fparams, sd->handleType(), 0, LINKd, stc | STCref);

FuncDeclaration *fop = new FuncDeclaration(declLoc, Loc(), Id::assign, stc, tf);
Expand Down Expand Up @@ -477,7 +477,7 @@ FuncDeclaration *buildXopEquals(StructDeclaration *sd, Scope *sc)
/* const bool opEquals(ref const S s);
*/
Parameters *parameters = new Parameters;
parameters->push(new Parameter(STCref | STCconst, sd->type, NULL, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, NULL, NULL, NULL));
tfeqptr = new TypeFunction(parameters, Type::tbool, 0, LINKd);
tfeqptr->mod = MODconst;
tfeqptr = (TypeFunction *)tfeqptr->semantic(Loc(), &scx);
Expand Down Expand Up @@ -510,8 +510,8 @@ FuncDeclaration *buildXopEquals(StructDeclaration *sd, Scope *sc)
Loc loc = Loc(); // loc is unnecessary so errors are gagged

Parameters *parameters = new Parameters;
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::p, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::q, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::p, NULL, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::q, NULL, NULL));
TypeFunction *tf = new TypeFunction(parameters, Type::tbool, 0, LINKd);

Identifier *id = Id::xopEquals;
Expand Down Expand Up @@ -562,7 +562,7 @@ FuncDeclaration *buildXopCmp(StructDeclaration *sd, Scope *sc)
/* const int opCmp(ref const S s);
*/
Parameters *parameters = new Parameters;
parameters->push(new Parameter(STCref | STCconst, sd->type, NULL, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, NULL, NULL, NULL));
tfcmpptr = new TypeFunction(parameters, Type::tint32, 0, LINKd);
tfcmpptr->mod = MODconst;
tfcmpptr = (TypeFunction *)tfcmpptr->semantic(Loc(), &scx);
Expand Down Expand Up @@ -635,8 +635,8 @@ FuncDeclaration *buildXopCmp(StructDeclaration *sd, Scope *sc)
Loc loc = Loc(); // loc is unnecessary so errors are gagged

Parameters *parameters = new Parameters;
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::p, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::q, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::p, NULL, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::q, NULL, NULL));
TypeFunction *tf = new TypeFunction(parameters, Type::tint32, 0, LINKd);

Identifier *id = Id::xopCmp;
Expand Down Expand Up @@ -748,7 +748,7 @@ FuncDeclaration *buildXtoHash(StructDeclaration *sd, Scope *sc)
Loc loc = Loc(); // internal code should have no loc to prevent coverage

Parameters *parameters = new Parameters();
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::p, NULL));
parameters->push(new Parameter(STCref | STCconst, sd->type, Id::p, NULL, NULL));
TypeFunction *tf = new TypeFunction(parameters, Type::thash_t, 0, LINKd, STCnothrow | STCtrusted);

Identifier *id = Id::xtoHash;
Expand Down
2 changes: 1 addition & 1 deletion src/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Type *TupleDeclaration::getType()
Identifier *id = new Identifier(name, TOKidentifier);
Parameter *arg = new Parameter(STCin, t, id, NULL);
#else
Parameter *arg = new Parameter(0, t, NULL, NULL);
Parameter *arg = new Parameter(0, t, NULL, NULL, NULL);
#endif
(*args)[i] = arg;
if (!t->deco)
Expand Down
9 changes: 5 additions & 4 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
args->setDim(arguments->dim - nparams);
for (size_t i = 0; i < arguments->dim - nparams; i++)
{
Parameter *arg = new Parameter(STCin, (*arguments)[nparams + i]->type, NULL, NULL);
Parameter *arg = new Parameter(STCin, (*arguments)[nparams + i]->type, NULL, NULL, NULL);
(*args)[i] = arg;
}

Expand Down Expand Up @@ -6295,7 +6295,7 @@ Expression *IsExp::semantic(Scope *sc)
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
BaseClass *b = (*cd->baseclasses)[i];
args->push(new Parameter(STCin, b->type, NULL, NULL));
args->push(new Parameter(STCin, b->type, NULL, NULL, NULL));
}
tded = new TypeTuple(args);
}
Expand Down Expand Up @@ -6343,8 +6343,9 @@ Expression *IsExp::semantic(Scope *sc)
arg->defaultArg->op == TOKerror)
return new ErrorExp();
args->push(new Parameter(arg->storageClass, arg->type,
(tok2 == TOKparameters) ? arg->ident : NULL,
(tok2 == TOKparameters) ? arg->defaultArg : NULL));
(tok2 == TOKparameters) ? arg->ident : NULL,
(tok2 == TOKparameters) ? arg->defaultArg : NULL,
arg->userAttribDecl));
}
tded = new TypeTuple(args);
break;
Expand Down
47 changes: 44 additions & 3 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ void FuncDeclaration::semantic(Scope *sc)
Parameter *p = NULL;
if (outId)
{
p = new Parameter(STCref | STCconst, f->nextOf(), outId, NULL);
p = new Parameter(STCref | STCconst, f->nextOf(), outId, NULL, NULL);
fparams->push(p);
}
TypeFunction *tf = new TypeFunction(fparams, Type::tvoid, 0, LINKd);
Expand Down Expand Up @@ -1214,10 +1214,37 @@ void FuncDeclaration::semantic(Scope *sc)
genCmain(sc);

assert(type->ty != Terror || errors);

//semantic for parameters' UDAs
for (size_t i = 0; i < nparams; i++)
{
Parameter *param = Parameter::getNth(f->parameters, i);
if (param && param->userAttribDecl)
param->userAttribDecl->semantic(sc);
}
}

void FuncDeclaration::semantic2(Scope *sc)
{
#if 0
printf("FuncDeclaration::semantic2('%s')\n", toPrettyChars());
#endif
if (semanticRun >= PASSsemantic2)
return;
assert(semanticRun <= PASSsemantic2);
semanticRun = PASSsemantic2;

if (!type || type->ty != Tfunction) return;
TypeFunction *f = (TypeFunction *)type;
if (!f->parameters) return;
size_t nparams = Parameter::dim(f->parameters);
//semantic for parameters' UDAs
for (size_t i = 0; i < nparams; i++)
{
Parameter *param = Parameter::getNth(f->parameters, i);
if (param && param->userAttribDecl)
param->userAttribDecl->semantic2(sc);
}
}

// Do the semantic analysis on the internals of the function.
Expand Down Expand Up @@ -1428,6 +1455,8 @@ void FuncDeclaration::semantic3(Scope *sc)
parameters->push(v);
localsymtab->insert(v);
v->parent = this;
if (fparam->userAttribDecl)
v->userAttribDecl = fparam->userAttribDecl;
}
}

Expand Down Expand Up @@ -2188,10 +2217,22 @@ void FuncDeclaration::semantic3(Scope *sc)
* done by TemplateInstance::semantic.
* Otherwise, error gagging should be temporarily ungagged by functionSemantic3.
*/
semanticRun = PASSsemantic3done;
semantic3Errors = (global.errors != nerrors) || (fbody && fbody->isErrorStatement());
if (type->ty == Terror)
errors = true;

if (!errors)
{
assert(f);
size_t nparams = f->parameters ? Parameter::dim(f->parameters) : 0;
for (size_t i = 0; i < nparams; i++)
{
Parameter *param = Parameter::getNth(f->parameters, i);
if (param && param->userAttribDecl)
param->userAttribDecl->semantic3(sc);
}
}
semanticRun = PASSsemantic3done;
semantic3Errors = (global.errors != nerrors) || (fbody && fbody->isErrorStatement());
//printf("-FuncDeclaration::semantic3('%s.%s', sc = %p, loc = %s)\n", parent->toChars(), toChars(), sc, loc.toChars());
//fflush(stdout);
}
Expand Down
6 changes: 6 additions & 0 deletions src/hdrgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,12 @@ class PrettyPrintVisitor : public Visitor

void visit(Parameter *p)
{
if (p->userAttribDecl)
{
buf->writestring("@(");
argsToBuffer(p->userAttribDecl->atts);
buf->writestring(") ");
}
if (p->storageClass & STCauto)
buf->writestring("auto ");

Expand Down
40 changes: 21 additions & 19 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ Type *stripDefaultArgs(Type *t)
{
Parameter *p = (*params)[i];
Type *ta = stripDefaultArgs(p->type);
if (ta != p->type || p->defaultArg || p->ident)
if (ta != p->type || p->defaultArg || p->ident || p->userAttribDecl)
{
if (params == parameters)
{
Expand All @@ -1583,7 +1583,7 @@ Type *stripDefaultArgs(Type *t)
(*params)[j] = (*parameters)[j];
}
StorageClass stc = p->storageClass & (~STCauto); // issue 14656
(*params)[i] = new Parameter(stc, ta, NULL, NULL);
(*params)[i] = new Parameter(stc, ta, NULL, NULL, NULL);
}
}
}
Expand Down Expand Up @@ -2037,7 +2037,7 @@ Type *TypeFunction::substWildTo(unsigned)
continue;
if (params == parameters)
params = parameters->copy();
(*params)[i] = new Parameter(p->storageClass, t, NULL, NULL);
(*params)[i] = new Parameter(p->storageClass, t, NULL, NULL, NULL);
}
if (next == tret && params == parameters)
return this;
Expand Down Expand Up @@ -3706,7 +3706,7 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident, int f
Parameters *params = new Parameters;
Type *next = n->ty == Twchar ? Type::twchar : Type::tchar;
Type *arrty = next->arrayOf();
params->push(new Parameter(0, arrty, NULL, NULL));
params->push(new Parameter(0, arrty, NULL, NULL, NULL));
reverseFd[i] = FuncDeclaration::genCfunc(params, arrty, reverseName[i]);
}

Expand All @@ -3729,7 +3729,7 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident, int f
Parameters *params = new Parameters;
Type *next = n->ty == Twchar ? Type::twchar : Type::tchar;
Type *arrty = next->arrayOf();
params->push(new Parameter(0, arrty, NULL, NULL));
params->push(new Parameter(0, arrty, NULL, NULL, NULL));
sortFd[i] = FuncDeclaration::genCfunc(params, arrty, sortName[i]);
}

Expand All @@ -3754,8 +3754,8 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident, int f
if (!adReverse_fd)
{
Parameters *params = new Parameters;
params->push(new Parameter(0, Type::tvoid->arrayOf(), NULL, NULL));
params->push(new Parameter(0, Type::tsize_t, NULL, NULL));
params->push(new Parameter(0, Type::tvoid->arrayOf(), NULL, NULL, NULL));
params->push(new Parameter(0, Type::tsize_t, NULL, NULL, NULL));
adReverse_fd = FuncDeclaration::genCfunc(params, Type::tvoid->arrayOf(), Id::adReverse);
}
fd = adReverse_fd;
Expand All @@ -3778,8 +3778,8 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident, int f
if (!fd)
{
Parameters *params = new Parameters;
params->push(new Parameter(0, Type::tvoid->arrayOf(), NULL, NULL));
params->push(new Parameter(0, Type::dtypeinfo->type, NULL, NULL));
params->push(new Parameter(0, Type::tvoid->arrayOf(), NULL, NULL, NULL));
params->push(new Parameter(0, Type::dtypeinfo->type, NULL, NULL, NULL));
fd = FuncDeclaration::genCfunc(params, Type::tvoid->arrayOf(), "_adSort");
}
ec = new VarExp(Loc(), fd);
Expand Down Expand Up @@ -4786,7 +4786,7 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident, int
if (fd_aaLen == NULL)
{
Parameters *fparams = new Parameters();
fparams->push(new Parameter(STCin, this, NULL, NULL));
fparams->push(new Parameter(STCin, this, NULL, NULL, NULL));
fd_aaLen = FuncDeclaration::genCfunc(fparams, Type::tsize_t, Id::aaLen);
TypeFunction *tf = (TypeFunction *)fd_aaLen->type;
tf->purity = PUREconst;
Expand Down Expand Up @@ -5608,7 +5608,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
{
Parameter *narg = (*tt->arguments)[j];
(*newparams)[j] = new Parameter(narg->storageClass | fparam->storageClass,
narg->type, narg->ident, narg->defaultArg);
narg->type, narg->ident, narg->defaultArg, narg->userAttribDecl);
}
fparam->type = new TypeTuple(newparams);
}
Expand Down Expand Up @@ -8685,7 +8685,7 @@ TypeTuple::TypeTuple(Expressions *exps)
{ Expression *e = (*exps)[i];
if (e->type->ty == Ttuple)
e->error("cannot form tuple of tuples");
Parameter *arg = new Parameter(STCundefined, e->type, NULL, NULL);
Parameter *arg = new Parameter(STCundefined, e->type, NULL, NULL, NULL);
(*arguments)[i] = arg;
}
}
Expand All @@ -8711,15 +8711,15 @@ TypeTuple::TypeTuple(Type *t1)
: Type(Ttuple)
{
arguments = new Parameters();
arguments->push(new Parameter(0, t1, NULL, NULL));
arguments->push(new Parameter(0, t1, NULL, NULL, NULL));
}

TypeTuple::TypeTuple(Type *t1, Type *t2)
: Type(Ttuple)
{
arguments = new Parameters();
arguments->push(new Parameter(0, t1, NULL, NULL));
arguments->push(new Parameter(0, t2, NULL, NULL));
arguments->push(new Parameter(0, t1, NULL, NULL, NULL));
arguments->push(new Parameter(0, t2, NULL, NULL, NULL));
}

const char *TypeTuple::kind()
Expand Down Expand Up @@ -9016,25 +9016,27 @@ Expression *TypeNull::defaultInit(Loc loc) { return new NullExp(Loc(), Type::tnu

/***************************** Parameter *****************************/

Parameter::Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg)
Parameter::Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg, UserAttributeDeclaration *userAttribDecl)
{
this->type = type;
this->ident = ident;
this->storageClass = storageClass;
this->defaultArg = defaultArg;
this->userAttribDecl = userAttribDecl;
}

Parameter *Parameter::create(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg)
Parameter *Parameter::create(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg, UserAttributeDeclaration *userAttribDecl)
{
return new Parameter(storageClass, type, ident, defaultArg);
return new Parameter(storageClass, type, ident, defaultArg, userAttribDecl);
}

Parameter *Parameter::syntaxCopy()
{
return new Parameter(storageClass,
type ? type->syntaxCopy() : NULL,
ident,
defaultArg ? defaultArg->syntaxCopy() : NULL);
defaultArg ? defaultArg->syntaxCopy() : NULL,
userAttribDecl ? (UserAttributeDeclaration *)userAttribDecl->syntaxCopy(NULL) : NULL);
}

Parameters *Parameter::arraySyntaxCopy(Parameters *parameters)
Expand Down
7 changes: 5 additions & 2 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,12 @@ class Parameter : public RootObject
Type *type;
Identifier *ident;
Expression *defaultArg;
UserAttributeDeclaration *userAttribDecl; // user defined attributes

Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg);
static Parameter *create(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg);
Parameter(StorageClass storageClass, Type *type, Identifier *ident,
Expression *defaultArg, UserAttributeDeclaration *userAttribDecl);
static Parameter *create(StorageClass storageClass, Type *type, Identifier *ident,
Expression *defaultArg, UserAttributeDeclaration *userAttribDecl);
Parameter *syntaxCopy();
Type *isLazyArray();
// kludge for template.isType()
Expand Down
Loading