Mercurial > projects > ldc
annotate dmd/parse.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 | 8026319762be |
children | a413ae7329bf |
rev | line source |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
336
diff
changeset
|
3 // Copyright (c) 1999-2009 by Digital Mars |
1 | 4 // All Rights Reserved |
5 // written by Walter Bright | |
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 #ifndef DMD_PARSE_H | |
12 #define DMD_PARSE_H | |
13 | |
14 #ifdef __DMC__ | |
15 #pragma once | |
16 #endif /* __DMC__ */ | |
17 | |
18 #include "arraytypes.h" | |
19 #include "lexer.h" | |
20 #include "enum.h" | |
21 | |
22 struct Type; | |
336 | 23 struct TypeQualified; |
1 | 24 struct Expression; |
25 struct Declaration; | |
26 struct Statement; | |
27 struct Import; | |
28 struct Initializer; | |
29 struct FuncDeclaration; | |
30 struct CtorDeclaration; | |
336 | 31 struct PostBlitDeclaration; |
1 | 32 struct DtorDeclaration; |
33 struct StaticCtorDeclaration; | |
34 struct StaticDtorDeclaration; | |
35 struct ConditionalDeclaration; | |
36 struct InvariantDeclaration; | |
37 struct UnitTestDeclaration; | |
38 struct NewDeclaration; | |
39 struct DeleteDeclaration; | |
40 struct Condition; | |
41 struct Module; | |
42 struct ModuleDeclaration; | |
43 struct TemplateDeclaration; | |
44 struct TemplateInstance; | |
45 struct StaticAssert; | |
46 | |
47 /************************************ | |
48 * These control how parseStatement() works. | |
49 */ | |
50 | |
51 enum ParseStatementFlags | |
52 { | |
53 PSsemi = 1, // empty ';' statements are allowed | |
54 PSscope = 2, // start a new scope | |
55 PScurly = 4, // { } statement is required | |
56 PScurlyscope = 8, // { } starts a new scope | |
57 }; | |
58 | |
59 | |
60 struct Parser : Lexer | |
61 { | |
62 ModuleDeclaration *md; | |
63 enum LINK linkage; | |
64 Loc endloc; // set to location of last right curly | |
65 int inBrackets; // inside [] of array index or slice | |
66 | |
67 Parser(Module *module, unsigned char *base, unsigned length, int doDocComment); | |
68 | |
69 Array *parseModule(); | |
70 Array *parseDeclDefs(int once); | |
71 Array *parseBlock(); | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1195
diff
changeset
|
72 void composeStorageClass(unsigned stc); |
1 | 73 TemplateDeclaration *parseTemplateDeclaration(); |
74 TemplateParameters *parseTemplateParameterList(); | |
75 Dsymbol *parseMixin(); | |
76 Objects *parseTemplateArgumentList(); | |
77 StaticAssert *parseStaticAssert(); | |
78 enum LINK parseLinkage(); | |
79 Condition *parseDebugCondition(); | |
80 Condition *parseVersionCondition(); | |
81 Condition *parseStaticIfCondition(); | |
82 CtorDeclaration *parseCtor(); | |
83 DtorDeclaration *parseDtor(); | |
84 StaticCtorDeclaration *parseStaticCtor(); | |
85 StaticDtorDeclaration *parseStaticDtor(); | |
86 InvariantDeclaration *parseInvariant(); | |
87 UnitTestDeclaration *parseUnitTest(); | |
88 NewDeclaration *parseNew(); | |
89 DeleteDeclaration *parseDelete(); | |
90 Arguments *parseParameters(int *pvarargs); | |
91 EnumDeclaration *parseEnum(); | |
92 Dsymbol *parseAggregate(); | |
93 BaseClasses *parseBaseClasses(); | |
94 Import *parseImport(Array *decldefs, int isstatic); | |
95 Type *parseBasicType(); | |
96 Type *parseBasicType2(Type *t); | |
97 Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL); | |
98 Array *parseDeclarations(); | |
99 void parseContracts(FuncDeclaration *f); | |
100 Statement *parseStatement(int flags); | |
101 Initializer *parseInitializer(); | |
102 void check(Loc loc, enum TOK value); | |
103 void check(enum TOK value); | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
336
diff
changeset
|
104 void check(enum TOK value, const char *string); |
1 | 105 int isDeclaration(Token *t, int needId, enum TOK endtok, Token **pt); |
106 int isBasicType(Token **pt); | |
107 int isDeclarator(Token **pt, int *haveId, enum TOK endtok); | |
108 int isParameters(Token **pt); | |
109 int isExpression(Token **pt); | |
110 int isTemplateInstance(Token *t, Token **pt); | |
111 int skipParens(Token *t, Token **pt); | |
112 | |
113 Expression *parseExpression(); | |
114 Expression *parsePrimaryExp(); | |
115 Expression *parseUnaryExp(); | |
116 Expression *parsePostExp(Expression *e); | |
117 Expression *parseMulExp(); | |
118 Expression *parseAddExp(); | |
119 Expression *parseShiftExp(); | |
120 Expression *parseRelExp(); | |
121 Expression *parseEqualExp(); | |
122 Expression *parseCmpExp(); | |
123 Expression *parseAndExp(); | |
124 Expression *parseXorExp(); | |
125 Expression *parseOrExp(); | |
126 Expression *parseAndAndExp(); | |
127 Expression *parseOrOrExp(); | |
128 Expression *parseCondExp(); | |
129 Expression *parseAssignExp(); | |
130 | |
131 Expressions *parseArguments(); | |
132 | |
133 Expression *parseNewExp(Expression *thisexp); | |
134 | |
135 void addComment(Dsymbol *s, unsigned char *blockComment); | |
136 }; | |
137 | |
138 #endif /* DMD_PARSE_H */ |