2006-05-10 02:40:43 +00:00
|
|
|
#ifndef DOBJTYPE_H
|
|
|
|
#define DOBJTYPE_H
|
|
|
|
|
|
|
|
#ifndef __DOBJECT_H__
|
|
|
|
#error You must #include "dobject.h" to get dobjtype.h
|
|
|
|
#endif
|
|
|
|
|
2008-10-19 21:43:36 +00:00
|
|
|
#include "thingdef/thingdef_type.h"
|
2010-02-12 06:04:57 +00:00
|
|
|
#include "vm.h"
|
2008-10-19 21:43:36 +00:00
|
|
|
|
2013-08-11 01:24:12 +00:00
|
|
|
// Variable/parameter/field flags -------------------------------------------
|
|
|
|
|
|
|
|
// Making all these different storage types use a common set of flags seems
|
|
|
|
// like the simplest thing to do.
|
|
|
|
|
2013-08-15 02:56:21 +00:00
|
|
|
#define VARF_Optional (1<<0) // func param is optional
|
|
|
|
#define VARF_Method (1<<1) // func has an implied self parameter
|
|
|
|
#define VARF_Action (1<<2) // func has implied owner and state parameters
|
2013-08-22 03:39:28 +00:00
|
|
|
#define VARF_Native (1<<3) // func is native code/don't auto serialize field
|
2013-08-11 01:24:12 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
// Symbol information -------------------------------------------------------
|
|
|
|
|
2009-09-16 01:39:44 +00:00
|
|
|
class PSymbol : public DObject
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2009-09-16 01:39:44 +00:00
|
|
|
DECLARE_ABSTRACT_CLASS(PSymbol, DObject);
|
|
|
|
public:
|
2008-06-06 02:17:28 +00:00
|
|
|
virtual ~PSymbol();
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
FName SymbolName;
|
2008-10-19 21:43:36 +00:00
|
|
|
|
|
|
|
protected:
|
2010-04-03 02:06:51 +00:00
|
|
|
PSymbol(FName name) { SymbolName = name; }
|
2006-11-29 04:51:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// An action function -------------------------------------------------------
|
2013-08-15 03:00:16 +00:00
|
|
|
|
2008-08-12 14:30:07 +00:00
|
|
|
struct FState;
|
2008-08-14 08:52:55 +00:00
|
|
|
struct StateCallData;
|
2010-02-12 06:04:57 +00:00
|
|
|
class VMFrameStack;
|
|
|
|
struct VMValue;
|
|
|
|
struct VMReturn;
|
|
|
|
typedef int (*actionf_p)(VMFrameStack *stack, VMValue *param, int numparam, VMReturn *ret, int numret);/*(VM_ARGS)*/
|
|
|
|
class VMFunction;
|
2006-11-29 04:51:16 +00:00
|
|
|
|
2010-02-12 06:04:57 +00:00
|
|
|
// A VM function ------------------------------------------------------------
|
2006-11-29 04:51:16 +00:00
|
|
|
|
2009-09-23 00:24:47 +00:00
|
|
|
class PSymbolVMFunction : public PSymbol
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2009-09-23 00:24:47 +00:00
|
|
|
DECLARE_CLASS(PSymbolVMFunction, PSymbol);
|
|
|
|
HAS_OBJECT_POINTERS;
|
2006-11-29 04:51:16 +00:00
|
|
|
public:
|
2009-09-23 00:24:47 +00:00
|
|
|
VMFunction *Function;
|
2006-11-29 11:14:40 +00:00
|
|
|
|
2010-04-03 02:06:51 +00:00
|
|
|
PSymbolVMFunction(FName name) : PSymbol(name) {}
|
|
|
|
PSymbolVMFunction() : PSymbol(NAME_None) {}
|
2009-09-23 00:24:47 +00:00
|
|
|
};
|
|
|
|
|
2013-10-29 18:51:25 +00:00
|
|
|
// A symbol for a type ------------------------------------------------------
|
|
|
|
|
|
|
|
class PSymbolType : public PSymbol
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PSymbolType, PSymbol);
|
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
|
|
|
class PType *Type;
|
|
|
|
|
|
|
|
PSymbolType(FName name, class PType *ty) : PSymbol(name), Type(ty) {}
|
|
|
|
PSymbolType() : PSymbol(NAME_None) {}
|
|
|
|
};
|
|
|
|
|
2009-09-23 00:24:47 +00:00
|
|
|
// A symbol table -----------------------------------------------------------
|
|
|
|
|
2009-09-16 01:39:44 +00:00
|
|
|
struct PSymbolTable
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2009-09-16 01:39:44 +00:00
|
|
|
PSymbolTable();
|
2013-10-30 02:52:28 +00:00
|
|
|
PSymbolTable(PSymbolTable *parent);
|
2006-11-29 04:51:16 +00:00
|
|
|
~PSymbolTable();
|
|
|
|
|
2009-09-17 01:36:14 +00:00
|
|
|
size_t MarkSymbols();
|
2009-09-16 01:39:44 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
// Sets the table to use for searches if this one doesn't contain the
|
|
|
|
// requested symbol.
|
|
|
|
void SetParentTable (PSymbolTable *parent);
|
|
|
|
|
|
|
|
// Finds a symbol in the table, optionally searching parent tables
|
|
|
|
// as well.
|
|
|
|
PSymbol *FindSymbol (FName symname, bool searchparents) const;
|
|
|
|
|
|
|
|
// Places the symbol in the table and returns a pointer to it or NULL if
|
|
|
|
// a symbol with the same name is already in the table. This symbol is
|
|
|
|
// not copied and will be freed when the symbol table is destroyed.
|
|
|
|
PSymbol *AddSymbol (PSymbol *sym);
|
|
|
|
|
2008-06-06 02:17:28 +00:00
|
|
|
// Frees all symbols from this table.
|
|
|
|
void ReleaseSymbols();
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
private:
|
2010-03-30 04:11:16 +00:00
|
|
|
typedef TMap<FName, PSymbol *> MapType;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
PSymbolTable *ParentSymbolTable;
|
2010-03-30 04:11:16 +00:00
|
|
|
MapType Symbols;
|
2009-10-25 02:19:51 +00:00
|
|
|
|
|
|
|
friend class DObject;
|
2006-11-29 04:51:16 +00:00
|
|
|
};
|
|
|
|
|
2013-10-29 18:51:25 +00:00
|
|
|
extern PSymbolTable GlobalSymbols;
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
// Basic information shared by all types ------------------------------------
|
|
|
|
|
|
|
|
// Only one copy of a type is ever instantiated at one time.
|
|
|
|
// - Enums, classes, and structs are defined by their names and outer classes.
|
|
|
|
// - Pointers are uniquely defined by the type they point at.
|
|
|
|
// - ClassPointers are also defined by their class restriction.
|
|
|
|
// - Arrays are defined by their element type and count.
|
|
|
|
// - DynArrays are defined by their element type.
|
|
|
|
// - Maps are defined by their key and value types.
|
|
|
|
// - Prototypes are defined by the argument and return types.
|
|
|
|
// - Functions are defined by their names and outer objects.
|
|
|
|
// In table form:
|
|
|
|
// Outer Name Type Type2 Count
|
|
|
|
// Enum * *
|
|
|
|
// Class * *
|
|
|
|
// Struct * *
|
|
|
|
// Function * *
|
|
|
|
// Pointer *
|
|
|
|
// ClassPointer + *
|
|
|
|
// Array * *
|
|
|
|
// DynArray *
|
|
|
|
// Map * *
|
|
|
|
// Prototype *+ *+
|
|
|
|
|
2013-10-18 04:01:04 +00:00
|
|
|
struct ZCC_ExprConstant;
|
2010-04-16 02:57:51 +00:00
|
|
|
class PClassType;
|
|
|
|
class PType : public DObject
|
|
|
|
{
|
|
|
|
//DECLARE_ABSTRACT_CLASS_WITH_META(PType, DObject, PClassType);
|
|
|
|
// We need to unravel the _WITH_META macro, since PClassType isn't defined yet,
|
|
|
|
// and we can't define it until we've defined PClass. But we can't define that
|
|
|
|
// without defining PType.
|
|
|
|
DECLARE_ABSTRACT_CLASS(PType, DObject)
|
2010-04-22 04:12:42 +00:00
|
|
|
HAS_OBJECT_POINTERS;
|
2010-04-16 02:57:51 +00:00
|
|
|
protected:
|
|
|
|
enum { MetaClassNum = CLASSREG_PClassType };
|
|
|
|
public:
|
|
|
|
typedef PClassType MetaClass;
|
|
|
|
MetaClass *GetClass() const;
|
|
|
|
|
2013-10-18 04:01:04 +00:00
|
|
|
struct Conversion
|
|
|
|
{
|
|
|
|
Conversion(PType *target, void (*convert)(ZCC_ExprConstant *, class FSharedStringArena &))
|
|
|
|
: TargetType(target), ConvertConstant(convert) {}
|
|
|
|
|
|
|
|
PType *TargetType;
|
|
|
|
void (*ConvertConstant)(ZCC_ExprConstant *val, class FSharedStringArena &strdump);
|
|
|
|
};
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
unsigned int Size; // this type's size
|
|
|
|
unsigned int Align; // this type's preferred alignment
|
|
|
|
PType *HashNext; // next type in this type table
|
2013-10-29 18:53:54 +00:00
|
|
|
PSymbolTable Symbols;
|
2010-04-16 02:57:51 +00:00
|
|
|
|
|
|
|
PType();
|
2010-04-22 04:12:42 +00:00
|
|
|
PType(unsigned int size, unsigned int align);
|
2010-04-16 02:57:51 +00:00
|
|
|
virtual ~PType();
|
|
|
|
|
2013-10-18 04:01:04 +00:00
|
|
|
bool AddConversion(PType *target, void (*convertconst)(ZCC_ExprConstant *, class FSharedStringArena &));
|
|
|
|
|
|
|
|
int FindConversion(PType *target, const Conversion **slots, int numslots);
|
|
|
|
|
2013-08-22 03:36:46 +00:00
|
|
|
// Sets the value of a variable of this type at (addr)
|
|
|
|
virtual void SetValue(void *addr, int val);
|
|
|
|
|
|
|
|
// Gets the value of a variable of this type at (addr)
|
2013-08-24 02:50:33 +00:00
|
|
|
virtual int GetValueInt(void *addr) const;
|
|
|
|
|
2013-08-24 02:52:04 +00:00
|
|
|
// Gets the opcode to store from a register to memory
|
|
|
|
virtual int GetStoreOp() const;
|
|
|
|
|
|
|
|
// Gets the opcode to load from memory to a register
|
|
|
|
virtual int GetLoadOp() const;
|
|
|
|
|
|
|
|
// Gets the register type for this type
|
|
|
|
virtual int GetRegType() const;
|
2013-08-22 03:36:46 +00:00
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
// Returns true if this type matches the two identifiers. Referring to the
|
|
|
|
// above table, any type is identified by at most two characteristics. Each
|
|
|
|
// type that implements this function will cast these to the appropriate type.
|
|
|
|
// It is up to the caller to make sure they are the correct types. There is
|
|
|
|
// only one prototype for this function in order to simplify type table
|
|
|
|
// management.
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
2010-04-16 02:57:51 +00:00
|
|
|
|
2010-04-22 04:12:42 +00:00
|
|
|
// Get the type IDs used by IsMatch
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
2010-04-22 04:12:42 +00:00
|
|
|
|
2013-10-29 18:53:54 +00:00
|
|
|
size_t PropagateMark();
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
static void StaticInit();
|
2013-10-18 04:01:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Stuff for type conversion searches
|
|
|
|
class VisitQueue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VisitQueue() : In(0), Out(0) {}
|
|
|
|
void Push(PType *type);
|
|
|
|
PType *Pop();
|
|
|
|
bool IsEmpty() { return In == Out; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// This is a fixed-sized ring buffer.
|
|
|
|
PType *Queue[64];
|
|
|
|
int In, Out;
|
|
|
|
|
|
|
|
void Advance(int &ptr)
|
|
|
|
{
|
|
|
|
ptr = (ptr + 1) & (countof(Queue) - 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class VisitedNodeSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VisitedNodeSet() { memset(Buckets, 0, sizeof(Buckets)); }
|
|
|
|
void Insert(PType *node);
|
|
|
|
bool Check(const PType *node);
|
|
|
|
|
|
|
|
private:
|
|
|
|
PType *Buckets[32];
|
|
|
|
|
|
|
|
size_t Hash(const PType *type) { return size_t(type) >> 4; }
|
|
|
|
};
|
|
|
|
|
|
|
|
TArray<Conversion> Conversions;
|
|
|
|
PType *PredType;
|
|
|
|
PType *VisitNext;
|
|
|
|
short PredConv;
|
|
|
|
short Distance;
|
|
|
|
|
|
|
|
void MarkPred(PType *pred, int conv, int dist)
|
|
|
|
{
|
|
|
|
PredType = pred;
|
|
|
|
PredConv = conv;
|
|
|
|
Distance = dist;
|
|
|
|
}
|
|
|
|
void FillConversionPath(const Conversion **slots);
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
2013-09-21 02:10:20 +00:00
|
|
|
// Not-really-a-type types --------------------------------------------------
|
|
|
|
|
|
|
|
class PErrorType : public PType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PErrorType, PType);
|
|
|
|
public:
|
|
|
|
PErrorType() : PType(0, 1) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PVoidType : public PType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PVoidType, PType);
|
|
|
|
public:
|
|
|
|
PVoidType() : PType(0, 1) {}
|
|
|
|
};
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
// Some categorization typing -----------------------------------------------
|
|
|
|
|
|
|
|
class PBasicType : public PType
|
|
|
|
{
|
|
|
|
DECLARE_ABSTRACT_CLASS(PBasicType, PType);
|
2010-04-22 04:12:42 +00:00
|
|
|
public:
|
|
|
|
PBasicType();
|
|
|
|
PBasicType(unsigned int size, unsigned int align);
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PCompoundType : public PType
|
|
|
|
{
|
|
|
|
DECLARE_ABSTRACT_CLASS(PCompoundType, PType);
|
|
|
|
};
|
|
|
|
|
|
|
|
class PNamedType : public PCompoundType
|
|
|
|
{
|
|
|
|
DECLARE_ABSTRACT_CLASS(PNamedType, PCompoundType);
|
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
|
|
|
DObject *Outer; // object this type is contained within
|
|
|
|
FName TypeName; // this type's name
|
|
|
|
|
|
|
|
PNamedType() : Outer(NULL) {}
|
2013-08-08 01:13:48 +00:00
|
|
|
PNamedType(FName name, DObject *outer) : Outer(outer), TypeName(name) {}
|
2010-04-16 02:57:51 +00:00
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Basic types --------------------------------------------------------------
|
|
|
|
|
|
|
|
class PInt : public PBasicType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PInt, PBasicType);
|
2010-04-22 04:12:42 +00:00
|
|
|
public:
|
|
|
|
PInt(unsigned int size, bool unsign);
|
|
|
|
|
2013-08-22 03:36:46 +00:00
|
|
|
virtual void SetValue(void *addr, int val);
|
2013-08-24 02:50:33 +00:00
|
|
|
virtual int GetValueInt(void *addr) const;
|
2013-08-24 02:52:04 +00:00
|
|
|
virtual int GetStoreOp() const;
|
|
|
|
virtual int GetLoadOp() const;
|
|
|
|
virtual int GetRegType() const;
|
2013-08-22 03:36:46 +00:00
|
|
|
|
2010-04-22 04:12:42 +00:00
|
|
|
bool Unsigned;
|
|
|
|
protected:
|
|
|
|
PInt();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
2013-09-29 02:08:30 +00:00
|
|
|
class PBool : public PInt
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PBool, PInt);
|
|
|
|
public:
|
2013-10-30 02:53:58 +00:00
|
|
|
PBool();
|
2013-09-29 02:08:30 +00:00
|
|
|
};
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
class PFloat : public PBasicType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PFloat, PBasicType);
|
2010-04-22 04:12:42 +00:00
|
|
|
public:
|
|
|
|
PFloat(unsigned int size);
|
2013-08-22 03:36:46 +00:00
|
|
|
|
|
|
|
virtual void SetValue(void *addr, int val);
|
2013-08-24 02:50:33 +00:00
|
|
|
virtual int GetValueInt(void *addr) const;
|
2013-08-24 02:52:04 +00:00
|
|
|
virtual int GetStoreOp() const;
|
|
|
|
virtual int GetLoadOp() const;
|
|
|
|
virtual int GetRegType() const;
|
2010-04-22 04:12:42 +00:00
|
|
|
protected:
|
|
|
|
PFloat();
|
2013-10-30 02:53:58 +00:00
|
|
|
private:
|
|
|
|
struct SymbolInitF
|
|
|
|
{
|
|
|
|
ENamedName Name;
|
|
|
|
double Value;
|
|
|
|
};
|
|
|
|
struct SymbolInitI
|
|
|
|
{
|
|
|
|
ENamedName Name;
|
|
|
|
int Value;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetSingleSymbols();
|
|
|
|
void SetDoubleSymbols();
|
|
|
|
void SetSymbols(const SymbolInitF *syminit, size_t count);
|
|
|
|
void SetSymbols(const SymbolInitI *syminit, size_t count);
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PString : public PBasicType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PString, PBasicType);
|
2010-04-22 04:12:42 +00:00
|
|
|
public:
|
|
|
|
PString();
|
2013-08-24 02:52:04 +00:00
|
|
|
|
|
|
|
virtual int GetRegType() const;
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Variations of integer types ----------------------------------------------
|
|
|
|
|
|
|
|
class PName : public PInt
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PName, PInt);
|
2010-04-22 04:12:42 +00:00
|
|
|
public:
|
|
|
|
PName();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PSound : public PInt
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PSound, PInt);
|
2010-04-22 04:12:42 +00:00
|
|
|
public:
|
|
|
|
PSound();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PColor : public PInt
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PColor, PInt);
|
2010-04-22 04:12:42 +00:00
|
|
|
public:
|
|
|
|
PColor();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
2013-08-24 02:53:54 +00:00
|
|
|
// Variations of floating point types ---------------------------------------
|
|
|
|
// These get converted to floats when they're loaded from memory.
|
|
|
|
|
|
|
|
class PFixed : public PFloat
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PFixed, PFloat);
|
|
|
|
public:
|
|
|
|
PFixed();
|
|
|
|
|
|
|
|
virtual void SetValue(void *addr, int val);
|
|
|
|
virtual int GetValueInt(void *addr) const;
|
|
|
|
virtual int GetStoreOp() const;
|
|
|
|
virtual int GetLoadOp() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PAngle : public PFloat
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PAngle, PFloat);
|
|
|
|
public:
|
|
|
|
PAngle();
|
|
|
|
|
|
|
|
virtual void SetValue(void *addr, int val);
|
|
|
|
virtual int GetValueInt(void *addr) const;
|
|
|
|
virtual int GetStoreOp() const;
|
|
|
|
virtual int GetLoadOp() const;
|
|
|
|
};
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
// Pointers -----------------------------------------------------------------
|
|
|
|
|
2013-09-21 02:10:20 +00:00
|
|
|
class PStatePointer : public PBasicType
|
2013-08-15 02:53:03 +00:00
|
|
|
{
|
2013-09-21 02:10:20 +00:00
|
|
|
DECLARE_CLASS(PStatePointer, PBasicType);
|
2013-08-15 02:53:03 +00:00
|
|
|
public:
|
|
|
|
PStatePointer();
|
|
|
|
};
|
|
|
|
|
2013-09-21 02:10:20 +00:00
|
|
|
class PPointer : public PBasicType
|
2010-04-16 02:57:51 +00:00
|
|
|
{
|
2013-09-21 02:10:20 +00:00
|
|
|
DECLARE_CLASS(PPointer, PBasicType);
|
2010-04-16 02:57:51 +00:00
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
2010-06-06 04:15:28 +00:00
|
|
|
PPointer(PType *pointsat);
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
PType *PointedType;
|
|
|
|
|
2013-08-24 02:52:04 +00:00
|
|
|
virtual int GetStoreOp() const;
|
|
|
|
virtual int GetLoadOp() const;
|
|
|
|
virtual int GetRegType() const;
|
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
|
|
|
protected:
|
|
|
|
PPointer();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PClassPointer : public PPointer
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PClassPointer, PPointer);
|
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
2013-09-21 02:10:20 +00:00
|
|
|
PClassPointer(class PClass *restrict);
|
2010-04-16 02:57:51 +00:00
|
|
|
|
2013-09-21 02:10:20 +00:00
|
|
|
class PClass *ClassRestriction;
|
2010-04-16 02:57:51 +00:00
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
|
|
|
protected:
|
|
|
|
PClassPointer();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Struct/class fields ------------------------------------------------------
|
|
|
|
|
2013-08-08 01:22:01 +00:00
|
|
|
// A PField describes a symbol that takes up physical space in the struct.
|
|
|
|
class PField : public PSymbol
|
2010-04-16 02:57:51 +00:00
|
|
|
{
|
2013-08-08 01:22:01 +00:00
|
|
|
DECLARE_CLASS(PField, PSymbol);
|
2010-04-16 02:57:51 +00:00
|
|
|
HAS_OBJECT_POINTERS
|
|
|
|
public:
|
2013-08-22 03:38:05 +00:00
|
|
|
PField(FName name, PType *type) : PSymbol(name), Offset(0), Type(type), Flags(0) {}
|
|
|
|
PField(FName name, PType *type, DWORD flags) : PSymbol(name), Offset(0), Type(type), Flags(flags) {}
|
2013-08-09 03:16:13 +00:00
|
|
|
|
2013-08-22 03:38:05 +00:00
|
|
|
unsigned int Offset;
|
|
|
|
PType *Type;
|
|
|
|
DWORD Flags;
|
2013-08-11 01:17:29 +00:00
|
|
|
protected:
|
|
|
|
PField();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Compound types -----------------------------------------------------------
|
|
|
|
|
|
|
|
class PEnum : public PNamedType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PEnum, PNamedType);
|
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
2013-08-08 01:13:48 +00:00
|
|
|
PEnum(FName name, DObject *outer);
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
PType *ValueType;
|
|
|
|
TMap<FName, int> Values;
|
2013-08-08 01:13:48 +00:00
|
|
|
protected:
|
|
|
|
PEnum();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PArray : public PCompoundType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PArray, PCompoundType);
|
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
2010-06-06 04:15:28 +00:00
|
|
|
PArray(PType *etype, unsigned int ecount);
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
PType *ElementType;
|
|
|
|
unsigned int ElementCount;
|
2013-08-09 03:20:16 +00:00
|
|
|
unsigned int ElementSize;
|
2010-04-16 02:57:51 +00:00
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
|
|
|
protected:
|
|
|
|
PArray();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// A vector is an array with extra operations.
|
|
|
|
class PVector : public PArray
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PVector, PArray);
|
|
|
|
HAS_OBJECT_POINTERS;
|
2010-06-06 04:15:28 +00:00
|
|
|
public:
|
|
|
|
PVector(unsigned int size);
|
|
|
|
protected:
|
|
|
|
PVector();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PDynArray : public PCompoundType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PDynArray, PCompoundType);
|
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
2010-06-06 04:15:28 +00:00
|
|
|
PDynArray(PType *etype);
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
PType *ElementType;
|
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
|
|
|
protected:
|
|
|
|
PDynArray();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PMap : public PCompoundType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PMap, PCompoundType);
|
|
|
|
HAS_OBJECT_POINTERS;
|
|
|
|
public:
|
2010-06-06 04:15:28 +00:00
|
|
|
PMap(PType *keytype, PType *valtype);
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
PType *KeyType;
|
|
|
|
PType *ValueType;
|
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
|
|
|
protected:
|
|
|
|
PMap();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PStruct : public PNamedType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PStruct, PNamedType);
|
|
|
|
public:
|
2013-08-08 01:14:27 +00:00
|
|
|
PStruct(FName name, DObject *outer);
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
TArray<PField *> Fields;
|
|
|
|
|
2013-08-24 02:56:18 +00:00
|
|
|
PField *AddField(FName name, PType *type, DWORD flags=0);
|
2013-08-09 03:16:13 +00:00
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
size_t PropagateMark();
|
2013-08-08 01:14:27 +00:00
|
|
|
protected:
|
|
|
|
PStruct();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PPrototype : public PCompoundType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PPrototype, PCompoundType);
|
|
|
|
public:
|
2013-08-10 03:48:02 +00:00
|
|
|
PPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes);
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
TArray<PType *> ArgumentTypes;
|
|
|
|
TArray<PType *> ReturnTypes;
|
|
|
|
|
|
|
|
size_t PropagateMark();
|
2010-06-06 04:15:28 +00:00
|
|
|
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
|
|
|
|
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
|
2013-08-10 03:48:02 +00:00
|
|
|
protected:
|
|
|
|
PPrototype();
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
2010-04-22 04:12:42 +00:00
|
|
|
// TBD: Should we really support overloading?
|
2013-08-11 01:17:55 +00:00
|
|
|
class PFunction : public PSymbol
|
2010-04-16 02:57:51 +00:00
|
|
|
{
|
2013-08-11 01:17:55 +00:00
|
|
|
DECLARE_CLASS(PFunction, PSymbol);
|
2010-04-16 02:57:51 +00:00
|
|
|
public:
|
|
|
|
struct Variant
|
|
|
|
{
|
|
|
|
PPrototype *Proto;
|
|
|
|
VMFunction *Implementation;
|
2013-08-11 01:24:12 +00:00
|
|
|
TArray<DWORD> ArgFlags; // Should be the same length as Proto->ArgumentTypes
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
TArray<Variant> Variants;
|
2013-08-15 02:56:21 +00:00
|
|
|
DWORD Flags;
|
|
|
|
|
2013-08-15 03:00:16 +00:00
|
|
|
unsigned AddVariant(PPrototype *proto, TArray<DWORD> &argflags, VMFunction *impl);
|
2010-04-16 02:57:51 +00:00
|
|
|
|
|
|
|
size_t PropagateMark();
|
2013-08-11 01:17:55 +00:00
|
|
|
|
2013-08-15 02:56:21 +00:00
|
|
|
PFunction(FName name) : PSymbol(name), Flags(0) {}
|
|
|
|
PFunction() : PSymbol(NAME_None), Flags(0) {}
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
// Meta-info for every class derived from DObject ---------------------------
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
class PClassClass;
|
|
|
|
class PClass : public PStruct
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2010-04-16 02:57:51 +00:00
|
|
|
DECLARE_CLASS(PClass, PStruct);
|
2009-09-17 01:36:14 +00:00
|
|
|
HAS_OBJECT_POINTERS;
|
2010-03-25 20:38:00 +00:00
|
|
|
protected:
|
|
|
|
virtual void Derive(PClass *newclass);
|
2010-04-16 02:57:51 +00:00
|
|
|
// We unravel _WITH_META here just as we did for PType.
|
|
|
|
enum { MetaClassNum = CLASSREG_PClassClass };
|
2009-09-17 01:36:14 +00:00
|
|
|
public:
|
2010-04-16 02:57:51 +00:00
|
|
|
typedef PClassClass MetaClass;
|
|
|
|
MetaClass *GetClass() const;
|
|
|
|
|
|
|
|
static void StaticInit();
|
|
|
|
static void StaticShutdown();
|
|
|
|
static void StaticBootstrap();
|
2006-05-10 02:40:43 +00:00
|
|
|
|
|
|
|
// Per-class information -------------------------------------
|
|
|
|
PClass *ParentClass; // the class this class derives from
|
|
|
|
const size_t *Pointers; // object pointers defined by this class *only*
|
|
|
|
const size_t *FlatPointers; // object pointers defined by this class and all its superclasses; not initialized by default
|
|
|
|
BYTE *Defaults;
|
2008-08-12 09:57:59 +00:00
|
|
|
bool bRuntimeClass; // class was defined at run-time, not compile-time
|
2006-05-10 02:40:43 +00:00
|
|
|
|
|
|
|
void (*ConstructNative)(void *);
|
|
|
|
|
|
|
|
// The rest are all functions and static data ----------------
|
2009-09-17 01:36:14 +00:00
|
|
|
PClass();
|
|
|
|
~PClass();
|
2010-04-16 02:57:51 +00:00
|
|
|
void InsertIntoHash();
|
|
|
|
DObject *CreateNew() const;
|
|
|
|
PClass *CreateDerivedClass(FName name, unsigned int size);
|
2009-10-25 02:19:51 +00:00
|
|
|
unsigned int Extend(unsigned int extension);
|
2010-04-16 02:57:51 +00:00
|
|
|
void InitializeActorInfo();
|
|
|
|
void BuildFlatPointers();
|
2008-08-06 22:59:24 +00:00
|
|
|
const PClass *NativeClass() const;
|
2006-05-10 02:40:43 +00:00
|
|
|
|
|
|
|
// Returns true if this type is an ancestor of (or same as) the passed type.
|
2010-04-16 02:57:51 +00:00
|
|
|
bool IsAncestorOf(const PClass *ti) const
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
|
|
|
while (ti)
|
|
|
|
{
|
|
|
|
if (this == ti)
|
|
|
|
return true;
|
|
|
|
ti = ti->ParentClass;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-16 02:57:51 +00:00
|
|
|
inline bool IsDescendantOf(const PClass *ti) const
|
2006-05-10 02:40:43 +00:00
|
|
|
{
|
2010-04-16 02:57:51 +00:00
|
|
|
return ti->IsAncestorOf(this);
|
2006-05-10 02:40:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-24 14:59:28 +00:00
|
|
|
// Find a type, given its name.
|
2010-04-16 02:57:51 +00:00
|
|
|
static PClass *FindClass(const char *name) { return FindClass(FName(name, true)); }
|
|
|
|
static PClass *FindClass(const FString &name) { return FindClass(FName(name, true)); }
|
|
|
|
static PClass *FindClass(ENamedName name) { return FindClass(FName(name)); }
|
|
|
|
static PClass *FindClass(FName name);
|
|
|
|
static PClassActor *FindActor(const char *name) { return FindActor(FName(name, true)); }
|
|
|
|
static PClassActor *FindActor(const FString &name) { return FindActor(FName(name, true)); }
|
|
|
|
static PClassActor *FindActor(ENamedName name) { return FindActor(FName(name)); }
|
|
|
|
static PClassActor *FindActor(FName name);
|
|
|
|
PClass *FindClassTentative(FName name); // not static!
|
|
|
|
|
|
|
|
static TArray<PClass *> AllClasses;
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
|
|
|
|
static bool bShutdown;
|
2006-05-10 02:40:43 +00:00
|
|
|
};
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
class PClassType : public PClass
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PClassType, PClass);
|
|
|
|
protected:
|
|
|
|
virtual void Derive(PClass *newclass);
|
|
|
|
public:
|
|
|
|
PClassType();
|
|
|
|
|
|
|
|
PClass *TypeTableType; // The type to use for hashing into the type table
|
|
|
|
};
|
|
|
|
|
|
|
|
inline PType::MetaClass *PType::GetClass() const
|
|
|
|
{
|
|
|
|
return static_cast<MetaClass *>(DObject::GetClass());
|
|
|
|
}
|
|
|
|
|
|
|
|
class PClassClass : public PClassType
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PClassClass, PClassType);
|
|
|
|
public:
|
|
|
|
PClassClass();
|
|
|
|
};
|
|
|
|
|
|
|
|
inline PClass::MetaClass *PClass::GetClass() const
|
|
|
|
{
|
|
|
|
return static_cast<MetaClass *>(DObject::GetClass());
|
|
|
|
}
|
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
// A class that hasn't had its parent class defined yet ---------------------
|
|
|
|
|
|
|
|
class PClassWaitingForParent : public PClass
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PClassWaitingForParent, PClass);
|
|
|
|
public:
|
|
|
|
PClassWaitingForParent(FName myname, FName parentname);
|
|
|
|
|
|
|
|
FName ParentName;
|
|
|
|
};
|
|
|
|
|
2010-04-16 02:57:51 +00:00
|
|
|
// Type tables --------------------------------------------------------------
|
|
|
|
|
|
|
|
struct FTypeTable
|
|
|
|
{
|
|
|
|
enum { HASH_SIZE = 1021 };
|
|
|
|
|
|
|
|
PType *TypeHash[HASH_SIZE];
|
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
PType *FindType(PClass *metatype, intptr_t parm1, intptr_t parm2, size_t *bucketnum);
|
2012-10-27 02:04:35 +00:00
|
|
|
void ReplaceType(PType *newtype, PType *oldtype, size_t bucket);
|
2010-06-06 04:15:28 +00:00
|
|
|
void AddType(PType *type, PClass *metatype, intptr_t parm1, intptr_t parm2, size_t bucket);
|
2010-04-22 04:12:42 +00:00
|
|
|
void AddType(PType *type);
|
|
|
|
void Mark();
|
2010-04-24 03:10:58 +00:00
|
|
|
void Clear();
|
2010-04-16 02:57:51 +00:00
|
|
|
|
2013-08-10 03:41:36 +00:00
|
|
|
static size_t Hash(const PClass *p1, intptr_t p2, intptr_t p3);
|
2010-04-16 02:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern FTypeTable TypeTable;
|
|
|
|
|
2010-06-06 04:15:28 +00:00
|
|
|
// Returns a type from the TypeTable. Will create one if it isn't present.
|
|
|
|
PVector *NewVector(unsigned int size);
|
|
|
|
PMap *NewMap(PType *keytype, PType *valuetype);
|
|
|
|
PArray *NewArray(PType *type, unsigned int count);
|
|
|
|
PDynArray *NewDynArray(PType *type);
|
|
|
|
PPointer *NewPointer(PType *type);
|
|
|
|
PClassPointer *NewClassPointer(PClass *restrict);
|
|
|
|
PClassWaitingForParent *NewUnknownClass(FName myname, FName parentname);
|
2013-08-08 01:13:48 +00:00
|
|
|
PEnum *NewEnum(FName name, DObject *outer);
|
2013-08-08 01:14:27 +00:00
|
|
|
PStruct *NewStruct(FName name, DObject *outer);
|
2013-08-10 03:48:02 +00:00
|
|
|
PPrototype *NewPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes);
|
2010-06-06 04:15:28 +00:00
|
|
|
|
|
|
|
// Built-in types -----------------------------------------------------------
|
|
|
|
|
2013-09-21 02:10:20 +00:00
|
|
|
extern PErrorType *TypeError;
|
|
|
|
extern PVoidType *TypeVoid;
|
2010-06-06 04:15:28 +00:00
|
|
|
extern PInt *TypeSInt8, *TypeUInt8;
|
|
|
|
extern PInt *TypeSInt16, *TypeUInt16;
|
|
|
|
extern PInt *TypeSInt32, *TypeUInt32;
|
2013-09-29 02:08:30 +00:00
|
|
|
extern PBool *TypeBool;
|
2010-06-06 04:15:28 +00:00
|
|
|
extern PFloat *TypeFloat32, *TypeFloat64;
|
|
|
|
extern PString *TypeString;
|
|
|
|
extern PName *TypeName;
|
|
|
|
extern PSound *TypeSound;
|
|
|
|
extern PColor *TypeColor;
|
2013-08-15 02:53:03 +00:00
|
|
|
extern PStatePointer *TypeState;
|
2013-08-24 02:53:54 +00:00
|
|
|
extern PFixed *TypeFixed;
|
|
|
|
extern PAngle *TypeAngle;
|
2010-06-06 04:15:28 +00:00
|
|
|
|
2013-09-11 03:01:00 +00:00
|
|
|
// A constant value ---------------------------------------------------------
|
|
|
|
|
|
|
|
class PSymbolConst : public PSymbol
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PSymbolConst, PSymbol);
|
|
|
|
public:
|
|
|
|
PType *ValueType;
|
|
|
|
|
|
|
|
PSymbolConst(FName name, PType *type=NULL) : PSymbol(name), ValueType(type) {}
|
|
|
|
PSymbolConst() : PSymbol(NAME_None), ValueType(NULL) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// A constant numeric value -------------------------------------------------
|
|
|
|
|
|
|
|
class PSymbolConstNumeric : public PSymbolConst
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PSymbolConstNumeric, PSymbolConst);
|
|
|
|
public:
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int Value;
|
|
|
|
double Float;
|
2013-10-24 03:46:34 +00:00
|
|
|
void *Pad;
|
2013-09-11 03:01:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PSymbolConstNumeric(FName name, PType *type=NULL) : PSymbolConst(name, type) {}
|
2013-09-21 02:10:20 +00:00
|
|
|
PSymbolConstNumeric(FName name, PType *type, int val) : PSymbolConst(name, type), Value(val) {}
|
2013-10-30 02:53:58 +00:00
|
|
|
PSymbolConstNumeric(FName name, PType *type, unsigned int val) : PSymbolConst(name, type), Value((int)val) {}
|
2013-09-21 02:10:20 +00:00
|
|
|
PSymbolConstNumeric(FName name, PType *type, double val) : PSymbolConst(name, type), Float(val) {}
|
2013-09-11 03:01:00 +00:00
|
|
|
PSymbolConstNumeric() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// A constant string value --------------------------------------------------
|
|
|
|
|
|
|
|
class PSymbolConstString : public PSymbolConst
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(PSymbolConstString, PSymbolConst);
|
|
|
|
public:
|
|
|
|
FString Str;
|
|
|
|
|
|
|
|
PSymbolConstString(FName name, FString &str) : PSymbolConst(name, TypeString), Str(str) {}
|
|
|
|
PSymbolConstString() {}
|
|
|
|
};
|
|
|
|
|
2006-05-10 02:40:43 +00:00
|
|
|
#endif
|