Mercurial > projects > ldc
comparison dmd/mtype.c @ 1103:b30fe7e1dbb9
- Updated to DMD frontend 1.041.
- Removed dmd/inifile.c , it's not under a free license, replaced with libconfig based config file.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Thu, 12 Mar 2009 20:37:27 +0100 |
parents | dc608dc33081 |
children | e7f0c2b48047 |
comparison
equal
deleted
inserted
replaced
1102:ae950bd712d3 | 1103:b30fe7e1dbb9 |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2008 by Digital Mars | 3 // Copyright (c) 1999-2009 by Digital Mars |
4 // All Rights Reserved | 4 // All Rights Reserved |
5 // written by Walter Bright | 5 // written by Walter Bright |
6 // http://www.digitalmars.com | 6 // http://www.digitalmars.com |
7 // License for redistribution is by either the Artistic License | 7 // License for redistribution is by either the Artistic License |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | 8 // in artistic.txt, or the GNU General Public License in gnu.txt. |
47 #include <bits/mathdef.h> | 47 #include <bits/mathdef.h> |
48 #endif | 48 #endif |
49 static double zero = 0; | 49 static double zero = 0; |
50 #endif | 50 #endif |
51 | 51 |
52 #include "mem.h" | 52 #include "rmem.h" |
53 | 53 |
54 #include "dsymbol.h" | 54 #include "dsymbol.h" |
55 #include "mtype.h" | 55 #include "mtype.h" |
56 #include "scope.h" | 56 #include "scope.h" |
57 #include "init.h" | 57 #include "init.h" |
211 mangleChar[Tinstance] = '@'; | 211 mangleChar[Tinstance] = '@'; |
212 mangleChar[Terror] = '@'; | 212 mangleChar[Terror] = '@'; |
213 mangleChar[Ttypeof] = '@'; | 213 mangleChar[Ttypeof] = '@'; |
214 mangleChar[Ttuple] = 'B'; | 214 mangleChar[Ttuple] = 'B'; |
215 mangleChar[Tslice] = '@'; | 215 mangleChar[Tslice] = '@'; |
216 mangleChar[Treturn] = '@'; | |
216 | 217 |
217 for (i = 0; i < TMAX; i++) | 218 for (i = 0; i < TMAX; i++) |
218 { if (!mangleChar[i]) | 219 { if (!mangleChar[i]) |
219 fprintf(stdmsg, "ty = %d\n", i); | 220 fprintf(stdmsg, "ty = %d\n", i); |
220 assert(mangleChar[i]); | 221 assert(mangleChar[i]); |
707 va_start(ap, format); | 708 va_start(ap, format); |
708 ::verror(loc, format, ap); | 709 ::verror(loc, format, ap); |
709 va_end( ap ); | 710 va_end( ap ); |
710 } | 711 } |
711 | 712 |
713 void Type::warning(Loc loc, const char *format, ...) | |
714 { | |
715 if (global.params.warnings && !global.gag) | |
716 { | |
717 fprintf(stdmsg, "warning - "); | |
718 va_list ap; | |
719 va_start(ap, format); | |
720 ::verror(loc, format, ap); | |
721 va_end( ap ); | |
722 } | |
723 } | |
724 | |
712 Identifier *Type::getTypeInfoIdent(int internal) | 725 Identifier *Type::getTypeInfoIdent(int internal) |
713 { | 726 { |
714 // _init_10TypeInfo_%s | 727 // _init_10TypeInfo_%s |
715 OutBuffer buf; | 728 OutBuffer buf; |
716 Identifier *id; | 729 Identifier *id; |
719 | 732 |
720 //toTypeInfoBuffer(&buf); | 733 //toTypeInfoBuffer(&buf); |
721 if (internal) | 734 if (internal) |
722 { buf.writeByte(mangleChar[ty]); | 735 { buf.writeByte(mangleChar[ty]); |
723 if (ty == Tarray) | 736 if (ty == Tarray) |
724 buf.writeByte(mangleChar[next->ty]); | 737 buf.writeByte(mangleChar[((TypeArray *)this)->next->ty]); |
725 } | 738 } |
726 else | 739 else |
727 toDecoBuffer(&buf); | 740 toDecoBuffer(&buf); |
728 len = buf.offset; | 741 len = buf.offset; |
729 name = (char *)alloca(19 + sizeof(len) * 3 + len + 1); | 742 name = (char *)alloca(19 + sizeof(len) * 3 + len + 1); |
744 } | 757 } |
745 | 758 |
746 | 759 |
747 void Type::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | 760 void Type::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) |
748 { | 761 { |
749 Type *t; | 762 //printf("Type::resolve() %s, %d\n", toChars(), ty); |
750 | 763 Type *t = semantic(loc, sc); |
751 t = semantic(loc, sc); | |
752 *pt = t; | 764 *pt = t; |
753 *pe = NULL; | 765 *pe = NULL; |
754 *ps = NULL; | 766 *ps = NULL; |
755 } | 767 } |
756 | 768 |
1871 { integer_t n, n2; | 1883 { integer_t n, n2; |
1872 | 1884 |
1873 dim = semanticLength(sc, tbn, dim); | 1885 dim = semanticLength(sc, tbn, dim); |
1874 | 1886 |
1875 dim = dim->optimize(WANTvalue | WANTinterpret); | 1887 dim = dim->optimize(WANTvalue | WANTinterpret); |
1876 if (sc->parameterSpecialization && dim->op == TOKvar && | 1888 if (sc && sc->parameterSpecialization && dim->op == TOKvar && |
1877 ((VarExp *)dim)->var->storage_class & STCtemplateparameter) | 1889 ((VarExp *)dim)->var->storage_class & STCtemplateparameter) |
1878 { | 1890 { |
1879 /* It could be a template parameter N which has no value yet: | 1891 /* It could be a template parameter N which has no value yet: |
1880 * template Foo(T : T[N], size_t N); | 1892 * template Foo(T : T[N], size_t N); |
1881 */ | 1893 */ |
1907 if (n2 >= 0x1000000) // put a 'reasonable' limit on it | 1919 if (n2 >= 0x1000000) // put a 'reasonable' limit on it |
1908 goto Loverflow; | 1920 goto Loverflow; |
1909 if (n && n2 / n != d2) | 1921 if (n && n2 / n != d2) |
1910 { | 1922 { |
1911 Loverflow: | 1923 Loverflow: |
1912 error(loc, "index %lld overflow for static array", d1); | 1924 error(loc, "index %jd overflow for static array", d1); |
1913 dim = new IntegerExp(0, 1, tsize_t); | 1925 dim = new IntegerExp(0, 1, tsize_t); |
1914 } | 1926 } |
1915 } | 1927 } |
1916 } | 1928 } |
1917 switch (tbn->ty) | 1929 switch (tbn->ty) |
1921 assert(dim); | 1933 assert(dim); |
1922 TypeTuple *tt = (TypeTuple *)tbn; | 1934 TypeTuple *tt = (TypeTuple *)tbn; |
1923 uinteger_t d = dim->toUInteger(); | 1935 uinteger_t d = dim->toUInteger(); |
1924 | 1936 |
1925 if (d >= tt->arguments->dim) | 1937 if (d >= tt->arguments->dim) |
1926 { error(loc, "tuple index %llu exceeds %u", d, tt->arguments->dim); | 1938 { error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim); |
1927 return Type::terror; | 1939 return Type::terror; |
1928 } | 1940 } |
1929 Argument *arg = (Argument *)tt->arguments->data[(size_t)d]; | 1941 Argument *arg = (Argument *)tt->arguments->data[(size_t)d]; |
1930 return arg->type; | 1942 return arg->type; |
1931 } | 1943 } |
1942 | 1954 |
1943 void TypeSArray::toDecoBuffer(OutBuffer *buf) | 1955 void TypeSArray::toDecoBuffer(OutBuffer *buf) |
1944 { | 1956 { |
1945 buf->writeByte(mangleChar[ty]); | 1957 buf->writeByte(mangleChar[ty]); |
1946 if (dim) | 1958 if (dim) |
1947 buf->printf("%llu", dim->toInteger()); | 1959 buf->printf("%ju", dim->toInteger()); |
1948 if (next) | 1960 if (next) |
1949 next->toDecoBuffer(buf); | 1961 next->toDecoBuffer(buf); |
1950 } | 1962 } |
1951 | 1963 |
1952 void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | 1964 void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) |
2634 Expression *TypeReference::defaultInit(Loc loc) | 2646 Expression *TypeReference::defaultInit(Loc loc) |
2635 { | 2647 { |
2636 #if LOGDEFAULTINIT | 2648 #if LOGDEFAULTINIT |
2637 printf("TypeReference::defaultInit() '%s'\n", toChars()); | 2649 printf("TypeReference::defaultInit() '%s'\n", toChars()); |
2638 #endif | 2650 #endif |
2639 Expression *e; | 2651 Expression *e = new NullExp(loc); |
2640 e = new NullExp(loc); | |
2641 e->type = this; | 2652 e->type = this; |
2642 return e; | 2653 return e; |
2643 } | 2654 } |
2644 | 2655 |
2645 int TypeReference::isZeroInit() | 2656 int TypeReference::isZeroInit() |
3717 this->exp = exp; | 3728 this->exp = exp; |
3718 } | 3729 } |
3719 | 3730 |
3720 Type *TypeTypeof::syntaxCopy() | 3731 Type *TypeTypeof::syntaxCopy() |
3721 { | 3732 { |
3733 //printf("TypeTypeof::syntaxCopy() %s\n", toChars()); | |
3722 TypeTypeof *t; | 3734 TypeTypeof *t; |
3723 | 3735 |
3724 t = new TypeTypeof(loc, exp->syntaxCopy()); | 3736 t = new TypeTypeof(loc, exp->syntaxCopy()); |
3725 t->syntaxCopyHelper(this); | 3737 t->syntaxCopyHelper(this); |
3726 return t; | 3738 return t; |
3952 if (!sym->symtab) | 3964 if (!sym->symtab) |
3953 goto Lfwd; | 3965 goto Lfwd; |
3954 s = sym->symtab->lookup(ident); | 3966 s = sym->symtab->lookup(ident); |
3955 if (!s) | 3967 if (!s) |
3956 { | 3968 { |
3957 return getProperty(e->loc, ident); | 3969 if (ident == Id::max || |
3970 ident == Id::min || | |
3971 ident == Id::init || | |
3972 ident == Id::stringof || | |
3973 !sym->memtype | |
3974 ) | |
3975 { | |
3976 return getProperty(e->loc, ident); | |
3977 } | |
3978 return sym->memtype->dotExp(sc, e, ident); | |
3958 } | 3979 } |
3959 m = s->isEnumMember(); | 3980 m = s->isEnumMember(); |
3960 em = m->value->copy(); | 3981 em = m->value->copy(); |
3961 em->loc = e->loc; | 3982 em->loc = e->loc; |
3962 return em; | 3983 return em; |
5036 TypeTuple::TypeTuple(Arguments *arguments) | 5057 TypeTuple::TypeTuple(Arguments *arguments) |
5037 : Type(Ttuple, NULL) | 5058 : Type(Ttuple, NULL) |
5038 { | 5059 { |
5039 //printf("TypeTuple(this = %p)\n", this); | 5060 //printf("TypeTuple(this = %p)\n", this); |
5040 this->arguments = arguments; | 5061 this->arguments = arguments; |
5062 //printf("TypeTuple() %s\n", toChars()); | |
5041 #ifdef DEBUG | 5063 #ifdef DEBUG |
5042 if (arguments) | 5064 if (arguments) |
5043 { | 5065 { |
5044 for (size_t i = 0; i < arguments->dim; i++) | 5066 for (size_t i = 0; i < arguments->dim; i++) |
5045 { | 5067 { |
5081 } | 5103 } |
5082 | 5104 |
5083 Type *TypeTuple::semantic(Loc loc, Scope *sc) | 5105 Type *TypeTuple::semantic(Loc loc, Scope *sc) |
5084 { | 5106 { |
5085 //printf("TypeTuple::semantic(this = %p)\n", this); | 5107 //printf("TypeTuple::semantic(this = %p)\n", this); |
5108 //printf("TypeTuple::semantic() %s\n", toChars()); | |
5086 if (!deco) | 5109 if (!deco) |
5087 deco = merge()->deco; | 5110 deco = merge()->deco; |
5088 | 5111 |
5089 /* Don't return merge(), because a tuple with one type has the | 5112 /* Don't return merge(), because a tuple with one type has the |
5090 * same deco as that type. | 5113 * same deco as that type. |
5204 upr = semanticLength(sc, tbn, upr); | 5227 upr = semanticLength(sc, tbn, upr); |
5205 upr = upr->optimize(WANTvalue); | 5228 upr = upr->optimize(WANTvalue); |
5206 uinteger_t i2 = upr->toUInteger(); | 5229 uinteger_t i2 = upr->toUInteger(); |
5207 | 5230 |
5208 if (!(i1 <= i2 && i2 <= tt->arguments->dim)) | 5231 if (!(i1 <= i2 && i2 <= tt->arguments->dim)) |
5209 { error(loc, "slice [%llu..%llu] is out of range of [0..%u]", i1, i2, tt->arguments->dim); | 5232 { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, tt->arguments->dim); |
5210 return Type::terror; | 5233 return Type::terror; |
5211 } | 5234 } |
5212 | 5235 |
5213 Arguments *args = new Arguments; | 5236 Arguments *args = new Arguments; |
5214 args->reserve(i2 - i1); | 5237 args->reserve(i2 - i1); |
5249 uinteger_t i2 = upr->toUInteger(); | 5272 uinteger_t i2 = upr->toUInteger(); |
5250 | 5273 |
5251 sc = sc->pop(); | 5274 sc = sc->pop(); |
5252 | 5275 |
5253 if (!(i1 <= i2 && i2 <= td->objects->dim)) | 5276 if (!(i1 <= i2 && i2 <= td->objects->dim)) |
5254 { error(loc, "slice [%llu..%llu] is out of range of [0..%u]", i1, i2, td->objects->dim); | 5277 { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, td->objects->dim); |
5255 goto Ldefault; | 5278 goto Ldefault; |
5256 } | 5279 } |
5257 | 5280 |
5258 if (i1 == 0 && i2 == td->objects->dim) | 5281 if (i1 == 0 && i2 == td->objects->dim) |
5259 { | 5282 { |