| 1 |
// Compiler implementation of the D programming language |
|---|
| 2 |
// Copyright (c) 1999-2006 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 DMD_AGGREGATE_H |
|---|
| 11 |
#define DMD_AGGREGATE_H |
|---|
| 12 |
|
|---|
| 13 |
#ifdef __DMC__ |
|---|
| 14 |
#pragma once |
|---|
| 15 |
#endif /* __DMC__ */ |
|---|
| 16 |
|
|---|
| 17 |
#include "root.h" |
|---|
| 18 |
#include "dsymbol.h" |
|---|
| 19 |
|
|---|
| 20 |
struct Identifier; |
|---|
| 21 |
struct Type; |
|---|
| 22 |
struct TypeFunction; |
|---|
| 23 |
struct Expression; |
|---|
| 24 |
struct FuncDeclaration; |
|---|
| 25 |
struct CtorDeclaration; |
|---|
| 26 |
struct DtorDeclaration; |
|---|
| 27 |
struct InvariantDeclaration; |
|---|
| 28 |
struct NewDeclaration; |
|---|
| 29 |
struct DeleteDeclaration; |
|---|
| 30 |
struct InterfaceDeclaration; |
|---|
| 31 |
struct ClassInfoDeclaration; |
|---|
| 32 |
struct VarDeclaration; |
|---|
| 33 |
struct dt_t; |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
struct AggregateDeclaration : ScopeDsymbol |
|---|
| 37 |
{ |
|---|
| 38 |
Type *type; |
|---|
| 39 |
unsigned storage_class; |
|---|
| 40 |
enum PROT protection; |
|---|
| 41 |
Type *handle; // 'this' type |
|---|
| 42 |
unsigned structsize; // size of struct |
|---|
| 43 |
unsigned alignsize; // size of struct for alignment purposes |
|---|
| 44 |
unsigned structalign; // struct member alignment in effect |
|---|
| 45 |
int hasUnions; // set if aggregate has overlapping fields |
|---|
| 46 |
Array fields; // VarDeclaration fields |
|---|
| 47 |
unsigned sizeok; // set when structsize contains valid data |
|---|
| 48 |
// 0: no size |
|---|
| 49 |
// 1: size is correct |
|---|
| 50 |
// 2: cannot determine size; fwd referenced |
|---|
| 51 |
int isdeprecated; // !=0 if deprecated |
|---|
| 52 |
Scope *scope; // !=NULL means context to use |
|---|
| 53 |
|
|---|
| 54 |
// Special member functions |
|---|
| 55 |
InvariantDeclaration *inv; // invariant |
|---|
| 56 |
NewDeclaration *aggNew; // allocator |
|---|
| 57 |
DeleteDeclaration *aggDelete; // deallocator |
|---|
| 58 |
|
|---|
| 59 |
#ifdef IN_GCC |
|---|
| 60 |
Array methods; // flat list of all methods for debug information |
|---|
| 61 |
#endif |
|---|
| 62 |
|
|---|
| 63 |
AggregateDeclaration(Loc loc, Identifier *id); |
|---|
| 64 |
void semantic2(Scope *sc); |
|---|
| 65 |
void semantic3(Scope *sc); |
|---|
| 66 |
void inlineScan(); |
|---|
| 67 |
unsigned size(Loc loc); |
|---|
| 68 |
static void alignmember(unsigned salign, unsigned size, unsigned *poffset); |
|---|
| 69 |
Type *getType(); |
|---|
| 70 |
void addField(Scope *sc, VarDeclaration *v); |
|---|
| 71 |
int isDeprecated(); // is aggregate deprecated? |
|---|
| 72 |
|
|---|
| 73 |
void emitComment(Scope *sc); |
|---|
| 74 |
void toDocBuffer(OutBuffer *buf); |
|---|
| 75 |
|
|---|
| 76 |
// For access checking |
|---|
| 77 |
virtual PROT getAccess(Dsymbol *smember); // determine access to smember |
|---|
| 78 |
int isFriendOf(AggregateDeclaration *cd); |
|---|
| 79 |
int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class? |
|---|
| 80 |
void accessCheck(Loc loc, Scope *sc, Dsymbol *smember); |
|---|
| 81 |
|
|---|
| 82 |
enum PROT prot(); |
|---|
| 83 |
|
|---|
| 84 |
// Back end |
|---|
| 85 |
Symbol *stag; // tag symbol for debug data |
|---|
| 86 |
Symbol *sinit; |
|---|
| 87 |
|
|---|
| 88 |
AggregateDeclaration *isAggregateDeclaration() { return this; } |
|---|
| 89 |
}; |
|---|
| 90 |
|
|---|
| 91 |
struct AnonymousAggregateDeclaration : AggregateDeclaration |
|---|
| 92 |
{ |
|---|
| 93 |
AnonymousAggregateDeclaration() |
|---|
| 94 |
: AggregateDeclaration(0, NULL) |
|---|
| 95 |
{ |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } |
|---|
| 99 |
}; |
|---|
| 100 |
|
|---|
| 101 |
struct StructDeclaration : AggregateDeclaration |
|---|
| 102 |
{ |
|---|
| 103 |
int zeroInit; // !=0 if initialize with 0 fill |
|---|
| 104 |
|
|---|
| 105 |
StructDeclaration(Loc loc, Identifier *id); |
|---|
| 106 |
Dsymbol *syntaxCopy(Dsymbol *s); |
|---|
| 107 |
void semantic(Scope *sc); |
|---|
| 108 |
void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| 109 |
char *mangle(); |
|---|
| 110 |
char *kind(); |
|---|
| 111 |
void toDocBuffer(OutBuffer *buf); |
|---|
| 112 |
|
|---|
| 113 |
PROT getAccess(Dsymbol *smember); // determine access to smember |
|---|
| 114 |
|
|---|
| 115 |
void toDebug(); // to symbolic debug info |
|---|
| 116 |
|
|---|
| 117 |
StructDeclaration *isStructDeclaration() { return this; } |
|---|
| 118 |
}; |
|---|
| 119 |
|
|---|
| 120 |
struct UnionDeclaration : StructDeclaration |
|---|
| 121 |
{ |
|---|
| 122 |
UnionDeclaration(Loc loc, Identifier *id); |
|---|
| 123 |
Dsymbol *syntaxCopy(Dsymbol *s); |
|---|
| 124 |
char *kind(); |
|---|
| 125 |
|
|---|
| 126 |
UnionDeclaration *isUnionDeclaration() { return this; } |
|---|
| 127 |
}; |
|---|
| 128 |
|
|---|
| 129 |
struct BaseClass |
|---|
| 130 |
{ |
|---|
| 131 |
Type *type; // (before semantic processing) |
|---|
| 132 |
enum PROT protection; // protection for the base interface |
|---|
| 133 |
|
|---|
| 134 |
ClassDeclaration *base; |
|---|
| 135 |
int offset; // 'this' pointer offset |
|---|
| 136 |
Array vtbl; // for interfaces: Array of FuncDeclaration's |
|---|
| 137 |
// making up the vtbl[] |
|---|
| 138 |
|
|---|
| 139 |
int baseInterfaces_dim; |
|---|
| 140 |
BaseClass *baseInterfaces; // if BaseClass is an interface, these |
|---|
| 141 |
// are a copy of the InterfaceDeclaration::interfaces |
|---|
| 142 |
|
|---|
| 143 |
BaseClass(); |
|---|
| 144 |
BaseClass(Type *type, enum PROT protection); |
|---|
| 145 |
|
|---|
| 146 |
int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); |
|---|
| 147 |
void copyBaseInterfaces(BaseClasses *); |
|---|
| 148 |
}; |
|---|
| 149 |
|
|---|
| 150 |
#define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size |
|---|
| 151 |
|
|---|
| 152 |
struct ClassDeclaration : AggregateDeclaration |
|---|
| 153 |
{ |
|---|
| 154 |
static ClassDeclaration *object; |
|---|
| 155 |
static ClassDeclaration *classinfo; |
|---|
| 156 |
|
|---|
| 157 |
ClassDeclaration *baseClass; // NULL only if this is Object |
|---|
| 158 |
CtorDeclaration *ctor; |
|---|
| 159 |
CtorDeclaration *defaultCtor; // default constructor |
|---|
| 160 |
FuncDeclarations dtors; // Array of destructors |
|---|
| 161 |
FuncDeclaration *staticCtor; |
|---|
| 162 |
FuncDeclaration *staticDtor; |
|---|
| 163 |
Array vtbl; // Array of FuncDeclaration's making up the vtbl[] |
|---|
| 164 |
Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] |
|---|
| 165 |
|
|---|
| 166 |
BaseClasses baseclasses; // Array of BaseClass's; first is super, |
|---|
| 167 |
// rest are Interface's |
|---|
| 168 |
|
|---|
| 169 |
int interfaces_dim; |
|---|
| 170 |
BaseClass **interfaces; // interfaces[interfaces_dim] for this class |
|---|
| 171 |
// (does not include baseClass) |
|---|
| 172 |
|
|---|
| 173 |
BaseClasses *vtblInterfaces; // array of base interfaces that have |
|---|
| 174 |
// their own vtbl[] |
|---|
| 175 |
|
|---|
| 176 |
ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration |
|---|
| 177 |
int com; // !=0 if this is a COM class |
|---|
| 178 |
int isauto; // !=0 if this is an auto class |
|---|
| 179 |
int isabstract; // !=0 if abstract class |
|---|
| 180 |
|
|---|
| 181 |
int isnested; // !=0 if is nested |
|---|
| 182 |
VarDeclaration *vthis; // 'this' parameter if this class is nested |
|---|
| 183 |
|
|---|
| 184 |
ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); |
|---|
| 185 |
Dsymbol *syntaxCopy(Dsymbol *s); |
|---|
| 186 |
void semantic(Scope *sc); |
|---|
| 187 |
void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| 188 |
int isBaseOf2(ClassDeclaration *cd); |
|---|
| 189 |
|
|---|
| 190 |
#define OFFSET_RUNTIME 0x76543210 |
|---|
| 191 |
virtual int isBaseOf(ClassDeclaration *cd, int *poffset); |
|---|
| 192 |
|
|---|
| 193 |
Dsymbol *search(Loc, Identifier *ident, int flags); |
|---|
| 194 |
FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); |
|---|
| 195 |
void interfaceSemantic(Scope *sc); |
|---|
| 196 |
int isNested(); |
|---|
| 197 |
int isCOMclass(); |
|---|
| 198 |
int isAbstract(); |
|---|
| 199 |
virtual int vtblOffset(); |
|---|
| 200 |
char *kind(); |
|---|
| 201 |
char *mangle(); |
|---|
| 202 |
void toDocBuffer(OutBuffer *buf); |
|---|
| 203 |
|
|---|
| 204 |
PROT getAccess(Dsymbol *smember); // determine access to smember |
|---|
| 205 |
|
|---|
| 206 |
void addLocalClass(ClassDeclarations *); |
|---|
| 207 |
|
|---|
| 208 |
// Back end |
|---|
| 209 |
void toDebug(); |
|---|
| 210 |
unsigned baseVtblOffset(BaseClass *bc); |
|---|
| 211 |
Symbol *toVtblSymbol(); |
|---|
| 212 |
void toDt2(dt_t **pdt, ClassDeclaration *cd); |
|---|
| 213 |
|
|---|
| 214 |
Symbol *vtblsym; |
|---|
| 215 |
|
|---|
| 216 |
ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } |
|---|
| 217 |
}; |
|---|
| 218 |
|
|---|
| 219 |
struct InterfaceDeclaration : ClassDeclaration |
|---|
| 220 |
{ |
|---|
| 221 |
InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); |
|---|
| 222 |
Dsymbol *syntaxCopy(Dsymbol *s); |
|---|
| 223 |
void semantic(Scope *sc); |
|---|
| 224 |
int isBaseOf(ClassDeclaration *cd, int *poffset); |
|---|
| 225 |
int isBaseOf(BaseClass *bc, int *poffset); |
|---|
| 226 |
char *kind(); |
|---|
| 227 |
int vtblOffset(); |
|---|
| 228 |
|
|---|
| 229 |
InterfaceDeclaration *isInterfaceDeclaration() { return this; } |
|---|
| 230 |
}; |
|---|
| 231 |
|
|---|
| 232 |
#endif /* DMD_AGGREGATE_H */ |
|---|