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