You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

132 lines
2.8 KiB

#ifndef STRUCTS_H
#define STRUCTS_H
// 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
struct _empty_S {
};
struct _PS {
int x;
int y;
};
typedef struct PS {
int x;
int y;
} APS;
struct _CS {
int x;
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 {
int x;
int y;
// type: _nested_struct
struct _nested_struct {
int x;
int y;
} nested1;
} host_struct;
typedef struct _nested_struct nested_struct;
#endif //STRUCTS_H