annotate dmd/DeclarationExp.d @ 135:af1bebfd96a4 dmd2037

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