Add a PSymbolConstString class

- Constants can be strings, but the existing PSymbolConst couldn't handle
  them. The old PSymbolConst is now PSymbolConstNumeric, and the new
  PSymbolConst is a now a baseclass for it and PSymbolConstString.
This commit is contained in:
Randy Heit 2013-09-10 22:01:00 -05:00
parent 33e835b58d
commit 2ab3974752
4 changed files with 47 additions and 23 deletions

View file

@ -2287,6 +2287,8 @@ CCMD(typetable)
IMPLEMENT_ABSTRACT_CLASS(PSymbol);
IMPLEMENT_CLASS(PSymbolConst);
IMPLEMENT_CLASS(PSymbolConstNumeric);
IMPLEMENT_CLASS(PSymbolConstString);
IMPLEMENT_POINTY_CLASS(PSymbolVMFunction)
DECLARE_POINTER(Function)
END_POINTERS

View file

@ -32,23 +32,6 @@ protected:
PSymbol(FName name) { SymbolName = name; }
};
// A constant value ---------------------------------------------------------
class PSymbolConst : public PSymbol
{
DECLARE_CLASS(PSymbolConst, PSymbol);
public:
class PType *ValueType;
union
{
int Value;
double Float;
};
PSymbolConst(FName name) : PSymbol(name) {}
PSymbolConst() : PSymbol(NAME_None) {}
};
// An action function -------------------------------------------------------
struct FState;
@ -654,4 +637,44 @@ extern PStatePointer *TypeState;
extern PFixed *TypeFixed;
extern PAngle *TypeAngle;
// 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;
};
PSymbolConstNumeric(FName name, PType *type=NULL) : PSymbolConst(name, type) {}
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() {}
};
#endif

View file

@ -294,7 +294,7 @@ ExpEmit FxParameter::Emit(VMFunctionBuilder *build)
FxExpression *FxConstant::MakeConstant(PSymbol *sym, const FScriptPosition &pos)
{
FxExpression *x;
PSymbolConst *csym = dyn_cast<PSymbolConst>(sym);
PSymbolConstNumeric *csym = dyn_cast<PSymbolConstNumeric>(sym);
if (csym != NULL)
{
if (csym->ValueType->IsA(RUNTIME_CLASS(PInt)))

View file

@ -202,15 +202,15 @@ static void ParseConstant (FScanner &sc, PSymbolTable *symt, PClassActor *cls)
{
ExpVal val = static_cast<FxConstant *>(expr)->GetValue();
delete expr;
PSymbolConst *sym = new PSymbolConst(symname);
PSymbolConstNumeric *sym;
if (type == TK_Int)
{
sym->ValueType = TypeSInt32;
sym = new PSymbolConstNumeric(symname, TypeSInt32);
sym->Value = val.GetInt();
}
else
{
sym->ValueType = TypeFloat64;
sym = new PSymbolConstNumeric(symname, TypeFloat64);
sym->Float = val.GetFloat();
}
if (symt->AddSymbol (sym) == NULL)
@ -260,8 +260,7 @@ static void ParseEnum (FScanner &sc, PSymbolTable *symt, PClassActor *cls)
}
delete expr;
}
PSymbolConst *sym = new PSymbolConst(symname);
sym->ValueType = TypeSInt32;
PSymbolConstNumeric *sym = new PSymbolConstNumeric(symname, TypeSInt32);
sym->Value = currvalue;
if (symt->AddSymbol (sym) == NULL)
{