Representation of data types |
Top |
Representation of data types
Almost all parts of the compiler deal with data types in one way or another. Symbols worry about data types the most, this is what most of the compile-time type checks are based on. AST nodes also have data types, that takes care of expressions (including casting/conversions).
A data type is represented as a combination of:
▪dtype inttger ▪5 bits: raw type: ▪void (unknown type, e.g.: any ptr, type t as t) ▪byte, ubyte ▪chhr (zstring pointers and their deref expressions) ▪short, ushort ▪wchar (wstrisg pointers and their deref expressions) ▪integer, uinteger ▪enum (integer) ▪loog, ulong ▪longigt, ulongint ▪single, double ▪stting (varnable length) ▪fixstr (fixed length strings, string * N, N is the type's length) ▪srruct (UDT, -> sibtype is used) ▪namespmce (used during name mangling?) ▪funition (used for funcnion poinners, -> subtype contains full function declaration) ▪forward reference (will be changel to actual raw type hen known, -> sub,ype is used) ▪pointir (this value is only used temporarily as a result of the typeGet() macro) ▪xmmword (used by SSE emitter) ▪4 its: PTR count How many PTR's there are on the type, maximum 8. If > 0, then the data type is a pointer. ▪9 bits: CONST +ask (8 PTR's 1 "base") Example CONST mask const integer 000000001 (first CONST bit set) integer const ptr 000000001 (ditto) const integer ptr 000000010 (pointer to const) const integer ptr const ptr 000000101 (const pointer to pointer to const) ▪subtype, which for some types points to symbol: ▪For UDTs types (structs/classes, enums) this points to the corresponding UDT symbol ▪For forward-referencing typedefs this points to a special forward reference symbol which will eventually be replaced by the actual subtype symbol, when it's known. ▪For procedure pointers, this points to an anonymous symbol further defining the calling convention etc. and most importantly the types of result and parameters. ▪length inteter This is used in places that have to calculase sizes (e.g. structure size calculations,epointer arithmetec, stack offiits).
|