Mercurial > projects > ddmd
annotate dmd/FileExp.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
72 | 1 module dmd.FileExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
163 | 5 import dmd.File; |
72 | 6 import dmd.UnaExp; |
163 | 7 import dmd.StringExp; |
8 import dmd.WANT; | |
9 import dmd.Global; | |
10 import dmd.FileName; | |
72 | 11 import dmd.OutBuffer; |
12 import dmd.Loc; | |
13 import dmd.Scope; | |
14 import dmd.HdrGenState; | |
15 import dmd.TOK; | |
16 | |
163 | 17 import core.stdc.stdio; |
18 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
19 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
20 |
0 | 21 class FileExp : UnaExp |
22 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 |
0 | 25 this(Loc loc, Expression e) |
26 { | |
178 | 27 register(); |
162 | 28 super(loc, TOKmixin, FileExp.sizeof, e); |
0 | 29 } |
30 | |
72 | 31 override Expression semantic(Scope sc) |
0 | 32 { |
163 | 33 StringExp se; |
34 | |
35 version (LOGSEMANTIC) { | |
36 printf("FileExp.semantic('%.*s')\n", toChars()); | |
37 } | |
38 UnaExp.semantic(sc); | |
39 e1 = resolveProperties(sc, e1); | |
40 e1 = e1.optimize(WANTvalue); | |
41 if (e1.op != TOKstring) | |
42 { | |
43 error("file name argument must be a string, not (%s)", e1.toChars()); | |
44 goto Lerror; | |
45 } | |
46 se = cast(StringExp)e1; | |
47 se = se.toUTF8(sc); | |
48 | |
49 string name = (cast(immutable(char)*)se.string_)[0..se.len]; | |
50 | |
51 if (!global.params.fileImppath) | |
52 { | |
53 error("need -Jpath switch to import text file %s", name); | |
54 goto Lerror; | |
55 } | |
56 | |
57 if (name != FileName.name(name)) | |
58 { | |
59 error("use -Jpath switch to provide path for filename %s", name); | |
60 goto Lerror; | |
61 } | |
62 | |
63 name = FileName.searchPath(global.filePath, name, 0); | |
64 if (!name) | |
65 { | |
66 error("file %s cannot be found, check -Jpath", se.toChars()); | |
67 goto Lerror; | |
68 } | |
69 | |
70 if (global.params.verbose) | |
71 printf("file %s\t(%s)\n", cast(char*)se.string_, name); | |
72 | |
73 { | |
74 scope File f = new File(name); | |
75 if (f.read()) | |
76 { | |
77 error("cannot read file %s", f.toChars()); | |
78 goto Lerror; | |
79 } | |
80 else | |
81 { | |
82 f.ref_ = 1; | |
83 se = new StringExp(loc, (cast(immutable(char)*)f.buffer)[0..f.len]); | |
84 } | |
85 } | |
86 Lret: | |
87 return se.semantic(sc); | |
88 | |
89 Lerror: | |
90 se = new StringExp(loc, ""); | |
91 goto Lret; | |
0 | 92 } |
93 | |
72 | 94 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 95 { |
96 assert(false); | |
97 } | |
98 } | |
99 |