annotate dmd/DeclarationExp.d @ 79:43073c7c7769

updated to 2.035 also implemented a few missing functions still crashes in Import.importAll though
author Trass3r
date Mon, 30 Aug 2010 03:57:51 +0200
parents ad4792a1cfd6
children e28b18c23469
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1 module dmd.DeclarationExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
4 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.ExpInitializer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.Loc;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
9 import dmd.STC;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
10 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
11 import dmd.InlineCostState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
12 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
13 import dmd.InlineDoState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
14 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
15 import dmd.TupleDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
16 import dmd.InlineScanState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
17 import dmd.Dsymbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
18 import dmd.AttribDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
19 import dmd.VarDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
20 import dmd.Global;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
21 import dmd.TOK;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
22 import dmd.VoidInitializer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
23 import dmd.GlobalExpressions;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
24 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
25 import dmd.codegen.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
26
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
27 // Declaration of a symbol
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
28
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 class DeclarationExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 Dsymbol declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 this(Loc loc, Dsymbol declaration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
35 super(loc, TOK.TOKdeclaration, DeclarationExp.sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this.declaration = declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
39 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 return new DeclarationExp(loc, declaration.syntaxCopy(null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
44 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
46 if (type)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
47 return this;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
48
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
49 version (LOGSEMANTIC) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
50 printf("DeclarationExp.semantic() %s\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
51 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
52
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
53 /* This is here to support extern(linkage) declaration,
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
54 * where the extern(linkage) winds up being an AttribDeclaration
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
55 * wrapper.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
56 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
57 Dsymbol s = declaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
58
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
59 AttribDeclaration ad = declaration.isAttribDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
60 if (ad)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
61 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
62 if (ad.decl && ad.decl.dim == 1)
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
63 s = ad.decl[0];
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
64 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
65
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
66 if (s.isVarDeclaration())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
67 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
68 // Do semantic() on initializer first, so:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
69 // int a = a;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
70 // will be illegal.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
71 declaration.semantic(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
72 s.parent = sc.parent;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
73 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
74
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
75 //printf("inserting '%s' %p into sc = %p\n", s.toChars(), s, sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
76 // Insert into both local scope and function scope.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
77 // Must be unique in both.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
78 if (s.ident)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
79 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
80 if (!sc.insert(s))
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
81 error("declaration %s is already defined", s.toPrettyChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
82 else if (sc.func)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
83 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
84 VarDeclaration v = s.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
85 if (s.isFuncDeclaration() && !sc.func.localsymtab.insert(s))
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
86 error("declaration %s is already defined in another scope in %s", s.toPrettyChars(), sc.func.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
87 else if (!global.params.useDeprecated)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
88 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
89 // Disallow shadowing
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
90
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
91 for (Scope scx = sc.enclosing; scx && scx.func is sc.func; scx = scx.enclosing)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
92 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
93 Dsymbol s2;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
94
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
95 if (scx.scopesym && scx.scopesym.symtab && (s2 = scx.scopesym.symtab.lookup(s.ident)) !is null && s !is s2)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
96 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
97 error("shadowing declaration %s is deprecated", s.toPrettyChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
98 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
99 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
100 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
101 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
102 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
103 if (!s.isVarDeclaration())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
104 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
105 Scope sc2 = sc;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
106 if (sc2.stc & (STC.STCpure | STC.STCnothrow))
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
107 sc2 = sc.push();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
108 sc2.stc &= ~(STC.STCpure | STC.STCnothrow);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
109 declaration.semantic(sc2);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
110 if (sc2 != sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
111 sc2.pop();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
112
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
113 s.parent = sc.parent;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
114 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
115 if (!global.errors)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
116 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
117 declaration.semantic2(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
118 if (!global.errors)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
119 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
120 declaration.semantic3(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
121
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
122 if (!global.errors && global.params.useInline)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
123 declaration.inlineScan();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
124 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
125 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
126
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
127 type = Type.tvoid;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
131 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
133 version (LOG) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
134 printf("DeclarationExp.interpret() %s\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
135 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
136 Expression e;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
137 VarDeclaration v = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
138 if (v)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
139 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
140 Dsymbol s = v.toAlias();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
141 if (s == v && !v.isStatic() && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
142 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
143 ExpInitializer ie = v.init.isExpInitializer();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
144 if (ie)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
145 e = ie.exp.interpret(istate);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
146 else if (v.init.isVoidInitializer())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
147 e = null;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
148 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
149 ///version (DMDV2) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
150 else if (s == v && (v.isConst() || v.isInvariant()) && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
151 ///} else {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
152 /// else if (s == v && v.isConst() && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
153 ///}
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
154 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
155 e = v.init.toExpression();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
156 if (!e)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
157 e = EXP_CANT_INTERPRET;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
158 else if (!e.type)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
159 e.type = v.type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
160 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
161 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
162 else if (declaration.isAttribDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
163 declaration.isTemplateMixin() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
164 declaration.isTupleDeclaration())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
165 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
166 // These can be made to work, too lazy now
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
167 error("Declaration %s is not yet implemented in CTFE", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
168
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
169 e = EXP_CANT_INTERPRET;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
170 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
171 else
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
172 { // Others should not contain executable code, so are trivial to evaluate
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
173 e = null;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
174 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
175 version (LOG) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
176 printf("-DeclarationExp.interpret(%.*s): %p\n", toChars(), e);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
177 }
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
178 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
181 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
186 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 declaration.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
191 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
193 //printf("DeclarationExp::toElem() %s\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
194 elem* e = Dsymbol_toElem(declaration, irs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
198 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
202
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
204 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
206 VarDeclaration v = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
207 if (v && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
208 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
209 ExpInitializer ie = v.init.isExpInitializer();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
210 return ie && ie.exp.canThrow();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
211 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
212
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
216 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
218 int cost = 0;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
219 VarDeclaration vd;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
220
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
221 //printf("DeclarationExp.inlineCost()\n");
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
222 vd = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
223 if (vd)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
224 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
225 TupleDeclaration td = vd.toAlias().isTupleDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
226 if (td)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
227 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
228 static if (true) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
229 return COST_MAX; // finish DeclarationExp.doInline
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
230 } else {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
231 for (size_t i = 0; i < td.objects.dim; i++)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
232 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
233 Object o = cast(Object)td.objects.data[i];
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
234 Expression eo = cast(Expression)o;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
235 if (eo is null)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
236 return COST_MAX;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
237
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
238 if (eo.op != TOKdsymbol)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
239 return COST_MAX;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
240 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
241
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
242 return td.objects.dim;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
243 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
244 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
245 if (!ics.hdrscan && vd.isDataseg())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
246 return COST_MAX;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
247
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
248 cost += 1;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
249
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
250 // Scan initializer (vd.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
251 if (vd.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
252 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
253 ExpInitializer ie = vd.init.isExpInitializer();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
254
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
255 if (ie)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
256 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
257 cost += ie.exp.inlineCost(ics);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
258 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
259 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
260 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
261
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
262 // These can contain functions, which when copied, get output twice.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
263 if (declaration.isStructDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
264 declaration.isClassDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
265 declaration.isFuncDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
266 declaration.isTypedefDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
267 declaration.isTemplateMixin()
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
268 )
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
269 return COST_MAX;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
270
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
271 //printf("DeclarationExp.inlineCost('%s')\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 return cost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
275 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
277 DeclarationExp de = cast(DeclarationExp)copy();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
278 VarDeclaration vd;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
279
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
280 //printf("DeclarationExp.doInline(%s)\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
281 vd = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
282 if (vd)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
283 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
284 static if (false) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
285 // Need to figure this out before inlining can work for tuples
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
286 TupleDeclaration td = vd.toAlias().isTupleDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
287 if (td)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
288 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
289 for (size_t i = 0; i < td.objects.dim; i++)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
290 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
291 DsymbolExp se = cast(DsymbolExp)td.objects.data[i];
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
292 assert(se.op == TOKdsymbol);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
293 se.s;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
294 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
295 return st.objects.dim;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
296 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
297 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
298 if (vd.isStatic())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
299 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
300 ;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
301 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
302 else
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
303 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
304 VarDeclaration vto = new VarDeclaration(vd.loc, vd.type, vd.ident, vd.init);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
305
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
306 ///*vto = *vd;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
307 memcpy(cast(void*)vto, cast(void*)vd, VarDeclaration.classinfo.init.length);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
308
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
309 vto.parent = ids.parent;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
310 vto.csym = null;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
311 vto.isym = null;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
312
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
313 ids.from.push(cast(void*)vd);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
314 ids.to.push(cast(void*)vto);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
315
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
316 if (vd.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
317 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
318 if (vd.init.isVoidInitializer())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
319 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
320 vto.init = new VoidInitializer(vd.init.loc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
321 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
322 else
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
323 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
324 Expression e = vd.init.toExpression();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
325 assert(e);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
326 vto.init = new ExpInitializer(e.loc, e.doInline(ids));
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
327 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
328 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
329 de.declaration = vto;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
330 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
331 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
332 /* This needs work, like DeclarationExp.toElem(), if we are
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
333 * to handle TemplateMixin's. For now, we just don't inline them.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
334 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 return de;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
338 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
340 //printf("DeclarationExp.inlineScan()\n");
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
341 scanVar(declaration, iss);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345