root/trunk/src/mtype.h

Revision 842, 28.3 kB (checked in by walter, 1 year ago)

bugzilla 190 and 4753

  • Property svn:eol-style set to native
Line 
1 // Compiler implementation of the D programming language
2 // Copyright (c) 1999-2010 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_MTYPE_H
11 #define DMD_MTYPE_H
12
13 #ifdef __DMC__
14 #pragma once
15 #endif /* __DMC__ */
16
17 #include "root.h"
18 #include "stringtable.h"
19
20 #include "arraytypes.h"
21 #include "expression.h"
22
23 struct Scope;
24 struct Identifier;
25 struct Expression;
26 struct StructDeclaration;
27 struct ClassDeclaration;
28 struct VarDeclaration;
29 struct EnumDeclaration;
30 struct TypedefDeclaration;
31 struct TypeInfoDeclaration;
32 struct Dsymbol;
33 struct TemplateInstance;
34 struct CppMangleState;
35 struct TemplateDeclaration;
36 enum LINK;
37
38 struct TypeBasic;
39 struct HdrGenState;
40 struct Parameter;
41
42 // Back end
43 #if IN_GCC
44 union tree_node; typedef union tree_node TYPE;
45 typedef TYPE type;
46 #else
47 typedef struct TYPE type;
48 #endif
49 struct Symbol;
50 struct TypeTuple;
51
52 enum ENUMTY
53 {
54     Tarray,             // slice array, aka T[]
55     Tsarray,            // static array, aka T[dimension]
56     Tnarray,            // resizable array, aka T[new]
57     Taarray,            // associative array, aka T[type]
58     Tpointer,
59     Treference,
60     Tfunction,
61     Tident,
62     Tclass,
63     Tstruct,
64
65     Tenum,
66     Ttypedef,
67     Tdelegate,
68     Tnone,
69     Tvoid,
70     Tint8,
71     Tuns8,
72     Tint16,
73     Tuns16,
74     Tint32,
75
76     Tuns32,
77     Tint64,
78     Tuns64,
79     Tfloat32,
80     Tfloat64,
81     Tfloat80,
82     Timaginary32,
83     Timaginary64,
84     Timaginary80,
85     Tcomplex32,
86
87     Tcomplex64,
88     Tcomplex80,
89     Tbit,
90     Tbool,
91     Tchar,
92     Twchar,
93     Tdchar,
94     Terror,
95     Tinstance,
96     Ttypeof,
97
98     Ttuple,
99     Tslice,
100     Treturn,
101     TMAX
102 };
103 typedef unsigned char TY;       // ENUMTY
104
105 #define Tascii Tchar
106
107 extern int Tsize_t;
108 extern int Tptrdiff_t;
109
110
111 struct Type : Object
112 {
113     TY ty;
114     unsigned char mod;  // modifiers MODxxxx
115         /* pick this order of numbers so switch statements work better
116          */
117         #define MODconst     1  // type is const
118         #define MODimmutable 4  // type is immutable
119         #define MODshared    2  // type is shared
120         #define MODwild      8  // type is wild
121         #define MODmutable   0x10       // type is mutable (only used in wildcard matching)
122     char *deco;
123
124     /* These are cached values that are lazily evaluated by constOf(), invariantOf(), etc.
125      * They should not be referenced by anybody but mtype.c.
126      * They can be NULL if not lazily evaluated yet.
127      * Note that there is no "shared immutable", because that is just immutable
128      * Naked == no MOD bits
129      */
130
131     Type *cto;          // MODconst ? naked version of this type : const version
132     Type *ito;          // MODimmutable ? naked version of this type : immutable version
133     Type *sto;          // MODshared ? naked version of this type : shared mutable version
134     Type *scto;         // MODshared|MODconst ? naked version of this type : shared const version
135     Type *wto;          // MODwild ? naked version of this type : wild version
136     Type *swto;         // MODshared|MODwild ? naked version of this type : shared wild version
137
138     Type *pto;          // merged pointer to this type
139     Type *rto;          // reference to this type
140     Type *arrayof;      // array of this type
141     TypeInfoDeclaration *vtinfo;        // TypeInfo object for this Type
142
143     type *ctype;        // for back end
144
145     #define tvoid       basic[Tvoid]
146     #define tint8       basic[Tint8]
147     #define tuns8       basic[Tuns8]
148     #define tint16      basic[Tint16]
149     #define tuns16      basic[Tuns16]
150     #define tint32      basic[Tint32]
151     #define tuns32      basic[Tuns32]
152     #define tint64      basic[Tint64]
153     #define tuns64      basic[Tuns64]
154     #define tfloat32    basic[Tfloat32]
155     #define tfloat64    basic[Tfloat64]
156     #define tfloat80    basic[Tfloat80]
157
158     #define timaginary32 basic[Timaginary32]
159     #define timaginary64 basic[Timaginary64]
160     #define timaginary80 basic[Timaginary80]
161
162     #define tcomplex32  basic[Tcomplex32]
163     #define tcomplex64  basic[Tcomplex64]
164     #define tcomplex80  basic[Tcomplex80]
165
166     #define tbit        basic[Tbit]
167     #define tbool       basic[Tbool]
168     #define tchar       basic[Tchar]
169     #define twchar      basic[Twchar]
170     #define tdchar      basic[Tdchar]
171
172     // Some special types
173     #define tshiftcnt   tint32          // right side of shift expression
174 //    #define tboolean  tint32          // result of boolean expression
175     #define tboolean    tbool           // result of boolean expression
176     #define tindex      tsize_t         // array/ptr index
177     static Type *tvoidptr;              // void*
178     static Type *tstring;               // immutable(char)[]
179     #define terror      basic[Terror]   // for error recovery
180
181     #define tsize_t     basic[Tsize_t]          // matches size_t alias
182     #define tptrdiff_t  basic[Tptrdiff_t]       // matches ptrdiff_t alias
183     #define thash_t     tsize_t                 // matches hash_t alias
184
185     static ClassDeclaration *typeinfo;
186     static ClassDeclaration *typeinfoclass;
187     static ClassDeclaration *typeinfointerface;
188     static ClassDeclaration *typeinfostruct;
189     static ClassDeclaration *typeinfotypedef;
190     static ClassDeclaration *typeinfopointer;
191     static ClassDeclaration *typeinfoarray;
192     static ClassDeclaration *typeinfostaticarray;
193     static ClassDeclaration *typeinfoassociativearray;
194     static ClassDeclaration *typeinfoenum;
195     static ClassDeclaration *typeinfofunction;
196     static ClassDeclaration *typeinfodelegate;
197     static ClassDeclaration *typeinfotypelist;
198     static ClassDeclaration *typeinfoconst;
199     static ClassDeclaration *typeinfoinvariant;
200     static ClassDeclaration *typeinfoshared;
201     static ClassDeclaration *typeinfowild;
202
203     static TemplateDeclaration *associativearray;
204
205     static Type *basic[TMAX];
206     static unsigned char mangleChar[TMAX];
207     static unsigned char sizeTy[TMAX];
208     static StringTable stringtable;
209
210     // These tables are for implicit conversion of binary ops;
211     // the indices are the type of operand one, followed by operand two.
212     static unsigned char impcnvResult[TMAX][TMAX];
213     static unsigned char impcnvType1[TMAX][TMAX];
214     static unsigned char impcnvType2[TMAX][TMAX];
215
216     // If !=0, give warning on implicit conversion
217     static unsigned char impcnvWarn[TMAX][TMAX];
218
219     Type(TY ty);
220     virtual Type *syntaxCopy();
221     int equals(Object *o);
222     int dyncast() { return DYNCAST_TYPE; } // kludge for template.isType()
223     int covariant(Type *t);
224     char *toChars();
225     static char needThisPrefix();
226     static void init();
227     d_uns64 size();
228     virtual d_uns64 size(Loc loc);
229     virtual unsigned alignsize();
230     virtual Type *semantic(Loc loc, Scope *sc);
231     Type *trySemantic(Loc loc, Scope *sc);
232     virtual void toDecoBuffer(OutBuffer *buf, int flag = 0);
233     Type *merge();
234     Type *merge2();
235     virtual void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs);
236     virtual void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
237     void toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod);
238     void modToBuffer(OutBuffer *buf);
239 #if CPP_MANGLE
240     virtual void toCppMangle(OutBuffer *buf, CppMangleState *cms);
241 #endif
242     virtual int isintegral();
243     virtual int isfloating();   // real, imaginary, or complex
244     virtual int isreal();
245     virtual int isimaginary();
246     virtual int iscomplex();
247     virtual int isscalar();
248     virtual int isunsigned();
249     virtual int isscope();
250     virtual int isString();
251     virtual int isAssignable();
252     virtual int checkBoolean(); // if can be converted to boolean value
253     virtual void checkDeprecated(Loc loc, Scope *sc);
254     int isConst()       { return mod & MODconst; }
255     int isImmutable()   { return mod & MODimmutable; }
256     int isMutable()     { return !(mod & (MODconst | MODimmutable | MODwild)); }
257     int isShared()      { return mod & MODshared; }
258     int isSharedConst() { return mod == (MODshared | MODconst); }
259     int isWild()        { return mod & MODwild; }
260     int isSharedWild()  { return mod == (MODshared | MODwild); }
261     int isNaked()       { return mod == 0; }
262     Type *constOf();
263     Type *invariantOf();
264     Type *mutableOf();
265     Type *sharedOf();
266     Type *sharedConstOf();
267     Type *unSharedOf();
268     Type *wildOf();
269     Type *sharedWildOf();
270     void fixTo(Type *t);
271     void check();
272     Type *castMod(unsigned mod);
273     Type *addMod(unsigned mod);
274     Type *addStorageClass(StorageClass stc);
275     Type *pointerTo();
276     Type *referenceTo();
277     Type *arrayOf();
278     virtual Type *makeConst();
279     virtual Type *makeInvariant();
280     virtual Type *makeShared();
281     virtual Type *makeSharedConst();
282     virtual Type *makeWild();
283     virtual Type *makeSharedWild();
284     virtual Type *makeMutable();
285     virtual Dsymbol *toDsymbol(Scope *sc);
286     virtual Type *toBasetype();
287     virtual Type *toHeadMutable();
288     virtual int isBaseOf(Type *t, int *poffset);
289     virtual MATCH constConv(Type *to);
290     virtual MATCH implicitConvTo(Type *to);
291     virtual ClassDeclaration *isClassHandle();
292     virtual Expression *getProperty(Loc loc, Identifier *ident);
293     virtual Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
294     Expression *noMember(Scope *sc, Expression *e, Identifier *ident);
295     virtual unsigned memalign(unsigned salign);
296     virtual Expression *defaultInit(Loc loc = 0);
297     virtual Expression *defaultInitLiteral(Loc loc = 0);
298     virtual int isZeroInit(Loc loc = 0);                // if initializer is 0
299     virtual dt_t **toDt(dt_t **pdt);
300     Identifier *getTypeInfoIdent(int internal);
301     virtual MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
302     virtual void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps);
303     Expression *getInternalTypeInfo(Scope *sc);
304     Expression *getTypeInfo(Scope *sc);
305     virtual TypeInfoDeclaration *getTypeInfoDeclaration();
306     virtual int builtinTypeInfo();
307     virtual Type *reliesOnTident();
308     virtual int hasWild();
309     virtual unsigned wildMatch(Type *targ);
310     virtual Expression *toExpression();
311     virtual int hasPointers();
312     virtual TypeTuple *toArgTypes();
313     virtual Type *nextOf();
314     uinteger_t sizemask();
315
316     static void error(Loc loc, const char *format, ...);
317     static void warning(Loc loc, const char *format, ...);
318
319     // For backend
320     virtual unsigned totym();
321     virtual type *toCtype();
322     virtual type *toCParamtype();
323     virtual Symbol *toSymbol();
324
325     // For eliminating dynamic_cast
326     virtual TypeBasic *isTypeBasic();
327 };
328
329 struct TypeError : Type
330 {
331     TypeError();
332
333     void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs);
334
335     d_uns64 size(Loc loc);
336     Expression *getProperty(Loc loc, Identifier *ident);
337     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
338     Expression *defaultInit(Loc loc);
339     Expression *defaultInitLiteral(Loc loc);
340 };
341
342 struct TypeNext : Type
343 {
344     Type *next;
345
346     TypeNext(TY ty, Type *next);
347     void toDecoBuffer(OutBuffer *buf, int flag);
348     void checkDeprecated(Loc loc, Scope *sc);
349     Type *reliesOnTident();
350     int hasWild();
351     unsigned wildMatch(Type *targ);
352     Type *nextOf();
353     Type *makeConst();
354     Type *makeInvariant();
355     Type *makeShared();
356     Type *makeSharedConst();
357     Type *makeWild();
358     Type *makeSharedWild();
359     Type *makeMutable();
360     MATCH constConv(Type *to);
361     void transitive();
362 };
363
364 struct TypeBasic : Type
365 {
366     const char *dstring;
367     unsigned flags;
368
369     TypeBasic(TY ty);
370     Type *syntaxCopy();
371     d_uns64 size(Loc loc);
372     unsigned alignsize();
373     Expression *getProperty(Loc loc, Identifier *ident);
374     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
375     char *toChars();
376     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
377 #if CPP_MANGLE
378     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
379 #endif
380     int isintegral();
381     int isbit();
382     int isfloating();
383     int isreal();
384     int isimaginary();
385     int iscomplex();
386     int isscalar();
387     int isunsigned();
388     MATCH implicitConvTo(Type *to);
389     Expression *defaultInit(Loc loc);
390     int isZeroInit(Loc loc);
391     int builtinTypeInfo();
392     TypeTuple *toArgTypes();
393
394     // For eliminating dynamic_cast
395     TypeBasic *isTypeBasic();
396 };
397
398 struct TypeArray : TypeNext
399 {
400     TypeArray(TY ty, Type *next);
401     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
402 };
403
404 // Static array, one with a fixed dimension
405 struct TypeSArray : TypeArray
406 {
407     Expression *dim;
408
409     TypeSArray(Type *t, Expression *dim);
410     Type *syntaxCopy();
411     d_uns64 size(Loc loc);
412     unsigned alignsize();
413     Type *semantic(Loc loc, Scope *sc);
414     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps);
415     void toDecoBuffer(OutBuffer *buf, int flag);
416     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
417     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
418     int isString();
419     int isZeroInit(Loc loc);
420     unsigned memalign(unsigned salign);
421     MATCH constConv(Type *to);
422     MATCH implicitConvTo(Type *to);
423     Expression *defaultInit(Loc loc);
424     Expression *defaultInitLiteral(Loc loc);
425     dt_t **toDt(dt_t **pdt);
426     dt_t **toDtElem(dt_t **pdt, Expression *e);
427     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
428     TypeInfoDeclaration *getTypeInfoDeclaration();
429     Expression *toExpression();
430     int hasPointers();
431     TypeTuple *toArgTypes();
432 #if CPP_MANGLE
433     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
434 #endif
435
436     type *toCtype();
437     type *toCParamtype();
438 };
439
440 // Dynamic array, no dimension
441 struct TypeDArray : TypeArray
442 {
443     TypeDArray(Type *t);
444     Type *syntaxCopy();
445     d_uns64 size(Loc loc);
446     unsigned alignsize();
447     Type *semantic(Loc loc, Scope *sc);
448     void toDecoBuffer(OutBuffer *buf, int flag);
449     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
450     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
451     int isString();
452     int isZeroInit(Loc loc);
453     int checkBoolean();
454     MATCH implicitConvTo(Type *to);
455     Expression *defaultInit(Loc loc);
456     int builtinTypeInfo();
457     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
458     TypeInfoDeclaration *getTypeInfoDeclaration();
459     int hasPointers();
460     TypeTuple *toArgTypes();
461 #if CPP_MANGLE
462     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
463 #endif
464
465     type *toCtype();
466 };
467
468 struct TypeAArray : TypeArray
469 {
470     Type *index;                // key type
471     Loc loc;
472     Scope *sc;
473
474     StructDeclaration *impl;    // implementation
475
476     TypeAArray(Type *t, Type *index);
477     Type *syntaxCopy();
478     d_uns64 size(Loc loc);
479     Type *semantic(Loc loc, Scope *sc);
480     StructDeclaration *getImpl();
481     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps);
482     void toDecoBuffer(OutBuffer *buf, int flag);
483     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
484     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
485     Expression *defaultInit(Loc loc);
486     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
487     int isZeroInit(Loc loc);
488     int checkBoolean();
489     TypeInfoDeclaration *getTypeInfoDeclaration();
490     int hasPointers();
491     TypeTuple *toArgTypes();
492     MATCH implicitConvTo(Type *to);
493     MATCH constConv(Type *to);
494 #if CPP_MANGLE
495     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
496 #endif
497
498     // Back end
499     Symbol *aaGetSymbol(const char *func, int flags);
500
501     type *toCtype();
502 };
503
504 struct TypePointer : TypeNext
505 {
506     TypePointer(Type *t);
507     Type *syntaxCopy();
508     Type *semantic(Loc loc, Scope *sc);
509     d_uns64 size(Loc loc);
510     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
511     MATCH implicitConvTo(Type *to);
512     int isscalar();
513     Expression *defaultInit(Loc loc);
514     int isZeroInit(Loc loc);
515     TypeInfoDeclaration *getTypeInfoDeclaration();
516     int hasPointers();
517     TypeTuple *toArgTypes();
518 #if CPP_MANGLE
519     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
520 #endif
521
522     type *toCtype();
523 };
524
525 struct TypeReference : TypeNext
526 {
527     TypeReference(Type *t);
528     Type *syntaxCopy();
529     Type *semantic(Loc loc, Scope *sc);
530     d_uns64 size(Loc loc);
531     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
532     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
533     Expression *defaultInit(Loc loc);
534     int isZeroInit(Loc loc);
535 #if CPP_MANGLE
536     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
537 #endif
538 };
539
540 enum RET
541 {
542     RETregs     = 1,    // returned in registers
543     RETstack    = 2,    // returned on stack
544 };
545
546 enum TRUST
547 {
548     TRUSTdefault = 0,
549     TRUSTsystem = 1,    // @system (same as TRUSTdefault)
550     TRUSTtrusted = 2,   // @trusted
551     TRUSTsafe = 3,      // @safe
552 };
553
554 enum PURE
555 {
556     PUREimpure = 0,     // not pure at all
557     PUREweak = 1,       // no mutable globals are read or written
558     PUREconst = 2,      // parameters are values or const
559     PUREstrong = 3,     // parameters are values or immutable
560     PUREfwdref = 4,     // it's pure, but not known which level yet
561 };
562
563 struct TypeFunction : TypeNext
564 {
565     // .next is the return type
566
567     Parameters *parameters;     // function parameters
568     int varargs;        // 1: T t, ...) style for variable number of arguments
569                         // 2: T t ...) style for variable number of arguments
570     bool isnothrow;     // true: nothrow
571     bool isproperty;    // can be called without parentheses
572     bool isref;         // true: returns a reference
573     enum LINK linkage;  // calling convention
574     enum TRUST trust;   // level of trust
575     enum PURE purity;   // PURExxxx
576     Expressions *fargs; // function arguments
577
578     int inuse;
579
580     TypeFunction(Parameters *parameters, Type *treturn, int varargs, enum LINK linkage, StorageClass stc = 0);
581     Type *syntaxCopy();
582     Type *semantic(Loc loc, Scope *sc);
583     void purityLevel();
584     void toDecoBuffer(OutBuffer *buf, int flag);
585     void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs);
586     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
587     void attributesToCBuffer(OutBuffer *buf, int mod);
588     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
589     TypeInfoDeclaration *getTypeInfoDeclaration();
590     Type *reliesOnTident();
591 #if CPP_MANGLE
592     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
593 #endif
594     bool parameterEscapes(Parameter *p);
595
596     int callMatch(Expression *ethis, Expressions *toargs, int flag = 0);
597     type *toCtype();
598     enum RET retStyle();
599
600     unsigned totym();
601 };
602
603 struct TypeDelegate : TypeNext
604 {
605     // .next is a TypeFunction
606
607     TypeDelegate(Type *t);
608     Type *syntaxCopy();
609     Type *semantic(Loc loc, Scope *sc);
610     d_uns64 size(Loc loc);
611     unsigned alignsize();
612     MATCH implicitConvTo(Type *to);
613     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
614     Expression *defaultInit(Loc loc);
615     int isZeroInit(Loc loc);
616     int checkBoolean();
617     TypeInfoDeclaration *getTypeInfoDeclaration();
618     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
619     int hasPointers();
620     TypeTuple *toArgTypes();
621 #if CPP_MANGLE
622     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
623 #endif
624
625     type *toCtype();
626 };
627
628 struct TypeQualified : Type
629 {
630     Loc loc;
631     Array idents;       // array of Identifier's representing ident.ident.ident etc.
632
633     TypeQualified(TY ty, Loc loc);
634     void syntaxCopyHelper(TypeQualified *t);
635     void addIdent(Identifier *ident);
636     void toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs);
637     d_uns64 size(Loc loc);
638     void resolveHelper(Loc loc, Scope *sc, Dsymbol *s, Dsymbol *scopesym,
639         Expression **pe, Type **pt, Dsymbol **ps);
640 };
641
642 struct TypeIdentifier : TypeQualified
643 {
644     Identifier *ident;
645
646     TypeIdentifier(Loc loc, Identifier *ident);
647     Type *syntaxCopy();
648     //char *toChars();
649     void toDecoBuffer(OutBuffer *buf, int flag);
650     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
651     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps);
652     Dsymbol *toDsymbol(Scope *sc);
653     Type *semantic(Loc loc, Scope *sc);
654     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
655     Type *reliesOnTident();
656     Expression *toExpression();
657 };
658
659 /* Similar to TypeIdentifier, but with a TemplateInstance as the root
660  */
661 struct TypeInstance : TypeQualified
662 {
663     TemplateInstance *tempinst;
664
665     TypeInstance(Loc loc, TemplateInstance *tempinst);
666     Type *syntaxCopy();
667     //char *toChars();
668     //void toDecoBuffer(OutBuffer *buf, int flag);
669     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
670     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps);
671     Type *semantic(Loc loc, Scope *sc);
672     Dsymbol *toDsymbol(Scope *sc);
673     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
674 };
675
676 struct TypeTypeof : TypeQualified
677 {
678     Expression *exp;
679     int inuse;
680
681     TypeTypeof(Loc loc, Expression *exp);
682     Type *syntaxCopy();
683     Dsymbol *toDsymbol(Scope *sc);
684     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
685     Type *semantic(Loc loc, Scope *sc);
686     d_uns64 size(Loc loc);
687 };
688
689 struct TypeReturn : TypeQualified
690 {
691     TypeReturn(Loc loc);
692     Type *syntaxCopy();
693     Dsymbol *toDsymbol(Scope *sc);
694     Type *semantic(Loc loc, Scope *sc);
695     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
696 };
697
698 struct TypeStruct : Type
699 {
700     StructDeclaration *sym;
701
702     TypeStruct(StructDeclaration *sym);
703     d_uns64 size(Loc loc);
704     unsigned alignsize();
705     char *toChars();
706     Type *syntaxCopy();
707     Type *semantic(Loc loc, Scope *sc);
708     Dsymbol *toDsymbol(Scope *sc);
709     void toDecoBuffer(OutBuffer *buf, int flag);
710     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
711     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
712     unsigned memalign(unsigned salign);
713     Expression *defaultInit(Loc loc);
714     Expression *defaultInitLiteral(Loc loc);
715     int isZeroInit(Loc loc);
716     int isAssignable();
717     int checkBoolean();
718     dt_t **toDt(dt_t **pdt);
719     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
720     TypeInfoDeclaration *getTypeInfoDeclaration();
721     int hasPointers();
722     TypeTuple *toArgTypes();
723     MATCH implicitConvTo(Type *to);
724     MATCH constConv(Type *to);
725     Type *toHeadMutable();
726 #if CPP_MANGLE
727     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
728 #endif
729
730     type *toCtype();
731 };
732
733 struct TypeEnum : Type
734 {
735     EnumDeclaration *sym;
736
737     TypeEnum(EnumDeclaration *sym);
738     Type *syntaxCopy();
739     d_uns64 size(Loc loc);
740     unsigned alignsize();
741     char *toChars();
742     Type *semantic(Loc loc, Scope *sc);
743     Dsymbol *toDsymbol(Scope *sc);
744     void toDecoBuffer(OutBuffer *buf, int flag);
745     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
746     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
747     Expression *getProperty(Loc loc, Identifier *ident);
748     int isintegral();
749     int isfloating();
750     int isreal();
751     int isimaginary();
752     int iscomplex();
753     int isscalar();
754     int isunsigned();
755     int checkBoolean();
756     int isAssignable();
757     MATCH implicitConvTo(Type *to);
758     MATCH constConv(Type *to);
759     Type *toBasetype();
760     Expression *defaultInit(Loc loc);
761     int isZeroInit(Loc loc);
762     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
763     TypeInfoDeclaration *getTypeInfoDeclaration();
764     int hasPointers();
765     TypeTuple *toArgTypes();
766 #if CPP_MANGLE
767     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
768 #endif
769
770     type *toCtype();
771 };
772
773 struct TypeTypedef : Type
774 {
775     TypedefDeclaration *sym;
776
777     TypeTypedef(TypedefDeclaration *sym);
778     Type *syntaxCopy();
779     d_uns64 size(Loc loc);
780     unsigned alignsize();
781     char *toChars();
782     Type *semantic(Loc loc, Scope *sc);
783     Dsymbol *toDsymbol(Scope *sc);
784     void toDecoBuffer(OutBuffer *buf, int flag);
785     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
786     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
787     Expression *getProperty(Loc loc, Identifier *ident);
788     int isbit();
789     int isintegral();
790     int isfloating();
791     int isreal();
792     int isimaginary();
793     int iscomplex();
794     int isscalar();
795     int isunsigned();
796     int checkBoolean();
797     int isAssignable();
798     Type *toBasetype();
799     MATCH implicitConvTo(Type *to);
800     MATCH constConv(Type *to);
801     Expression *defaultInit(Loc loc);
802     Expression *defaultInitLiteral(Loc loc);
803     int isZeroInit(Loc loc);
804     dt_t **toDt(dt_t **pdt);
805     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
806     TypeInfoDeclaration *getTypeInfoDeclaration();
807     int hasPointers();
808     TypeTuple *toArgTypes();
809     int hasWild();
810     Type *toHeadMutable();
811 #if CPP_MANGLE
812     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
813 #endif
814
815     type *toCtype();
816     type *toCParamtype();
817 };
818
819 struct TypeClass : Type
820 {
821     ClassDeclaration *sym;
822
823     TypeClass(ClassDeclaration *sym);
824     d_uns64 size(Loc loc);
825     char *toChars();
826     Type *syntaxCopy();
827     Type *semantic(Loc loc, Scope *sc);
828     Dsymbol *toDsymbol(Scope *sc);
829     void toDecoBuffer(OutBuffer *buf, int flag);
830     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
831     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
832     ClassDeclaration *isClassHandle();
833     int isBaseOf(Type *t, int *poffset);
834     MATCH implicitConvTo(Type *to);
835     Expression *defaultInit(Loc loc);
836     int isZeroInit(Loc loc);
837     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
838     int isscope();
839     int checkBoolean();
840     TypeInfoDeclaration *getTypeInfoDeclaration();
841     int hasPointers();
842     TypeTuple *toArgTypes();
843     int builtinTypeInfo();
844 #if DMDV2
845     Type *toHeadMutable();
846     MATCH constConv(Type *to);
847 #if CPP_MANGLE
848     void toCppMangle(OutBuffer *buf, CppMangleState *cms);
849 #endif
850 #endif
851
852     type *toCtype();
853
854     Symbol *toSymbol();
855 };
856
857 struct TypeTuple : Type
858 {
859     Parameters *arguments;      // types making up the tuple
860
861     TypeTuple(Parameters *arguments);
862     TypeTuple(Expressions *exps);
863     TypeTuple();
864     TypeTuple(Type *t1);
865     TypeTuple(Type *t1, Type *t2);
866     Type *syntaxCopy();
867     Type *semantic(Loc loc, Scope *sc);
868     int equals(Object *o);
869     Type *reliesOnTident();
870     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
871     void toDecoBuffer(OutBuffer *buf, int flag);
872     Expression *getProperty(Loc loc, Identifier *ident);
873     TypeInfoDeclaration *getTypeInfoDeclaration();
874 };
875
876 struct TypeSlice : TypeNext
877 {
878     Expression *lwr;
879     Expression *upr;
880
881     TypeSlice(Type *next, Expression *lwr, Expression *upr);
882     Type *syntaxCopy();
883     Type *semantic(Loc loc, Scope *sc);
884     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps);
885     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
886 };
887
888 struct TypeNewArray : TypeNext
889 {
890     TypeNewArray(Type *next);
891     void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
892 };
893
894 /**************************************************************/
895
896 //enum InOut { None, In, Out, InOut, Lazy };
897
898 struct Parameter : Object
899 {
900     //enum InOut inout;
901     StorageClass storageClass;
902     Type *type;
903     Identifier *ident;
904     Expression *defaultArg;
905
906     Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg);
907     Parameter *syntaxCopy();
908     Type *isLazyArray();
909     void toDecoBuffer(OutBuffer *buf);
910     static Parameters *arraySyntaxCopy(Parameters *args);
911     static char *argsTypesToChars(Parameters *args, int varargs);
912     static void argsCppMangle(OutBuffer *buf, CppMangleState *cms, Parameters *arguments, int varargs);
913     static void argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *arguments, int varargs);
914     static void argsToDecoBuffer(OutBuffer *buf, Parameters *arguments);
915     static int isTPL(Parameters *arguments);
916     static size_t dim(Parameters *arguments);
917     static Parameter *getNth(Parameters *arguments, size_t nth, size_t *pn = NULL);
918 };
919
920 extern int PTRSIZE;
921 extern int REALSIZE;
922 extern int REALPAD;
923 extern int Tsize_t;
924 extern int Tptrdiff_t;
925
926 int arrayTypeCompatible(Loc loc, Type *t1, Type *t2);
927 int arrayTypeCompatibleWithoutCasting(Loc loc, Type *t1, Type *t2);
928 void MODtoBuffer(OutBuffer *buf, unsigned char mod);
929 int MODimplicitConv(unsigned char modfrom, unsigned char modto);
930 int MODmerge(unsigned char mod1, unsigned char mod2);
931
932 #endif /* DMD_MTYPE_H */
Note: See TracBrowser for help on using the browser.