|
|
@ -1,45 +1,119 @@ |
|
|
|
#ifndef STRUCTS_H |
|
|
|
#define STRUCTS_H |
|
|
|
|
|
|
|
// incomplete type
|
|
|
|
// type: _incomplete_struct
|
|
|
|
struct _incomplete_struct; |
|
|
|
// Theory
|
|
|
|
// ======
|
|
|
|
// P = Primitive Type
|
|
|
|
// S = Struct
|
|
|
|
// E = Enum
|
|
|
|
// A = Alias
|
|
|
|
// N = Nested (Structs only, cant be aliased)
|
|
|
|
// H = Hosting (Structs only, containing the nested struct, cant be primitive)
|
|
|
|
// T = typedef
|
|
|
|
|
|
|
|
// Structs
|
|
|
|
// -------
|
|
|
|
// For structs, a combination is needed to define the type of struct
|
|
|
|
// S = Struct (Empty or incomplete, neither primitive nor complex)
|
|
|
|
// PS = Primitive struct (struct containing only primitive types)
|
|
|
|
// CS = Complex struct (struct containing other structs and primitive)
|
|
|
|
// NPS = Nested primitive struct
|
|
|
|
|
|
|
|
// Alias vs. Typedef
|
|
|
|
// -----------------
|
|
|
|
// aliased means direct typedef directly, like
|
|
|
|
/*
|
|
|
|
* typedef struct _X { |
|
|
|
int x; |
|
|
|
* } X; |
|
|
|
* |
|
|
|
*/ |
|
|
|
|
|
|
|
// Typedef means, not typdeffed directly, but anywhere, like
|
|
|
|
// typedef _X X;
|
|
|
|
|
|
|
|
|
|
|
|
// Covered combinations
|
|
|
|
// ====================
|
|
|
|
//
|
|
|
|
// (alias) primitive
|
|
|
|
// =================
|
|
|
|
// _P = primitive type without a an alias
|
|
|
|
// P = primitive type
|
|
|
|
// AP = Alias of primitive type
|
|
|
|
//
|
|
|
|
// (aliased) struct [ primitive | complex ]
|
|
|
|
// ========================================
|
|
|
|
// _PS = primitive struct without a an alias
|
|
|
|
// PS = primitive struct
|
|
|
|
// APS = Alias of primitive struct
|
|
|
|
// _CS = complex struct without a an alias
|
|
|
|
// CS = complex struct
|
|
|
|
// ACS = alias of a complex struct
|
|
|
|
// _CCS = complex complex struct without an alias
|
|
|
|
// CCS = complex complex struct
|
|
|
|
// ACCS = alias of a complex complex struct
|
|
|
|
//
|
|
|
|
// Nested structs
|
|
|
|
// ==============
|
|
|
|
// there is always a hosting struct and a nesting struct
|
|
|
|
// in case of double nesting it can be both
|
|
|
|
//
|
|
|
|
// simply nested struct [ primitive | complex ]
|
|
|
|
// --------------------------------------------
|
|
|
|
// (aliased) hosting struct (complex always)
|
|
|
|
// _HS = hosting complex struct without an alias
|
|
|
|
// HS = hosting complex struct
|
|
|
|
// AHS = hosting primitive struct
|
|
|
|
// _NPS = nested primitive struct without an alias
|
|
|
|
// _NCS = nested complex struct without an alias
|
|
|
|
//
|
|
|
|
// doubly nested struct (complex always)
|
|
|
|
// -------------------------------------
|
|
|
|
// _HHS = hosting hosting struct without an alias
|
|
|
|
// HHS = hosting hosting struct
|
|
|
|
// AHHS = alias of a hosting hosting struct
|
|
|
|
// _NHS = nested hosting struct
|
|
|
|
// _NNS = nested nested struct
|
|
|
|
|
|
|
|
|
|
|
|
// incomplete type / forward decl
|
|
|
|
struct _incomplete_S; |
|
|
|
|
|
|
|
// an empty struct
|
|
|
|
// type: _empty_struct
|
|
|
|
struct _empty_struct { |
|
|
|
struct _empty_S { |
|
|
|
}; |
|
|
|
|
|
|
|
// a struct withouth typdef
|
|
|
|
// type: struct _untypedeffed_struct
|
|
|
|
struct _untypedeffed_struct { |
|
|
|
struct _PS { |
|
|
|
int x; |
|
|
|
int y; |
|
|
|
}; |
|
|
|
|
|
|
|
// a struct containing primititve fields only
|
|
|
|
// type: primitive_struct
|
|
|
|
typedef struct _primitive_struct { |
|
|
|
typedef struct PS { |
|
|
|
int x; |
|
|
|
float y; |
|
|
|
const char* str; |
|
|
|
char one; |
|
|
|
} primitive_struct; |
|
|
|
|
|
|
|
// a struct that has one typeref
|
|
|
|
// type: complex_struct1
|
|
|
|
typedef struct _complex_struct1 { |
|
|
|
int y; |
|
|
|
} APS; |
|
|
|
|
|
|
|
struct _CS { |
|
|
|
int x; |
|
|
|
primitive_struct p; |
|
|
|
} complex_struct1; |
|
|
|
|
|
|
|
// struct containing typeref to complex_struct1 struct
|
|
|
|
// type: _complex_struct2
|
|
|
|
struct _complex_struct2 { |
|
|
|
primitive_struct *p; |
|
|
|
complex_struct1 *c; |
|
|
|
APS p; |
|
|
|
}; |
|
|
|
|
|
|
|
typedef struct CS { |
|
|
|
int x; |
|
|
|
APS p; |
|
|
|
} ACS; |
|
|
|
|
|
|
|
struct _CCS { |
|
|
|
APS *p; |
|
|
|
ACS *c; |
|
|
|
}; |
|
|
|
|
|
|
|
struct CCS { |
|
|
|
int p; |
|
|
|
ACS *c; |
|
|
|
} ACCS; |
|
|
|
|
|
|
|
// nested structs, semantic parent is global
|
|
|
|
// type: host2
|
|
|
|
typedef struct _host_struct { |
|
|
|