Mercurial > projects > dil
diff trunk/src/dil/semantic/Types.d @ 798:c24be8d4f6ab
Added documentation comments.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 01 Mar 2008 02:53:06 +0100 |
parents | f7688996bf08 |
children | 9e6c6bb73e5f |
line wrap: on
line diff
--- a/trunk/src/dil/semantic/Types.d Fri Feb 29 22:51:24 2008 +0100 +++ b/trunk/src/dil/semantic/Types.d Sat Mar 01 02:53:06 2008 +0100 @@ -9,6 +9,7 @@ import dil.lexer.Identifier; import dil.CompilerInfo; +/// The base type for all type structures. abstract class Type/* : Symbol*/ { Type next; /// The next type in the type structure. @@ -17,6 +18,10 @@ this(){} + /// Constructs a Type object. + /// Params: + /// next = the type's next type. + /// tid = the type's ID. this(Type next, TYP tid) { // this.sid = SYM.Type; @@ -25,12 +30,13 @@ this.tid = tid; } + /// Returns a pointer type to this type. TypePointer ptrTo() { return new TypePointer(this); } - /// Get byte size of this type. + /// Returns the byte size of this type. final size_t sizeOf() { return MITable.getSize(this); @@ -42,12 +48,14 @@ return sizeOf(); } + /// Returns true if this type has a symbol. bool hasSymbol() { return symbol !is null; } } +/// All basic types. E.g.: int, char, real etc. class TypeBasic : Type { this(TYP typ) @@ -56,7 +64,7 @@ } } -/// Dynamic array. +/// Dynamic array type. class TypeDArray : Type { this(Type next) @@ -65,7 +73,7 @@ } } -/// Associative array. +/// Associative array type. class TypeAArray : Type { Type keyType; @@ -76,7 +84,7 @@ } } -/// Static array. +/// Static array type. class TypeSArray : Type { size_t dimension; @@ -87,6 +95,7 @@ } } +/// Pointer type. class TypePointer : Type { this(Type next) @@ -95,6 +104,7 @@ } } +/// Reference type. class TypeReference : Type { this(Type next) @@ -103,6 +113,7 @@ } } +/// Enum type. class TypeEnum : Type { this(Symbol symbol, Type baseType) @@ -117,6 +128,7 @@ } } +/// Struct type. class TypeStruct : Type { this(Symbol symbol) @@ -126,6 +138,7 @@ } } +/// Class type. class TypeClass : Type { this(Symbol symbol) @@ -135,6 +148,7 @@ } } +/// Typedef type. class TypeTypedef : Type { this(Type next) @@ -143,6 +157,7 @@ } } +/// Function type. class TypeFunction : Type { this(Type next) @@ -151,6 +166,7 @@ } } +/// Delegate type. class TypeDelegate : Type { this(Type next) @@ -159,6 +175,7 @@ } } +/// Identifier type. class TypeIdentifier : Type { Identifier* ident; @@ -168,6 +185,7 @@ } } +/// Template instantiation type. class TypeTemplInstance : Type { this() @@ -176,6 +194,7 @@ } } +/// Template tuple type. class TypeTuple : Type { this(Type next) @@ -184,6 +203,7 @@ } } +/// Constant type. D2.0 class TypeConst : Type { this(Type next) @@ -192,6 +212,7 @@ } } +/// Invariant type. D2.0 class TypeInvariant : Type { this(Type next) @@ -200,7 +221,7 @@ } } -/// Represents a value related to a type. +/// Represents a value related to a Type. union Value { void* pvoid; @@ -216,6 +237,7 @@ creal creal_; } +/// Information related to a Type. struct TypeMetaInfo { char mangle; /// Mangle character of the type. @@ -223,6 +245,7 @@ Value* defaultInit; /// Default initialization value. } +/// Namespace for the meta info table. struct MITable { static: @@ -236,6 +259,7 @@ const Value VCNAN = {creal_:creal.nan}; /// Value complex NAN. private alias SIZE_NOT_AVAILABLE SNA; private alias PTR_SIZE PS; + /// The meta info table. private const TypeMetaInfo metaInfoTable[] = [ {'?', SNA}, // Error @@ -286,6 +310,7 @@ ]; static assert(metaInfoTable.length == TYP.max+1); + /// Returns the size of a type. size_t getSize(Type type) { auto size = metaInfoTable[type.tid].size; @@ -295,10 +320,11 @@ } } -/// A set of pre-defined types. +/// Namespace for a set of predefined types. struct Types { static: + /// Predefined basic types. TypeBasic Char, Wchar, Dchar, Bool, Byte, Ubyte, Short, Ushort, Int, Uint, Long, Ulong, @@ -307,9 +333,11 @@ Ifloat, Idouble, Ireal, Cfloat, Cdouble, Creal, Void; - TypeBasic Size_t, Ptrdiff_t; - TypePointer Void_ptr; - TypeBasic Error, Undefined; + TypeBasic Size_t; /// The size type. + TypeBasic Ptrdiff_t; /// The pointer difference type. + TypePointer Void_ptr; /// The void pointer type. + TypeBasic Error; /// The error type. + TypeBasic Undefined; /// The undefined type. /// Allocates an instance of TypeBasic and assigns it to typeName. template newTB(char[] typeName) @@ -317,6 +345,7 @@ const newTB = mixin(typeName~" = new TypeBasic(TYP."~typeName~")"); } + /// Initializes predefined types. static this() { newTB!("Char");