summaryrefslogtreecommitdiff
path: root/includes/compiler/CFunc.h
blob: a64cc74766b30cebc8922ae4e6a5e85153e86d6f (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
#ifndef COMPILER_CFUNC_H
#define COMPILER_CFUNC_H

#include "compiler/common.h"
#include "compiler/CScope.h"

#ifdef __MWERKS__
#pragma options align=mac68k
#endif

typedef struct DeclBlock {
    struct DeclBlock *next;
    ExceptionAction *dobjstack; // is type right?
    NameSpace *parent_nspace;
    short index;
} DeclBlock;

struct CLabel {
    CLabel *next;
    Statement *stmt;
    HashNameNode *uniquename;
    HashNameNode *name;
    PCodeLabel *pclabel;
    //void *sicg_label;
};

typedef enum StatementType {
    ST_NOP = 1,
    ST_LABEL,
    ST_GOTO,
    ST_EXPRESSION,
    ST_SWITCH,
    ST_IFGOTO,
    ST_IFNGOTO,
    ST_RETURN,
    ST_OVF,
    ST_EXIT,
    ST_ENTRY,
    ST_BEGINCATCH,
    ST_ENDCATCH,
    ST_ENDCATCHDTOR,
    ST_GOTOEXPR,
    ST_ASM,
    ST_BEGINLOOP,
    ST_ENDLOOP,
    ST_ILLEGAL
} StatementType;

enum {
    StmtFlag_1 = 1,
    StmtFlag_2 = 2,
    StmtFlag_4 = 4,
    StmtFlag_8 = 8,
    StmtFlag_10 = 0x10
};

// TODO: move me - ST_BEGINLOOP related?
typedef struct LoopInfo {
    int x0;
    int x4;
    short x8;
    Statement *stmt;
} LoopInfo;

struct Statement {
    Statement *next;
    StatementType type;
    char marked;
    UInt8 flags;
    UInt16 value;
    ENode *expr;
    CLabel *label;
    ExceptionAction *dobjstack;
    SInt32 sourceoffset;
    HashNameNode *sourcefilepath;
};

typedef struct InitExpr {
    struct InitExpr *next;
    ENode *expr;
    Object *object;
} InitExpr;

typedef enum CtorChainType {
    CtorChain_Base = 0,
    CtorChain_VBase = 1,
    CtorChain_MemberVar = 2
} CtorChainType;

typedef struct CtorChain {
    struct CtorChain *next;
    CtorChainType what;
    ENode *objexpr;
    union {
        ClassList *base; // 0
        VClassList *vbase; // 1
        ObjMemberVar *membervar; // 2
    } u;
} CtorChain;

typedef struct CFuncSave CFuncSave;

struct DeclThing {
    Type *thetype;
    UInt32 qual;
    SwitchInfo *switchinfo;
    CLabel *loopContinue;
    CLabel *loopBreak;
};

struct DefArgCtorInfo {
    Object *default_func;
    ENode *default_arg;
};

extern FuncArg elipsis;
extern FuncArg oldstyle;
extern ObjectList *arguments;
extern ObjectList *locals;
extern short localcount;
extern SInt32 curstmtvalue;
extern SInt32 sourceoffset;
extern HashNameNode *sourcefilepath;
extern SInt32 functionbodyoffset;
extern HashNameNode *functionbodypath;
extern InitExpr *init_expressions;
extern CLabel *Labels;
extern CtorChain *ctor_chain;
extern Statement *curstmt;

extern DeclBlock *CFunc_NewDeclBlock(void);
extern void CFunc_RestoreBlock(DeclBlock *block);
extern void CFunc_SetupLocalVarInfo(Object *obj);
extern ENode *CFunc_DefaultArg(Type *type, UInt32 qual, FuncArg *args);
extern Boolean CFunc_ParseFakeArgList(Boolean flag);
extern FuncArg *parameter_type_list(DeclInfo *declinfo);
extern CLabel *findlabel(void);
extern CLabel *newlabel(void);
extern Statement *CFunc_AppendStatement(StatementType sttype);
extern Statement *CFunc_InsertStatement(StatementType sttype, Statement *after);
extern Statement *CFunc_InsertBeforeStatement(StatementType sttype, Statement *before);
extern void CheckCLabels(void);
extern Object *create_temp_object(Type *type);
extern ENode *create_temp_node(Type *type);
extern ENode *create_temp_node2(Type *type);
extern void CFunc_WarnUnused(void);
extern void CFunc_CodeCleanup(Statement *stmt);
extern void CFunc_DestructorCleanup(Statement *stmt);
extern Statement *CFunc_GenerateLoop(Statement *stmt, Type *type, ENode *lowerBound, ENode *upperBound, ENode *increment1, ENode *increment2, ENode *(*callback)(ENode *, ENode *));
extern void CFunc_CompoundStatement(DeclThing *thing);
extern void CFunc_SetupNewFuncArgs(Object *func, FuncArg *args);
extern NameSpace *CFunc_FuncGenSetup(Statement *stmt, Object *func);
extern CFuncSave *CFunc_GetGlobalCompilerState(void);
extern void CFunc_SetGlobalCompilerState(CFuncSave *state);
extern void CFunc_Gen(Statement *stmt, Object *func, UInt8 unk);
extern void CFunc_CheckClassCtors(TypeClass *tclass);
extern void CFunc_ParseFuncDef(Object *func, DeclInfo *di, TypeClass *tclass, Boolean is_method, Boolean is_static, NameSpace *nspace);
extern void InitExpr_Register(ENode *expr, Object *object);
extern void CFunc_GenerateDummyFunction(Object *func);
extern void CFunc_GenerateSingleExprFunc(Object *func, ENode *expr);
extern void CFunc_GenerateDummyCtorFunc(Object *func, Object *real_ctor);

#ifdef __MWERKS__
#pragma options align=reset
#endif

#endif