1
|
1
|
|
2 // Compiler implementation of the D programming language
|
|
3 // Copyright (c) 1999-2007 by Digital Mars
|
|
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 INIT_H
|
|
12 #define INIT_H
|
|
13
|
|
14 #include "root.h"
|
|
15
|
|
16 #include "mars.h"
|
|
17 #include "arraytypes.h"
|
|
18
|
|
19 struct Identifier;
|
|
20 struct Expression;
|
|
21 struct Scope;
|
|
22 struct Type;
|
|
23 struct dt_t;
|
|
24 struct AggregateDeclaration;
|
|
25 struct VoidInitializer;
|
|
26 struct ArrayInitializer;
|
|
27 struct ExpInitializer;
|
|
28 struct StructInitializer;
|
|
29 #ifdef _DH
|
|
30 struct HdrGenState;
|
|
31 #endif
|
|
32
|
|
33 struct Initializer : Object
|
|
34 {
|
|
35 Loc loc;
|
|
36
|
|
37 Initializer(Loc loc);
|
|
38 virtual Initializer *syntaxCopy();
|
|
39 virtual Initializer *semantic(Scope *sc, Type *t);
|
|
40 virtual Type *inferType(Scope *sc);
|
|
41 virtual Expression *toExpression() = 0;
|
|
42 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0;
|
|
43 char *toChars();
|
|
44
|
|
45 static Initializers *arraySyntaxCopy(Initializers *ai);
|
|
46
|
|
47 virtual dt_t *toDt();
|
|
48
|
|
49 virtual VoidInitializer *isVoidInitializer() { return NULL; }
|
|
50 virtual ArrayInitializer *isArrayInitializer() { return NULL; }
|
|
51 virtual ExpInitializer *isExpInitializer() { return NULL; }
|
|
52 virtual StructInitializer *isStructInitializer() { return NULL; }
|
|
53 };
|
|
54
|
|
55 struct VoidInitializer : Initializer
|
|
56 {
|
|
57 Type *type; // type that this will initialize to
|
|
58
|
|
59 VoidInitializer(Loc loc);
|
|
60 Initializer *syntaxCopy();
|
|
61 Initializer *semantic(Scope *sc, Type *t);
|
|
62 Expression *toExpression();
|
|
63 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
64
|
|
65 dt_t *toDt();
|
|
66
|
|
67 virtual VoidInitializer *isVoidInitializer() { return this; }
|
|
68 };
|
|
69
|
|
70 struct StructInitializer : Initializer
|
|
71 {
|
|
72 Identifiers field; // of Identifier *'s
|
|
73 Initializers value; // parallel array of Initializer *'s
|
|
74
|
|
75 Array vars; // parallel array of VarDeclaration *'s
|
|
76 AggregateDeclaration *ad; // which aggregate this is for
|
|
77
|
|
78 StructInitializer(Loc loc);
|
|
79 Initializer *syntaxCopy();
|
|
80 void addInit(Identifier *field, Initializer *value);
|
|
81 Initializer *semantic(Scope *sc, Type *t);
|
|
82 Expression *toExpression();
|
|
83 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
84
|
|
85 dt_t *toDt();
|
|
86
|
|
87 virtual StructInitializer *isStructInitializer() { return this; }
|
|
88 };
|
|
89
|
|
90 struct ArrayInitializer : Initializer
|
|
91 {
|
|
92 Expressions index; // indices
|
|
93 Initializers value; // of Initializer *'s
|
|
94 unsigned dim; // length of array being initialized
|
|
95 Type *type; // type that array will be used to initialize
|
|
96 int sem; // !=0 if semantic() is run
|
|
97
|
|
98 ArrayInitializer(Loc loc);
|
|
99 Initializer *syntaxCopy();
|
|
100 void addInit(Expression *index, Initializer *value);
|
|
101 Initializer *semantic(Scope *sc, Type *t);
|
|
102 Type *inferType(Scope *sc);
|
|
103 Expression *toExpression();
|
|
104 Initializer *toAssocArrayInitializer();
|
|
105 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
106
|
|
107 dt_t *toDt();
|
|
108 dt_t *toDtBit(); // for bit arrays
|
|
109
|
|
110 ArrayInitializer *isArrayInitializer() { return this; }
|
|
111 };
|
|
112
|
|
113 struct ExpInitializer : Initializer
|
|
114 {
|
|
115 Expression *exp;
|
|
116
|
|
117 ExpInitializer(Loc loc, Expression *exp);
|
|
118 Initializer *syntaxCopy();
|
|
119 Initializer *semantic(Scope *sc, Type *t);
|
|
120 Type *inferType(Scope *sc);
|
|
121 Expression *toExpression();
|
|
122 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
123
|
|
124 dt_t *toDt();
|
|
125
|
|
126 virtual ExpInitializer *isExpInitializer() { return this; }
|
|
127 };
|
|
128
|
|
129 #endif
|