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