annotate dmd/TypedefDeclaration.d @ 22:fd4acc376c45

Implemented object file output and linking on linux.
author Robert Clipsham <robert@octarineparrot.com>
date Thu, 08 Apr 2010 04:21:03 +0100
parents 10317f0c89a5
children ee3a9f34dc48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypedefDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Dsymbol;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
9 import dmd.Module;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TypeTypedef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 class TypedefDeclaration : Declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 Type basetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 Initializer init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 int sem = 0;// 0: semantic() has not been run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 // 1: semantic() is in progress
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 // 2: semantic() has been run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 // 3: semantic2() has been run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this(Loc loc, Identifier id, Type basetype, Initializer init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 super(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this.type = new TypeTypedef(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 this.basetype = basetype.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this.init = init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 this.htype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 this.hbasetype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 this.sinit = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 Dsymbol syntaxCopy(Dsymbol)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 void semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 if (sem == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 sem = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 basetype = basetype.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 sem = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (sc.parent.isFuncDeclaration() && init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 storage_class |= sc.stc & STCdeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 else if (sem == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 error("circular definition");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 void semantic2(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (sem == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 sem = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 init = init.semantic(sc, basetype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 ExpInitializer ie = init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 if (ie)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 if (ie.exp.type == basetype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 ie.exp.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 string mangle()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 //printf("TypedefDeclaration::mangle() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 return Dsymbol.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 string kind()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 Type getType()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 return type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 Type htype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 Type hbasetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 void toDocBuffer(OutBuffer buf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 void toObjFile(int multiobj) // compile to .obj file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 //printf("TypedefDeclaration::toObjFile('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 toDebug();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 type.getTypeInfo(null); // generate TypeInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 TypeTypedef tc = cast(TypeTypedef)type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 if (type.isZeroInit(Loc(0)) || !tc.sym.init) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 } else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 SC scclass = SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 if (inTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 scclass = SCcomdat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 // Generate static initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 sinit.Sclass = scclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 sinit.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 version (ELFOBJ) { // Burton
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 sinit.Sseg = Segment.CDATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 version (MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 sinit.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 sinit.Sdt = tc.sym.init.toDt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 outdata(sinit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 void toDebug()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 int cvMember(ubyte* p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 TypedefDeclaration isTypedefDeclaration() { return this; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 Symbol* sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 Symbol* toInitializer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
180 }