2013-10-24 04:06:32 +00:00
|
|
|
#ifndef ZCC_COMPILE_H
|
|
|
|
#define ZCC_COMPILE_H
|
|
|
|
|
2016-10-10 22:56:47 +00:00
|
|
|
struct Baggage;
|
|
|
|
struct FPropertyInfo;
|
|
|
|
class AActor;
|
2016-10-12 15:50:23 +00:00
|
|
|
class FxExpression;
|
2016-10-10 22:56:47 +00:00
|
|
|
|
2016-10-08 13:27:20 +00:00
|
|
|
struct ZCC_StructWork
|
|
|
|
{
|
2016-10-09 23:18:47 +00:00
|
|
|
PSymbolTable TreeNodes;
|
2016-10-08 13:27:20 +00:00
|
|
|
ZCC_Struct *strct;
|
2016-10-09 13:47:31 +00:00
|
|
|
ZCC_Class *OuterDef;
|
|
|
|
PClass *Outer;
|
2016-10-08 13:27:20 +00:00
|
|
|
PSymbolTreeNode *node;
|
2016-10-09 13:47:31 +00:00
|
|
|
TArray<ZCC_Enum *> Enums;
|
2016-10-08 13:27:20 +00:00
|
|
|
TArray<ZCC_ConstantDef *> Constants;
|
2016-10-09 07:09:17 +00:00
|
|
|
TArray<ZCC_VarDeclarator *> Fields;
|
2016-10-08 13:27:20 +00:00
|
|
|
|
2016-10-09 13:47:31 +00:00
|
|
|
ZCC_StructWork(ZCC_Struct * s, PSymbolTreeNode *n, ZCC_Class *outer)
|
2016-10-08 13:27:20 +00:00
|
|
|
{
|
|
|
|
strct = s;
|
|
|
|
node = n;
|
2016-10-09 13:47:31 +00:00
|
|
|
OuterDef = outer;
|
|
|
|
Outer = nullptr;
|
2016-10-08 13:27:20 +00:00
|
|
|
};
|
|
|
|
|
2016-10-09 23:18:47 +00:00
|
|
|
FName NodeName() const
|
2016-10-08 13:27:20 +00:00
|
|
|
{
|
2016-10-09 23:18:47 +00:00
|
|
|
return strct->NodeName;
|
2016-10-08 13:27:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 23:18:47 +00:00
|
|
|
PStruct *Type()
|
2016-10-08 13:27:20 +00:00
|
|
|
{
|
2016-10-09 23:18:47 +00:00
|
|
|
return strct->Type;
|
2016-10-08 13:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ZCC_ClassWork
|
|
|
|
{
|
|
|
|
ZCC_Class *cls;
|
2016-10-09 23:18:47 +00:00
|
|
|
PSymbolTable TreeNodes;
|
2016-10-08 13:27:20 +00:00
|
|
|
PSymbolTreeNode *node;
|
2016-10-09 13:47:31 +00:00
|
|
|
TArray<ZCC_Enum *> Enums;
|
2016-10-08 13:27:20 +00:00
|
|
|
TArray<ZCC_ConstantDef *> Constants;
|
2016-10-09 07:09:17 +00:00
|
|
|
TArray<ZCC_VarDeclarator *> Fields;
|
2016-10-10 22:56:47 +00:00
|
|
|
TArray<ZCC_Default *> Defaults;
|
2016-10-11 16:53:10 +00:00
|
|
|
TArray<ZCC_FuncDeclarator *> Functions;
|
2016-10-12 15:50:23 +00:00
|
|
|
TArray<ZCC_States *> States;
|
2016-10-08 13:27:20 +00:00
|
|
|
|
|
|
|
ZCC_ClassWork(ZCC_Class * s, PSymbolTreeNode *n)
|
|
|
|
{
|
|
|
|
cls = s;
|
|
|
|
node = n;
|
2016-10-09 23:18:47 +00:00
|
|
|
}
|
2016-10-08 13:27:20 +00:00
|
|
|
|
2016-10-09 23:18:47 +00:00
|
|
|
FName NodeName() const
|
2016-10-08 13:27:20 +00:00
|
|
|
{
|
2016-10-09 23:18:47 +00:00
|
|
|
return cls->NodeName;
|
2016-10-08 13:27:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 23:18:47 +00:00
|
|
|
PClass *Type()
|
2016-10-08 13:27:20 +00:00
|
|
|
{
|
2016-10-09 23:18:47 +00:00
|
|
|
return cls->Type;
|
2016-10-08 13:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-08 20:16:10 +00:00
|
|
|
struct ZCC_ConstantWork
|
|
|
|
{
|
|
|
|
ZCC_ConstantDef *node;
|
|
|
|
PSymbolTable *outputtable;
|
|
|
|
};
|
|
|
|
|
2013-10-24 04:06:32 +00:00
|
|
|
class ZCCCompiler
|
|
|
|
{
|
|
|
|
public:
|
2016-10-08 11:34:37 +00:00
|
|
|
ZCCCompiler(ZCC_AST &tree, DObject *outer, PSymbolTable &symbols, PSymbolTable &outsymbols);
|
2016-10-09 23:18:47 +00:00
|
|
|
~ZCCCompiler();
|
2013-10-24 04:06:32 +00:00
|
|
|
int Compile();
|
|
|
|
|
|
|
|
private:
|
2016-10-08 13:27:20 +00:00
|
|
|
void ProcessClass(ZCC_Class *node, PSymbolTreeNode *tnode);
|
2016-10-09 13:47:31 +00:00
|
|
|
void ProcessStruct(ZCC_Struct *node, PSymbolTreeNode *tnode, ZCC_Class *outer);
|
2016-10-08 11:34:37 +00:00
|
|
|
void CreateStructTypes();
|
|
|
|
void CreateClassTypes();
|
2016-10-09 07:09:17 +00:00
|
|
|
void CopyConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PSymbolTable *ot);
|
2016-10-08 20:16:10 +00:00
|
|
|
void CompileAllConstants();
|
|
|
|
void AddConstant(ZCC_ConstantWork &constant);
|
|
|
|
bool CompileConstant(ZCC_ConstantDef *def, PSymbolTable *Symbols);
|
2013-10-24 04:06:32 +00:00
|
|
|
|
2016-10-09 13:47:31 +00:00
|
|
|
void CompileAllFields();
|
2016-10-09 23:18:47 +00:00
|
|
|
bool CompileFields(PStruct *type, TArray<ZCC_VarDeclarator *> &Fields, PClass *Outer, PSymbolTable *TreeNodes, bool forstruct);
|
2016-10-09 13:47:31 +00:00
|
|
|
FString FlagsToString(uint32_t flags);
|
2016-10-11 16:53:10 +00:00
|
|
|
PType *DetermineType(PType *outertype, ZCC_TreeNode *field, FName name, ZCC_Type *ztype, bool allowarraytypes);
|
2016-10-09 13:47:31 +00:00
|
|
|
PType *ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, PSymbolTable *sym);
|
|
|
|
PType *ResolveUserType(ZCC_BasicType *type, PSymbolTable *sym);
|
|
|
|
|
2016-10-10 22:56:47 +00:00
|
|
|
void InitDefaults();
|
|
|
|
void ProcessDefaultFlag(PClassActor *cls, ZCC_FlagStmt *flg);
|
|
|
|
void ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *flg, Baggage &bag);
|
|
|
|
void DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *pex, AActor *defaults, Baggage &bag);
|
|
|
|
int GetInt(ZCC_Expression *expr);
|
|
|
|
double GetDouble(ZCC_Expression *expr);
|
|
|
|
const char *GetString(ZCC_Expression *expr, bool silent = false);
|
|
|
|
|
2016-10-11 16:53:10 +00:00
|
|
|
void InitFunctions();
|
2016-10-12 15:50:23 +00:00
|
|
|
void CompileStates();
|
|
|
|
FxExpression *SetupActionFunction(PClassActor *cls, ZCC_TreeNode *sl);
|
2016-10-11 16:53:10 +00:00
|
|
|
|
2013-10-24 04:06:32 +00:00
|
|
|
TArray<ZCC_ConstantDef *> Constants;
|
2016-10-09 23:18:47 +00:00
|
|
|
TArray<ZCC_StructWork *> Structs;
|
|
|
|
TArray<ZCC_ClassWork *> Classes;
|
2013-10-26 03:01:18 +00:00
|
|
|
|
2016-10-09 23:18:47 +00:00
|
|
|
PSymbolTreeNode *AddTreeNode(FName name, ZCC_TreeNode *node, PSymbolTable *treenodes, bool searchparents = false);
|
2013-10-24 04:06:32 +00:00
|
|
|
|
2016-10-08 20:16:10 +00:00
|
|
|
ZCC_Expression *Simplify(ZCC_Expression *root, PSymbolTable *Symbols);
|
|
|
|
ZCC_Expression *SimplifyUnary(ZCC_ExprUnary *unary, PSymbolTable *Symbols);
|
|
|
|
ZCC_Expression *SimplifyBinary(ZCC_ExprBinary *binary, PSymbolTable *Symbols);
|
|
|
|
ZCC_Expression *SimplifyMemberAccess(ZCC_ExprMemberAccess *dotop, PSymbolTable *Symbols);
|
|
|
|
ZCC_Expression *SimplifyFunctionCall(ZCC_ExprFuncCall *callop, PSymbolTable *Symbols);
|
2013-10-24 04:06:32 +00:00
|
|
|
ZCC_OpProto *PromoteUnary(EZCCExprType op, ZCC_Expression *&expr);
|
|
|
|
ZCC_OpProto *PromoteBinary(EZCCExprType op, ZCC_Expression *&left, ZCC_Expression *&right);
|
|
|
|
|
|
|
|
ZCC_Expression *ApplyConversion(ZCC_Expression *expr, const PType::Conversion **route, int routelen);
|
|
|
|
ZCC_Expression *AddCastNode(PType *type, ZCC_Expression *expr);
|
|
|
|
|
2016-10-08 20:16:10 +00:00
|
|
|
ZCC_Expression *IdentifyIdentifier(ZCC_ExprID *idnode, PSymbolTable *sym);
|
2016-03-13 03:22:29 +00:00
|
|
|
ZCC_Expression *NodeFromSymbol(PSymbol *sym, ZCC_Expression *source, PSymbolTable *table);
|
2013-10-30 02:55:32 +00:00
|
|
|
ZCC_ExprConstant *NodeFromSymbolConst(PSymbolConst *sym, ZCC_Expression *idnode);
|
|
|
|
ZCC_ExprTypeRef *NodeFromSymbolType(PSymbolType *sym, ZCC_Expression *idnode);
|
2016-03-13 03:22:29 +00:00
|
|
|
|
2013-10-24 04:06:32 +00:00
|
|
|
|
2016-03-13 03:22:29 +00:00
|
|
|
void Warn(ZCC_TreeNode *node, const char *msg, ...);
|
|
|
|
void Error(ZCC_TreeNode *node, const char *msg, ...);
|
|
|
|
void MessageV(ZCC_TreeNode *node, const char *txtcolor, const char *msg, va_list argptr);
|
2013-10-24 04:06:32 +00:00
|
|
|
|
|
|
|
DObject *Outer;
|
2016-10-09 07:09:17 +00:00
|
|
|
PSymbolTable *GlobalTreeNodes;
|
2016-10-08 11:34:37 +00:00
|
|
|
PSymbolTable *OutputSymbols;
|
2013-10-24 04:06:32 +00:00
|
|
|
ZCC_AST &AST;
|
|
|
|
int ErrorCount;
|
|
|
|
int WarnCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ZCC_InitConversions();
|
|
|
|
|
|
|
|
#endif
|