2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2007 by Digital Mars
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.
17 #include "arraytypes.h"
24 struct AggregateDeclaration
;
25 struct VoidInitializer
;
26 struct StructInitializer
;
27 struct ArrayInitializer
;
28 struct ExpInitializer
;
33 struct Initializer
: Object
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;
45 static Initializers
*arraySyntaxCopy(Initializers
*ai
);
49 virtual VoidInitializer
*isVoidInitializer() { return NULL
; }
50 virtual StructInitializer
*isStructInitializer() { return NULL
; }
51 virtual ArrayInitializer
*isArrayInitializer() { return NULL
; }
52 virtual ExpInitializer
*isExpInitializer() { return NULL
; }
55 struct VoidInitializer
: Initializer
57 Type
*type
; // type that this will initialize to
59 VoidInitializer(Loc loc
);
60 Initializer
*syntaxCopy();
61 Initializer
*semantic(Scope
*sc
, Type
*t
);
62 Expression
*toExpression();
63 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
67 virtual VoidInitializer
*isVoidInitializer() { return this; }
70 struct StructInitializer
: Initializer
72 Identifiers field
; // of Identifier *'s
73 Initializers value
; // parallel array of Initializer *'s
75 Array vars
; // parallel array of VarDeclaration *'s
76 AggregateDeclaration
*ad
; // which aggregate this is for
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
);
87 StructInitializer
*isStructInitializer() { return this; }
90 struct ArrayInitializer
: Initializer
92 Expressions index
; // indices
93 Initializers value
; // of Initializer *'s
94 target_size_t 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
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
);
108 dt_t
*toDtBit(); // for bit arrays
110 ArrayInitializer
*isArrayInitializer() { return this; }
113 struct ExpInitializer
: Initializer
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
);
126 virtual ExpInitializer
*isExpInitializer() { return this; }