comparison dmd/aggregate.h @ 1:c53b6e3fe49a trunk

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