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