Mercurial > projects > ldc
annotate dmd/hdrgen.h @ 1499:df11cdec45a2
Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324.
The idea is to separate the notion of const from 'this variable can always be
replaced with its initializer' in the frontend. To do that, I introduced
Declaration::isSameAsInitializer, which is overridden in VarDeclaration to
return false for constants that have a struct literal initializer.
So
{{{
const S s = S(5);
void foo() { auto ps = &s; }
// is no longer replaced by
void foo() { auto ps = &(S(5)); }
}}}
To make taking the address of a struct constant with a struct-initializer
outside of function scope possible, I made sure that AddrExp::optimize doesn't
try to run the argument's optimization with WANTinterpret - that'd again
replace the constant with a struct literal temporary.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 14 Jun 2009 19:49:58 +0200 |
parents | c53b6e3fe49a |
children |
rev | line source |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2006 by Digital Mars | |
4 // All Rights Reserved | |
5 // initial header generation implementation by Dave Fladebo | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 | |
12 struct HdrGenState | |
13 { | |
14 int hdrgen; // 1 if generating header file | |
15 int ddoc; // 1 if generating Ddoc file | |
16 int console; // 1 if writing to console | |
17 int tpltMember; | |
18 int inCallExp; | |
19 int inPtrExp; | |
20 int inSlcExp; | |
21 int inDotExp; | |
22 int inBinExp; | |
23 int inArrExp; | |
24 int emitInst; | |
25 struct | |
26 { | |
27 int init; | |
28 int decl; | |
29 } FLinit; | |
30 | |
31 HdrGenState() { memset(this, 0, sizeof(HdrGenState)); } | |
32 }; | |
33 | |
34 |