Mercurial > projects > ddmd
annotate dmd/CompileDeclaration.d @ 72:2e2a5c3f943a
reduced warnings by adding override to the methods
think this also normalizes different line endings used all over the place
author | Trass3r |
---|---|
date | Sat, 28 Aug 2010 16:19:48 +0200 |
parents | 460959608115 |
children | e28b18c23469 |
rev | line source |
---|---|
0 | 1 module dmd.CompileDeclaration; |
2 | |
3 import dmd.AttribDeclaration; | |
13 | 4 import dmd.WANT; |
5 import dmd.TOK; | |
6 import dmd.StringExp; | |
7 import dmd.Parser; | |
0 | 8 import dmd.Expression; |
9 import dmd.ScopeDsymbol; | |
10 import dmd.Dsymbol; | |
11 import dmd.Loc; | |
12 import dmd.Scope; | |
13 import dmd.OutBuffer; | |
14 import dmd.HdrGenState; | |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
15 import dmd.TOK; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
16 import dmd.WANT; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
17 import dmd.StringExp; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
18 import dmd.Parser; |
0 | 19 |
20 // Mixin declarations | |
21 | |
22 class CompileDeclaration : AttribDeclaration | |
23 { | |
24 Expression exp; | |
13 | 25 ScopeDsymbol sd; |
26 bool compiled; | |
0 | 27 |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
28 this(Loc loc, Expression exp) |
0 | 29 { |
30 super(null); | |
13 | 31 //printf("CompileDeclaration(loc = %d)\n", loc.linnum); |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
32 this.loc = loc; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
33 this.exp = exp; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
34 this.sd = null; |
13 | 35 this.compiled = false; |
0 | 36 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
37 |
72 | 38 override Dsymbol syntaxCopy(Dsymbol s) |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
39 { |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
40 //printf("CompileDeclaration.syntaxCopy('%s')\n", toChars()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
41 CompileDeclaration sc = new CompileDeclaration(loc, exp.syntaxCopy()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
42 return sc; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
43 } |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
44 |
72 | 45 override bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) |
0 | 46 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
47 //printf("CompileDeclaration.addMember(sc = %p, memnum = %d)\n", sc, memnum); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
48 bool m = false; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
49 this.sd = sd; |
13 | 50 if (!memnum) |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
51 { /* No members yet, so parse the mixin now |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
52 */ |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
53 compileIt(sc); |
13 | 54 memnum = AttribDeclaration.addMember(sc, sd, memnum); |
55 compiled = true; | |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
56 } |
13 | 57 return memnum; |
0 | 58 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
59 |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
60 void compileIt(Scope sc) |
0 | 61 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
62 //printf("CompileDeclaration.compileIt(loc = %d)\n", loc.linnum); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
63 exp = exp.semantic(sc); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
64 exp = resolveProperties(sc, exp); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
65 exp = exp.optimize(WANT.WANTvalue | WANT.WANTinterpret); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
66 if (exp.op != TOK.TOKstring) |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
67 { exp.error("argument to mixin must be a string, not (%s)", exp.toChars()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
68 } |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
69 else |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
70 { |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
71 StringExp se = cast(StringExp)exp; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
72 se = se.toUTF8(sc); |
13 | 73 scope Parser p = new Parser(sc.module_, cast(ubyte*)se.string_, se.len, 0); |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
74 p.loc = loc; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
75 p.nextToken(); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
76 decl = p.parseDeclDefs(0); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
77 if (p.token.value != TOK.TOKeof) |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
78 exp.error("incomplete mixin declaration (%s)", se.toChars()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
79 } |
0 | 80 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
81 |
72 | 82 override void semantic(Scope sc) |
0 | 83 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
84 //printf("CompileDeclaration.semantic()\n"); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
85 |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
86 if (!compiled) |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
87 { |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
88 compileIt(sc); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
89 AttribDeclaration.addMember(sc, sd, 0); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
90 compiled = 1; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
91 } |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
92 AttribDeclaration.semantic(sc); |
0 | 93 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
94 |
72 | 95 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 96 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
97 buf.writestring("mixin("); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
98 exp.toCBuffer(buf, hgs); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
99 buf.writestring(");"); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
100 buf.writenl(); |
0 | 101 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
102 } |