summaryrefslogtreecommitdiff
path: root/includes/compiler/templates.h
blob: 227dd7b093fc6fe604cebe56fff2317e1e00bf0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#ifndef COMPILER_TEMPLATES_H
#define COMPILER_TEMPLATES_H

#include "compiler/common.h"
#include "compiler/types.h"
#include "compiler/tokens.h"

#ifdef __MWERKS__
#pragma options align=mac68k
#endif

typedef struct PackedDeclInfo { // ok
    Type *thetype;
    UInt32 qual;
    NameSpace *nspace;
    HashNameNode *name;
    TemplArg *expltargs;
    SInt16 storageclass;
    Section section;
    UInt8 exportflags;
    Boolean has_expltargs;
} PackedDeclInfo;

struct Template {
    Template *parent;
    TemplInstance *parentinst;
    TemplParam *params;
    Boolean is_class;
};

struct TemplateFriend { // verified via CPrec
    PackedDeclInfo decl;
    FileOffsetInfo fileoffset;
    TStream stream;
};

struct TemplateMember { // verified via CPrec
    struct TemplateMember *next;
    TemplParam *params;
    Object *object;
    FileOffsetInfo fileoffset;
    TStream stream;
    CPrepFileInfo *srcfile;
    SInt32 startoffset;
    SInt32 endoffset;
};

struct TemplInstance {
    // Template *templ;
    TemplInstance *parent;
    TemplArg *args;
    Boolean is_instantiated;
    Boolean is_specialized;
    Boolean is_extern;
    Boolean static_instantiated;
};
/*
struct __attribute__((packed)) TemplInstance
{
  Template *templ;
  TemplInstance *parent;
  TemplArg *args;
  unsigned __int8 is_instantiated;
  unsigned __int8 is_specialized;
  unsigned __int8 is_extern;
  unsigned __int8 static_instantiated;
};

 */

struct TemplParam { // verified via CPrec
    TemplParam *next;
    HashNameNode *name;
    TemplParamID pid;
    union {
        struct {
            Type *type;
            UInt32 qual;
        } typeparam;
        struct {
            Type *type;
            UInt32 qual;
            ENode *defaultarg;
        } paramdecl;
        struct {
            TemplParam *plist;
            Type *defaultarg;
        } templparam;
    } data;
};

struct TemplArg { // verified by CPrec
    TemplArg *next;
    TemplParamID pid;
    union {
        struct {
            Type *type;
            UInt32 qual;
        } typeparam;
        struct {
            ENode *expr;
            Boolean is_ref;
        } paramdecl;
        Type *ttargtype;
    } data;
    Boolean is_deduced;
};

struct TemplPartialSpec { // confirmed via CPrec (but templ might be a different type?)
    TemplPartialSpec *next;
    TemplClass *templ;
    TemplArg *args;
};

struct TemplStack {
    TemplStack *next;
    union {
        Object *func;
        TypeClass *theclass;
    } u;
    Boolean is_func;
    Boolean is_poi;
};

/***********/
/* Classes */
/***********/

struct TemplClass {
    TypeClass theclass;
    TemplClass *next;
    TemplClass *templ__parent;
    Type *x3A_maybe_parentinst;
    TemplParam *templ__params;
    TemplateMember *members;
    TemplClassInst *instances;
    TemplClass *pspec_owner;
    TemplPartialSpec *pspecs;
    TemplateAction *actions;
    // not confirmed these last 3 fields yet but there is space for them
    UInt16 lex_order_count;
    SInt8 align;
    UInt8 flags;
};

enum {
    TEMPLCLASS_FLAGS_2 = 2
};

struct TemplClassInst {
    TypeClass theclass;
    TemplClassInst *next;
    Type *x36; // not sure what this represents
    TemplClass *templ;
    TemplArg *inst_args;
    TemplArg *oargs;
    Boolean x46;
    Boolean x47;
};

#define TEMPL_CLASS(ty) ( (TemplClass *) (ty) )
#define TEMPL_CLASS_INST(ty) ( (TemplClassInst *) (ty) )
#define IS_TEMPL_CLASS(ty) ( IS_TYPE_CLASS(ty) && (TYPE_CLASS(ty)->flags & CLASS_FLAGS_100) )

/*************/
/* Functions */
/*************/

struct TemplateFunction { // verified via CPrec
    TemplateFunction *next;
    TemplateFunction *unk4; // parent?
    HashNameNode *name;
    TemplParam *params;
    TStream stream;
    TStreamElement deftoken;
    Object *tfunc;
    TemplFuncInstance *instances;
    CPrepFileInfo *srcfile;
    SInt32 startoffset;
    SInt32 endoffset;
};

struct TemplFuncInstance { // verified via CPrec
    TemplFuncInstance *next;
    Object *object;
    TemplArg *args;
    Boolean is_instantiated;
    Boolean is_specialized;
    Boolean is_extern;
    Boolean static_instantiated;
};

#define TEMPL_FUNC(ty) ( (TemplateFunction *) (ty) )
#define TEMPL_FUNC_INST(ty) ( (TemplFuncInstance *) (ty) )
#define IS_TEMPL_FUNC(ty) ( IS_TYPE_FUNC(ty) && (TYPE_FUNC(ty)->flags & FUNC_FLAGS_100000) )

/***********/
/* Actions */
/***********/

typedef enum TemplateActionType {
    TAT_NESTEDCLASS,
    TAT_ENUMTYPE,
    TAT_FRIEND,
    TAT_ENUMERATOR, // in pro7 but not pro8
    TAT_BASE,
    TAT_OBJECTINIT,
    TAT_USINGDECL,
    TAT_OBJECTDEF,
    TAT_ILLEGAL
} TemplateActionType;

struct TemplateAction { // verified via CPrec
    TemplateAction *next;
    TStreamElement source_ref;
    union {
        TemplClass *tclasstype;
        TypeEnum *enumtype;
        TemplateFriend *tfriend;
        struct {
            ObjEnumConst *objenumconst;
            ENode *initexpr;
        } enumerator;
        struct {
            Type *type;
            ClassList *insert_after;
            AccessType access;
            Boolean is_virtual;
        } base;
        struct {
            Object *object;
            ENode *initexpr;
        } objectinit;
        struct {
            TypeTemplDep *type;
            AccessType access;
        } usingdecl;
        ObjBase *refobj;
    } u;
    TemplateActionType type;
};

#ifdef __MWERKS__
#pragma options align=reset
#endif

#endif