Mercurial > projects > ldc
comparison dmd2/dsymbol.c @ 1452:638d16625da2
LDC 2 compiles again.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Sat, 30 May 2009 17:23:32 +0100 |
parents | 5fa3e0ea06e9 |
children | 54b3c1394d62 |
comparison
equal
deleted
inserted
replaced
1423:42bd767ec5a4 | 1452:638d16625da2 |
---|---|
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <string.h> | 12 #include <string.h> |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include "mem.h" | 15 #include "rmem.h" |
16 | 16 |
17 #include "mars.h" | 17 #include "mars.h" |
18 #include "dsymbol.h" | 18 #include "dsymbol.h" |
19 #include "aggregate.h" | 19 #include "aggregate.h" |
20 #include "identifier.h" | 20 #include "identifier.h" |
28 #include "init.h" | 28 #include "init.h" |
29 #include "import.h" | 29 #include "import.h" |
30 #include "template.h" | 30 #include "template.h" |
31 #include "attrib.h" | 31 #include "attrib.h" |
32 | 32 |
33 #if IN_LLVM | |
33 #include "../gen/enums.h" | 34 #include "../gen/enums.h" |
35 #endif | |
34 | 36 |
35 /****************************** Dsymbol ******************************/ | 37 /****************************** Dsymbol ******************************/ |
36 | 38 |
37 Dsymbol::Dsymbol() | 39 Dsymbol::Dsymbol() |
38 { | 40 { |
39 //printf("Dsymbol::Dsymbol(%p)\n", this); | 41 //printf("Dsymbol::Dsymbol(%p)\n", this); |
40 this->ident = NULL; | 42 this->ident = NULL; |
41 this->c_ident = NULL; | 43 this->c_ident = NULL; |
42 this->parent = NULL; | 44 this->parent = NULL; |
45 #if IN_DMD | |
43 this->csym = NULL; | 46 this->csym = NULL; |
44 this->isym = NULL; | 47 this->isym = NULL; |
48 #endif | |
45 this->loc = 0; | 49 this->loc = 0; |
46 this->comment = NULL; | 50 this->comment = NULL; |
47 | 51 |
52 #if IN_LLVM | |
48 this->llvmInternal = LLVMnone; | 53 this->llvmInternal = LLVMnone; |
54 this->irsym = NULL; | |
55 #endif | |
49 } | 56 } |
50 | 57 |
51 Dsymbol::Dsymbol(Identifier *ident) | 58 Dsymbol::Dsymbol(Identifier *ident) |
52 { | 59 { |
53 //printf("Dsymbol::Dsymbol(%p, ident)\n", this); | 60 //printf("Dsymbol::Dsymbol(%p, ident)\n", this); |
54 this->ident = ident; | 61 this->ident = ident; |
55 this->c_ident = NULL; | 62 this->c_ident = NULL; |
56 this->parent = NULL; | 63 this->parent = NULL; |
64 #if IN_DMD | |
57 this->csym = NULL; | 65 this->csym = NULL; |
58 this->isym = NULL; | 66 this->isym = NULL; |
67 #endif | |
59 this->loc = 0; | 68 this->loc = 0; |
60 this->comment = NULL; | 69 this->comment = NULL; |
61 | 70 |
71 #if IN_LLVM | |
62 this->llvmInternal = LLVMnone; | 72 this->llvmInternal = LLVMnone; |
73 this->irsym = NULL; | |
74 #endif | |
63 } | 75 } |
64 | 76 |
65 int Dsymbol::equals(Object *o) | 77 int Dsymbol::equals(Object *o) |
66 { Dsymbol *s; | 78 { Dsymbol *s; |
67 | 79 |
574 | 586 |
575 //printf("Dsymbol::getModule()\n"); | 587 //printf("Dsymbol::getModule()\n"); |
576 s = this; | 588 s = this; |
577 while (s) | 589 while (s) |
578 { | 590 { |
579 //printf("\ts = '%s'\n", s->toChars()); | 591 //printf("\ts = '%s'\n", s->toChars()); |
580 m = s->isModule(); | 592 m = s->isModule(); |
581 if (m) | 593 if (m) |
582 return m; | 594 return m; |
583 ti = s->isTemplateInstance(); | 595 ti = s->isTemplateInstance(); |
584 if (ti && ti->tmodule) | 596 if (ti && ti->tmodule) |
585 return ti->tmodule; | 597 return ti->tmodule; |
586 s = s->parent; | 598 s = s->parent; |
587 } | 599 } |
588 return NULL; | 600 return NULL; |
589 } | 601 } |
590 | 602 |
591 /************************************* | 603 /************************************* |
697 //if (strcmp(ident->toChars(),"c") == 0) *(char*)0=0; | 709 //if (strcmp(ident->toChars(),"c") == 0) *(char*)0=0; |
698 | 710 |
699 // Look in symbols declared in this module | 711 // Look in symbols declared in this module |
700 Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; | 712 Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; |
701 | 713 |
702 // hide private nonlocal symbols | 714 // hide the aliases generated by selective or renamed private imports |
703 if (flags & 1 && s && s->prot() == PROTprivate) | 715 if (s && flags & 1) |
704 s = NULL; | 716 if (AliasDeclaration* ad = s->isAliasDeclaration()) |
717 // may be a private alias to a function that is overloaded. these | |
718 // are sorted out during overload resolution, accept them here | |
719 if (ad->importprot == PROTprivate && !ad->aliassym->isFuncAliasDeclaration()) | |
720 s = NULL; | |
705 | 721 |
706 if (s) | 722 if (s) |
707 { | 723 { |
708 //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); | 724 //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); |
709 } | 725 } |
865 s1->error(loc, "conflicts with %s %s at %s", | 881 s1->error(loc, "conflicts with %s %s at %s", |
866 s2->kind(), | 882 s2->kind(), |
867 s2->toPrettyChars(), | 883 s2->toPrettyChars(), |
868 s2->locToChars()); | 884 s2->locToChars()); |
869 } | 885 } |
870 halt(); | |
871 } | 886 } |
872 | 887 |
873 Dsymbol *ScopeDsymbol::nameCollision(Dsymbol *s) | 888 Dsymbol *ScopeDsymbol::nameCollision(Dsymbol *s) |
874 { | 889 { |
875 Dsymbol *sprev; | 890 Dsymbol *sprev; |
1046 Expression *ce; | 1061 Expression *ce; |
1047 | 1062 |
1048 L1: | 1063 L1: |
1049 | 1064 |
1050 if (td) | 1065 if (td) |
1051 { | 1066 { /* $ gives the number of elements in the tuple |
1067 */ | |
1052 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); | 1068 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); |
1053 Expression *e = new IntegerExp(0, td->objects->dim, Type::tsize_t); | 1069 Expression *e = new IntegerExp(0, td->objects->dim, Type::tsize_t); |
1054 v->init = new ExpInitializer(0, e); | 1070 v->init = new ExpInitializer(0, e); |
1055 v->storage_class |= STCstatic | STCconst; | 1071 v->storage_class |= STCstatic | STCconst; |
1056 v->semantic(sc); | 1072 v->semantic(sc); |
1057 return v; | 1073 return v; |
1058 } | 1074 } |
1059 | 1075 |
1060 if (type) | 1076 if (type) |
1061 { | 1077 { /* $ gives the number of type entries in the type tuple |
1078 */ | |
1062 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); | 1079 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); |
1063 Expression *e = new IntegerExp(0, type->arguments->dim, Type::tsize_t); | 1080 Expression *e = new IntegerExp(0, type->arguments->dim, Type::tsize_t); |
1064 v->init = new ExpInitializer(0, e); | 1081 v->init = new ExpInitializer(0, e); |
1065 v->storage_class |= STCstatic | STCconst; | 1082 v->storage_class |= STCstatic | STCconst; |
1066 v->semantic(sc); | 1083 v->semantic(sc); |
1067 return v; | 1084 return v; |
1068 } | 1085 } |
1069 | 1086 |
1070 if (exp->op == TOKindex) | 1087 if (exp->op == TOKindex) |
1071 { | 1088 { /* array[index] where index is some function of $ |
1089 */ | |
1072 IndexExp *ie = (IndexExp *)exp; | 1090 IndexExp *ie = (IndexExp *)exp; |
1073 | 1091 |
1074 pvar = &ie->lengthVar; | 1092 pvar = &ie->lengthVar; |
1075 ce = ie->e1; | 1093 ce = ie->e1; |
1076 } | 1094 } |
1077 else if (exp->op == TOKslice) | 1095 else if (exp->op == TOKslice) |
1078 { | 1096 { /* array[lwr .. upr] where lwr or upr is some function of $ |
1097 */ | |
1079 SliceExp *se = (SliceExp *)exp; | 1098 SliceExp *se = (SliceExp *)exp; |
1080 | 1099 |
1081 pvar = &se->lengthVar; | 1100 pvar = &se->lengthVar; |
1082 ce = se->e1; | 1101 ce = se->e1; |
1083 } | 1102 } |
1084 else | 1103 else |
1104 /* Didn't find $, look in enclosing scope(s). | |
1105 */ | |
1085 return NULL; | 1106 return NULL; |
1086 | 1107 |
1108 /* If we are indexing into an array that is really a type | |
1109 * tuple, rewrite this as an index into a type tuple and | |
1110 * try again. | |
1111 */ | |
1087 if (ce->op == TOKtype) | 1112 if (ce->op == TOKtype) |
1088 { | 1113 { |
1089 Type *t = ((TypeExp *)ce)->type; | 1114 Type *t = ((TypeExp *)ce)->type; |
1090 if (t->ty == Ttuple) | 1115 if (t->ty == Ttuple) |
1091 { type = (TypeTuple *)t; | 1116 { type = (TypeTuple *)t; |
1092 goto L1; | 1117 goto L1; |
1093 } | 1118 } |
1094 } | 1119 } |
1095 | 1120 |
1096 if (!*pvar) | 1121 /* *pvar is lazily initialized, so if we refer to $ |
1097 { | 1122 * multiple times, it gets set only once. |
1123 */ | |
1124 if (!*pvar) // if not already initialized | |
1125 { /* Create variable v and set it to the value of $, | |
1126 * which will be a constant. | |
1127 */ | |
1098 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); | 1128 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); |
1099 | 1129 |
1100 if (ce->op == TOKvar) | 1130 if (ce->op == TOKvar) |
1101 { // if ce is const, get its initializer | 1131 { // if ce is const, get its initializer |
1102 ce = fromConstInitializer(WANTvalue | WANTinterpret, ce); | 1132 ce = fromConstInitializer(WANTvalue | WANTinterpret, ce); |
1146 { | 1176 { |
1147 delete tab; | 1177 delete tab; |
1148 } | 1178 } |
1149 | 1179 |
1150 Dsymbol *DsymbolTable::lookup(Identifier *ident) | 1180 Dsymbol *DsymbolTable::lookup(Identifier *ident) |
1151 { StringValue *sv; | 1181 { |
1152 | |
1153 #ifdef DEBUG | 1182 #ifdef DEBUG |
1154 assert(ident); | 1183 assert(ident); |
1155 assert(tab); | 1184 assert(tab); |
1156 #endif | 1185 #endif |
1157 sv = tab->lookup((char*)ident->string, ident->len); | 1186 StringValue *sv = tab->lookup((char*)ident->string, ident->len); |
1158 return (Dsymbol *)(sv ? sv->ptrvalue : NULL); | 1187 return (Dsymbol *)(sv ? sv->ptrvalue : NULL); |
1159 } | 1188 } |
1160 | 1189 |
1161 Dsymbol *DsymbolTable::insert(Dsymbol *s) | 1190 Dsymbol *DsymbolTable::insert(Dsymbol *s) |
1162 { StringValue *sv; | 1191 { StringValue *sv; |