Mercurial > projects > dang
annotate sema/DType.d @ 181:59cd211a1bd3
Better support for function pointers
author | Anders Halager <halager@gmail.com> |
---|---|
date | Fri, 25 Jul 2008 01:39:01 +0200 |
parents | 2a1a635bd531 |
children |
rev | line source |
---|---|
26 | 1 module sema.DType; |
2 | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
3 import lexer.Token, |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
4 ast.Exp; |
26 | 5 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
6 public |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
7 import sema.Operation; |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
27
diff
changeset
|
8 |
129 | 9 /// |
26 | 10 class DType |
11 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
12 private char[] id; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
13 private SourceLocation loc; |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
14 public DType actual; |
26 | 15 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
16 this(Identifier id, DType actual = null) |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
17 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
18 this.id = id.name; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
19 this.loc = id.startLoc(); |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
20 this.actual = actual is null? this : actual; |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
21 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
22 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
23 this(char[] id, DType actual = null) |
26 | 24 { |
25 this.id = id; | |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
26 this.actual = actual is null? this : actual; |
26 | 27 } |
28 | |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
29 /// Is this type a DStruct |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
30 bool isStruct() { return false; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
31 /// Return a DStruct if this is one, otherwise return null |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
32 DStruct asStruct() { return null; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
33 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
34 /// Is this type a DClass |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
35 bool isClass() { return false; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
36 /// Return a DClass if this is one, otherwise return null |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
37 DClass asClass() { return null; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
38 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
39 /// Is this type a DInterface |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
40 bool isInterface() { return false; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
41 /// Return a DInterface if this is one, otherwise return null |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
42 DInterface asInterface() { return null; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
43 |
136 | 44 /// Is this type a DStaticArray |
45 bool isStaticArray() { return false; } | |
46 /// Return a DStaticArray if this is one, otherwise return null | |
47 DStaticArray asStaticArray() { return null; } | |
48 | |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
49 /// Is this type a DArray |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
50 bool isArray() { return false; } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
51 /// Return a DArray if this is one, otherwise return null |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
52 DArray asArray() { return null; } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
53 |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
54 /// Is this type a DPointer |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
55 bool isPointer() { return false; } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
56 /// Return a DPointer if this is one, otherwise return null |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
57 DPointer asPointer() { return null; } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
58 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
59 /// Is this type a DFunction |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
60 bool isFunction() { return false; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
61 /// Return a DFunction if this is one, otherwise return null |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
62 DFunction asFunction() { return null; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
63 |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
64 /// Is this type a DFunction or a pointer to one |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
65 bool isCallable() { return false; } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
66 /// Return a DFunction if this one is available |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
67 DFunction asCallable() { return null; } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
68 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
69 /// Returns true for integers, reals and complex numbers |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
70 bool isArithmetic() { return false; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
71 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
72 /// Is this type a DInteger |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
73 bool isInteger() { return false; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
74 /// Return a DInteger if this is one, otherwise return null |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
75 DInteger asInteger() { return null; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
76 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
77 /// Is this type a DReal |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
78 bool isReal() { return false; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
79 /// Return a DReal if this is one, otherwise return null |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
80 DReal asReal() { return null; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
81 |
26 | 82 int opEquals(Object o) |
83 { | |
84 if (auto t = cast(DType)o) | |
85 return this.actual is t.actual; | |
86 return 0; | |
87 } | |
88 | |
89 int opCmp(Object o) | |
90 { | |
91 if (auto t = cast(DType)o) | |
92 return cast(void*)this.actual - cast(void*)t.actual; | |
93 return 0; | |
94 } | |
95 | |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
96 /** |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
97 Hashing is done by casting the reference to a void* and taking that |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
98 value, but this gives a bad distribution of hash-values. |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
99 |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
100 Multiple DType's allocated close to each other will only have a |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
101 difference in the lower bits of their hashes. |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
102 */ |
26 | 103 hash_t toHash() |
104 { | |
105 return cast(hash_t)(cast(void*)this); | |
106 } | |
179
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
107 |
160 | 108 char[] toString() |
109 { | |
110 return id; | |
111 } | |
179
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
112 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
113 char[] name() { return id; } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
114 SourceLocation getLoc() { return loc; } |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
115 int byteSize() { return 0; } |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
116 |
58 | 117 /** |
118 Can this type legally be converted to that type with no casts? | |
119 True for short -> int etc. | |
120 */ | |
121 bool hasImplicitConversionTo(DType that) { return false; } | |
122 | |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
123 /** |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
124 Get an Operation describing how to use the supplied operator on the two |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
125 types given. |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
126 */ |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
127 Operation getOperationWith(Operator op, DType other) |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
128 { |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
129 Operation res; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
130 return res; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
131 } |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
132 |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
133 /** |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
134 Get a type representing a pointer to this type (from int to int*) |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
135 */ |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
136 DPointer getPointerTo() |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
137 { |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
138 if(myPointer !is null) |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
139 return myPointer; |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
140 myPointer = new DPointer(this); |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
141 return myPointer; |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
142 } |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
143 private DPointer myPointer; |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
144 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
145 /** |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
146 Mangle the DType following the specs at http://digitalmars.com/d/1.0/abi.html |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
147 **/ |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
148 char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
149 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
150 /// expects to be void |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
151 return "v"; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
152 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
153 |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
154 /** |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
155 Get a type representing a static array of this type with length 'size' |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
156 */ |
136 | 157 DStaticArray getAsStaticArray(int size) |
81 | 158 { |
136 | 159 if(size in myStaticArray) |
160 return myStaticArray[size]; | |
161 myStaticArray[size] = new DStaticArray(this, size); | |
162 return myStaticArray[size]; | |
81 | 163 } |
136 | 164 private DStaticArray[int] myStaticArray; |
165 | |
166 DArray getAsArray() | |
167 { | |
168 if(myArray !is null) | |
169 return myArray; | |
170 myArray = new DArray(this); | |
171 return myArray; | |
172 } | |
173 private DArray myArray; | |
81 | 174 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
175 bool isSame(DType d) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
176 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
177 return d is this; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
178 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
179 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
180 static DInteger |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
181 Bool, |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
182 Byte, UByte, Short, UShort, |
103
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
183 Int, UInt, Long, ULong, |
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
184 Char, WChar, DChar; |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
185 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
186 static DReal Float, Double, Real; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
187 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
188 // Ignore - we dont support complex numbers yet |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
189 static DReal CFloat, CDouble, CReal; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
190 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
191 static DType Void; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
192 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
193 static this() |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
194 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
195 Void = new DType("void"); |
26 | 196 |
129 | 197 Bool = new DInteger("bool", 1, true); |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
198 Byte = new DInteger("byte", 8, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
199 UByte = new DInteger("ubyte", 8, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
200 Short = new DInteger("short", 16, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
201 UShort = new DInteger("ushort", 16, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
202 Int = new DInteger("int", 32, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
203 UInt = new DInteger("uint", 32, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
204 Long = new DInteger("long", 64, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
205 ULong = new DInteger("ulong", 64, true); |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
206 |
118
54585ad7e426
Added the DType -> llvm type mapping for some more types
Anders Halager <halager@gmail.com>
parents:
116
diff
changeset
|
207 Float = new DReal("float", 32); |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
208 Double = new DReal("double", 64); |
118
54585ad7e426
Added the DType -> llvm type mapping for some more types
Anders Halager <halager@gmail.com>
parents:
116
diff
changeset
|
209 Real = new DReal("real", 80); |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
210 |
103
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
211 Char = new DInteger("char", 8, true); |
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
212 WChar = new DInteger("wchar", 16, true); |
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
213 DChar = new DInteger("dchar", 32, true); |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
214 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
215 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
216 |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
217 /** |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
218 Class to represent the built-in numerical types, from byte to long, reals and |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
219 complex numbers. |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
220 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
221 Should not actually use this, but DInteger, DReal or DComplex. |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
222 */ |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
223 class DArithmetic : DType |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
224 { |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
225 private static char[][DArithmetic] mangle_types; |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
226 |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
227 static this() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
228 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
229 mangle_types = |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
230 [ |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
231 cast(DArithmetic) |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
232 Bool : "b", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
233 Byte : "g", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
234 UByte : "h", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
235 Short : "s", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
236 UShort : "t", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
237 Int : "i", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
238 UInt : "k", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
239 Long : "l", |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
240 ULong : "m", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
241 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
242 Float : "f", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
243 Double : "d", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
244 Real : "e", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
245 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
246 /* |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
247 CFloat : "q", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
248 CDouble : "r", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
249 CReal : "c", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
250 */ |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
251 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
252 Char : "a", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
253 WChar : "u", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
254 DChar : "w" |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
255 ]; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
256 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
257 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
258 this(char[] name, int bits, bool unsigned) |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
259 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
260 super(name, null); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
261 this.bits = bits; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
262 this.unsigned = unsigned; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
263 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
264 |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
265 override int byteSize() { return bits / 8; } |
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
266 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
267 bool isArithmetic() { return true; } |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
268 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
269 override Operation getOperationWith(Operator op, DType that) |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
270 { |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
271 Operation operation; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
272 if (this is that) |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
273 operation = Operation.builtin(op, unsigned, isReal()); |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
274 return operation; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
275 } |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
276 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
277 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
278 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
279 return mangle_types[this]; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
280 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
281 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
282 int bits; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
283 bool unsigned; |
26 | 284 } |
285 | |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
286 class DInteger : DArithmetic |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
287 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
288 this(char[] name, int bits, bool unsigned) |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
289 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
290 super(name, bits, unsigned); |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
291 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
292 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
293 override bool hasImplicitConversionTo(DType that) |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
294 { |
120
7d0898f77685
Implement the cast expression - works for integers and real/float/double
Anders Halager <halager@gmail.com>
parents:
119
diff
changeset
|
295 if (that.isInteger() || that.isReal()) |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
296 return true; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
297 return false; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
298 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
299 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
300 override bool isInteger() { return true; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
301 override DInteger asInteger() { return this; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
302 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
303 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
304 class DReal : DArithmetic |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
305 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
306 this(char[] name, int bits) |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
307 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
308 super(name, bits, false); |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
309 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
310 |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
118
diff
changeset
|
311 override bool hasImplicitConversionTo(DType that) |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
118
diff
changeset
|
312 { |
120
7d0898f77685
Implement the cast expression - works for integers and real/float/double
Anders Halager <halager@gmail.com>
parents:
119
diff
changeset
|
313 if (that.isInteger() || that.isReal()) |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
118
diff
changeset
|
314 return true; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
118
diff
changeset
|
315 return false; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
118
diff
changeset
|
316 } |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
118
diff
changeset
|
317 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
318 override bool isReal() { return true; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
319 override DReal asReal() { return this; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
320 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
321 |
26 | 322 class DStruct : DType |
323 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
324 this(Identifier id, DType actual = null) |
26 | 325 { |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
326 super(id, actual); |
26 | 327 } |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
27
diff
changeset
|
328 |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
329 int byteSize() { return bytes_total; } |
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
330 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
331 override bool isStruct() { return true; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
332 override DStruct asStruct() { return this; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
333 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
334 void addMember(DType type, char[] name) |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
27
diff
changeset
|
335 { |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
336 auto s = DStructMember(type, members.length); |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
337 members[name] = s; |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
27
diff
changeset
|
338 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
339 bytes_total += type.byteSize(); |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
340 } |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
27
diff
changeset
|
341 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
342 int indexOf(char[] name) |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
343 { |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
344 if(name in members) |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
345 return members[name].index; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
346 |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
347 return -1; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
348 } |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
349 |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
350 DType typeOf(char[] name) |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
351 { |
58 | 352 if (auto res = name in members) |
353 return res.type; | |
354 return null; | |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
355 } |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
356 |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
357 DStructMember[char[]] members; |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
358 private int bytes_total; |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
359 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
360 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
361 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
362 return "S"~Integer.toString(name.length)~name; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
363 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
364 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
365 override bool isSame(DType d) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
366 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
367 if (d is this) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
368 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
369 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
370 if (!d.isStruct) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
371 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
372 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
373 auto s = d.asStruct; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
374 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
375 return id == s.id; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
376 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
377 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
378 struct DStructMember |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
379 { |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
380 DType type; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
381 int index; |
132
a101853eaae0
Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents:
129
diff
changeset
|
382 |
a101853eaae0
Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents:
129
diff
changeset
|
383 char[] toString() |
a101853eaae0
Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents:
129
diff
changeset
|
384 { |
a101853eaae0
Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents:
129
diff
changeset
|
385 return type.toString(); |
a101853eaae0
Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents:
129
diff
changeset
|
386 } |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
387 } |
26 | 388 } |
389 | |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
390 class DClass : DType |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
391 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
392 this(Identifier id, DType actual = null) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
393 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
394 super(id, actual); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
395 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
396 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
397 int byteSize() { return bytes_total; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
398 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
399 override bool isClass() { return true; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
400 override DClass asClass() { return this; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
401 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
402 void addMember(DType type, char[] name) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
403 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
404 auto s = DClassMember(type, members.length); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
405 members[name] = s; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
406 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
407 bytes_total += type.byteSize(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
408 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
409 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
410 int indexOf(char[] name) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
411 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
412 if(name in members) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
413 return members[name].index; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
414 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
415 return -1; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
416 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
417 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
418 DType typeOf(char[] name) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
419 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
420 if (auto res = name in members) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
421 return res.type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
422 return null; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
423 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
424 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
425 DClassMember[char[]] members; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
426 private int bytes_total; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
427 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
428 override char[] mangle() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
429 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
430 return "S"~Integer.toString(name.length)~name; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
431 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
432 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
433 override bool isSame(DType d) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
434 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
435 if (d is this) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
436 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
437 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
438 if (!d.isClass) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
439 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
440 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
441 auto c = d.asClass; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
442 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
443 return id == c.id; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
444 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
445 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
446 struct DClassMember |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
447 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
448 DType type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
449 int index; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
450 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
451 char[] toString() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
452 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
453 return type.toString(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
454 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
455 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
456 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
457 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
458 class DInterface : DType |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
459 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
460 this(Identifier id, DType actual = null) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
461 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
462 super(id, actual); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
463 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
464 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
465 int byteSize() { return bytes_total; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
466 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
467 override bool isInterface() { return true; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
468 override DInterface asInterface() { return this; } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
469 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
470 void addMember(DType type, char[] name) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
471 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
472 auto s = DInterfaceMember(type, members.length); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
473 members[name] = s; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
474 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
475 bytes_total += type.byteSize(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
476 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
477 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
478 int indexOf(char[] name) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
479 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
480 if(name in members) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
481 return members[name].index; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
482 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
483 return -1; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
484 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
485 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
486 DType typeOf(char[] name) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
487 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
488 if (auto res = name in members) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
489 return res.type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
490 return null; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
491 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
492 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
493 override bool isSame(DType d) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
494 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
495 if (d is this) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
496 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
497 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
498 if (!d.isInterface) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
499 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
500 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
501 auto i = d.asInterface; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
502 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
503 return id == i.id; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
504 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
505 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
506 DInterfaceMember[char[]] members; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
507 private int bytes_total; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
508 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
509 override char[] mangle() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
510 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
511 return "S"~Integer.toString(name.length)~name; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
512 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
513 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
514 struct DInterfaceMember |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
515 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
516 DType type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
517 int index; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
518 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
519 char[] toString() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
520 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
521 return type.toString(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
522 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
523 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
524 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
525 |
136 | 526 class DStaticArray : DType |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
527 { |
81 | 528 this(DType arrayOf, int size, DType actual = null) |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
529 { |
160 | 530 super(arrayOf.id ~ "[" ~ Integer.toString(size) ~ "]", actual); |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
531 this.arrayOf = arrayOf; |
81 | 532 this.size = size; |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
533 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
534 |
136 | 535 override bool isStaticArray() { return true; } |
536 override DStaticArray asStaticArray() { return this; } | |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
537 |
81 | 538 int byteSize() { return arrayOf.byteSize * size; } |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
539 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
540 override bool isSame(DType d) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
541 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
542 if (d is this) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
543 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
544 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
545 if (!d.isArray) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
546 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
547 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
548 auto a = d.asStaticArray; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
549 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
550 if (size != a.size) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
551 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
552 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
553 return arrayOf.isSame(a.arrayOf); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
554 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
555 |
179
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
556 char[] toString() |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
557 { |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
558 return arrayOf.toString~"["~Integer.toString(size)~"]"; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
559 } |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
560 |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
561 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
562 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
563 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
564 return "G"~Integer.toString(size)~arrayOf.mangle; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
565 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
566 |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
567 DType arrayOf; |
81 | 568 const int size; |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
569 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
570 |
136 | 571 class DArray : DType |
572 { | |
573 this(DType arrayOf, DType actual = null) | |
574 { | |
575 super(id, actual); | |
576 this.arrayOf = arrayOf; | |
577 } | |
578 | |
579 override bool isArray() { return true; } | |
580 override DArray asArray() { return this; } | |
581 | |
582 int byteSize() { return 8; } // FIXME: Size is a pointer + on size. (platform depend) | |
583 | |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
584 override bool isSame(DType d) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
585 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
586 if (d is this) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
587 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
588 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
589 if (!d.isArray) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
590 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
591 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
592 auto a = d.asArray; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
593 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
594 return arrayOf.isSame(a.arrayOf); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
595 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
596 |
136 | 597 override char[] mangle() |
598 { | |
599 return "G"~arrayOf.mangle; // FIXME: Need correct mangling | |
600 } | |
601 | |
602 DType arrayOf; | |
603 } | |
604 | |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
605 class DPointer : DType |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
606 { |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
607 this(DType pointerOf, DType actual = null) |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
608 { |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
609 super(id, actual); |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
610 this.pointerOf = pointerOf; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
611 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
612 |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
613 override bool isPointer() { return true; } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
614 override DPointer asPointer() { return this; } |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
615 bool isCallable() { return pointerOf.isFunction(); } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
616 DFunction asCallable() { return pointerOf.asFunction(); } |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
617 |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
618 int byteSize() { return DType.Int.byteSize; } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
619 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
620 override bool isSame(DType d) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
621 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
622 if (d is this) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
623 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
624 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
625 if (!d.isPointer) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
626 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
627 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
628 auto p = d.asPointer; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
629 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
630 return pointerOf.isSame(p.pointerOf); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
631 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
632 |
179
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
633 char[] toString() |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
634 { |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
635 if (!pointerOf.isFunction) |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
636 return pointerOf.toString~"*"; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
637 |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
638 auto f = pointerOf.asFunction; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
639 |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
640 char[] res = f.returnType.toString~" function("; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
641 |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
642 foreach (i, p ; f.params) |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
643 res ~= i ? ", "~p.toString : p.toString; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
644 |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
645 return res ~ ")"; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
646 } |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
647 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
648 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
649 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
650 return "P"~pointerOf.mangle; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
651 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
652 |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
653 DType pointerOf; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
654 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
655 |
26 | 656 class DFunction : DType |
657 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
658 this(Identifier id, DType actual = null) |
26 | 659 { |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
660 super(id, actual); |
26 | 661 } |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
662 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
663 override bool isFunction() { return true; } |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
664 override DFunction asFunction() { return this; } |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
665 bool isCallable() { return true; } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
666 DFunction asCallable() { return this; } |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
667 |
136 | 668 override bool hasImplicitConversionTo(DType that) |
669 { | |
670 return returnType.hasImplicitConversionTo(that); | |
671 } | |
672 | |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
673 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
674 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
675 char[] res; |
129 | 676 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
677 res ~= "F"; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
678 |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
679 foreach(param ; params) |
129 | 680 res ~= param.mangle; |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
681 |
129 | 682 res ~= "Z"; |
683 res ~= returnType.mangle; | |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
684 |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
685 return res; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
686 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
687 |
179
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
688 char[] toString() |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
689 { |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
690 char[] res = returnType.toString~" ("; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
691 |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
692 foreach (i, p ; params) |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
693 res ~= i ? ", "~p.toString : p.toString; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
694 |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
695 return res ~ ")"; |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
696 } |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
697 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
698 override bool isSame(DType f) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
699 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
700 if (f is this) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
701 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
702 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
703 if (!f.isFunction) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
704 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
705 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
706 auto func = f.asFunction; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
707 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
708 if (returnType != func.returnType) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
709 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
710 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
711 if (params.length != func.params.length) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
712 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
713 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
714 foreach (i, p ; params) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
715 if (!p.isSame(func.params[0])) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
716 return false; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
717 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
718 return true; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
719 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
720 |
26 | 721 DType[] params; |
63
9f8131676242
Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents:
58
diff
changeset
|
722 DType returnType; |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
723 bool firstParamIsReturnValue = false; |
26 | 724 } |
725 |