annotate dmd/ConditionalStatement.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children c77e9f4f1793
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.ConditionalStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 class ConditionalStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 Condition condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 Statement ifbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 Statement elsebody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 this(Loc loc, Condition condition, Statement ifbody, Statement elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 this.condition = condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 this.ifbody = ifbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 this.elsebody = elsebody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
27 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
29 Statement e = null;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
30 if (elsebody)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
31 e = elsebody.syntaxCopy();
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
32 ConditionalStatement s = new ConditionalStatement(loc, condition.syntaxCopy(), ifbody.syntaxCopy(), e);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
33 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
36 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
64
4290d870944a More fixes
korDen
parents: 49
diff changeset
38 //printf("ConditionalStatement.semantic()\n");
4290d870944a More fixes
korDen
parents: 49
diff changeset
39
4290d870944a More fixes
korDen
parents: 49
diff changeset
40 // If we can short-circuit evaluate the if statement, don't do the
4290d870944a More fixes
korDen
parents: 49
diff changeset
41 // semantic analysis of the skipped code.
4290d870944a More fixes
korDen
parents: 49
diff changeset
42 // This feature allows a limited form of conditional compilation.
4290d870944a More fixes
korDen
parents: 49
diff changeset
43 if (condition.include(sc, null))
4290d870944a More fixes
korDen
parents: 49
diff changeset
44 {
4290d870944a More fixes
korDen
parents: 49
diff changeset
45 ifbody = ifbody.semantic(sc);
4290d870944a More fixes
korDen
parents: 49
diff changeset
46 return ifbody;
4290d870944a More fixes
korDen
parents: 49
diff changeset
47 }
4290d870944a More fixes
korDen
parents: 49
diff changeset
48 else
4290d870944a More fixes
korDen
parents: 49
diff changeset
49 {
4290d870944a More fixes
korDen
parents: 49
diff changeset
50 if (elsebody)
4290d870944a More fixes
korDen
parents: 49
diff changeset
51 elsebody = elsebody.semantic(sc);
4290d870944a More fixes
korDen
parents: 49
diff changeset
52 return elsebody;
4290d870944a More fixes
korDen
parents: 49
diff changeset
53 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
56 override Statements flatten(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 if (condition.include(sc, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 s = ifbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 s = elsebody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 Statements a = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 a.push(cast(void*)s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
71 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
76 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
81 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
85 }