2013-10-24 04:06:32 +00:00
|
|
|
#ifndef ZCC_COMPILE_H
|
|
|
|
#define ZCC_COMPILE_H
|
|
|
|
|
2016-10-08 13:27:20 +00:00
|
|
|
struct ZCC_StructWork
|
|
|
|
{
|
|
|
|
ZCC_Struct *strct;
|
|
|
|
PSymbolTreeNode *node;
|
|
|
|
TArray<ZCC_ConstantDef *> Constants;
|
|
|
|
|
|
|
|
ZCC_StructWork(ZCC_Struct * s, PSymbolTreeNode *n)
|
|
|
|
{
|
|
|
|
strct = s;
|
|
|
|
node = n;
|
|
|
|
};
|
|
|
|
|
|
|
|
ZCC_Struct *operator->()
|
|
|
|
{
|
|
|
|
return strct;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator ZCC_Struct *()
|
|
|
|
{
|
|
|
|
return strct;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ZCC_ClassWork
|
|
|
|
{
|
|
|
|
ZCC_Class *cls;
|
|
|
|
PSymbolTreeNode *node;
|
|
|
|
TArray<ZCC_ConstantDef *> Constants;
|
|
|
|
TArray<ZCC_StructWork> Structs;
|
|
|
|
|
|
|
|
ZCC_ClassWork(ZCC_Class * s, PSymbolTreeNode *n)
|
|
|
|
{
|
|
|
|
cls = s;
|
|
|
|
node = n;
|
|
|
|
};
|
|
|
|
|
|
|
|
ZCC_Class *operator->()
|
|
|
|
{
|
|
|
|
return cls;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator ZCC_Class *()
|
|
|
|
{
|
|
|
|
return cls;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
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);
|
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-08 11:34:37 +00:00
|
|
|
void CreateStructTypes();
|
|
|
|
void CreateClassTypes();
|
2016-03-13 03:22:29 +00:00
|
|
|
void CompileConstants(const TArray<ZCC_ConstantDef *> &defs);
|
2013-10-24 04:06:32 +00:00
|
|
|
PSymbolConst *CompileConstant(ZCC_ConstantDef *def);
|
|
|
|
|
|
|
|
TArray<ZCC_ConstantDef *> Constants;
|
2016-10-08 13:27:20 +00:00
|
|
|
TArray<ZCC_StructWork> Structs;
|
|
|
|
TArray<ZCC_ClassWork> Classes;
|
2013-10-26 03:01:18 +00:00
|
|
|
|
2016-10-08 13:27:20 +00:00
|
|
|
PSymbolTreeNode *AddNamedNode(ZCC_NamedNode *node, PSymbolTable *parentsym = nullptr);
|
2013-10-24 04:06:32 +00:00
|
|
|
|
|
|
|
ZCC_Expression *Simplify(ZCC_Expression *root);
|
|
|
|
ZCC_Expression *SimplifyUnary(ZCC_ExprUnary *unary);
|
|
|
|
ZCC_Expression *SimplifyBinary(ZCC_ExprBinary *binary);
|
2013-10-30 02:55:32 +00:00
|
|
|
ZCC_Expression *SimplifyMemberAccess(ZCC_ExprMemberAccess *dotop);
|
2013-10-31 01:53:02 +00:00
|
|
|
ZCC_Expression *SimplifyFunctionCall(ZCC_ExprFuncCall *callop);
|
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);
|
|
|
|
|
|
|
|
void PromoteToInt(ZCC_Expression *&expr);
|
|
|
|
void PromoteToUInt(ZCC_Expression *&expr);
|
|
|
|
void PromoteToDouble(ZCC_Expression *&expr);
|
|
|
|
void PromoteToString(ZCC_Expression *&expr);
|
|
|
|
|
|
|
|
ZCC_Expression *ApplyConversion(ZCC_Expression *expr, const PType::Conversion **route, int routelen);
|
|
|
|
ZCC_Expression *AddCastNode(PType *type, ZCC_Expression *expr);
|
|
|
|
|
|
|
|
ZCC_Expression *IdentifyIdentifier(ZCC_ExprID *idnode);
|
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-20 16:34:41 +00:00
|
|
|
PSymbol *CompileNode(ZCC_NamedNode *node);
|
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-03-13 03:22:29 +00:00
|
|
|
PSymbolTable *Symbols;
|
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
|