MWCC/includes/compiler/types.h

423 lines
11 KiB
C
Raw Permalink Normal View History

2022-10-25 19:30:28 +00:00
#ifndef COMPILER_TYPES_H
#define COMPILER_TYPES_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef enum TypeType {
TYPEVOID = 0,
TYPEINT,
TYPEFLOAT,
TYPEENUM,
TYPESTRUCT,
TYPECLASS,
TYPEFUNC,
TYPEBITFIELD,
TYPELABEL,
TYPETEMPLATE,
TYPEMEMBERPOINTER,
TYPEPOINTER,
TYPEARRAY,
TYPEOBJCID,
TYPETEMPLDEPEXPR,
TYPEILLEGAL = -1
} TypeType;
/// Common fields across all kinds of types
struct Type {
TypeType type;
SInt32 size;
};
typedef enum IntegralType {
IT_BOOL = 0,
IT_CHAR = 1,
IT_SCHAR = 2,
IT_UCHAR = 3,
IT_WCHAR_T = 4,
IT_SHORT = 5,
IT_USHORT = 6,
IT_INT = 7,
IT_UINT = 8,
IT_LONG = 9,
IT_ULONG = 10,
IT_LONGLONG = 11,
IT_ULONGLONG = 12,
IT_FLOAT = 13,
IT_SHORTDOUBLE = 14,
IT_DOUBLE = 15,
IT_LONGDOUBLE = 16,
IT_17 = 17,
IT_18 = 18,
IT_19 = 19,
IT_20 = 20,
IT_21 = 21,
IT_22 = 22,
IT_23 = 23,
IT_24 = 24
2022-10-25 19:30:28 +00:00
} IntegralType;
// This is probably actually called AtomType / TypeAtom
2022-10-25 19:30:28 +00:00
struct TypeIntegral {
TypeType type;
SInt32 size;
unsigned char integral;
};
2023-01-20 11:56:38 +00:00
struct TypeEnum {
2022-10-25 19:30:28 +00:00
TypeType type;
SInt32 size;
NameSpace *nspace;
ObjEnumConst *enumlist;
Type *enumtype;
HashNameNode *enumname;
};
struct TypeStruct {
TypeType type;
SInt32 size;
HashNameNode *name;
StructMember *members;
char stype;
SInt16 align;
};
struct StructMember {
StructMember *next;
Type *type;
HashNameNode *name;
SInt32 offset;
UInt32 qual;
};
2023-01-11 22:29:53 +00:00
enum {
2022-10-25 19:30:28 +00:00
STRUCT_TYPE_STRUCT = 0,
STRUCT_TYPE_UNION = 1,
2022-11-07 03:06:21 +00:00
STRUCT_TYPE_CLASS = 2,
STRUCT_TYPE_MAX = 3,
STRUCT_VECTOR_UCHAR = 4,
STRUCT_VECTOR_SCHAR = 5,
STRUCT_VECTOR_BCHAR = 6,
STRUCT_VECTOR_USHORT = 7,
STRUCT_VECTOR_SSHORT = 8,
STRUCT_VECTOR_BSHORT = 9,
STRUCT_VECTOR_UINT = 10,
STRUCT_VECTOR_SINT = 11,
STRUCT_VECTOR_BINT = 12,
STRUCT_VECTOR_FLOAT = 13,
STRUCT_VECTOR_PIXEL = 14
2023-01-11 22:29:53 +00:00
};
2022-10-25 19:30:28 +00:00
2023-01-20 11:56:38 +00:00
struct ClassList {
2022-11-07 03:06:21 +00:00
ClassList *next;
2022-10-25 19:30:28 +00:00
TypeClass *base;
SInt32 offset;
SInt32 voffset;
AccessType access;
Boolean is_virtual;
2022-11-07 03:06:21 +00:00
};
2022-10-25 19:30:28 +00:00
2023-01-20 11:56:38 +00:00
struct VClassList {
2022-11-07 03:06:21 +00:00
VClassList *next;
2022-10-25 19:30:28 +00:00
TypeClass *base;
2023-01-10 11:05:21 +00:00
SInt32 offset; // offset within the class instance
SInt32 voffset; // offset within the vtable
2022-10-25 19:30:28 +00:00
Boolean has_override;
2022-11-07 03:06:21 +00:00
};
2022-10-25 19:30:28 +00:00
2023-01-20 11:56:38 +00:00
typedef struct ClassFriend {
2022-10-25 19:30:28 +00:00
struct ClassFriend *next;
union {
TypeClass *theclass;
Object *obj;
} u;
Boolean isclass;
} ClassFriend;
2023-01-20 11:56:38 +00:00
struct BClassList {
2022-10-25 19:30:28 +00:00
struct BClassList *next;
Type *type;
};
2023-01-20 11:56:38 +00:00
typedef struct VTable {
2022-10-25 19:30:28 +00:00
Object *object;
TypeClass *owner;
SInt32 offset;
SInt32 size;
} VTable;
struct TypeClass {
TypeType type;
SInt32 size;
NameSpace *nspace;
HashNameNode *classname;
ClassList *bases;
VClassList *vbases;
ObjMemberVar *ivars;
ClassFriend *friends;
VTable *vtable;
SOMInfo *sominfo;
ObjCInfo *objcinfo;
UInt16 flags;
SInt8 mode;
SInt8 action;
SInt16 align;
UInt8 eflags;
};
2022-11-07 03:06:21 +00:00
typedef enum {
2023-01-20 11:56:38 +00:00
CLASS_MODE_STRUCT = 0,
CLASS_MODE_UNION = 1,
CLASS_MODE_CLASS = 2
2022-11-07 03:06:21 +00:00
} ClassMode;
2022-10-25 19:30:28 +00:00
enum {
2023-01-20 11:56:38 +00:00
CLASS_HANDLEOBJECT = 1, // class is a HandleObject
CLASS_COMPLETED = 2, // completed class?
CLASS_ABSTRACT = 8,
CLASS_SINGLE_OBJECT = 0x10, // inherits from SingleObject/SingleInheritance
CLASS_HAS_VBASES = 0x20,
CLASS_IS_CONVERTIBLE = 0x40, // defines at least one conversion function
CLASS_IS_TEMPL = 0x100, // is TemplClass
CLASS_IS_TEMPL_INST = 0x800, // is TemplClassInst
CLASS_IS_TEMPL_ANY = CLASS_IS_TEMPL | CLASS_IS_TEMPL_INST,
CLASS_EMPTY = 0x1000, // is 0 bytes (forced to 1 byte for ABI reasons)
CLASS_COM_OBJECT = 0x2000, // inherits from __comobject
2022-11-07 03:06:21 +00:00
CLASS_FLAGS_8000 = 0x8000
2022-10-25 19:30:28 +00:00
};
2022-11-07 03:06:21 +00:00
/// maps to TypeClass::eflags
enum {
CLASS_EFLAGS_INTERNAL = 1,
CLASS_EFLAGS_IMPORT = 2,
2023-01-10 11:05:21 +00:00
CLASS_EFLAGS_EXPORT = 4,
CLASS_EFLAGS_F0 = 0xF0
2022-11-07 03:06:21 +00:00
};
enum {
CLASS_ACTION_0 = 0,
CLASS_ACTION_1 = 1,
CLASS_ACTION_2 = 2,
CLASS_ACTION_3 = 3 // __javaobject
};
2022-10-25 19:30:28 +00:00
2022-12-29 12:32:55 +00:00
struct ExceptSpecList {
ExceptSpecList *next;
2022-10-25 19:30:28 +00:00
Type *type;
UInt32 qual;
2022-12-29 12:32:55 +00:00
};
2022-10-25 19:30:28 +00:00
struct FuncArg { // ok
struct FuncArg *next;
HashNameNode *name;
ENode *dexpr;
Type *type;
UInt32 qual;
SInt16 sclass;
Boolean is_array;
};
struct TypeFunc {
TypeType type;
SInt32 size;
FuncArg *args;
ExceptSpecList *exspecs;
Type *functype;
UInt32 qual;
UInt32 flags;
};
2023-01-20 11:56:38 +00:00
// TypeFunc::flags
2022-10-25 19:30:28 +00:00
enum {
2023-01-20 11:56:38 +00:00
FUNC_PASCAL = 1,
FUNC_DEFINED = 2, // does the function have a body?
2022-11-07 03:06:21 +00:00
FUNC_FLAGS_4 = 4,
2023-01-20 11:56:38 +00:00
FUNC_PURE = 8, // abstract
FUNC_METHOD = 0x10,
2022-12-29 12:32:55 +00:00
FUNC_FLAGS_20 = 0x20,
2023-01-20 11:56:38 +00:00
FUNC_CONVERSION = 0x40, // func that's like "operator SomeOtherType()"
2022-11-07 03:06:21 +00:00
FUNC_FLAGS_80 = 0x80,
2023-01-20 11:56:38 +00:00
FUNC_AUTO_GENERATED = 0x100, // an auto-generated ctor, dtor or assignment operator
FUNC_INTRINSIC = 0x200,
FUNC_NOTHROW = 0x400,
2022-12-29 12:32:55 +00:00
FUNC_FLAGS_800 = 0x800, // autoinlined?
2023-01-20 11:56:38 +00:00
FUNC_IS_CTOR = 0x1000, // is ctor
FUNC_IS_DTOR = 0x2000, // is dtor
FUNC_OBJC_METHOD = 0x4000,
FUNC_CONST = 0x8000,
FUNC_VOLATILE = 0x10000,
FUNC_FLAGS_CV = FUNC_CONST | FUNC_VOLATILE,
FUNC_IS_TEMPL = 0x100000, // the definition of a template
2022-12-29 12:32:55 +00:00
FUNC_FLAGS_200000 = 0x200000,
2023-01-10 11:05:21 +00:00
FUNC_FLAGS_400000 = 0x400000, // covariant?
2023-01-20 11:56:38 +00:00
FUNC_IS_TEMPL_INSTANCE = 0x800000, // a concrete instance of a template
FUNC_IS_TEMPL_ANY = FUNC_IS_TEMPL | FUNC_IS_TEMPL_INSTANCE,
2022-11-07 03:06:21 +00:00
FUNC_FLAGS_4000000 = 0x4000000,
FUNC_FLAGS_10000000 = 0x10000000,
2023-01-20 11:56:38 +00:00
FUNC_CALL_CONV_MASK = 0xF0000000 | FUNC_PASCAL
2022-10-25 19:30:28 +00:00
};
struct TypeMemberFunc {
2022-10-25 19:30:28 +00:00
TypeType type;
SInt32 size;
FuncArg *args;
ExceptSpecList *exspecs;
Type *functype;
UInt32 qual;
UInt32 flags;
TypeClass *theclass;
2023-01-20 11:56:38 +00:00
SInt32 vtbl_index; // index of this method within the vtable
SInt32 funcid; // ID used for tracking this method within browse data
Boolean is_static; // is static
2022-10-25 19:30:28 +00:00
};
struct TypeBitfield {
TypeType type;
SInt32 size;
Type *bitfieldtype;
2023-01-20 11:56:38 +00:00
char offset; // offset in bits
char bitlength; // size in bits
2022-10-25 19:30:28 +00:00
};
typedef enum TypeTemplDepType {
TEMPLDEP_ARGUMENT,
TEMPLDEP_QUALNAME,
TEMPLDEP_TEMPLATE,
TEMPLDEP_ARRAY,
TEMPLDEP_QUALTEMPL,
2023-01-20 11:56:38 +00:00
TEMPLDEP_BITFIELD
2022-10-25 19:30:28 +00:00
} TypeTemplDepType;
struct TypeTemplDep {
TypeType type;
SInt32 size;
TypeTemplDepType dtype;
union {
TemplParamID pid;
struct {
TypeTemplDep *type;
HashNameNode *name;
} qual;
struct {
TemplClass *templ;
TemplArg *args;
} templ;
struct {
Type *type;
ENode *index;
} array;
struct {
TypeTemplDep *type;
TemplArg *args;
} qualtempl;
struct {
Type *type;
ENode *size;
} bitfield;
} u;
};
struct TypeMemberPointer {
TypeType type;
SInt32 size;
Type *ty1;
Type *ty2;
UInt32 qual;
};
/// Used for TYPEPOINTER and TYPEARRAY
struct TypePointer {
TypeType type;
SInt32 size;
Type *target;
UInt32 qual;
};
2023-01-20 11:56:38 +00:00
/// Always has Q_IS_OBJC_ID set
2022-12-29 12:32:55 +00:00
struct TypeObjCID {
TypePointer pointer;
ObjCProtocolList *protocols;
short x12;
};
2022-10-25 19:30:28 +00:00
2022-11-07 03:06:21 +00:00
struct TypeList {
TypeList *next;
Type *type;
};
2022-10-25 19:30:28 +00:00
// Not sure if these existed originally, but they'll help
2022-11-07 03:06:21 +00:00
#define TYPE(ty) ((Type *) (ty))
2022-10-25 19:30:28 +00:00
#define TYPE_INTEGRAL(ty) ((TypeIntegral *) (ty))
#define TYPE_ENUM(ty) ((TypeEnum *) (ty))
#define TYPE_STRUCT(ty) ((TypeStruct *) (ty))
#define TYPE_CLASS(ty) ((TypeClass *) (ty))
#define TYPE_FUNC(ty) ((TypeFunc *) (ty))
#define TYPE_METHOD(ty) ((TypeMemberFunc *) (ty))
2022-10-25 19:30:28 +00:00
#define TYPE_BITFIELD(ty) ((TypeBitfield *) (ty))
#define TYPE_TEMPLATE(ty) ((TypeTemplDep *) (ty))
#define TYPE_MEMBER_POINTER(ty) ((TypeMemberPointer *) (ty))
#define TYPE_POINTER(ty) ((TypePointer *) (ty))
#define TPTR_TARGET(ty) (TYPE_POINTER(ty)->target)
#define TPTR_QUAL(ty) (TYPE_POINTER(ty)->qual)
2022-12-29 12:32:55 +00:00
#define TYPE_OBJC_ID(ty) ((TypeObjCID *) (ty))
2022-10-25 19:30:28 +00:00
2022-11-07 03:06:21 +00:00
#define IS_TYPE_VOID(ty) ( (ty)->type == TYPEVOID )
#define IS_TYPE_INT(ty) ( (ty)->type == TYPEINT )
#define IS_TYPE_ENUM(ty) ( (ty)->type == TYPEENUM )
#define IS_TYPE_INT_OR_ENUM(ty) ( IS_TYPE_INT(ty) || IS_TYPE_ENUM(ty) )
#define IS_TYPE_FLOAT(ty) ( (ty)->type == TYPEFLOAT )
#define IS_TYPE_INT_OR_FLOAT(ty) ( IS_TYPE_INT(ty) || IS_TYPE_FLOAT(ty) )
2022-11-07 03:06:21 +00:00
#define IS_TYPE_STRUCT(ty) ( (ty)->type == TYPESTRUCT )
#define IS_TYPE_CLASS(ty) ( (ty)->type == TYPECLASS )
2023-01-10 11:05:21 +00:00
#define IS_TYPE_SOM_CLASS(ty) ( (ty)->type == TYPECLASS && TYPE_CLASS((ty))->sominfo )
2022-12-29 12:32:55 +00:00
#define IS_TYPE_OBJC_CLASS(ty) ( (ty)->type == TYPECLASS && TYPE_CLASS((ty))->objcinfo )
2022-11-07 03:06:21 +00:00
#define IS_TYPE_FUNC(ty) ( (ty)->type == TYPEFUNC )
2023-01-20 11:56:38 +00:00
#define IS_TYPEFUNC_METHOD(ty) ( (ty)->flags & FUNC_METHOD )
#define IS_TYPE_METHOD(ty) ( IS_TYPE_FUNC(ty) && IS_TYPEFUNC_METHOD(TYPE_FUNC(ty)) )
2023-01-10 11:05:21 +00:00
#define IS_TYPE_NONMETHOD(ty) ( IS_TYPE_FUNC(ty) && !IS_TYPEFUNC_METHOD(TYPE_FUNC(ty)) )
2023-01-20 11:56:38 +00:00
#define IS_TYPE_NONSTATIC_METHOD(ty) ( IS_TYPE_FUNC(ty) && IS_TYPEFUNC_METHOD(TYPE_FUNC(ty)) && !TYPE_METHOD(ty)->is_static )
#define IS_TYPE_STATIC_METHOD(ty) ( IS_TYPE_FUNC(ty) && IS_TYPEFUNC_METHOD(TYPE_FUNC(ty)) && TYPE_METHOD(ty)->is_static )
#define IS_TYPEFUNC_NONSTATIC_METHOD(ty) ( IS_TYPEFUNC_METHOD(ty) && !TYPE_METHOD(ty)->is_static )
#define IS_TYPEFUNC_STATIC_METHOD(ty) ( IS_TYPEFUNC_METHOD(ty) && TYPE_METHOD(ty)->is_static )
2022-11-07 03:06:21 +00:00
#define IS_TYPE_TEMPLATE(ty) ( (ty)->type == TYPETEMPLATE )
#define IS_TYPE_POINTER(ty) ( (ty)->type == TYPEPOINTER || (ty)->type == TYPEARRAY )
#define IS_TYPE_POINTER_ONLY(ty) ( (ty)->type == TYPEPOINTER )
#define IS_TYPE_REFERENCE(ty) ( (ty)->type == TYPEPOINTER && (TYPE_POINTER(ty)->qual & Q_REFERENCE) )
#define IS_TYPEPOINTER_REFERENCE(ty) ( (ty)->qual & Q_REFERENCE )
#define IS_TYPE_ARRAY(ty) ( (ty)->type == TYPEARRAY )
#define IS_TYPE_BITFIELD(ty) ( (ty)->type == TYPEBITFIELD )
#define IS_TYPE_TEMPLDEPEXPR(ty) ( (ty)->type == TYPETEMPLDEPEXPR )
#define IS_TYPESTRUCT_VECTOR(ty) ( (ty)->stype >= STRUCT_VECTOR_UCHAR && (ty)->stype <= STRUCT_VECTOR_PIXEL )
2022-11-07 03:06:21 +00:00
#define IS_TYPE_VECTOR(ty) ( (ty)->type == TYPESTRUCT && IS_TYPESTRUCT_VECTOR(TYPE_STRUCT(ty)) )
#define IS_TYPE_NONVECTOR_STRUCT(ty) ( (ty)->type == TYPESTRUCT && !IS_TYPESTRUCT_VECTOR(TYPE_STRUCT(ty)) )
#define IS_TYPE_MEMBERPOINTER(ty) ( (ty)->type == TYPEMEMBERPOINTER )
#define IS_TYPE_4BYTES_MEMBERPOINTER(ty) ( ((ty)->type == TYPEMEMBERPOINTER) && ((ty)->size == 4u) )
#define IS_TYPE_12BYTES_MEMBERPOINTER(ty) ( ((ty)->type == TYPEMEMBERPOINTER) && ((ty)->size == 12u) )
#define TYPE_FITS_IN_REGISTER(ty) ( ((ty)->type == TYPEINT) || ((ty)->type == TYPEENUM) || (IS_TYPE_POINTER(ty) && ((ty)->type != TYPEARRAY)) || IS_TYPE_4BYTES_MEMBERPOINTER(ty) )
#define TYPE_IS_8BYTES(ty) ( (((ty)->type == TYPEINT) || ((ty)->type == TYPEENUM)) && ((ty)->size == 8) )
#define TYPE_FITS_IN_REGISTER_2(ty) ( ((ty)->type == TYPEINT) || ((ty)->type == TYPEENUM) || IS_TYPE_POINTER(ty) || IS_TYPE_4BYTES_MEMBERPOINTER(ty) )
2022-11-07 03:06:21 +00:00
#define OBJ_GET_TARGET_VOLATILE(obj) ( IS_TYPE_POINTER((obj)->type) ? (TYPE_POINTER((obj)->type)->qual & Q_VOLATILE) : ((obj)->qual & Q_VOLATILE) )
#define OBJ_GET_TARGET_CONST(obj) ( IS_TYPE_POINTER((obj)->type) ? (TYPE_POINTER((obj)->type)->qual & Q_CONST) : ((obj)->qual & Q_CONST) )
2022-10-25 19:30:28 +00:00
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif