Mercurial > projects > ddmd
annotate dmd/PragmaStatement.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 |
rev | line source |
---|---|
0 | 1 module dmd.PragmaStatement; |
2 | |
114 | 3 import dmd.common; |
97 | 4 import dmd.expression.Util; |
0 | 5 import dmd.Statement; |
97 | 6 import dmd.StringExp; |
7 import dmd.Id; | |
0 | 8 import dmd.Identifier; |
97 | 9 import dmd.Dsymbol; |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
10 import dmd.Expression; |
0 | 11 import dmd.Loc; |
12 import dmd.Identifier; | |
13 import dmd.Scope; | |
14 import dmd.OutBuffer; | |
15 import dmd.HdrGenState; | |
16 import dmd.IRState; | |
17 import dmd.BE; | |
97 | 18 import dmd.TOK; |
19 import dmd.WANT; | |
0 | 20 |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
21 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
|
22 |
0 | 23 class PragmaStatement : Statement |
24 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 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
|
26 |
97 | 27 Identifier ident; |
28 Expressions args; // array of Expression's | |
29 Statement body_; | |
0 | 30 |
97 | 31 this(Loc loc, Identifier ident, Expressions args, Statement body_) |
0 | 32 { |
178 | 33 register(); |
0 | 34 super(loc); |
97 | 35 this.ident = ident; |
36 this.args = args; | |
37 this.body_ = body_; | |
0 | 38 } |
39 | |
97 | 40 override Statement syntaxCopy() |
0 | 41 { |
97 | 42 Statement b = null; |
43 if (body_) | |
44 b = body_.syntaxCopy(); | |
45 PragmaStatement s = new PragmaStatement(loc, | |
46 ident, Expression.arraySyntaxCopy(args), b); | |
47 return s; | |
48 | |
0 | 49 } |
50 | |
97 | 51 override Statement semantic(Scope sc) |
0 | 52 { |
97 | 53 // Should be merged with PragmaDeclaration |
54 //writef("PragmaStatement.semantic() %s\n", toChars()); | |
55 //writef("body = %p\n", body_); | |
56 if (ident == Id.msg) | |
57 { | |
58 if (args) | |
59 { | |
60 foreach (Expression e; args) | |
61 { | |
62 e = e.semantic(sc); | |
63 e = e.optimize(WANTvalue | WANTinterpret); | |
64 if (e.op == TOK.TOKstring) | |
65 { | |
66 StringExp se = cast(StringExp)e; | |
67 writef("%.*s", se.len, cast(char*)se.string_); | |
68 } | |
69 else | |
70 writef(e.toChars()); | |
71 } | |
72 writef("\n"); | |
73 } | |
74 } | |
75 else if (ident == Id.lib) | |
76 { | |
77 static if (true) | |
78 { | |
79 /* Should this be allowed? | |
80 */ | |
81 error("pragma(lib) not allowed as statement"); | |
82 } | |
83 else | |
84 { | |
85 if (!args || args.dim != 1) | |
86 error("string expected for library name"); | |
87 else | |
88 { | |
89 Expression e = args[0]; | |
0 | 90 |
97 | 91 e = e.semantic(sc); |
92 e = e.optimize(WANTvalue | WANTinterpret); | |
93 args[0] = e; | |
94 if (e.op != TOKstring) | |
95 error("string expected for library name, not '%s'", e.toChars()); | |
96 else if (global.params.verbose) | |
97 { | |
98 StringExp se = cast(StringExp)e; | |
99 writef("library %.*s\n", se.len, se.string_); | |
100 } | |
101 } | |
102 } | |
103 } | |
104 //version(DMDV2) // TODO: | |
105 //{ | |
106 else if (ident == Id.startaddress) | |
107 { | |
108 if (!args || args.dim != 1) | |
109 error("function name expected for start address"); | |
110 else | |
111 { | |
112 Expression e = args[0]; | |
113 e = e.semantic(sc); | |
114 e = e.optimize(WANTvalue | WANTinterpret); | |
115 args[0] = e; | |
116 Dsymbol sa = getDsymbol(e); | |
117 if (!sa || !sa.isFuncDeclaration()) | |
118 error("function name expected for start address, not '%s'", e.toChars()); | |
119 if (body_) | |
120 { | |
121 body_ = body_.semantic(sc); | |
122 } | |
123 return this; | |
124 } | |
125 } | |
126 //} | |
127 else | |
128 error("unrecognized pragma(%s)", ident.toChars()); | |
129 | |
130 if (body_) | |
131 { | |
132 body_ = body_.semantic(sc); | |
133 } | |
134 return body_; | |
0 | 135 } |
136 | |
97 | 137 override bool usesEH() |
138 { | |
139 return body_ && body_.usesEH(); | |
140 } | |
141 | |
142 override BE blockExit() | |
0 | 143 { |
97 | 144 BE result = BEfallthru; |
145 static if (false) // currently, no code is generated for Pragma's, so it's just fallthru | |
146 { | |
147 if (arrayExpressionCanThrow(args)) | |
148 result |= BEthrow; | |
149 if (body_) | |
150 result |= body_.blockExit(); | |
151 } | |
152 return result; | |
0 | 153 } |
154 | |
97 | 155 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 156 { |
97 | 157 buf.writestring("pragma ("); |
158 buf.writestring(ident.toChars()); | |
159 if (args && args.dim) | |
160 { | |
161 buf.writestring(", "); | |
162 argsToCBuffer(buf, args, hgs); | |
163 } | |
164 buf.writeByte(')'); | |
165 if (body_) | |
166 { | |
167 buf.writenl(); | |
168 buf.writeByte('{'); | |
169 buf.writenl(); | |
170 | |
171 body_.toCBuffer(buf, hgs); | |
172 | |
173 buf.writeByte('}'); | |
174 buf.writenl(); | |
175 } | |
176 else | |
177 { | |
178 buf.writeByte(';'); | |
179 buf.writenl(); | |
180 } | |
181 | |
0 | 182 } |
183 | |
97 | 184 override void toIR(IRState* irs) |
0 | 185 { |
186 assert(false); | |
187 } | |
72 | 188 } |