comparison dmd/mtype.c @ 1617:6820110de311

Merge DMD r301: a little refactor and harmonize --- dmd/declaration.h | 1 + dmd/func.c | 30 ++++++++++++++++++++++++++++++ dmd/mtype.c | 51 +++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 68 insertions(+), 14 deletions(-)
author Leandro Lucarella <llucax@gmail.com>
date Wed, 06 Jan 2010 15:18:21 -0300
parents 081c48283153
children c61782a76dff
comparison
equal deleted inserted replaced
1616:c94049033c20 1617:6820110de311
2963 { 2963 {
2964 //printf("already done\n"); 2964 //printf("already done\n");
2965 return this; 2965 return this;
2966 } 2966 }
2967 //printf("TypeFunction::semantic() this = %p\n", this); 2967 //printf("TypeFunction::semantic() this = %p\n", this);
2968 2968 //printf("TypeFunction::semantic() %s, sc->stc = %x\n", toChars(), sc->stc);
2969
2970 /* Copy in order to not mess up original.
2971 * This can produce redundant copies if inferring return type,
2972 * as semantic() will get called again on this.
2973 */
2969 TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction)); 2974 TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction));
2970 memcpy(tf, this, sizeof(TypeFunction)); 2975 memcpy(tf, this, sizeof(TypeFunction));
2971 if (parameters) 2976 if (parameters)
2972 { tf->parameters = (Parameters *)parameters->copy(); 2977 { tf->parameters = (Parameters *)parameters->copy();
2973 for (size_t i = 0; i < parameters->dim; i++) 2978 for (size_t i = 0; i < parameters->dim; i++)
2980 2985
2981 tf->linkage = sc->linkage; 2986 tf->linkage = sc->linkage;
2982 if (tf->next) 2987 if (tf->next)
2983 { 2988 {
2984 tf->next = tf->next->semantic(loc,sc); 2989 tf->next = tf->next->semantic(loc,sc);
2990 #if !SARRAYVALUE
2985 if (tf->next->toBasetype()->ty == Tsarray) 2991 if (tf->next->toBasetype()->ty == Tsarray)
2986 { error(loc, "functions cannot return static array %s", tf->next->toChars()); 2992 { error(loc, "functions cannot return static array %s", tf->next->toChars());
2987 tf->next = Type::terror; 2993 tf->next = Type::terror;
2988 } 2994 }
2995 #endif
2989 if (tf->next->toBasetype()->ty == Tfunction) 2996 if (tf->next->toBasetype()->ty == Tfunction)
2990 { error(loc, "functions cannot return a function"); 2997 { error(loc, "functions cannot return a function");
2991 tf->next = Type::terror; 2998 tf->next = Type::terror;
2992 } 2999 }
2993 if (tf->next->toBasetype()->ty == Ttuple) 3000 if (tf->next->toBasetype()->ty == Ttuple)
3006 argsc->stc = 0; // don't inherit storage class 3013 argsc->stc = 0; // don't inherit storage class
3007 argsc->protection = PROTpublic; 3014 argsc->protection = PROTpublic;
3008 3015
3009 size_t dim = Parameter::dim(tf->parameters); 3016 size_t dim = Parameter::dim(tf->parameters);
3010 for (size_t i = 0; i < dim; i++) 3017 for (size_t i = 0; i < dim; i++)
3011 { Parameter *arg = Parameter::getNth(tf->parameters, i); 3018 { Parameter *fparam = Parameter::getNth(tf->parameters, i);
3012 3019
3013 tf->inuse++; 3020 tf->inuse++;
3014 arg->type = arg->type->semantic(loc, argsc); 3021 fparam->type = fparam->type->semantic(loc, argsc);
3015 if (tf->inuse == 1) tf->inuse--; 3022 if (tf->inuse == 1) tf->inuse--;
3016 3023
3017 // each function needs its own copy of a tuple arg, since 3024 // each function needs its own copy of a tuple arg, since
3018 // they mustn't share arg flags like inreg, ... 3025 // they mustn't share arg flags like inreg, ...
3019 if (arg->type->ty == Ttuple) { 3026 if (fparam->type->ty == Ttuple) {
3020 arg->type = arg->type->syntaxCopy(); 3027 fparam->type = fparam->type->syntaxCopy();
3021 tf->inuse++; 3028 tf->inuse++;
3022 arg->type = arg->type->semantic(loc,sc); 3029 fparam->type = fparam->type->semantic(loc,sc);
3023 if (tf->inuse == 1) tf->inuse--; 3030 if (tf->inuse == 1) tf->inuse--;
3024 } 3031 }
3025 3032
3026 Type *t = arg->type->toBasetype(); 3033 Type *t = fparam->type->toBasetype();
3027 3034
3028 if (arg->storageClass & (STCout | STCref | STClazy)) 3035 if (fparam->storageClass & (STCout | STCref | STClazy))
3029 { 3036 {
3030 if (t->ty == Tsarray) 3037 if (t->ty == Tsarray)
3031 error(loc, "cannot have out or ref parameter of type %s", t->toChars()); 3038 error(loc, "cannot have out or ref parameter of type %s", t->toChars());
3032 } 3039 }
3033 if (!(arg->storageClass & STClazy) && t->ty == Tvoid) 3040 if (!(fparam->storageClass & STClazy) && t->ty == Tvoid)
3034 error(loc, "cannot have parameter of type %s", arg->type->toChars()); 3041 error(loc, "cannot have parameter of type %s", fparam->type->toChars());
3035 3042
3036 if (arg->defaultArg) 3043 if (fparam->defaultArg)
3037 { 3044 {
3038 arg->defaultArg = arg->defaultArg->semantic(argsc); 3045 fparam->defaultArg = fparam->defaultArg->semantic(argsc);
3039 arg->defaultArg = resolveProperties(argsc, arg->defaultArg); 3046 fparam->defaultArg = resolveProperties(argsc, fparam->defaultArg);
3040 arg->defaultArg = arg->defaultArg->implicitCastTo(argsc, arg->type); 3047 fparam->defaultArg = fparam->defaultArg->implicitCastTo(argsc, fparam->type);
3041 } 3048 }
3042 3049
3043 /* If arg turns out to be a tuple, the number of parameters may 3050 /* If arg turns out to be a tuple, the number of parameters may
3044 * change. 3051 * change.
3045 */ 3052 */
3046 if (t->ty == Ttuple) 3053 if (t->ty == Ttuple)
3047 { dim = Parameter::dim(tf->parameters); 3054 {
3055 // Propagate storage class from tuple parameters to their element-parameters.
3056 TypeTuple *tt = (TypeTuple *)t;
3057 if (tt->arguments)
3058 {
3059 size_t tdim = tt->arguments->dim;
3060 for (size_t j = 0; j < tdim; j++)
3061 { Parameter *narg = (Parameter *)tt->arguments->data[j];
3062 narg->storageClass = fparam->storageClass;
3063 }
3064 }
3065
3066 /* Reset number of parameters, and back up one to do this arg again,
3067 * now that it is the first element of a tuple
3068 */
3069 dim = Parameter::dim(tf->parameters);
3048 i--; 3070 i--;
3071 continue;
3049 } 3072 }
3050 } 3073 }
3051 argsc->pop(); 3074 argsc->pop();
3052 } 3075 }
3053 if (tf->next) 3076 if (tf->next)