Mercurial > projects > ldc
comparison dmd/expression.c @ 1607:207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
---
dmd/arrayop.c | 30 ++++----
dmd/arraytypes.h | 2 +-
dmd/class.c | 8 +-
dmd/declaration.c | 10 ++--
dmd/declaration.h | 16 ++--
dmd/doc.c | 12 ++--
dmd/dsymbol.c | 4 +-
dmd/expression.c | 48 +++++++-------
dmd/expression.h | 32 +++++-----
dmd/func.c | 78 +++++++++++-----------
dmd/init.c | 2 +-
dmd/interpret.c | 8 +-
dmd/mtype.c | 190 ++++++++++++++++++++++++++--------------------------
dmd/mtype.h | 32 +++++-----
dmd/opover.c | 34 +++++-----
dmd/parse.c | 40 ++++++------
dmd/parse.h | 2 +-
dmd/statement.c | 90 +++++++++++++-------------
dmd/statement.h | 14 ++--
dmd/struct.c | 8 +-
dmd/template.c | 30 ++++----
gen/functions.cpp | 10 ++--
gen/functions.h | 2 +-
gen/tocall.cpp | 10 ++--
gen/typinf.cpp | 6 +-
25 files changed, 359 insertions(+), 359 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:20 -0300 |
parents | 1d5721f9ae18 |
children | 1d0220dd613a |
comparison
equal
deleted
inserted
replaced
1606:1b24e9c7cc26 | 1607:207a8a438dea |
---|---|
554 | 554 |
555 /**************************************** | 555 /**************************************** |
556 * Preprocess arguments to function. | 556 * Preprocess arguments to function. |
557 */ | 557 */ |
558 | 558 |
559 void preFunctionArguments(Loc loc, Scope *sc, Expressions *exps) | 559 void preFunctionParameters(Loc loc, Scope *sc, Expressions *exps) |
560 { | 560 { |
561 if (exps) | 561 if (exps) |
562 { | 562 { |
563 expandTuples(exps); | 563 expandTuples(exps); |
564 | 564 |
625 * 2. add default arguments for any missing arguments | 625 * 2. add default arguments for any missing arguments |
626 * 3. do default promotions on arguments corresponding to ... | 626 * 3. do default promotions on arguments corresponding to ... |
627 * 4. add hidden _arguments[] argument | 627 * 4. add hidden _arguments[] argument |
628 */ | 628 */ |
629 | 629 |
630 void functionArguments(Loc loc, Scope *sc, TypeFunction *tf, Expressions *arguments) | 630 void functionParameters(Loc loc, Scope *sc, TypeFunction *tf, Expressions *arguments) |
631 { | 631 { |
632 unsigned n; | 632 unsigned n; |
633 | 633 |
634 //printf("functionArguments()\n"); | 634 //printf("functionParameters()\n"); |
635 assert(arguments); | 635 assert(arguments); |
636 size_t nargs = arguments ? arguments->dim : 0; | 636 size_t nargs = arguments ? arguments->dim : 0; |
637 size_t nparams = Argument::dim(tf->parameters); | 637 size_t nparams = Parameter::dim(tf->parameters); |
638 | 638 |
639 if (nargs > nparams && tf->varargs == 0) | 639 if (nargs > nparams && tf->varargs == 0) |
640 error(loc, "expected %zu arguments, not %zu for non-variadic function type %s", nparams, nargs, tf->toChars()); | 640 error(loc, "expected %zu arguments, not %zu for non-variadic function type %s", nparams, nargs, tf->toChars()); |
641 | 641 |
642 n = (nargs > nparams) ? nargs : nparams; // n = max(nargs, nparams) | 642 n = (nargs > nparams) ? nargs : nparams; // n = max(nargs, nparams) |
652 arg = NULL; | 652 arg = NULL; |
653 Type *tb; | 653 Type *tb; |
654 | 654 |
655 if (i < nparams) | 655 if (i < nparams) |
656 { | 656 { |
657 Argument *p = Argument::getNth(tf->parameters, i); | 657 Parameter *p = Parameter::getNth(tf->parameters, i); |
658 | 658 |
659 if (!arg) | 659 if (!arg) |
660 { | 660 { |
661 if (!p->defaultArg) | 661 if (!p->defaultArg) |
662 { | 662 { |
3608 newtype = type; // in case type gets cast to something else | 3608 newtype = type; // in case type gets cast to something else |
3609 tb = type->toBasetype(); | 3609 tb = type->toBasetype(); |
3610 //printf("tb: %s, deco = %s\n", tb->toChars(), tb->deco); | 3610 //printf("tb: %s, deco = %s\n", tb->toChars(), tb->deco); |
3611 | 3611 |
3612 arrayExpressionSemantic(newargs, sc); | 3612 arrayExpressionSemantic(newargs, sc); |
3613 preFunctionArguments(loc, sc, newargs); | 3613 preFunctionParameters(loc, sc, newargs); |
3614 arrayExpressionSemantic(arguments, sc); | 3614 arrayExpressionSemantic(arguments, sc); |
3615 preFunctionArguments(loc, sc, arguments); | 3615 preFunctionParameters(loc, sc, arguments); |
3616 | 3616 |
3617 if (thisexp && tb->ty != Tclass) | 3617 if (thisexp && tb->ty != Tclass) |
3618 error("e.new is only for allocating nested classes, not %s", tb->toChars()); | 3618 error("e.new is only for allocating nested classes, not %s", tb->toChars()); |
3619 | 3619 |
3620 if (tb->ty == Tclass) | 3620 if (tb->ty == Tclass) |
3725 tf = (TypeFunction *)f->type; | 3725 tf = (TypeFunction *)f->type; |
3726 type = tf->next; | 3726 type = tf->next; |
3727 | 3727 |
3728 if (!arguments) | 3728 if (!arguments) |
3729 arguments = new Expressions(); | 3729 arguments = new Expressions(); |
3730 functionArguments(loc, sc, tf, arguments); | 3730 functionParameters(loc, sc, tf, arguments); |
3731 } | 3731 } |
3732 else | 3732 else |
3733 { | 3733 { |
3734 if (arguments && arguments->dim) | 3734 if (arguments && arguments->dim) |
3735 error("no constructor for %s", cd->toChars()); | 3735 error("no constructor for %s", cd->toChars()); |
3746 f = cd->aggNew->overloadResolve(loc, NULL, newargs, sc->module); | 3746 f = cd->aggNew->overloadResolve(loc, NULL, newargs, sc->module); |
3747 allocator = f->isNewDeclaration(); | 3747 allocator = f->isNewDeclaration(); |
3748 assert(allocator); | 3748 assert(allocator); |
3749 | 3749 |
3750 tf = (TypeFunction *)f->type; | 3750 tf = (TypeFunction *)f->type; |
3751 functionArguments(loc, sc, tf, newargs); | 3751 functionParameters(loc, sc, tf, newargs); |
3752 } | 3752 } |
3753 else | 3753 else |
3754 { | 3754 { |
3755 if (newargs && newargs->dim) | 3755 if (newargs && newargs->dim) |
3756 error("no allocator for %s", cd->toChars()); | 3756 error("no allocator for %s", cd->toChars()); |
3779 f = f->overloadResolve(loc, NULL, newargs, sc->module); | 3779 f = f->overloadResolve(loc, NULL, newargs, sc->module); |
3780 allocator = f->isNewDeclaration(); | 3780 allocator = f->isNewDeclaration(); |
3781 assert(allocator); | 3781 assert(allocator); |
3782 | 3782 |
3783 tf = (TypeFunction *)f->type; | 3783 tf = (TypeFunction *)f->type; |
3784 functionArguments(loc, sc, tf, newargs); | 3784 functionParameters(loc, sc, tf, newargs); |
3785 | 3785 |
3786 e = new VarExp(loc, f); | 3786 e = new VarExp(loc, f); |
3787 e = new CallExp(loc, e, newargs); | 3787 e = new CallExp(loc, e, newargs); |
3788 e = e->semantic(sc); | 3788 e = e->semantic(sc); |
3789 e->type = type->pointerTo(); | 3789 e->type = type->pointerTo(); |
4747 // If class or interface, get the base class and interfaces | 4747 // If class or interface, get the base class and interfaces |
4748 if (targ->ty != Tclass) | 4748 if (targ->ty != Tclass) |
4749 goto Lno; | 4749 goto Lno; |
4750 else | 4750 else |
4751 { ClassDeclaration *cd = ((TypeClass *)targ)->sym; | 4751 { ClassDeclaration *cd = ((TypeClass *)targ)->sym; |
4752 Arguments *args = new Arguments; | 4752 Parameters *args = new Parameters; |
4753 args->reserve(cd->baseclasses.dim); | 4753 args->reserve(cd->baseclasses.dim); |
4754 for (size_t i = 0; i < cd->baseclasses.dim; i++) | 4754 for (size_t i = 0; i < cd->baseclasses.dim; i++) |
4755 { BaseClass *b = (BaseClass *)cd->baseclasses.data[i]; | 4755 { BaseClass *b = (BaseClass *)cd->baseclasses.data[i]; |
4756 args->push(new Argument(STCin, b->type, NULL, NULL)); | 4756 args->push(new Parameter(STCin, b->type, NULL, NULL)); |
4757 } | 4757 } |
4758 tded = new TypeTuple(args); | 4758 tded = new TypeTuple(args); |
4759 } | 4759 } |
4760 break; | 4760 break; |
4761 | 4761 |
4778 tded = targ; | 4778 tded = targ; |
4779 | 4779 |
4780 /* Generate tuple from function parameter types. | 4780 /* Generate tuple from function parameter types. |
4781 */ | 4781 */ |
4782 assert(tded->ty == Tfunction); | 4782 assert(tded->ty == Tfunction); |
4783 Arguments *params = ((TypeFunction *)tded)->parameters; | 4783 Parameters *params = ((TypeFunction *)tded)->parameters; |
4784 size_t dim = Argument::dim(params); | 4784 size_t dim = Parameter::dim(params); |
4785 Arguments *args = new Arguments; | 4785 Parameters *args = new Parameters; |
4786 args->reserve(dim); | 4786 args->reserve(dim); |
4787 for (size_t i = 0; i < dim; i++) | 4787 for (size_t i = 0; i < dim; i++) |
4788 { Argument *arg = Argument::getNth(params, i); | 4788 { Parameter *arg = Parameter::getNth(params, i); |
4789 assert(arg && arg->type); | 4789 assert(arg && arg->type); |
4790 args->push(new Argument(arg->storageClass, arg->type, NULL, NULL)); | 4790 args->push(new Parameter(arg->storageClass, arg->type, NULL, NULL)); |
4791 } | 4791 } |
4792 tded = new TypeTuple(args); | 4792 tded = new TypeTuple(args); |
4793 break; | 4793 break; |
4794 } | 4794 } |
4795 case TOKreturn: | 4795 case TOKreturn: |
6385 return e; | 6385 return e; |
6386 } | 6386 } |
6387 } | 6387 } |
6388 | 6388 |
6389 arrayExpressionSemantic(arguments, sc); | 6389 arrayExpressionSemantic(arguments, sc); |
6390 preFunctionArguments(loc, sc, arguments); | 6390 preFunctionParameters(loc, sc, arguments); |
6391 | 6391 |
6392 if (e1->op == TOKdotvar && t1->ty == Tfunction || | 6392 if (e1->op == TOKdotvar && t1->ty == Tfunction || |
6393 e1->op == TOKdottd) | 6393 e1->op == TOKdottd) |
6394 { | 6394 { |
6395 DotVarExp *dve; | 6395 DotVarExp *dve; |
6666 assert(tf->ty == Tfunction); | 6666 assert(tf->ty == Tfunction); |
6667 type = tf->next; | 6667 type = tf->next; |
6668 | 6668 |
6669 if (!arguments) | 6669 if (!arguments) |
6670 arguments = new Expressions(); | 6670 arguments = new Expressions(); |
6671 functionArguments(loc, sc, tf, arguments); | 6671 functionParameters(loc, sc, tf, arguments); |
6672 | 6672 |
6673 assert(type); | 6673 assert(type); |
6674 | 6674 |
6675 if (f && f->tintro) | 6675 if (f && f->tintro) |
6676 { | 6676 { |
7469 { te = (TupleExp *)e1; | 7469 { te = (TupleExp *)e1; |
7470 length = te->exps->dim; | 7470 length = te->exps->dim; |
7471 } | 7471 } |
7472 else if (e1->op == TOKtype) // slicing a type tuple | 7472 else if (e1->op == TOKtype) // slicing a type tuple |
7473 { tup = (TypeTuple *)t; | 7473 { tup = (TypeTuple *)t; |
7474 length = Argument::dim(tup->arguments); | 7474 length = Parameter::dim(tup->arguments); |
7475 } | 7475 } |
7476 else | 7476 else |
7477 assert(0); | 7477 assert(0); |
7478 | 7478 |
7479 if (i1 <= i2 && i2 <= length) | 7479 if (i1 <= i2 && i2 <= length) |
7488 exps->data[i] = (void *)e; | 7488 exps->data[i] = (void *)e; |
7489 } | 7489 } |
7490 e = new TupleExp(loc, exps); | 7490 e = new TupleExp(loc, exps); |
7491 } | 7491 } |
7492 else | 7492 else |
7493 { Arguments *args = new Arguments; | 7493 { Parameters *args = new Parameters; |
7494 args->reserve(j2 - j1); | 7494 args->reserve(j2 - j1); |
7495 for (size_t i = j1; i < j2; i++) | 7495 for (size_t i = j1; i < j2; i++) |
7496 { Argument *arg = Argument::getNth(tup->arguments, i); | 7496 { Parameter *arg = Parameter::getNth(tup->arguments, i); |
7497 args->push(arg); | 7497 args->push(arg); |
7498 } | 7498 } |
7499 e = new TypeExp(e1->loc, new TypeTuple(args)); | 7499 e = new TypeExp(e1->loc, new TypeTuple(args)); |
7500 } | 7500 } |
7501 e = e->semantic(sc); | 7501 e = e->semantic(sc); |
7869 length = te->exps->dim; | 7869 length = te->exps->dim; |
7870 } | 7870 } |
7871 else if (e1->op == TOKtype) | 7871 else if (e1->op == TOKtype) |
7872 { | 7872 { |
7873 tup = (TypeTuple *)t1; | 7873 tup = (TypeTuple *)t1; |
7874 length = Argument::dim(tup->arguments); | 7874 length = Parameter::dim(tup->arguments); |
7875 } | 7875 } |
7876 else | 7876 else |
7877 assert(0); | 7877 assert(0); |
7878 | 7878 |
7879 if (index < length) | 7879 if (index < length) |
7880 { | 7880 { |
7881 | 7881 |
7882 if (e1->op == TOKtuple) | 7882 if (e1->op == TOKtuple) |
7883 e = (Expression *)te->exps->data[(size_t)index]; | 7883 e = (Expression *)te->exps->data[(size_t)index]; |
7884 else | 7884 else |
7885 e = new TypeExp(e1->loc, Argument::getNth(tup->arguments, (size_t)index)->type); | 7885 e = new TypeExp(e1->loc, Parameter::getNth(tup->arguments, (size_t)index)->type); |
7886 } | 7886 } |
7887 else | 7887 else |
7888 { | 7888 { |
7889 error("array index [%ju] is outside array bounds [0 .. %zu]", | 7889 error("array index [%ju] is outside array bounds [0 .. %zu]", |
7890 index, length); | 7890 index, length); |