mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 14:51:40 +00:00
Use new type system with DECORATE
This commit is contained in:
parent
15b6c11748
commit
f23c0121c5
5 changed files with 197 additions and 364 deletions
|
@ -5,7 +5,6 @@
|
|||
#error You must #include "dobject.h" to get dobjtype.h
|
||||
#endif
|
||||
|
||||
#include "thingdef/thingdef_type.h"
|
||||
#include "vm.h"
|
||||
|
||||
// Variable/parameter/field flags -------------------------------------------
|
||||
|
|
|
@ -84,7 +84,7 @@ struct FCompileContext
|
|||
|
||||
struct ExpVal
|
||||
{
|
||||
ExpValType Type;
|
||||
PType *Type;
|
||||
union
|
||||
{
|
||||
int Int;
|
||||
|
@ -94,13 +94,13 @@ struct ExpVal
|
|||
|
||||
ExpVal()
|
||||
{
|
||||
Type = VAL_Int;
|
||||
Type = TypeSInt32;
|
||||
Int = 0;
|
||||
}
|
||||
|
||||
~ExpVal()
|
||||
{
|
||||
if (Type == VAL_String)
|
||||
if (Type == TypeString)
|
||||
{
|
||||
((FString *)&pointer)->~FString();
|
||||
}
|
||||
|
@ -108,14 +108,14 @@ struct ExpVal
|
|||
|
||||
ExpVal(const FString &str)
|
||||
{
|
||||
Type = VAL_String;
|
||||
Type = TypeString;
|
||||
::new(&pointer) FString(str);
|
||||
}
|
||||
|
||||
ExpVal(const ExpVal &o)
|
||||
{
|
||||
Type = o.Type;
|
||||
if (o.Type == VAL_String)
|
||||
if (o.Type == TypeString)
|
||||
{
|
||||
::new(&pointer) FString(*(FString *)&o.pointer);
|
||||
}
|
||||
|
@ -127,12 +127,12 @@ struct ExpVal
|
|||
|
||||
ExpVal &operator=(const ExpVal &o)
|
||||
{
|
||||
if (Type == VAL_String)
|
||||
if (Type == TypeString)
|
||||
{
|
||||
((FString *)&pointer)->~FString();
|
||||
}
|
||||
Type = o.Type;
|
||||
if (o.Type == VAL_String)
|
||||
if (o.Type == TypeString)
|
||||
{
|
||||
::new(&pointer) FString(*(FString *)&o.pointer);
|
||||
}
|
||||
|
@ -145,27 +145,30 @@ struct ExpVal
|
|||
|
||||
int GetInt() const
|
||||
{
|
||||
return Type == VAL_Int? Int : Type == VAL_Float? int(Float) : 0;
|
||||
int regtype = Type->GetRegType();
|
||||
return regtype == REGT_INT ? Int : regtype == REGT_FLOAT ? int(Float) : 0;
|
||||
}
|
||||
|
||||
double GetFloat() const
|
||||
{
|
||||
return Type == VAL_Int? double(Int) : Type == VAL_Float? Float : 0;
|
||||
int regtype = Type->GetRegType();
|
||||
return regtype == REGT_INT ? double(Int) : regtype == REGT_FLOAT ? Float : 0;
|
||||
}
|
||||
|
||||
const FString GetString() const
|
||||
{
|
||||
return Type == VAL_String ? *(FString *)&pointer : Type == VAL_Name ? FString(FName(ENamedName(Int)).GetChars()) : "";
|
||||
return Type == TypeString ? *(FString *)&pointer : Type == TypeName ? FString(FName(ENamedName(Int)).GetChars()) : "";
|
||||
}
|
||||
|
||||
bool GetBool() const
|
||||
{
|
||||
return (Type == VAL_Int || Type == VAL_Sound) ? !!Int : Type == VAL_Float? Float!=0. : false;
|
||||
int regtype = Type->GetRegType();
|
||||
return regtype == REGT_INT ? !!Int : regtype == REGT_FLOAT ? Float!=0. : false;
|
||||
}
|
||||
|
||||
FName GetName() const
|
||||
{
|
||||
return Type == VAL_Name? ENamedName(Int) : NAME_None;
|
||||
return Type == TypeName ? ENamedName(Int) : NAME_None;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -195,7 +198,7 @@ protected:
|
|||
{
|
||||
isresolved = false;
|
||||
ScriptPosition = pos;
|
||||
ValueType = VAL_Unresolved;
|
||||
ValueType = NULL;
|
||||
}
|
||||
public:
|
||||
virtual ~FxExpression() {}
|
||||
|
@ -205,11 +208,13 @@ public:
|
|||
virtual bool isConstant() const;
|
||||
virtual void RequestAddress();
|
||||
virtual VMFunction *GetDirectFunction();
|
||||
bool IsNumeric() const { return ValueType->GetRegType() == REGT_INT || ValueType->GetRegType() == REGT_FLOAT; }
|
||||
bool IsPointer() const { return ValueType->GetRegType() == REGT_POINTER; }
|
||||
|
||||
virtual ExpEmit Emit(VMFunctionBuilder *build);
|
||||
|
||||
FScriptPosition ScriptPosition;
|
||||
FExpressionType ValueType;
|
||||
PType *ValueType;
|
||||
|
||||
bool isresolved;
|
||||
};
|
||||
|
@ -288,35 +293,35 @@ class FxConstant : public FxExpression
|
|||
public:
|
||||
FxConstant(int val, const FScriptPosition &pos) : FxExpression(pos)
|
||||
{
|
||||
ValueType = value.Type = VAL_Int;
|
||||
ValueType = value.Type = TypeSInt32;
|
||||
value.Int = val;
|
||||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(double val, const FScriptPosition &pos) : FxExpression(pos)
|
||||
{
|
||||
ValueType = value.Type = VAL_Float;
|
||||
ValueType = value.Type = TypeFloat64;
|
||||
value.Float = val;
|
||||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(FSoundID val, const FScriptPosition &pos) : FxExpression(pos)
|
||||
{
|
||||
ValueType = value.Type = VAL_Sound;
|
||||
ValueType = value.Type = TypeSound;
|
||||
value.Int = val;
|
||||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(FName val, const FScriptPosition &pos) : FxExpression(pos)
|
||||
{
|
||||
ValueType = value.Type = VAL_Name;
|
||||
ValueType = value.Type = TypeName;
|
||||
value.Int = val;
|
||||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(const FString &str, const FScriptPosition &pos) : FxExpression(pos)
|
||||
{
|
||||
ValueType = VAL_String;
|
||||
ValueType = TypeString;
|
||||
value = ExpVal(str);
|
||||
isresolved = true;
|
||||
}
|
||||
|
@ -328,18 +333,18 @@ public:
|
|||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(const PClass *val, const FScriptPosition &pos) : FxExpression(pos)
|
||||
FxConstant(PClass *val, const FScriptPosition &pos) : FxExpression(pos)
|
||||
{
|
||||
value.pointer = (void*)val;
|
||||
ValueType = val;
|
||||
value.Type = VAL_Class;
|
||||
value.Type = NewClassPointer(RUNTIME_CLASS(AActor));
|
||||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(FState *state, const FScriptPosition &pos) : FxExpression(pos)
|
||||
{
|
||||
value.pointer = state;
|
||||
ValueType = value.Type = VAL_State;
|
||||
ValueType = value.Type = TypeState;
|
||||
isresolved = true;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -127,7 +127,7 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type, bool c
|
|||
v = MAKEARGB(1, RPART(c), GPART(c), BPART(c));
|
||||
}
|
||||
ExpVal val;
|
||||
val.Type = VAL_Color;
|
||||
val.Type = TypeColor;
|
||||
val.Int = v;
|
||||
x = new FxConstant(val, sc);
|
||||
}
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
#ifndef THINGDEF_TYPE_H
|
||||
#define THINGDEF_TYPE_H
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
enum ExpValType
|
||||
{
|
||||
VAL_Unresolved, // type not yet known
|
||||
VAL_Int, // integer number
|
||||
VAL_Float, // floating point number
|
||||
VAL_Unknown, // nothing
|
||||
VAL_Array, // Array (very limited right now)
|
||||
VAL_Object, // Object reference
|
||||
VAL_Class, // Class reference
|
||||
VAL_Sound, // Sound identifier. Internally it's an int.
|
||||
VAL_Name, // A Name
|
||||
VAL_String, // A string
|
||||
VAL_Color, // A color
|
||||
VAL_State, // A State pointer
|
||||
|
||||
// only used for accessing external variables to ensure proper conversion
|
||||
VAL_Fixed,
|
||||
VAL_Angle,
|
||||
VAL_Bool,
|
||||
};
|
||||
|
||||
struct FExpressionType
|
||||
{
|
||||
BYTE Type;
|
||||
BYTE BaseType;
|
||||
WORD size; // for arrays;
|
||||
const PClass *ClassType;
|
||||
|
||||
FExpressionType &operator=(int typeval)
|
||||
{
|
||||
Type = typeval;
|
||||
BaseType = 0;
|
||||
size = 0;
|
||||
ClassType = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FExpressionType &operator=(const PClass *cls)
|
||||
{
|
||||
Type = VAL_Class;
|
||||
BaseType = 0;
|
||||
size = 0;
|
||||
ClassType = cls;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(int typeval) const
|
||||
{
|
||||
return Type == typeval;
|
||||
}
|
||||
|
||||
bool operator!=(int typeval) const
|
||||
{
|
||||
return Type != typeval;
|
||||
}
|
||||
|
||||
bool isNumeric() const
|
||||
{
|
||||
return Type == VAL_Float || Type == VAL_Int;
|
||||
}
|
||||
|
||||
bool isPointer() const
|
||||
{
|
||||
return Type == VAL_Object || Type == VAL_Class;
|
||||
}
|
||||
|
||||
FExpressionType GetBaseType() const
|
||||
{
|
||||
FExpressionType ret = *this;
|
||||
ret.Type = BaseType;
|
||||
ret.BaseType = 0;
|
||||
ret.size = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// currently only used for args[].
|
||||
// Needs to be done differently for a generic implementation!
|
||||
void MakeArray(int siz)
|
||||
{
|
||||
BaseType = Type;
|
||||
Type = VAL_Array;
|
||||
size = siz;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue