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