72
|
1 module dmd.CompileExp;
|
|
2
|
114
|
3 import dmd.common;
|
72
|
4 import dmd.Expression;
|
|
5 import dmd.UnaExp;
|
|
6 import dmd.OutBuffer;
|
|
7 import dmd.Loc;
|
|
8 import dmd.Scope;
|
|
9 import dmd.HdrGenState;
|
|
10 import dmd.TOK;
|
|
11 import dmd.PREC;
|
|
12 import dmd.WANT;
|
|
13 import dmd.StringExp;
|
|
14 import dmd.Type;
|
|
15 import dmd.Parser;
|
|
16
|
|
17 import dmd.expression.Util;
|
|
18
|
|
19 class CompileExp : UnaExp
|
|
20 {
|
|
21 this(Loc loc, Expression e)
|
|
22 {
|
|
23 super(loc, TOK.TOKmixin, this.sizeof, e);
|
|
24 }
|
|
25
|
|
26 override Expression semantic(Scope sc)
|
|
27 {
|
|
28 version (LOGSEMANTIC) {
|
|
29 printf("CompileExp.semantic('%s')\n", toChars());
|
|
30 }
|
|
31 UnaExp.semantic(sc);
|
|
32 e1 = resolveProperties(sc, e1);
|
|
33 e1 = e1.optimize(WANT.WANTvalue | WANT.WANTinterpret);
|
|
34 if (e1.op != TOK.TOKstring)
|
|
35 { error("argument to mixin must be a string, not (%s)", e1.toChars());
|
|
36 type = Type.terror;
|
|
37 return this;
|
|
38 }
|
|
39 StringExp se = cast(StringExp)e1;
|
|
40 se = se.toUTF8(sc);
|
|
41 Parser p = new Parser(sc.module_, cast(ubyte*)se.string_, se.len, 0);
|
|
42 p.loc = loc;
|
|
43 p.nextToken();
|
|
44 //printf("p.loc.linnum = %d\n", p.loc.linnum);
|
|
45 Expression e = p.parseExpression();
|
|
46 if (p.token.value != TOK.TOKeof)
|
|
47 error("incomplete mixin expression (%s)", se.toChars());
|
|
48 return e.semantic(sc);
|
|
49 }
|
|
50
|
|
51 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
52 {
|
|
53 buf.writestring("mixin(");
|
|
54 expToCBuffer(buf, hgs, e1, PREC.PREC_assign);
|
|
55 buf.writeByte(')');
|
|
56 }
|
|
57 }
|