Mercurial > projects > dang
annotate sema/DType.d @ 27:9031487e97d7 new_gen
Various changes related to DType
* Drop the typeToLLVM table from LLVMGen
* Removed circular dependency
* Added basic types to DType
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sun, 20 Apr 2008 01:08:50 +0200 |
parents | b4dc2b2c0e38 |
children | 69464d465284 |
rev | line source |
---|---|
26 | 1 module sema.DType; |
2 | |
3 import tango.text.Util : jhash; | |
4 | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
5 import LLVM = llvm.llvm; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
6 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
7 import lexer.Token, |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
8 ast.Exp; |
26 | 9 |
10 class DType | |
11 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
12 private char[] id; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
13 private Location loc; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
14 public DType actual; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
15 private LLVM.Type llvmType; |
26 | 16 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
17 this(Identifier id, DType actual = null) |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
18 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
19 Token temp = id.token; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
20 this.id = temp.get; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
21 this.loc = temp.location; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
22 if (actual !is null) |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
23 this.actual = this; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
24 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
25 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
26 this(char[] id, DType actual = null) |
26 | 27 { |
28 this.id = id; | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
29 if (actual !is null) |
26 | 30 this.actual = this; |
31 } | |
32 | |
33 int opEquals(Object o) | |
34 { | |
35 if (auto t = cast(DType)o) | |
36 return this.actual is t.actual; | |
37 return 0; | |
38 } | |
39 | |
40 int opCmp(Object o) | |
41 { | |
42 if (auto t = cast(DType)o) | |
43 return cast(void*)this.actual - cast(void*)t.actual; | |
44 return 0; | |
45 } | |
46 | |
47 hash_t toHash() | |
48 { | |
49 return cast(hash_t)(cast(void*)this); | |
50 } | |
51 | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
52 char[] name() { return id; } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
53 LLVM.Type llvm() { return llvmType; } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
54 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
55 static DInteger |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
56 Bool, |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
57 Byte, UByte, Short, UShort, |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
58 Int, UInt, Long, ULong; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
59 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
60 static DType Void; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
61 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
62 static this() |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
63 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
64 Void = new DType("void"); |
26 | 65 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
66 Bool = new DInteger("bool", 1, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
67 Byte = new DInteger("byte", 8, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
68 UByte = new DInteger("ubyte", 8, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
69 Short = new DInteger("short", 16, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
70 UShort = new DInteger("ushort", 16, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
71 Int = new DInteger("int", 32, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
72 UInt = new DInteger("uint", 32, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
73 Long = new DInteger("long", 64, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
74 ULong = new DInteger("ulong", 64, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
75 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
76 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
77 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
78 class DInteger : DType |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
79 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
80 this(char[] name, int bits, bool unsigned) |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
81 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
82 super(name, null); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
83 this.bits = bits; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
84 this.unsigned = unsigned; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
85 llvmType = LLVM.IntegerType.Get(bits); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
86 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
87 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
88 int bits; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
89 bool unsigned; |
26 | 90 } |
91 | |
92 class DStruct : DType | |
93 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
94 this(Identifier id, DType actual = null) |
26 | 95 { |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
96 super(id, actual); |
26 | 97 } |
98 DType[] members; | |
99 } | |
100 | |
101 class DFunction : DType | |
102 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
103 this(Identifier id, DType actual = null) |
26 | 104 { |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
105 super(id, actual); |
26 | 106 } |
107 DType[] params; | |
108 DType return_type; | |
109 } | |
110 |