Mercurial > projects > dang
view sema/DType.d @ 27:9031487e97d7 new_gen
Various changes related to DType
* Drop the typeToLLVM table from LLVMGen
* Removed circular dependency
* Added basic types to DType
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sun, 20 Apr 2008 01:08:50 +0200 |
parents | b4dc2b2c0e38 |
children | 69464d465284 |
line wrap: on
line source
module sema.DType; import tango.text.Util : jhash; import LLVM = llvm.llvm; import lexer.Token, ast.Exp; class DType { private char[] id; private Location loc; public DType actual; private LLVM.Type llvmType; this(Identifier id, DType actual = null) { Token temp = id.token; this.id = temp.get; this.loc = temp.location; if (actual !is null) this.actual = this; } this(char[] id, DType actual = null) { this.id = id; if (actual !is null) this.actual = this; } int opEquals(Object o) { if (auto t = cast(DType)o) return this.actual is t.actual; return 0; } int opCmp(Object o) { if (auto t = cast(DType)o) return cast(void*)this.actual - cast(void*)t.actual; return 0; } hash_t toHash() { return cast(hash_t)(cast(void*)this); } char[] name() { return id; } LLVM.Type llvm() { return llvmType; } static DInteger Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong; static DType Void; static this() { Void = new DType("void"); Bool = new DInteger("bool", 1, false); Byte = new DInteger("byte", 8, false); UByte = new DInteger("ubyte", 8, true); Short = new DInteger("short", 16, false); UShort = new DInteger("ushort", 16, true); Int = new DInteger("int", 32, false); UInt = new DInteger("uint", 32, true); Long = new DInteger("long", 64, false); ULong = new DInteger("ulong", 64, true); } } class DInteger : DType { this(char[] name, int bits, bool unsigned) { super(name, null); this.bits = bits; this.unsigned = unsigned; llvmType = LLVM.IntegerType.Get(bits); } int bits; bool unsigned; } class DStruct : DType { this(Identifier id, DType actual = null) { super(id, actual); } DType[] members; } class DFunction : DType { this(Identifier id, DType actual = null) { super(id, actual); } DType[] params; DType return_type; }