annotate src/dil/semantic/Types.d @ 820:1d06b4aed7cf

Revised code in the first pass. Added code to handle anonymous unions and structs. Hope the idea will work. Added type to class Aggregate and isAnonymous to some other Symbol classes.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 14 Mar 2008 15:42:08 +0100
parents bcb74c9b895c
children 1ecf05e680ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
1 /++
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 Author: Aziz Köksal
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 License: GPL3
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 +/
617
0749f30ef2d0 Added member 'EnumType type' to class Enum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 615
diff changeset
5 module dil.semantic.Types;
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
6
700
8e252b7c1459 Resolved cyclic dependency of dil.semantic.Types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 692
diff changeset
7 import dil.semantic.Symbol;
595
f6e5bff58b10 Moved dil.TypesEnum to dil.semantic.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 589
diff changeset
8 import dil.semantic.TypesEnum;
600
041eae272362 Moved dil.Identifier to dil.lexer.Identifier.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 595
diff changeset
9 import dil.lexer.Identifier;
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
10 import dil.CompilerInfo;
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
11
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
12 /// The base type for all type structures.
615
a05457530ac2 Added member ident to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 600
diff changeset
13 abstract class Type/* : Symbol*/
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
14 {
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
15 Type next; /// The next type in the type structure.
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
16 TYP tid; /// The ID of the type.
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
17 Symbol symbol; /// Not null if this type has a symbol.
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
18
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
19 this(){}
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
20
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
21 /// Constructs a Type object.
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
22 /// Params:
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
23 /// next = the type's next type.
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
24 /// tid = the type's ID.
536
0781ac288537 Added some semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 527
diff changeset
25 this(Type next, TYP tid)
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
26 {
615
a05457530ac2 Added member ident to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 600
diff changeset
27 // this.sid = SYM.Type;
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 548
diff changeset
28
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
29 this.next = next;
536
0781ac288537 Added some semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 527
diff changeset
30 this.tid = tid;
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
31 }
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
32
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
33 /// Returns a pointer type to this type.
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
34 TypePointer ptrTo()
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
35 {
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
36 return new TypePointer(this);
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
37 }
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
38
804
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
39 /// Returns a dynamic array type using this type as its base.
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
40 TypeDArray arrayOf()
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
41 {
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
42 return new TypeDArray(this);
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
43 }
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
44
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
45 /// Returns an associative array type using this type as its base.
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
46 /// Params:
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
47 /// key = the key type.
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
48 TypeAArray arrayOf(Type key)
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
49 {
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
50 return new TypeAArray(this, key);
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
51 }
9e6c6bb73e5f Implemented visit methods for some type nodes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 798
diff changeset
52
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
53 /// Returns the byte size of this type.
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
54 final size_t sizeOf()
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
55 {
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
56 return MITable.getSize(this);
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
57 }
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
58
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
59 /// Size is not in MITable. Find out via virtual method.
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
60 size_t sizeOf_()
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
61 {
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
62 return sizeOf();
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
63 }
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
64
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
65 /// Returns true if this type has a symbol.
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
66 bool hasSymbol()
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
67 {
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
68 return symbol !is null;
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
69 }
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
70 }
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
71
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
72 /// All basic types. E.g.: int, char, real etc.
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
73 class TypeBasic : Type
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
74 {
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
75 this(TYP typ)
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
76 {
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
77 super(null, typ);
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
78 }
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
79 }
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
80
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
81 /// Dynamic array type.
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
82 class TypeDArray : Type
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
83 {
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
84 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
85 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
86 super(next, TYP.DArray);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
87 }
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
88 }
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
89
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
90 /// Associative array type.
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
91 class TypeAArray : Type
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
92 {
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
93 Type keyType;
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
94 this(Type next, Type keyType)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
95 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
96 super(next, TYP.AArray);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
97 this.keyType = keyType;
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
98 }
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
99 }
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
100
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
101 /// Static array type.
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
102 class TypeSArray : Type
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
103 {
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
104 size_t dimension;
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
105 this(Type next, size_t dimension)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
106 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
107 super(next, TYP.SArray);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
108 this.dimension = dimension;
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
109 }
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
110 }
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
111
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
112 /// Pointer type.
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
113 class TypePointer : Type
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
114 {
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
115 this(Type next)
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
116 {
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
117 super(next, TYP.Pointer);
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
118 }
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
119 }
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
120
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
121 /// Reference type.
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
122 class TypeReference : Type
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
123 {
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
124 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
125 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
126 super(next, TYP.Reference);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
127 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
128 }
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
129
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
130 /// Enum type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
131 class TypeEnum : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
132 {
820
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
133 this(Symbol symbol)
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
134 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
135 super(baseType, TYP.Enum);
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
136 this.symbol = symbol;
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
137 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
138
820
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
139 /// Setter for the base type.
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
140 void baseType(Type type)
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
141 {
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
142 next = type;
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
143 }
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
144
1d06b4aed7cf Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
145 /// Getter for the base type.
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
146 Type baseType()
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
147 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
148 return next;
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
149 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
150 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
151
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
152 /// Struct type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
153 class TypeStruct : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
154 {
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
155 this(Symbol symbol)
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
156 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
157 super(null, TYP.Struct);
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
158 this.symbol = symbol;
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
159 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
160 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
161
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
162 /// Class type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
163 class TypeClass : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
164 {
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
165 this(Symbol symbol)
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
166 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
167 super(null, TYP.Class);
796
f7688996bf08 Added member symbol to class Type.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 700
diff changeset
168 this.symbol = symbol;
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
169 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
170 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
171
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
172 /// Typedef type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
173 class TypeTypedef : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
174 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
175 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
176 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
177 super(next, TYP.Typedef);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
178 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
179 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
180
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
181 /// Function type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
182 class TypeFunction : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
183 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
184 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
185 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
186 super(next, TYP.Function);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
187 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
188 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
189
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
190 /// Delegate type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
191 class TypeDelegate : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
192 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
193 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
194 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
195 super(next, TYP.Delegate);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
196 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
197 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
198
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
199 /// Identifier type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
200 class TypeIdentifier : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
201 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
202 Identifier* ident;
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
203 this(Identifier* ident)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
204 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
205 super(null, TYP.Identifier);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
206 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
207 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
208
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
209 /// Template instantiation type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
210 class TypeTemplInstance : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
211 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
212 this()
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
213 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
214 super(null, TYP.TInstance);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
215 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
216 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
217
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
218 /// Template tuple type.
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
219 class TypeTuple : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
220 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
221 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
222 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
223 super(next, TYP.Tuple);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
224 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
225 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
226
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
227 /// Constant type. D2.0
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
228 class TypeConst : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
229 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
230 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
231 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
232 super(next, TYP.Const);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
233 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
234 }
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
235
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
236 /// Invariant type. D2.0
688
839c0c61af2b Renamed some semantic types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 617
diff changeset
237 class TypeInvariant : Type
526
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
238 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
239 this(Type next)
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
240 {
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
241 super(next, TYP.Const);
ee22dc0ba82c Added more Type classes to dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 525
diff changeset
242 }
512
112c17300069 Added module dil.TypeSystem.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
243 }
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
244
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
245 /// Represents a value related to a Type.
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
246 union Value
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
247 {
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
248 void* pvoid;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
249 bool bool_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
250 dchar dchar_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
251 long long_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
252 ulong ulong_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
253 int int_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
254 uint uint_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
255 float float_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
256 double double_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
257 real real_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
258 creal creal_;
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
259 }
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
260
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
261 /// Information related to a Type.
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
262 struct TypeMetaInfo
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
263 {
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
264 char mangle; /// Mangle character of the type.
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
265 ushort size; /// Byte size of the type.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
266 Value* defaultInit; /// Default initialization value.
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
267 }
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
268
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
269 /// Namespace for the meta info table.
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
270 struct MITable
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
271 {
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
272 static:
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
273 const ushort SIZE_NOT_AVAILABLE = 0; /// Size not available.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
274 const Value VZERO = {int_:0}; /// Value 0.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
275 const Value VNULL = {pvoid:null}; /// Value null.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
276 const Value V0xFF = {dchar_:0xFF}; /// Value 0xFF.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
277 const Value V0xFFFF = {dchar_:0xFFFF}; /// Value 0xFFFF.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
278 const Value VFALSE = {bool_:false}; /// Value false.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
279 const Value VNAN = {float_:float.nan}; /// Value NAN.
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
280 const Value VCNAN = {creal_:creal.nan}; /// Value complex NAN.
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
281 private alias SIZE_NOT_AVAILABLE SNA;
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
282 private alias PTR_SIZE PS;
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
283 /// The meta info table.
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
284 private const TypeMetaInfo metaInfoTable[] = [
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
285 {'?', SNA}, // Error
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
286
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
287 {'a', 1, &V0xFF}, // Char
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
288 {'u', 2, &V0xFFFF}, // Wchar
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
289 {'w', 4, &V0xFFFF}, // Dchar
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
290 {'b', 1, &VFALSE}, // Bool
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
291 {'g', 1, &VZERO}, // Byte
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
292 {'h', 1, &VZERO}, // Ubyte
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
293 {'s', 2, &VZERO}, // Short
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
294 {'t', 2, &VZERO}, // Ushort
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
295 {'i', 4, &VZERO}, // Int
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
296 {'k', 4, &VZERO}, // Uint
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
297 {'l', 8, &VZERO}, // Long
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
298 {'m', 8, &VZERO}, // Ulong
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
299 {'?', 16, &VZERO}, // Cent
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
300 {'?', 16, &VZERO}, // Ucent
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
301 {'f', 4, &VNAN}, // Float
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
302 {'d', 8, &VNAN}, // Double
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
303 {'e', 12, &VNAN}, // Real
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
304 {'o', 4, &VNAN}, // Ifloat
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
305 {'p', 8, &VNAN}, // Idouble
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
306 {'j', 12, &VNAN}, // Ireal
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
307 {'q', 8, &VCNAN}, // Cfloat
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
308 {'r', 16, &VCNAN}, // Cdouble
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
309 {'c', 24, &VCNAN}, // Creal
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
310 {'v', 1}, // void
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
311
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
312 {'n', SNA}, // None
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
313
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
314 {'A', PS*2, &VNULL}, // Dynamic array
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
315 {'G', PS*2, &VNULL}, // Static array
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
316 {'H', PS*2, &VNULL}, // Associative array
522
812f497b20dc Added module dil.TypesEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 512
diff changeset
317
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
318 {'E', SNA}, // Enum
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
319 {'S', SNA}, // Struct
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
320 {'C', PS, &VNULL}, // Class
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
321 {'T', SNA}, // Typedef
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
322 {'F', PS}, // Function
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
323 {'D', PS*2, &VNULL}, // Delegate
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
324 {'P', PS, &VNULL}, // Pointer
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
325 {'R', PS, &VNULL}, // Reference
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
326 {'I', SNA}, // Identifier
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
327 {'?', SNA}, // Template instance
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
328 {'B', SNA}, // Tuple
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
329 {'x', SNA}, // Const, D2
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
330 {'y', SNA}, // Invariant, D2
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
331 ];
548
faf16f4e7fc8 Added union Value and updated metaInfoTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 536
diff changeset
332 static assert(metaInfoTable.length == TYP.max+1);
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
333
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
334 /// Returns the size of a type.
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
335 size_t getSize(Type type)
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
336 {
536
0781ac288537 Added some semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 527
diff changeset
337 auto size = metaInfoTable[type.tid].size;
527
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
338 if (size == SIZE_NOT_AVAILABLE)
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
339 return type.sizeOf_();
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
340 return size;
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
341 }
c8c3aec130f7 Added struct MITable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 526
diff changeset
342 }
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
343
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
344 /// Namespace for a set of predefined types.
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
345 struct Types
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
346 {
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
347 static:
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
348 /// Predefined basic types.
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
349 TypeBasic Char, Wchar, Dchar, Bool,
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
350 Byte, Ubyte, Short, Ushort,
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
351 Int, Uint, Long, Ulong,
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
352 Cent, Ucent,
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
353 Float, Double, Real,
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
354 Ifloat, Idouble, Ireal,
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
355 Cfloat, Cdouble, Creal, Void;
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
356
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
357 TypeBasic Size_t; /// The size type.
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
358 TypeBasic Ptrdiff_t; /// The pointer difference type.
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
359 TypePointer Void_ptr; /// The void pointer type.
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
360 TypeBasic Error; /// The error type.
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
361 TypeBasic Undefined; /// The undefined type.
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
362
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
363 /// Allocates an instance of TypeBasic and assigns it to typeName.
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
364 template newTB(char[] typeName)
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
365 {
617
0749f30ef2d0 Added member 'EnumType type' to class Enum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 615
diff changeset
366 const newTB = mixin(typeName~" = new TypeBasic(TYP."~typeName~")");
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
367 }
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
368
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 796
diff changeset
369 /// Initializes predefined types.
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
370 static this()
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
371 {
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
372 newTB!("Char");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
373 newTB!("Wchar");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
374 newTB!("Dchar");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
375 newTB!("Bool");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
376 newTB!("Byte");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
377 newTB!("Ubyte");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
378 newTB!("Short");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
379 newTB!("Ushort");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
380 newTB!("Int");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
381 newTB!("Uint");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
382 newTB!("Long");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
383 newTB!("Ulong");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
384 newTB!("Cent");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
385 newTB!("Ucent");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
386 newTB!("Float");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
387 newTB!("Double");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
388 newTB!("Real");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
389 newTB!("Ifloat");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
390 newTB!("Idouble");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
391 newTB!("Ireal");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
392 newTB!("Cfloat");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
393 newTB!("Cdouble");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
394 newTB!("Creal");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
395 newTB!("Void");
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
396 version(X86_64)
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
397 {
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
398 Size_t = Ulong;
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
399 Ptrdiff_t = Long;
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
400 }
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
401 else
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
402 {
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
403 Size_t = Uint;
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
404 Ptrdiff_t = Int;
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
405 }
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
406 Void_ptr = Void.ptrTo;
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 548
diff changeset
407 Error = new TypeBasic(TYP.Error);
536
0781ac288537 Added some semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 527
diff changeset
408 Undefined = new TypeBasic(TYP.Error);
525
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
409 }
a3f66502ea64 Added struct Types with pre-defined types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 522
diff changeset
410 }