Mercurial > projects > ldc
comparison dmd2/mtype.c @ 1577:e4f7b5d9c68a
DMD 2.032 Merge.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 08 Sep 2009 10:07:56 +0100 |
parents | 54b3c1394d62 |
children |
comparison
equal
deleted
inserted
replaced
1576:4551475bc6b6 | 1577:e4f7b5d9c68a |
---|---|
196 | 196 |
197 for (i = 0; i < TMAX; i++) | 197 for (i = 0; i < TMAX; i++) |
198 sizeTy[i] = sizeof(TypeBasic); | 198 sizeTy[i] = sizeof(TypeBasic); |
199 sizeTy[Tsarray] = sizeof(TypeSArray); | 199 sizeTy[Tsarray] = sizeof(TypeSArray); |
200 sizeTy[Tarray] = sizeof(TypeDArray); | 200 sizeTy[Tarray] = sizeof(TypeDArray); |
201 //sizeTy[Tnarray] = sizeof(TypeNArray); | |
201 sizeTy[Taarray] = sizeof(TypeAArray); | 202 sizeTy[Taarray] = sizeof(TypeAArray); |
202 sizeTy[Tpointer] = sizeof(TypePointer); | 203 sizeTy[Tpointer] = sizeof(TypePointer); |
203 sizeTy[Treference] = sizeof(TypeReference); | 204 sizeTy[Treference] = sizeof(TypeReference); |
204 sizeTy[Tfunction] = sizeof(TypeFunction); | 205 sizeTy[Tfunction] = sizeof(TypeFunction); |
205 sizeTy[Tdelegate] = sizeof(TypeDelegate); | 206 sizeTy[Tdelegate] = sizeof(TypeDelegate); |
214 sizeTy[Tslice] = sizeof(TypeSlice); | 215 sizeTy[Tslice] = sizeof(TypeSlice); |
215 sizeTy[Treturn] = sizeof(TypeReturn); | 216 sizeTy[Treturn] = sizeof(TypeReturn); |
216 | 217 |
217 mangleChar[Tarray] = 'A'; | 218 mangleChar[Tarray] = 'A'; |
218 mangleChar[Tsarray] = 'G'; | 219 mangleChar[Tsarray] = 'G'; |
220 mangleChar[Tnarray] = '@'; | |
219 mangleChar[Taarray] = 'H'; | 221 mangleChar[Taarray] = 'H'; |
220 mangleChar[Tpointer] = 'P'; | 222 mangleChar[Tpointer] = 'P'; |
221 mangleChar[Treference] = 'R'; | 223 mangleChar[Treference] = 'R'; |
222 mangleChar[Tfunction] = 'F'; | 224 mangleChar[Tfunction] = 'F'; |
223 mangleChar[Tident] = 'I'; | 225 mangleChar[Tident] = 'I'; |
1149 if (this->mod & MODshared) | 1151 if (this->mod & MODshared) |
1150 buf->writeByte(')'); | 1152 buf->writeByte(')'); |
1151 } | 1153 } |
1152 } | 1154 } |
1153 | 1155 |
1156 void Type::modToBuffer(OutBuffer *buf) | |
1157 { | |
1158 if (mod & MODshared) | |
1159 buf->writestring(" shared"); | |
1160 if (mod & MODconst) | |
1161 buf->writestring(" const"); | |
1162 if (mod & MODinvariant) | |
1163 buf->writestring(" immutable"); | |
1164 } | |
1165 | |
1154 /************************************ | 1166 /************************************ |
1155 */ | 1167 */ |
1156 | 1168 |
1157 Type *Type::merge() | 1169 Type *Type::merge() |
1158 { Type *t; | 1170 { Type *t; |
1648 | 1660 |
1649 Type *TypeNext::reliesOnTident() | 1661 Type *TypeNext::reliesOnTident() |
1650 { | 1662 { |
1651 return next->reliesOnTident(); | 1663 return next->reliesOnTident(); |
1652 } | 1664 } |
1665 | |
1666 /******************************* | |
1667 * For TypeFunction, nextOf() can return NULL if the function return | |
1668 * type is meant to be inferred, and semantic() hasn't yet ben run | |
1669 * on the function. After semantic(), it must no longer be NULL. | |
1670 */ | |
1653 | 1671 |
1654 Type *TypeNext::nextOf() | 1672 Type *TypeNext::nextOf() |
1655 { | 1673 { |
1656 return next; | 1674 return next; |
1657 } | 1675 } |
3249 int TypeDArray::hasPointers() | 3267 int TypeDArray::hasPointers() |
3250 { | 3268 { |
3251 return TRUE; | 3269 return TRUE; |
3252 } | 3270 } |
3253 | 3271 |
3272 | |
3273 /***************************** TypeNewArray *****************************/ | |
3274 | |
3275 #if 0 | |
3276 | |
3277 TypeNewArray::TypeNewArray(Type *telement) | |
3278 : TypeArray(Tnewarray, telement) | |
3279 { | |
3280 sym = NULL; | |
3281 } | |
3282 | |
3283 Type *TypeNewArray::syntaxCopy() | |
3284 { | |
3285 Type *t = next->syntaxCopy(); | |
3286 if (t == next) | |
3287 t = this; | |
3288 else | |
3289 { t = new TypeNewArray(t); | |
3290 t->mod = mod; | |
3291 } | |
3292 return t; | |
3293 } | |
3294 | |
3295 d_uns64 TypeNewArray::size(Loc loc) | |
3296 { | |
3297 //printf("TypeNewArray::size()\n"); | |
3298 return PTRSIZE; | |
3299 } | |
3300 | |
3301 unsigned TypeNewArray::alignsize() | |
3302 { | |
3303 return PTRSIZE; | |
3304 } | |
3305 | |
3306 Type *TypeNewArray::semantic(Loc loc, Scope *sc) | |
3307 { Type *tn = next; | |
3308 | |
3309 tn = next->semantic(loc,sc); | |
3310 Type *tbn = tn->toBasetype(); | |
3311 switch (tbn->ty) | |
3312 { | |
3313 case Tfunction: | |
3314 case Tnone: | |
3315 case Ttuple: | |
3316 error(loc, "can't have array of %s", tbn->toChars()); | |
3317 tn = next = tint32; | |
3318 break; | |
3319 case Tstruct: | |
3320 { TypeStruct *ts = (TypeStruct *)tbn; | |
3321 if (ts->sym->isnested) | |
3322 error(loc, "cannot have array of inner structs %s", ts->toChars()); | |
3323 break; | |
3324 } | |
3325 } | |
3326 if (tn->isauto()) | |
3327 error(loc, "cannot have array of auto %s", tn->toChars()); | |
3328 | |
3329 next = tn; | |
3330 transitive(); | |
3331 return merge(); | |
3332 } | |
3333 | |
3334 void TypeNewArray::toDecoBuffer(OutBuffer *buf, int flag) | |
3335 { | |
3336 Type::toDecoBuffer(buf, flag); | |
3337 buf->writeByte('e'); | |
3338 if (next) | |
3339 next->toDecoBuffer(buf, (flag & 0x100) ? 0 : mod); | |
3340 } | |
3341 | |
3342 void TypeNewArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3343 { | |
3344 if (mod != this->mod) | |
3345 { toCBuffer3(buf, hgs, mod); | |
3346 return; | |
3347 } | |
3348 next->toCBuffer2(buf, hgs, this->mod); | |
3349 buf->writestring("[new]"); | |
3350 } | |
3351 | |
3352 #endif | |
3353 | |
3254 /***************************** TypeAArray *****************************/ | 3354 /***************************** TypeAArray *****************************/ |
3255 | 3355 |
3256 TypeAArray::TypeAArray(Type *t, Type *index) | 3356 TypeAArray::TypeAArray(Type *t, Type *index) |
3257 : TypeArray(Taarray, t) | 3357 : TypeArray(Taarray, t) |
3258 { | 3358 { |
3772 this->varargs = varargs; | 3872 this->varargs = varargs; |
3773 this->linkage = linkage; | 3873 this->linkage = linkage; |
3774 this->inuse = 0; | 3874 this->inuse = 0; |
3775 this->isnothrow = false; | 3875 this->isnothrow = false; |
3776 this->ispure = false; | 3876 this->ispure = false; |
3877 this->isproperty = false; | |
3777 this->isref = false; | 3878 this->isref = false; |
3778 | 3879 |
3779 #if IN_LLVM | 3880 #if IN_LLVM |
3780 this->funcdecl = NULL; | 3881 this->funcdecl = NULL; |
3781 #endif | 3882 #endif |
3787 Arguments *params = Argument::arraySyntaxCopy(parameters); | 3888 Arguments *params = Argument::arraySyntaxCopy(parameters); |
3788 TypeFunction *t = new TypeFunction(params, treturn, varargs, linkage); | 3889 TypeFunction *t = new TypeFunction(params, treturn, varargs, linkage); |
3789 t->mod = mod; | 3890 t->mod = mod; |
3790 t->isnothrow = isnothrow; | 3891 t->isnothrow = isnothrow; |
3791 t->ispure = ispure; | 3892 t->ispure = ispure; |
3893 t->isproperty = isproperty; | |
3792 t->isref = isref; | 3894 t->isref = isref; |
3793 return t; | 3895 return t; |
3794 } | 3896 } |
3795 | 3897 |
3796 /******************************* | 3898 /******************************* |
3956 | 4058 |
3957 default: | 4059 default: |
3958 assert(0); | 4060 assert(0); |
3959 } | 4061 } |
3960 buf->writeByte(mc); | 4062 buf->writeByte(mc); |
3961 | 4063 if (ispure || isnothrow || isproperty || isref) |
3962 if (ispure || isnothrow || isref) | |
3963 { | 4064 { |
3964 if (ispure) | 4065 if (ispure) |
3965 buf->writestring("Na"); | 4066 buf->writestring("Na"); |
3966 if (isnothrow) | 4067 if (isnothrow) |
3967 buf->writestring("Nb"); | 4068 buf->writestring("Nb"); |
3968 if (isref) | 4069 if (isref) |
3969 buf->writestring("Nc"); | 4070 buf->writestring("Nc"); |
4071 if (isproperty) | |
4072 buf->writestring("Nd"); | |
3970 } | 4073 } |
3971 | 4074 |
3972 // LDC: if we're not producing a mangle string, add the this | 4075 // LDC: if we're not producing a mangle string, add the this |
3973 // type to prevent merging different member function | 4076 // type to prevent merging different member function |
3974 if (!mangle && funcdecl) | 4077 if (!mangle && funcdecl) |
4024 | 4127 |
4025 if (ispure) | 4128 if (ispure) |
4026 buf->writestring("pure "); | 4129 buf->writestring("pure "); |
4027 if (isnothrow) | 4130 if (isnothrow) |
4028 buf->writestring("nothrow "); | 4131 buf->writestring("nothrow "); |
4132 if (isproperty) | |
4133 buf->writestring("@property "); | |
4029 if (isref) | 4134 if (isref) |
4030 buf->writestring("ref "); | 4135 buf->writestring("ref "); |
4031 | 4136 |
4032 if (next && (!ident || ident->toHChars2() == ident->toChars())) | 4137 if (next && (!ident || ident->toHChars2() == ident->toChars())) |
4033 next->toCBuffer2(buf, hgs, 0); | 4138 next->toCBuffer2(buf, hgs, 0); |
4096 | 4201 |
4097 /* Use postfix style for attributes | 4202 /* Use postfix style for attributes |
4098 */ | 4203 */ |
4099 if (mod != this->mod) | 4204 if (mod != this->mod) |
4100 { | 4205 { |
4101 if (mod & MODconst) | 4206 modToBuffer(buf); |
4102 buf->writestring(" const"); | |
4103 if (mod & MODinvariant) | |
4104 buf->writestring(" immutable"); | |
4105 if (mod & MODshared) | |
4106 buf->writestring(" shared"); | |
4107 } | 4207 } |
4108 if (ispure) | 4208 if (ispure) |
4109 buf->writestring(" pure"); | 4209 buf->writestring(" pure"); |
4110 if (isnothrow) | 4210 if (isnothrow) |
4111 buf->writestring(" nothrow"); | 4211 buf->writestring(" nothrow"); |
4212 if (isproperty) | |
4213 buf->writestring(" @property"); | |
4112 if (isref) | 4214 if (isref) |
4113 buf->writestring(" ref"); | 4215 buf->writestring(" ref"); |
4114 | 4216 |
4115 inuse--; | 4217 inuse--; |
4116 } | 4218 } |
6168 | 6270 |
6169 char *TypeClass::toChars() | 6271 char *TypeClass::toChars() |
6170 { | 6272 { |
6171 if (mod) | 6273 if (mod) |
6172 return Type::toChars(); | 6274 return Type::toChars(); |
6173 return sym->toPrettyChars(); | 6275 return (char *)sym->toPrettyChars(); |
6174 } | 6276 } |
6175 | 6277 |
6176 Type *TypeClass::syntaxCopy() | 6278 Type *TypeClass::syntaxCopy() |
6177 { | 6279 { |
6178 return this; | 6280 return this; |