annotate dmd/DeclarationExp.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 cab4c37afb89
children ad4792a1cfd6
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;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
9 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
10 import dmd.InlineCostState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
11 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
12 import dmd.InlineDoState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
13 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
14 import dmd.TupleDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
15 import dmd.InlineScanState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
16 import dmd.Dsymbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
17 import dmd.AttribDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
18 import dmd.VarDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
19 import dmd.Global;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
20 import dmd.TOK;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
21 import dmd.VoidInitializer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
22 import dmd.GlobalExpressions;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
23 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
24 import dmd.codegen.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
25
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
26 // Declaration of a symbol
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
27
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 class DeclarationExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 Dsymbol declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this(Loc loc, Dsymbol declaration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
34 super(loc, TOK.TOKdeclaration, DeclarationExp.sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.declaration = declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
38 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 return new DeclarationExp(loc, declaration.syntaxCopy(null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
43 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
45 if (type)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
46 return this;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
47
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
48 version (LOGSEMANTIC) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
49 printf("DeclarationExp.semantic() %s\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
50 }
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 /* This is here to support extern(linkage) declaration,
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
53 * where the extern(linkage) winds up being an AttribDeclaration
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
54 * wrapper.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
55 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
56 Dsymbol s = declaration;
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 AttribDeclaration ad = declaration.isAttribDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
59 if (ad)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
60 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
61 if (ad.decl && ad.decl.dim == 1)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
62 s = cast(Dsymbol)ad.decl.data[0];
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
63 }
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 if (s.isVarDeclaration())
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 // Do semantic() on initializer first, so:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
68 // int a = a;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
69 // will be illegal.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
70 declaration.semantic(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
71 s.parent = sc.parent;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
72 }
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 //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
75 // Insert into both local scope and function scope.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
76 // Must be unique in both.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
77 if (s.ident)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
78 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
79 if (!sc.insert(s))
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
80 error("declaration %s is already defined", s.toPrettyChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
81 else if (sc.func)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
82 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
83 VarDeclaration v = s.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
84 if (s.isFuncDeclaration() && !sc.func.localsymtab.insert(s))
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
85 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
86 else if (!global.params.useDeprecated)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
87 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
88 // Disallow shadowing
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 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
91 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
92 Dsymbol s2;
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 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
95 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
96 error("shadowing declaration %s is deprecated", s.toPrettyChars());
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 }
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 if (!s.isVarDeclaration())
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 declaration.semantic(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
105 s.parent = sc.parent;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
106 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
107 if (!global.errors)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
108 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
109 declaration.semantic2(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
110 if (!global.errors)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
111 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
112 declaration.semantic3(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
113
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
114 if (!global.errors && global.params.useInline)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
115 declaration.inlineScan();
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 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
118
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
119 type = Type.tvoid;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
123 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
125 version (LOG) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
126 printf("DeclarationExp.interpret() %s\n", toChars());
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 Expression e;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
129 VarDeclaration v = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
130 if (v)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
131 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
132 Dsymbol s = v.toAlias();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
133 if (s == v && !v.isStatic() && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
134 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
135 ExpInitializer ie = v.init.isExpInitializer();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
136 if (ie)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
137 e = ie.exp.interpret(istate);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
138 else if (v.init.isVoidInitializer())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
139 e = null;
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 ///version (DMDV2) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
142 else if (s == v && (v.isConst() || v.isInvariant()) && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
143 ///} else {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
144 /// else if (s == v && v.isConst() && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
145 ///}
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
146 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
147 e = v.init.toExpression();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
148 if (!e)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
149 e = EXP_CANT_INTERPRET;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
150 else if (!e.type)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
151 e.type = v.type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
152 }
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 else if (declaration.isAttribDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
155 declaration.isTemplateMixin() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
156 declaration.isTupleDeclaration())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
157 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
158 // These can be made to work, too lazy now
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
159 error("Declaration %s is not yet implemented in CTFE", toChars());
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 e = EXP_CANT_INTERPRET;
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
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
164 { // 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
165 e = null;
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 version (LOG) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
168 printf("-DeclarationExp.interpret(%.*s): %p\n", toChars(), e);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
169 }
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
170 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
173 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
178 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 declaration.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
183 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
185 //printf("DeclarationExp::toElem() %s\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
186 elem* e = Dsymbol_toElem(declaration, irs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
190 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
194
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
196 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
198 VarDeclaration v = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
199 if (v && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
200 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
201 ExpInitializer ie = v.init.isExpInitializer();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
202 return ie && ie.exp.canThrow();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
203 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
204
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
208 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
210 int cost = 0;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
211 VarDeclaration vd;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
212
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
213 //printf("DeclarationExp.inlineCost()\n");
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
214 vd = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
215 if (vd)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
216 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
217 TupleDeclaration td = vd.toAlias().isTupleDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
218 if (td)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
219 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
220 static if (true) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
221 return COST_MAX; // finish DeclarationExp.doInline
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
222 } else {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
223 for (size_t i = 0; i < td.objects.dim; i++)
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 Object o = cast(Object)td.objects.data[i];
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
226 Expression eo = cast(Expression)o;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
227 if (eo is null)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
228 return COST_MAX;
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 if (eo.op != TOKdsymbol)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
231 return COST_MAX;
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
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
234 return td.objects.dim;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
235 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
236 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
237 if (!ics.hdrscan && vd.isDataseg())
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 cost += 1;
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 // Scan initializer (vd.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
243 if (vd.init)
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 ExpInitializer ie = vd.init.isExpInitializer();
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 (ie)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
248 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
249 cost += ie.exp.inlineCost(ics);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
250 }
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 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
253
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
254 // These can contain functions, which when copied, get output twice.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
255 if (declaration.isStructDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
256 declaration.isClassDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
257 declaration.isFuncDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
258 declaration.isTypedefDeclaration() ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
259 declaration.isTemplateMixin()
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 return COST_MAX;
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 //printf("DeclarationExp.inlineCost('%s')\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 return cost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
267 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
269 DeclarationExp de = cast(DeclarationExp)copy();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
270 VarDeclaration vd;
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 //printf("DeclarationExp.doInline(%s)\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
273 vd = declaration.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
274 if (vd)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
275 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
276 static if (false) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
277 // 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
278 TupleDeclaration td = vd.toAlias().isTupleDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
279 if (td)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
280 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
281 for (size_t i = 0; i < td.objects.dim; i++)
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 DsymbolExp se = cast(DsymbolExp)td.objects.data[i];
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
284 assert(se.op == TOKdsymbol);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
285 se.s;
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 return st.objects.dim;
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 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
290 if (vd.isStatic())
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 ;
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 else
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
295 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
296 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
297
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
298 ///*vto = *vd;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
299 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
300
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
301 vto.parent = ids.parent;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
302 vto.csym = null;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
303 vto.isym = null;
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 ids.from.push(cast(void*)vd);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
306 ids.to.push(cast(void*)vto);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
307
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
308 if (vd.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
309 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
310 if (vd.init.isVoidInitializer())
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.init = new VoidInitializer(vd.init.loc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
313 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
314 else
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 Expression e = vd.init.toExpression();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
317 assert(e);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
318 vto.init = new ExpInitializer(e.loc, e.doInline(ids));
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 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
321 de.declaration = vto;
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 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
324 /* This needs work, like DeclarationExp.toElem(), if we are
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
325 * 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
326 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 return de;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
330 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
332 //printf("DeclarationExp.inlineScan()\n");
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
333 scanVar(declaration, iss);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337