annotate dmd/Module.d @ 192:eb38fdcb3e62 default tip

updated to compile with dmd2.062
author korDen
date Sat, 02 Mar 2013 01:25:52 -0800
parents b0d41ff5e0df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Package;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.StaticDtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Id;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
11 import dmd.SharedStaticCtorDeclaration;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
12 import dmd.SharedStaticDtorDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Import;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.ModuleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.File;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Identifier;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
18 import dmd.Json;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.ModuleInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Macro;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.Escape;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.FileName;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Parser;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.Cstate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.REG;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.backend.SFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.backend.TF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.backend.RTLSYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.targ_types;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.backend.glue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
60 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
61
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
65 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
66
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 uint readwordLE(ushort* p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 version (__I86__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 return *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 return ((cast(ubyte*)p)[1] << 8) | (cast(ubyte*)p)[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 uint readwordBE(ushort* p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 return ((cast(ubyte*)p)[0] << 8) | (cast(ubyte*)p)[1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 uint readlongLE(uint* p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 version (__I86__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 return (cast(ubyte*)p)[0] |
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 ((cast(ubyte*)p)[1] << 8) |
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 ((cast(ubyte*)p)[2] << 16) |
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 ((cast(ubyte*)p)[3] << 24);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 uint readlongBE(uint* p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 return (cast(ubyte*)p)[3] |
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 ((cast(ubyte*)p)[2] << 8) |
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 ((cast(ubyte*)p)[1] << 16) |
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 ((cast(ubyte*)p)[0] << 24);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 /* Segments */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 enum Segment {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 CODE = 1, /* code segment */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 DATA = 2, /* initialized data */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 CDATA = 3, /* constant data */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 UDATA = 4, /* uninitialized data */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 UNKNOWN = -1, /* unknown segment */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
110 struct seg_data
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 int SDseg; // omf file segment index
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 targ_size_t SDoffset; // starting offset for data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 bool isfarseg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 int seg; // segment number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 int lnameidx; // lname idx of segment name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 int classidx; // lname idx of class name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 uint attr; // segment attribute
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 targ_size_t origsize; // original size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 int seek; // seek position in output file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 extern (C) extern __gshared seg_data** SegData;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 ref targ_size_t Offset(Segment seg) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 return SegData[seg].SDoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 ref targ_size_t Doffset() {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 return SegData[Segment.DATA].SDoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 ref targ_size_t CDoffset() {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 return SegData[Segment.CDATA].SDoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 ref targ_size_t UDoffset() {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 return SegData[Segment.UDATA].SDoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 enum CF {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 CFes = 1, // generate an ES: segment override for this instr
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 CFjmp16 = 2, // need 16 bit jump offset (long branch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 CFtarg = 4, // this code is the target of a jump
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 CFseg = 8, // get segment of immediate value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 CFoff = 0x10, // get offset of immediate value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 CFss = 0x20, // generate an SS: segment override (not with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 // CFes at the same time, though!)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 CFpsw = 0x40, // we need the flags result after this instruction
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 CFopsize = 0x80, // prefix with operand size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 CFaddrsize = 0x100, // prefix with address size
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
153 CFds = 0x200, // need DS override (not with es, ss, or cs )
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 CFcs = 0x400, // need CS override
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 CFfs = 0x800, // need FS override
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 CFgs = (CFcs | CFfs), // need GS override
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 CFwait = 0x1000, // If I32 it indicates when to output a WAIT
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 CFselfrel = 0x2000, // if self-relative
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 CFunambig = 0x4000, // indicates cannot be accessed by other addressing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 // modes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 CFtarg2 = 0x8000, // like CFtarg, but we can't optimize this away
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 CFvolatile = 0x10000, // volatile reference, do not schedule
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 CFclassinit = 0x20000, // class init code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 CFSEG = (CFes | CFss | CFds | CFcs | CFfs | CFgs),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 CFPREFIX = (CFSEG | CFopsize | CFaddrsize),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 class Module : Package
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
171 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
172
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 string arg; // original argument name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 ModuleDeclaration md; // if !null, the contents of the ModuleDeclaration declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 File srcfile; // input source file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 File objfile; // output .obj file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 File hdrfile; // 'header' file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 File symfile; // output symbol file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 File docfile; // output documentation file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 uint errors; // if any errors in file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 uint numlines; // number of lines in source file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 int isHtml; // if it is an HTML file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 int isDocFile; // if it is a documentation input file, not D source
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 int needmoduleinfo; /// TODO: change to bool
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 int strictlyneedmoduleinfo;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 int selfimports; // 0: don't know, 1: does not, 2: does
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 int selfImports() // returns !=0 if module imports itself
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 int insearch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 Identifier searchCacheIdent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 Dsymbol searchCacheSymbol; // cached value of search
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 int searchCacheFlags; // cached flags
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 int semanticstarted; // has semantic() been started?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 int semanticRun; // has semantic() been done?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 int root; // != 0 if this is a 'root' module,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 // i.e. a module that will be taken all the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 // way to an object file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 Module importedFrom; // module from command line we're imported from,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 // i.e. a module that will be taken all the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 // way to an object file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 Array decldefs; // top level declarations for this Module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 Array aimports; // all imported modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 ModuleInfoDeclaration vmoduleinfo;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 uint debuglevel; // debug level
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 128
diff changeset
216 Vector!string debugids; // debug identifiers
010eb8f0e18d further work on dmd test suite
korDen
parents: 128
diff changeset
217 Vector!string debugidsNot; // forward referenced debug identifiers
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 uint versionlevel; // version level
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
220 Vector!(string) versionids; // version identifiers
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
221 Vector!(string) versionidsNot; // forward referenced version identifiers
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 Macro macrotable; // document comment macros
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 Escape escapetable; // document comment escapes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 bool safe; // TRUE if module is marked as 'safe'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 this(string filename, Identifier ident, int doDocComment, int doHdrGen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
229 register();
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
230
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 super(ident);
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
232
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
233 versionids = new Vector!string;
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
234 versionidsNot = new Vector!string;
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
235
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 FileName objfilename;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
237
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 aimports = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
240 //writefln("Module.Module(filename = '%s', ident = '%s')", filename, ident.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 this.arg = filename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 FileName srcfilename = FileName.defaultExt(filename, global.mars_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 if (!srcfilename.equalsExt(global.mars_ext) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 !srcfilename.equalsExt(global.hdr_ext) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 !srcfilename.equalsExt("dd"))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 if (srcfilename.equalsExt("html") ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 srcfilename.equalsExt("htm") ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 srcfilename.equalsExt("xhtml"))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 error("html source files is deprecated %s", srcfilename.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 isHtml = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 error("source file name '%s' must have .%s extension", srcfilename.toChars(), global.mars_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 string argobj;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (global.params.objname)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 argobj = global.params.objname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 else if (global.params.preservePaths)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 argobj = filename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 argobj = FileName.name(filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 if (!FileName.absolute(argobj))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 argobj = FileName.combine(global.params.objdir, argobj);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 if (global.params.objname)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 objfilename = new FileName(argobj);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 objfilename = FileName.forceExt(argobj, global.obj_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 FileName symfilename = FileName.forceExt(filename, global.sym_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
282 //writeln(srcfilename.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 srcfile = new File(srcfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 if (doDocComment) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 setDocfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 if (doHdrGen) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 setHdrfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 objfile = new File(objfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 symfile = new File(symfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 128
diff changeset
297 static Module load(Loc loc, Vector!Identifier packages, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 Module m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 string filename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 //writef("Module.load(ident = '%s')\n", ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 // Build module filename by turning:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 // foo.bar.baz
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 // into:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 // foo\bar\baz
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 filename = ident.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 if (packages && packages.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 128
diff changeset
311 scope OutBuffer buf = new OutBuffer();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
313 foreach (pid; packages)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
314 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 buf.writestring(pid.toChars());
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
316 version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
317 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 buf.writeByte('\\');
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
319 }
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
320 else
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
321 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 buf.writeByte('/');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 buf.writestring(filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 filename = buf.extractString();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 m = new Module(filename, ident, 0, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 m.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 /* Search along global.path for .di file, then .d file.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 string result = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 FileName fdi = FileName.forceExt(filename, global.hdr_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 FileName fd = FileName.forceExt(filename, global.mars_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 string sdi = fdi.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 string sd = fd.toChars();
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
339
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 if (FileName.exists(sdi)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 result = sdi;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 } else if (FileName.exists(sd)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 result = sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 } else if (FileName.absolute(filename)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 foreach (p; global.path)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 string n = FileName.combine(p, sdi);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 if (FileName.exists(n))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 result = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 n = FileName.combine(p, sd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 if (FileName.exists(n))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 result = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
368 if (result) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 m.srcfile = new File(result);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
370 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
374 write("import ");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 if (packages)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 {
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
377 foreach (pid; packages)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
378 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 writef("%s.", pid.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 writef("%s\t(%s)\n", ident.toChars(), m.srcfile.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 m.read(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 m.parse();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 d_gcc_magic_module(m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 29
diff changeset
395 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
399
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
400 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
401 {
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
402 buf.writestring("{\n");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
403
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
404 if (md)
acd69f84627e further work
Trass3r
parents: 81
diff changeset
405 JsonProperty(buf, Pname, md.toChars());
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
406
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
407 JsonProperty(buf, Pkind, kind());
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
408
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
409 JsonProperty(buf, Pfile, srcfile.toChars());
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
410
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
411 if (comment)
acd69f84627e further work
Trass3r
parents: 81
diff changeset
412 JsonProperty(buf, Pcomment, comment);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
413
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
414 JsonString(buf, Pmembers);
acd69f84627e further work
Trass3r
parents: 81
diff changeset
415 buf.writestring(" : [\n");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
416
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
417 size_t offset = buf.offset;
acd69f84627e further work
Trass3r
parents: 81
diff changeset
418 foreach (Dsymbol s; members)
acd69f84627e further work
Trass3r
parents: 81
diff changeset
419 {
acd69f84627e further work
Trass3r
parents: 81
diff changeset
420 if (offset != buf.offset)
acd69f84627e further work
Trass3r
parents: 81
diff changeset
421 {
acd69f84627e further work
Trass3r
parents: 81
diff changeset
422 buf.writestring(",\n");
acd69f84627e further work
Trass3r
parents: 81
diff changeset
423 offset = buf.offset;
acd69f84627e further work
Trass3r
parents: 81
diff changeset
424 }
acd69f84627e further work
Trass3r
parents: 81
diff changeset
425 s.toJsonBuffer(buf);
acd69f84627e further work
Trass3r
parents: 81
diff changeset
426 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
427
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
428 JsonRemoveComma(buf);
acd69f84627e further work
Trass3r
parents: 81
diff changeset
429 buf.writestring("]\n");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
430
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
431 buf.writestring("}\n");
acd69f84627e further work
Trass3r
parents: 81
diff changeset
432 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
433
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 29
diff changeset
434 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 return "module";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
438
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 void setDocfile() // set docfile member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
443
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 void read(Loc loc) // read file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
446 //writefln("Module.read('%s') file '%s'", toChars(), srcfile.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 if (srcfile.read())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 error(loc, "cannot read file '%s'", srcfile.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
453
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 void parse(bool dump_source = false) // syntactic parse
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 void parse() // syntactic parse
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 uint le;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 uint bom;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 //printf("Module.parse()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 string srcname = srcfile.name.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 //printf("Module.parse(srcname = '%s')\n", srcname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 ubyte* buf = srcfile.buffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 uint buflen = srcfile.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 if (buflen >= 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 /* Convert all non-UTF-8 formats to UTF-8.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 * BOM : http://www.unicode.org/faq/utf_bom.html
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 * 00 00 FE FF UTF-32BE, big-endian
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 * FF FE 00 00 UTF-32LE, little-endian
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 * FE FF UTF-16BE, big-endian
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 * FF FE UTF-16LE, little-endian
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 * EF BB BF UTF-8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 bom = 1; // assume there's a BOM
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 if (buf[0] == 0xFF && buf[1] == 0xFE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 if (buflen >= 4 && buf[2] == 0 && buf[3] == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 { // UTF-32LE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 le = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 Lutf32:
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
492 OutBuffer dbuf = new OutBuffer();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 uint* pu = cast(uint*)buf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 uint* pumax = &pu[buflen / 4];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 if (buflen & 3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 { error("odd length of UTF-32 char source %u", buflen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 dbuf.reserve(buflen / 4);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 for (pu += bom; pu < pumax; pu++)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
503 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 uint u = le ? readlongLE(pu) : readlongBE(pu);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 if (u & ~0x7F)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 if (u > 0x10FFFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 { error("UTF-32 value %08x greater than 0x10FFFF", u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 dbuf.writeUTF8(u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 dbuf.writeByte(u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 dbuf.writeByte(0); // add 0 as sentinel for scanner
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 buflen = dbuf.offset - 1; // don't include sentinel in count
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 buf = cast(ubyte*) dbuf.extractData();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
521 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 // UTF-16LE (X86)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 // Convert it to UTF-8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 le = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 Lutf16:
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
527 OutBuffer dbuf = new OutBuffer();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 ushort* pu = cast(ushort*)(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 ushort *pumax = &pu[buflen / 2];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 if (buflen & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 { error("odd length of UTF-16 char source %u", buflen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 dbuf.reserve(buflen / 2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 for (pu += bom; pu < pumax; pu++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 uint u = le ? readwordLE(pu) : readwordBE(pu);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 if (u & ~0x7F)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 if (u >= 0xD800 && u <= 0xDBFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 { uint u2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 if (++pu > pumax)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 { error("surrogate UTF-16 high value %04x at EOF", u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 u2 = le ? readwordLE(pu) : readwordBE(pu);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 if (u2 < 0xDC00 || u2 > 0xDFFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 { error("surrogate UTF-16 low value %04x out of range", u2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 u = (u - 0xD7C0) << 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 u |= (u2 - 0xDC00);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 else if (u >= 0xDC00 && u <= 0xDFFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 error("unpaired surrogate UTF-16 value %04x", u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 else if (u == 0xFFFE || u == 0xFFFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 error("illegal UTF-16 value %04x", u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 dbuf.writeUTF8(u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 dbuf.writeByte(u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 dbuf.writeByte(0); // add 0 as sentinel for scanner
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 buflen = dbuf.offset - 1; // don't include sentinel in count
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 buf = cast(ubyte*) dbuf.extractData();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 else if (buf[0] == 0xFE && buf[1] == 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 { // UTF-16BE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 le = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 goto Lutf16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 else if (buflen >= 4 && buf[0] == 0 && buf[1] == 0 && buf[2] == 0xFE && buf[3] == 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 { // UTF-32BE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 le = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 goto Lutf32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 else if (buflen >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 { // UTF-8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 buf += 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 buflen -= 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 /* There is no BOM. Make use of Arcane Jill's insight that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 * the first char of D source must be ASCII to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 * figure out the encoding.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 bom = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 if (buflen >= 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 { if (buf[1] == 0 && buf[2] == 0 && buf[3] == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 { // UTF-32LE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 le = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 goto Lutf32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 else if (buf[0] == 0 && buf[1] == 0 && buf[2] == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 { // UTF-32BE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 le = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 goto Lutf32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 if (buflen >= 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 if (buf[1] == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 { // UTF-16LE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 le = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 goto Lutf16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 else if (buf[0] == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 { // UTF-16BE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 le = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 goto Lutf16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 // It's UTF-8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 if (buf[0] >= 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 { error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 version (IN_GCC) {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
636 // dump utf-8 encoded source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 if (dump_source)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 { // %% srcname could contain a path ...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 d_gcc_dump_source(srcname, "utf-8", buf, buflen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 /* If it starts with the string "Ddoc", then it's a documentation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 * source file.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 if (buflen >= 4 && memcmp(buf, "Ddoc".ptr, 4) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
648 comment = cast(string) ((buf + 4)[0 .. buflen]);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 isDocFile = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 if (!docfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 setDocfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 if (isHtml)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 ///OutBuffer dbuf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 ///Html h = new Html(srcname, buf, buflen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 ///h.extractCode(dbuf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 ///buf = dbuf.data;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 ///buflen = dbuf.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
663 version (IN_GCC)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
664 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 // dump extracted source
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 ///if (dump_source)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 /// d_gcc_dump_source(srcname, "d.utf-8", buf, buflen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
671 auto p = new Parser(this, buf, buflen, docfile !is null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 p.nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 members = p.parseModule();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 md = p.md;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 numlines = p.loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 DsymbolTable dst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 if (md !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 this.ident = md.id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 this.safe = md.safe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 dst = super.resolve(md.packages, &this.parent, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
687 dst = global.modules;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 /* Check to see if module name is a valid identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 if (!Lexer.isValidIdentifier(this.ident.toChars()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 error("has non-identifier characters in filename, use module declaration instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
694
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 // Update global list of modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 if (!dst.insert(this))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 if (md)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 error(loc, "is in multiple packages %s", md.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 error(loc, "is in multiple defined");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
705 global.amodules.push(cast(void*)this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
710 override void importAll(Scope prevsc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
711 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
712 //writef("+Module.importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
713
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
714 if (scope_ !is null)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
715 return; // already done
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
716
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
717 /* Note that modules get their own scope, from scratch.
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
718 * This is so regardless of where in the syntax a module
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
719 * gets imported, it is unaffected by context.
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
720 * Ignore prevsc.
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
721 */
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
722 Scope sc = Scope.createGlobal(this); // create root scope
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
723
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
724 // Add import of "object" if this module isn't "object"
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
725 if (ident != Id.object)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
726 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
727 if (members.dim == 0 || members[0].ident != Id.object)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
728 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
729 Import im = new Import(Loc(), null, Id.object, null, 0);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
730 members.shift(im);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
731 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
732 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
733
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
734 if (!symtab)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
735 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
736 // Add all symbols into module's symbol table
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
737 symtab = new DsymbolTable();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
738 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
739 s.addMember(null, sc.scopesym, 1);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
740 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
741 // anything else should be run after addMember, so version/debug symbols are defined
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
742
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
743 /* Set scope for the symbols so that if we forward reference
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
744 * a symbol, it can possibly be resolved on the spot.
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
745 * If this works out well, it can be extended to all modules
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
746 * before any semantic() on any of them.
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
747 */
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
748 setScope(sc); // remember module scope for semantic
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
749 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
750 s.setScope(sc);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
751
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
752 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
753 s.importAll(sc);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
754
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
755 sc = sc.pop();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
756 sc.pop(); // 2 pops because Scope::createGlobal() created 2
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
757 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
758
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 void semantic() // semantic analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 if (semanticstarted)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 //printf("+Module.semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 semanticstarted = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 // Note that modules get their own scope, from scratch.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 // This is so regardless of where in the syntax a module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 // gets imported, it is unaffected by context.
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
770 Scope sc = scope_; // // see if already got one from importAll()
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
771 if (!sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
772 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
773 writef("test2\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
774 Scope.createGlobal(this); // create root scope
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
775 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
777 //writef("Module = %p, linkage = %d\n", sc.scopesym, sc.linkage);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
779 static if (false)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
780 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 // Add import of "object" if this module isn't "object"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 if (ident !is Id.object)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
784 auto im = new Import(Loc(0), null, Id.object, null, 0);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
785 members.shift(im);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 // Add all symbols into module's symbol table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 symtab = new DsymbolTable();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
790 foreach(s; members)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
791 {
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 5
diff changeset
792 s.addMember(null, sc.scopesym, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 /* Set scope for the symbols so that if we forward reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 * a symbol, it can possibly be resolved on the spot.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 * If this works out well, it can be extended to all modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 * before any semantic() on any of them.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 */
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
800 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 s.setScope(sc);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
802 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 // Pass 1 semantic routines: do public side of the definition
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
805 foreach (Dsymbol s; members)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
806 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 //writef("\tModule('%s'): '%s'.semantic()\n", toChars(), s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 runDeferredSemantic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
812 if (!scope_)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
813 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
814 sc = sc.pop();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
815 sc.pop(); // 2 pops because Scope.createGlobal() created 2
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
816 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 semanticRun = semanticstarted;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 //printf("-Module.semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
820
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 void semantic2() // pass 2 semantic analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
823 auto deferred = global.deferred;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 if (deferred.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 for (int i = 0; i < deferred.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 Dsymbol sd = cast(Dsymbol)deferred.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 sd.error("unable to resolve forward reference in definition");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 //printf("Module.semantic2('%s'): parent = %p\n", toChars(), parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 if (semanticstarted >= 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 assert(semanticstarted == 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 semanticstarted = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 // Note that modules get their own scope, from scratch.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 // This is so regardless of where in the syntax a module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 // gets imported, it is unaffected by context.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 Scope sc = Scope.createGlobal(this); // create root scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 //printf("Module = %p\n", sc.scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 // Pass 2 semantic routines: do initializers and function bodies
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
847 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 s.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 semanticRun = semanticstarted;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 //printf("-Module.semantic2('%s'): parent = %p\n", toChars(), parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
855
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 void semantic3() // pass 3 semantic analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 //printf("Module.semantic3('%s'): parent = %p\n", toChars(), parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 if (semanticstarted >= 3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 assert(semanticstarted == 2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 semanticstarted = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 // Note that modules get their own scope, from scratch.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 // This is so regardless of where in the syntax a module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 // gets imported, it is unaffected by context.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 Scope sc = Scope.createGlobal(this); // create root scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 //printf("Module = %p\n", sc.scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 // Pass 3 semantic routines: do initializers and function bodies
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
871 foreach(Dsymbol s; members)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
872 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 //printf("Module %s: %s.semantic3()\n", toChars(), s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 s.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 semanticRun = semanticstarted;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
881
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 29
diff changeset
882 override void inlineScan() // scan for functions to inline
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 if (semanticstarted >= 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 assert(semanticstarted == 3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 semanticstarted = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 // Note that modules get their own scope, from scratch.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 // This is so regardless of where in the syntax a module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 // gets imported, it is unaffected by context.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 //printf("Module = %p\n", sc.scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
895 foreach(Dsymbol s; members)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
896 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 //if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 //printf("inline scan symbol %s\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 s.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 semanticRun = semanticstarted;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
904
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 void setHdrfile() // set hdrfile member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 FileName hdrfilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 string arghdr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 if (global.params.hdrname)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 arghdr = global.params.hdrname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 else if (global.params.preservePaths)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 arghdr = arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 arghdr = FileName.name(arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 if (!FileName.absolute(arghdr))
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
917 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 //FileName.ensurePathExists(global.params.hdrdir);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 arghdr = FileName.combine(global.params.hdrdir, arghdr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 if (global.params.hdrname)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 hdrfilename = new FileName(arghdr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 hdrfilename = FileName.forceExt(arghdr, global.hdr_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 if (hdrfilename.str == srcfile.name.str)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
927 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 error("Source file and 'header' file have same name '%s'", srcfile.name.str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 hdrfile = new File(hdrfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
934
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 void genhdrfile() // generate D import file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
941
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 * Generate .obj file for Module.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 void genobjfile(int multiobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 //EEcontext *ee = env.getEEcontext();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 //printf("Module.genobjfile(multiobj = %d) %s\n", multiobj, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
951 auto lastmname = global.lastmname = srcfile.toChars();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 obj_initfile(toStringz(lastmname), null, toStringz(toPrettyChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
955 global.eictor = null;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
956 global.ictorlocalgot = null;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
957 global.ector = null;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
958 global.ectorgates.setDim(0);
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
959 global.edtor = null;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
960 global.esharedctor = null;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
961 global.esharedctorgates.setDim(0);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
962 global.eshareddtor = null;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
963 global.etest = null;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
964 global.dtorcount = 0;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
965 global.shareddtorcount = 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 if (doppelganger)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 /* Generate a reference to the moduleinfo, so the module constructors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 * and destructors get linked in.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 Module m = cast(Module)aimports.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 assert(m);
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
974 if (m.sictor || m.sctor || m.sdtor || m.ssharedctor || m.sshareddtor)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 Symbol* s = m.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 //objextern(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 //if (!s.Sxtrnnum) objextdef(s.Sident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 if (!s.Sxtrnnum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 //printf("%s\n", s.Sident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 /* This should work, but causes optlink to fail in common/newlib.asm */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 objextdef(s.Sident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 } else {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
986 version (ELFOBJ_OR_MACHOBJ) {///ELFOBJ || MACHOBJ
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
987 int nbytes = reftoident(Segment.DATA, Offset(Segment.DATA), s, 0, CF.CFoff);
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
988 Offset(Segment.DATA) += nbytes;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 int nbytes = reftoident(Segment.DATA, Doffset, s, 0, CF.CFoff);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 Doffset() += nbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 if (global.params.cov)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 /* Create coverage identifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 * private uint[numlines] __coverage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 cov = symbol_calloc("__coverage");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 cov.Stype = type_fake(TYM.TYint);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 cov.Stype.Tmangle = mTYman.mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 cov.Stype.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 cov.Sclass = SC.SCstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 cov.Sfl = FL.FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 version (ELFOBJ_OR_MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 cov.Sseg = Segment.UDATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 dtnzeros(&cov.Sdt, 4 * numlines);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 outdata(cov);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 slist_add(cov);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
1016 covb = cast(uint*)GC.calloc(((numlines + 32) / 32) * (*covb).sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1018
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
1019 foreach(Dsymbol member; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 member.toObjFile(multiobj);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1021
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 if (global.params.cov)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 /* Generate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 * bit[numlines] __bcoverage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 Symbol* bcov = symbol_calloc("__bcoverage");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 bcov.Stype = type_fake(TYM.TYuint);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 bcov.Stype.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 bcov.Sclass = SC.SCstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 bcov.Sfl = FL.FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 version (ELFOBJ_OR_MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 bcov.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 dtnbytes(&bcov.Sdt, (numlines + 32) / 32 * (*covb).sizeof, cast(char*)covb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 outdata(bcov);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1038 ///free(covb);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 covb = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 /* Generate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 * _d_cover_register(uint[] __coverage, BitArray __bcoverage, string filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 * and prepend it to the static constructor.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 /* t will be the type of the functions generated:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 * extern (C) void func();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 type* t = type_alloc(TYM.TYnfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 t.Tflags |= TF.TFprototype | TF.TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 t.Tmangle = mTYman.mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 t.Tnext = tsvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 tsvoid.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 sictor = toSymbolX("__modictor", SC.SCglobal, t, "FZv");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 cstate.CSpsymtab = &sictor.Sfunc.Flocsym;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1057 global.localgot = global.ictorlocalgot;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 e = el_params(el_ptr(cov), el_long(TYM.TYuint, numlines),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 el_ptr(bcov), el_long(TYM.TYuint, numlines),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 toEfilename(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 e = el_bin(OPER.OPcall, TYM.TYvoid, el_var(rtlsym[RTLSYM.RTLSYM_DCOVER]), e);
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1065 global.eictor = el_combine(e, global.eictor);
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1066 global.ictorlocalgot = global.localgot;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 // If coverage / static constructor / destructor / unittest calls
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1070 if (global.eictor || global.ector || global.ectorgates.dim || global.edtor || global.esharedctor || global.esharedctorgates.dim || global.eshareddtor || global.etest)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 /* t will be the type of the functions generated:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 * extern (C) void func();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 type* t = type_alloc(TYM.TYnfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 t.Tflags |= TF.TFprototype | TF.TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 t.Tmangle = mTYman.mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 t.Tnext = tsvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 tsvoid.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080
170
96c0fff6897d more global state cleanup
korDen
parents: 169
diff changeset
1081 enum moddeco = "FZv";
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1083 if (global.eictor)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1085 global.localgot = global.ictorlocalgot;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 block* b = block_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 b.BC = BC.BCret;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1089 b.Belem = global.eictor;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 sictor.Sfunc.Fstartblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 writefunc(sictor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1094 if (global.ector || global.ectorgates.dim)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1096 global.localgot = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 sctor = toSymbolX("__modctor", SC.SCglobal, t, moddeco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 cstate.CSpsymtab = &sctor.Sfunc.Flocsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1100 for (int i = 0; i < global.ectorgates.dim; i++)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1101 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1102 StaticDtorDeclaration f = cast(StaticDtorDeclaration)global.ectorgates.data[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 Symbol* s = f.vgate.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 elem* e = el_var(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 e = el_bin(OPER.OPaddass, TYM.TYint, e, el_long(TYM.TYint, 1));
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1107 global.ector = el_combine(global.ector, e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 block* b = block_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 b.BC = BC.BCret;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1112 b.Belem = global.ector;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 sctor.Sfunc.Fstartblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 writefunc(sctor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 version (STATICCTOR) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 obj_staticctor(sctor, dtorcount, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1120 if (global.edtor)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1122 global.localgot = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 sdtor = toSymbolX("__moddtor", SC.SCglobal, t, moddeco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 block* b = block_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 b.BC = BC.BCret;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1127 b.Belem = global.edtor;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 sdtor.Sfunc.Fstartblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 writefunc(sdtor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1131
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1132 if (global.esharedctor || global.esharedctorgates.dim)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1133 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1134 global.localgot = null;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1135 ssharedctor = toSymbolX("__modsharedctor", SCglobal, t, moddeco);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1136 cstate.CSpsymtab = &ssharedctor.Sfunc.Flocsym;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1137
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1138 for (int i = 0; i < global.esharedctorgates.dim; i++)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1139 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1140 SharedStaticDtorDeclaration f = cast(SharedStaticDtorDeclaration)global.esharedctorgates.data[i];
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1141
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1142 Symbol* s = f.vgate.toSymbol();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1143 elem* e = el_var(s);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1144 e = el_bin(OPaddass, TYint, e, el_long(TYint, 1));
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1145 global.esharedctor = el_combine(global.esharedctor, e);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1146 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1147
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1148 block* b = block_calloc();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1149 b.BC = BCret;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1150 b.Belem = global.esharedctor;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1151 ssharedctor.Sfunc.Fstartblock = b;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1152 writefunc(ssharedctor);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1153 version (STATICCTOR) {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1154 obj_staticctor(ssharedctor, shareddtorcount, 1);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1155 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1156 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1157
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1158 if (global.eshareddtor)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1159 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1160 global.localgot = null;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1161 sshareddtor = toSymbolX("__modshareddtor", SCglobal, t, moddeco);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1162
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1163 block *b = block_calloc();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1164 b.BC = BCret;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1165 b.Belem = global.eshareddtor;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1166 sshareddtor.Sfunc.Fstartblock = b;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1167 writefunc(sshareddtor);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1168 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1169
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1171 if (global.etest)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1173 global.localgot = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 stest = toSymbolX("__modtest", SC.SCglobal, t, moddeco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 block* b = block_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 b.BC = BC.BCret;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1178 b.Belem = global.etest;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 stest.Sfunc.Fstartblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 writefunc(stest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 if (doppelganger)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 genmoduleinfo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 if (doppelganger)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 obj_termfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 if (global.params.multiobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 { /* This is necessary because the main .obj for this module is written
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 * first, but determining whether marray or massert are needed is done
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 * possibly later in the doppelganger modules.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 * Another way to fix it is do the main one last.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 toModuleAssert();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 toModuleArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 // If module assert
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 for (int i = 0; i < 2; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 Symbol* ma = i ? marray : massert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 if (ma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 elem* elinnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 elem* efilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
1213 global.localgot = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 // Call dassert(filename, line)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 // Get sole parameter, linnum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 Symbol* sp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 sp = symbol_calloc("linnum".ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 sp.Stype = type_fake(TYM.TYint);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 sp.Stype.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 sp.Sclass = SC.SCfastpar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 sp.Spreg = REG.AX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 sp.Sflags &= ~SFL.SFLspill;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 sp.Sfl = FL.FLpara; // FLauto?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 cstate.CSpsymtab = &ma.Sfunc.Flocsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 symbol_add(sp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 elinnum = el_var(sp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 efilename = toEmodulename();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 elem *e = el_var(rtlsym[i ? RTLSYM.RTLSYM_DARRAY : RTLSYM.RTLSYM_DASSERT]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 e = el_bin(OPER.OPcall, TYM.TYvoid, e, el_param(elinnum, efilename));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 block* b = block_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 b.BC = BC.BCret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 b.Belem = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 ma.Sfunc.Fstartblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 ma.Sclass = SC.SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 ma.Sfl = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 writefunc(ma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1247
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 // Always generate module info, because of templates and -cov
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 if (1 || needModuleInfo())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 genmoduleinfo();
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
1253 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1254
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 obj_termfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1257
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 void gensymfile()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1262
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 void gendocfile()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1267
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 * Determine if we need to generate an instance of ModuleInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 * for this Module.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 bool needModuleInfo()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 {
96
acd69f84627e further work
Trass3r
parents: 81
diff changeset
1274 // writef("needModuleInfo() %s, %d, %d\n", toChars(), needmoduleinfo, global.params.cov);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 return needmoduleinfo || global.params.cov;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1277
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 29
diff changeset
1278 override Dsymbol search(Loc loc, Identifier ident, int flags)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 /* Since modules can be circularly referenced,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 * need to stop infinite recursive searches.
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1282 * This is done with the cache.
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 //printf("%s Module.search('%s', flags = %d) insearch = %d\n", toChars(), ident.toChars(), flags, insearch);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 if (insearch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 s = null;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1289 else if (searchCacheIdent == ident && searchCacheFlags == flags)
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1290 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 s = searchCacheSymbol;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1292 //printf("%s Module.search('%s', flags = %d) insearch = %d searchCacheSymbol = %s\n", toChars(), ident.toChars(), flags, insearch, searchCacheSymbol ? searchCacheSymbol.toChars() : "null");
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1293 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 insearch = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 s = ScopeDsymbol.search(loc, ident, flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 insearch = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 searchCacheIdent = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 searchCacheSymbol = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 searchCacheFlags = flags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1306
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 void deleteObjFile()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 if (global.params.obj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 objfile.remove();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 if (docfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 docfile.remove();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1315 override Dsymbol symtabInsert(Dsymbol s)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1316 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1317 searchCacheIdent = null; // symbol is inserted, so invalidate cache
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1318 return Package.symtabInsert(s);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1319 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1320
29
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1321 /*******************************************
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1322 * Can't run semantic on s now, try again later.
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1323 */
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1324 void addDeferredSemantic(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
1326 auto deferred = global.deferred;
29
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1327 // Don't add it if it is already there
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1328 for (int i = 0; i < deferred.dim; i++)
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1329 {
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1330 Dsymbol sd = cast(Dsymbol)deferred.data[i];
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1331
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1332 if (sd == s)
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1333 return;
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1334 }
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1335
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1336 //printf("Module::addDeferredSemantic('%s')\n", s.toChars());
29
9fe59705c82d Implemented Module.addDeferredSemantic, removed -release from the linux commands file.
Robert Clipsham <robert@octarineparrot.com>
parents: 23
diff changeset
1337 deferred.push(cast(void*)s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1339
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 * Run semantic() on deferred symbols.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1344 static void runDeferredSemantic()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 {
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1346 if (global.dprogress == 0)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1347 return;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1348
170
96c0fff6897d more global state cleanup
korDen
parents: 169
diff changeset
1349 if (global.nested)
96c0fff6897d more global state cleanup
korDen
parents: 169
diff changeset
1350 return;
96c0fff6897d more global state cleanup
korDen
parents: 169
diff changeset
1351 //if (deferred.dim) printf("+Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
96c0fff6897d more global state cleanup
korDen
parents: 169
diff changeset
1352 global.nested++;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1353
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
1354 auto deferred = global.deferred;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1355
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1356 size_t len;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
1359 global.dprogress = 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 len = deferred.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 if (!len)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 Dsymbol *todo;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 Dsymbol tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 if (len == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 todo = &tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 {
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1372 version(Bug4054)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1373 todo = cast(Dsymbol*)GC.malloc(len * (Dsymbol*).sizeof);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1374 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 todo = cast(Dsymbol*)alloca(len * (Dsymbol*).sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 assert(todo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 memcpy(todo, deferred.data, len * (Dsymbol*).sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 deferred.setDim(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 for (int i = 0; i < len; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 Dsymbol s = todo[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 s.semantic(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 //printf("deferred: %s, parent = %s\n", s.toChars(), s.parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388 //printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress);
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
1389 } while (deferred.dim < len || global.dprogress); // while making progress
170
96c0fff6897d more global state cleanup
korDen
parents: 169
diff changeset
1390 global.nested--;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 //printf("-Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 }
81
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1393
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1394 /************************************
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1395 * Recursively look at every module this module imports,
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1396 * return TRUE if it imports m.
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1397 * Can be used to detect circular imports.
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1398 */
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1399 bool imports(Module m)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 {
81
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1401 // writef("%s Module::imports(%s)\n", toChars(), m.toChars());
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1402 int aimports_dim = aimports.dim;
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1403 static if (false)
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1404 {
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1405 for (int i = 0; i < aimports.dim; i++)
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1406 { Module mi = cast(Module)aimports.data[i];
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1407 writef("\t[%d] %s\n", i, mi.toChars());
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1408 }
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1409 }
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1410 for (int i = 0; i < aimports.dim; i++)
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1411 { Module mi = cast(Module)aimports.data[i];
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1412 if (mi == m)
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1413 return true;
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1414 if (!mi.insearch)
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1415 {
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1416 mi.insearch = 1;
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1417 bool r = mi.imports(m);
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1418 if (r)
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1419 return r;
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1420 }
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1421 }
722df8e7509c * fixed win32_lib
Trass3r
parents: 79
diff changeset
1422 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 int doppelganger; // sub-module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 Symbol* cov; // private uint[] __coverage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 uint* covb; // bit array of valid code line numbers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 Symbol* sictor; // module order independent constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 Symbol* sctor; // module constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 Symbol* sdtor; // module destructor
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1434 Symbol* ssharedctor; // module shared constructor
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1435 Symbol* sshareddtor; // module shared destructor
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 Symbol* stest; // module unit test
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 Symbol* sfilename; // symbol for filename
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 Symbol* massert; // module assert function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441 Symbol* toModuleAssert() // get module assert function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 if (!massert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 t = type_alloc(TYjfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 t.Tflags |= TFprototype | TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 t.Tmangle = mTYman_d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 t.Tnext = tsvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 tsvoid.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 massert = toSymbolX("__assert", SCextern, t, "FiZv");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 massert.Sfl = FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 massert.Sflags |= SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456 slist_add(massert);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458 return massert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 Symbol* marray; // module array bounds function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 Symbol* toModuleArray() // get module array bounds function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 if (!marray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 t = type_alloc(TYjfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 t.Tflags |= TFprototype | TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 t.Tmangle = mTYman_d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 t.Tnext = tsvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 tsvoid.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 marray = toSymbolX("__array", SCextern, t, "Z");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 marray.Sfl = FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 marray.Sflags |= SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 slist_add(marray);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 return marray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 static Symbol* gencritsec()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1487
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 elem* toEfilename()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 elem* efilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 if (!sfilename)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 dt_t* dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 string id = srcfile.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 int len = id.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 dtdword(&dt, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 dtabytes(&dt,TYnptr, 0, len + 1, toStringz(id));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501 sfilename = symbol_generate(SCstatic,type_fake(TYdarray));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 sfilename.Sdt = dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 sfilename.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 version (ELFOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 sfilename.Sseg = Segment.CDATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 version (MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 // Because of PIC and CDATA being in the _TEXT segment, cannot
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 // have pointers in CDATA
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 sfilename.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 outdata(sfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 efilename = el_var(sfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 return efilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1518
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 * Generate elem that is a pointer to the module file name.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 elem* toEmodulename()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524 elem *efilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 // Get filename
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 if (needModuleInfo())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1528 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 /* Class ModuleInfo is defined in std.moduleinfo.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 * The first member is the name of it, char name[],
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 * which will be at offset 8.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 Symbol* si = toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 // Use this instead so -fPIC will work
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 efilename = el_ptr(si);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538 efilename = el_bin(OPadd, TYnptr, efilename, el_long(TYuint, 8));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 efilename = el_una(OPind, TYdarray, efilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 efilename = el_var(si);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 efilename.Ety = TYdarray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 efilename.EV.sp.Voffset += 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 else // generate our own filename
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 efilename = toEfilename();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 return efilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 * Create the "ModuleInfo" symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 */
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 29
diff changeset
1556 override Symbol* toSymbol()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 if (!csym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561
170
96c0fff6897d more global state cleanup
korDen
parents: 169
diff changeset
1562 s = toSymbolX("__ModuleInfo", SC.SCextern, global.scc.Stype, "Z");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563 s.Sfl = FL.FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 s.Sflags |= SFL.SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 csym = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568 return csym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 // Put out instance of ModuleInfo for this Module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572 void genmoduleinfo()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 //printf("Module.genmoduleinfo() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 Symbol* msym = toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 //dumpSymbol(msym);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1579
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 uint offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 version (DMDV2) {
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1582 uint sizeof_ModuleInfo = 16 * PTRSIZE;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1583 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1584 uint sizeof_ModuleInfo = 14 * PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1585 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1586
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1587 version (MODULEINFO_IS_STRUCT) {} else {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1588 sizeof_ModuleInfo -= 2 * PTRSIZE;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1589 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1590 //printf("moduleinfo size = x%x\n", sizeof_ModuleInfo);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1591
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1592 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1593
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1594 csym.Sclass = SC.SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1595
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1596 csym.Sfl = FL.FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1598 /* The layout is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1599 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1600 void **vptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1601 monitor_t monitor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1602 char[] name; // class name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1603 ModuleInfo importedModules[];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1604 ClassInfo localClasses[];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1605 uint flags; // initialization state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606 void *ctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 void *dtor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608 void *unitTest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610 void *ictor;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1611 void *sharedctor;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1612 void *shareddtor;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1613 uint index;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1614 void*[1] reserved;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617 dt_t* dt = null;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1618 version (MODULEINFO_IS_STRUCT) {} else {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
1619 if (global.moduleinfo)
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 129
diff changeset
1620 dtxoff(&dt, global.moduleinfo.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for ModuleInfo
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1622 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 //printf("moduleinfo is null\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 dtdword(&dt, 0); // BUG: should be an assert()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626 dtdword(&dt, 0); // monitor
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1627 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 // name[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1629 string name = toPrettyChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 size_t namelen = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631 dtdword(&dt, namelen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632 dtabytes(&dt, TYM.TYnptr, 0, namelen + 1, toStringz(name));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634 ClassDeclarations aclasses = new ClassDeclarations();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1635
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1636 //printf("members.dim = %d\n", members.dim);
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
1637 foreach(Dsymbol member; members)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1638 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 //printf("\tmember '%s'\n", member.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640 member.addLocalClass(aclasses);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 // importedModules[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 int aimports_dim = aimports.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 for (int i = 0; i < aimports.dim; i++)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1646 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1647 Module m = cast(Module)aimports.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1648 if (!m.needModuleInfo())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1649 aimports_dim--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1650 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652 dtdword(&dt, aimports_dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653 if (aimports_dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1654 dtxoff(&dt, csym, sizeof_ModuleInfo, TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1655 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1656 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1657
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 // localClasses[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 dtdword(&dt, aclasses.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1660 if (aclasses.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1661 dtxoff(&dt, csym, sizeof_ModuleInfo + aimports_dim * PTRSIZE, TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1662 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1663 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1664
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1665 if (needmoduleinfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1666 dtdword(&dt, 8|0); // flags (4 means MIstandalone)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1667 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1668 dtdword(&dt, 8|4); // flags (4 means MIstandalone)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1669
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1670 if (ssharedctor)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1671 dtxoff(&dt, ssharedctor, 0, TYnptr);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1672 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1673 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1674
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1675 if (sshareddtor)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1676 dtxoff(&dt, sshareddtor, 0, TYnptr);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1677 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1678 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1679
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1680 if (stest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1681 dtxoff(&dt, stest, 0, TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1682 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1683 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1684
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1685 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1686 FuncDeclaration sgetmembers = findGetMembers();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1687 if (sgetmembers)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1688 dtxoff(&dt, sgetmembers.toSymbol(), 0, TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1689 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1690 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1691 dtdword(&dt, 0); // xgetMembers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1692
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1693 if (sictor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1694 dtxoff(&dt, sictor, 0, TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1695 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1696 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1698 version (DMDV2) {
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1699 if (sctor)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1700 dtxoff(&dt, sctor, 0, TYnptr);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1701 else
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1702 dtdword(&dt, 0);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1703
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1704 if (sdtor)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1705 dtxoff(&dt, sdtor, 0, TYnptr);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1706 else
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1707 dtdword(&dt, 0);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1708
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1709 dtdword(&dt, 0); // index
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1710
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1711 // void*[1] reserved;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1712 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1713 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1714 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1715
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1716 for (int i = 0; i < aimports.dim; i++)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1717 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1718 Module m = cast(Module)aimports.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1719
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1720 if (m.needModuleInfo())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 170
diff changeset
1721 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1722 Symbol* s = m.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1723
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1724 /* Weak references don't pull objects in from the library,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1725 * they resolve to 0 if not pulled in by something else.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1726 * Don't pull in a module just because it was imported.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1727 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1728 version (OMFOBJ) {// Optlink crashes with weak symbols at EIP 41AFE7, 402000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1729 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1730 s.Sflags |= SFL.SFLweak;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1731 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1732 dtxoff(&dt, s, 0, TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1733 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1735
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1736 foreach (cd; aclasses)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 dtxoff(&dt, cd.toSymbol(), 0, TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1740
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1741 csym.Sdt = dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1742 version (ELFOBJ_OR_MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1743 // Cannot be CONST because the startup code sets flag bits in it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1744 csym.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1745 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1746
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1747 outdata(csym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1748
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1749 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1750
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1751 obj_moduleinfo(msym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1752 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1753
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 29
diff changeset
1754 override Module isModule() { return this; }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1755 }