| 1 |
// Compiler implementation of the D programming language |
|---|
| 2 |
// Copyright (c) 1999-2007 by Digital Mars |
|---|
| 3 |
// All Rights Reserved |
|---|
| 4 |
// written by Walter Bright |
|---|
| 5 |
// http://www.digitalmars.com |
|---|
| 6 |
// License for redistribution is by either the Artistic License |
|---|
| 7 |
// in artistic.txt, or the GNU General Public License in gnu.txt. |
|---|
| 8 |
// See the included readme.txt for details. |
|---|
| 9 |
|
|---|
| 10 |
#ifndef INIT_H |
|---|
| 11 |
#define INIT_H |
|---|
| 12 |
|
|---|
| 13 |
#include "root.h" |
|---|
| 14 |
|
|---|
| 15 |
#include "mars.h" |
|---|
| 16 |
#include "arraytypes.h" |
|---|
| 17 |
|
|---|
| 18 |
struct Identifier; |
|---|
| 19 |
struct Expression; |
|---|
| 20 |
struct Scope; |
|---|
| 21 |
struct Type; |
|---|
| 22 |
struct dt_t; |
|---|
| 23 |
struct AggregateDeclaration; |
|---|
| 24 |
struct VoidInitializer; |
|---|
| 25 |
struct StructInitializer; |
|---|
| 26 |
struct ArrayInitializer; |
|---|
| 27 |
struct ExpInitializer; |
|---|
| 28 |
#ifdef _DH |
|---|
| 29 |
struct HdrGenState; |
|---|
| 30 |
#endif |
|---|
| 31 |
|
|---|
| 32 |
struct Initializer : Object |
|---|
| 33 |
{ |
|---|
| 34 |
Loc loc; |
|---|
| 35 |
|
|---|
| 36 |
Initializer(Loc loc); |
|---|
| 37 |
virtual Initializer *syntaxCopy(); |
|---|
| 38 |
virtual Initializer *semantic(Scope *sc, Type *t); |
|---|
| 39 |
virtual Type *inferType(Scope *sc); |
|---|
| 40 |
virtual Expression *toExpression() = 0; |
|---|
| 41 |
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; |
|---|
| 42 |
char *toChars(); |
|---|
| 43 |
|
|---|
| 44 |
static Initializers *arraySyntaxCopy(Initializers *ai); |
|---|
| 45 |
|
|---|
| 46 |
virtual dt_t *toDt(); |
|---|
| 47 |
|
|---|
| 48 |
virtual VoidInitializer *isVoidInitializer() { return NULL; } |
|---|
| 49 |
virtual StructInitializer *isStructInitializer() { return NULL; } |
|---|
| 50 |
virtual ArrayInitializer *isArrayInitializer() { return NULL; } |
|---|
| 51 |
virtual ExpInitializer *isExpInitializer() { return NULL; } |
|---|
| 52 |
}; |
|---|
| 53 |
|
|---|
| 54 |
struct VoidInitializer : Initializer |
|---|
| 55 |
{ |
|---|
| 56 |
Type *type; // type that this will initialize to |
|---|
| 57 |
|
|---|
| 58 |
VoidInitializer(Loc loc); |
|---|
| 59 |
Initializer *syntaxCopy(); |
|---|
| 60 |
Initializer *semantic(Scope *sc, Type *t); |
|---|
| 61 |
Expression *toExpression(); |
|---|
| 62 |
void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| 63 |
|
|---|
| 64 |
dt_t *toDt(); |
|---|
| 65 |
|
|---|
| 66 |
virtual VoidInitializer *isVoidInitializer() { return this; } |
|---|
| 67 |
}; |
|---|
| 68 |
|
|---|
| 69 |
struct StructInitializer : Initializer |
|---|
| 70 |
{ |
|---|
| 71 |
Identifiers field; // of Identifier *'s |
|---|
| 72 |
Initializers value; // parallel array of Initializer *'s |
|---|
| 73 |
|
|---|
| 74 |
Array vars; // parallel array of VarDeclaration *'s |
|---|
| 75 |
AggregateDeclaration *ad; // which aggregate this is for |
|---|
| 76 |
|
|---|
| 77 |
StructInitializer(Loc loc); |
|---|
| 78 |
Initializer *syntaxCopy(); |
|---|
| 79 |
void addInit(Identifier *field, Initializer *value); |
|---|
| 80 |
Initializer *semantic(Scope *sc, Type *t); |
|---|
| 81 |
Expression *toExpression(); |
|---|
| 82 |
void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| 83 |
|
|---|
| 84 |
dt_t *toDt(); |
|---|
| 85 |
|
|---|
| 86 |
StructInitializer *isStructInitializer() { return this; } |
|---|
| 87 |
}; |
|---|
| 88 |
|
|---|
| 89 |
struct ArrayInitializer : Initializer |
|---|
| 90 |
{ |
|---|
| 91 |
Expressions index; // indices |
|---|
| 92 |
Initializers value; // of Initializer *'s |
|---|
| 93 |
unsigned dim; // length of array being initialized |
|---|
| 94 |
Type *type; // type that array will be used to initialize |
|---|
| 95 |
int sem; // !=0 if semantic() is run |
|---|
| 96 |
|
|---|
| 97 |
ArrayInitializer(Loc loc); |
|---|
| 98 |
Initializer *syntaxCopy(); |
|---|
| 99 |
void addInit(Expression *index, Initializer *value); |
|---|
| 100 |
Initializer *semantic(Scope *sc, Type *t); |
|---|
| 101 |
int isAssociativeArray(); |
|---|
| 102 |
Type *inferType(Scope *sc); |
|---|
| 103 |
Expression *toExpression(); |
|---|
| 104 |
Expression *toAssocArrayLiteral(); |
|---|
| 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 |
|---|