- first stage of simplifying the type system.
Let's use inline checkers in PType instead of constantly having to do clumsy IsKindOf checks etc. Once complete this also means that the types can be taken out of the class hierarchy, freeing up some common names.
This commit is contained in:
parent
522ce59be2
commit
b2d944974e
16 changed files with 152 additions and 137 deletions
|
|
@ -593,7 +593,7 @@ static void PrintExprConstant(FLispString &out, ZCC_TreeNode *node)
|
|||
{
|
||||
out.AddName(ENamedName(enode->IntVal));
|
||||
}
|
||||
else if (enode->Type->IsKindOf(RUNTIME_CLASS(PInt)))
|
||||
else if (enode->Type->isIntCompatible())
|
||||
{
|
||||
out.AddInt(enode->IntVal, static_cast<PInt *>(enode->Type)->Unsigned);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ enum_def(X) ::= ENUM(T) IDENTIFIER(A) enum_type(B) LBRACE opt_enum_list(C) RBRAC
|
|||
// Compute implicit values by adding one to the preceding value.
|
||||
assert(prev->Value != NULL);
|
||||
// If the preceding node is a constant, then we can do this now.
|
||||
if (prev->Value->Operation == PEX_ConstValue && prev->Value->Type->IsA(RUNTIME_CLASS(PInt)))
|
||||
if (prev->Value->Operation == PEX_ConstValue && prev->Value->Type->isInt())
|
||||
{
|
||||
NEW_INTCONST_NODE(cval, prev->Value->Type, static_cast<ZCC_ExprConstant *>(prev->Value)->IntVal + 1, node);
|
||||
node->Value = cval;
|
||||
|
|
@ -1256,9 +1256,9 @@ unary_expr(X) ::= primary(X).
|
|||
unary_expr(X) ::= SUB unary_expr(A). [UNARY]
|
||||
{
|
||||
ZCC_ExprConstant *con = static_cast<ZCC_ExprConstant *>(A);
|
||||
if (A->Operation == PEX_ConstValue && (con->Type->IsA(RUNTIME_CLASS(PInt)) || con->Type->IsA(RUNTIME_CLASS(PFloat))))
|
||||
if (A->Operation == PEX_ConstValue && (con->Type->isInt() || con->Type->isFloat()))
|
||||
{ // For constants, manipulate the child node directly, and don't create a new node.
|
||||
if (con->Type->IsA(RUNTIME_CLASS(PInt)))
|
||||
if (con->Type->isInt())
|
||||
{
|
||||
con->IntVal = -con->IntVal;
|
||||
}
|
||||
|
|
@ -1280,7 +1280,7 @@ unary_expr(X) ::= ADD unary_expr(A). [UNARY]
|
|||
// it so we can type check that it is being applied to something numeric.
|
||||
// But we can do that right now for constant numerals.
|
||||
ZCC_ExprConstant *con = static_cast<ZCC_ExprConstant *>(A);
|
||||
if (A->Operation != PEX_ConstValue || (!con->Type->IsA(RUNTIME_CLASS(PInt)) && !con->Type->IsA(RUNTIME_CLASS(PFloat))))
|
||||
if (A->Operation != PEX_ConstValue || (!con->Type->isInt() && !con->Type->isFloat()))
|
||||
{
|
||||
UNARY_EXPR(A,PEX_AntiNegate);
|
||||
X = expr1;
|
||||
|
|
|
|||
|
|
@ -873,13 +873,13 @@ void ZCCCompiler::AddConstant(ZCC_ConstantWork &constant)
|
|||
{
|
||||
def->Symbol = new PSymbolConstString(def->NodeName, *(cval->StringVal));
|
||||
}
|
||||
else if (cval->Type->IsA(RUNTIME_CLASS(PInt)))
|
||||
else if (cval->Type->isInt())
|
||||
{
|
||||
// How do we get an Enum type in here without screwing everything up???
|
||||
//auto type = def->Type != nullptr ? def->Type : cval->Type;
|
||||
def->Symbol = new PSymbolConstNumeric(def->NodeName, cval->Type, cval->IntVal);
|
||||
}
|
||||
else if (cval->Type->IsA(RUNTIME_CLASS(PFloat)))
|
||||
else if (cval->Type->isFloat())
|
||||
{
|
||||
if (def->Type != nullptr)
|
||||
{
|
||||
|
|
@ -899,13 +899,13 @@ void ZCCCompiler::AddConstant(ZCC_ConstantWork &constant)
|
|||
{
|
||||
def->Symbol = new PSymbolConstString(def->NodeName, c.GetString());
|
||||
}
|
||||
else if (c.Type->IsA(RUNTIME_CLASS(PInt)))
|
||||
else if (c.Type->isInt())
|
||||
{
|
||||
// How do we get an Enum type in here without screwing everything up???
|
||||
//auto type = def->Type != nullptr ? def->Type : cval->Type;
|
||||
def->Symbol = new PSymbolConstNumeric(def->NodeName, c.Type, c.GetInt());
|
||||
}
|
||||
else if (c.Type->IsA(RUNTIME_CLASS(PFloat)))
|
||||
else if (c.Type->isFloat())
|
||||
{
|
||||
if (def->Type != nullptr)
|
||||
{
|
||||
|
|
@ -974,7 +974,7 @@ void ZCCCompiler::CompileArrays(ZCC_StructWork *work)
|
|||
FArgumentList values;
|
||||
|
||||
// Don't use narrow typea for casting.
|
||||
if (ctype->IsA(RUNTIME_CLASS(PInt))) ctype = static_cast<PInt*>(ztype)->Unsigned ? TypeUInt32 : TypeSInt32;
|
||||
if (ctype->isInt()) ctype = static_cast<PInt*>(ztype)->Unsigned ? TypeUInt32 : TypeSInt32;
|
||||
else if (ctype == TypeFloat32) ctype = TypeFloat64;
|
||||
|
||||
ConvertNodeList(values, sas->Values);
|
||||
|
|
@ -1077,13 +1077,13 @@ ZCC_ExprConstant *ZCCCompiler::NodeFromSymbolConst(PSymbolConst *sym, ZCC_Expres
|
|||
if (val->Type != TypeError)
|
||||
{
|
||||
assert(sym->IsKindOf(RUNTIME_CLASS(PSymbolConstNumeric)));
|
||||
if (sym->ValueType->IsKindOf(RUNTIME_CLASS(PInt)))
|
||||
if (sym->ValueType->isIntCompatible())
|
||||
{
|
||||
val->IntVal = static_cast<PSymbolConstNumeric *>(sym)->Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(sym->ValueType->IsKindOf(RUNTIME_CLASS(PFloat)));
|
||||
assert(sym->ValueType->isFloat());
|
||||
val->DoubleVal = static_cast<PSymbolConstNumeric *>(sym)->Float;
|
||||
}
|
||||
}
|
||||
|
|
@ -1752,7 +1752,7 @@ PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize,
|
|||
ex = ex->Resolve(ctx);
|
||||
|
||||
if (ex == nullptr) return TypeError;
|
||||
if (!ex->isConstant() || !ex->ValueType->IsA(RUNTIME_CLASS(PInt)))
|
||||
if (!ex->isConstant() || !ex->ValueType->isInt())
|
||||
{
|
||||
Error(arraysize, "Array index must be an integer constant");
|
||||
return TypeError;
|
||||
|
|
@ -2023,15 +2023,15 @@ void ZCCCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *prop
|
|||
{
|
||||
*(PalEntry*)addr = V_GetColor(nullptr, GetStringConst(ex, ctx), &ex->ScriptPosition);
|
||||
}
|
||||
else if (f->Type->IsKindOf(RUNTIME_CLASS(PInt)))
|
||||
else if (f->Type->isIntCompatible())
|
||||
{
|
||||
static_cast<PInt*>(f->Type)->SetValue(addr, GetIntConst(ex, ctx));
|
||||
}
|
||||
else if (f->Type->IsKindOf(RUNTIME_CLASS(PFloat)))
|
||||
else if (f->Type->isFloat())
|
||||
{
|
||||
static_cast<PFloat*>(f->Type)->SetValue(addr, GetFloatConst(ex, ctx));
|
||||
}
|
||||
else if (f->Type->IsKindOf(RUNTIME_CLASS(PString)))
|
||||
else if (f->Type == TypeString)
|
||||
{
|
||||
*(FString*)addr = GetStringConst(ex, ctx);
|
||||
}
|
||||
|
|
@ -2304,7 +2304,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
|
|||
do
|
||||
{
|
||||
auto type = DetermineType(c->Type(), f, f->Name, t, false, false);
|
||||
if (type->IsKindOf(RUNTIME_CLASS(PContainerType)) && type != TypeVector2 && type != TypeVector3)
|
||||
if (type->isContainer() && type != TypeVector2 && type != TypeVector3)
|
||||
{
|
||||
// structs and classes only get passed by pointer.
|
||||
type = NewPointer(type);
|
||||
|
|
@ -3228,23 +3228,23 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast)
|
|||
case AST_ExprConstant:
|
||||
{
|
||||
auto cnst = static_cast<ZCC_ExprConstant *>(ast);
|
||||
if (cnst->Type->IsA(RUNTIME_CLASS(PName)))
|
||||
if (cnst->Type == TypeName)
|
||||
{
|
||||
return new FxConstant(FName(ENamedName(cnst->IntVal)), *ast);
|
||||
}
|
||||
else if (cnst->Type->IsA(RUNTIME_CLASS(PInt)))
|
||||
else if (cnst->Type->isInt())
|
||||
{
|
||||
return new FxConstant(cnst->IntVal, *ast);
|
||||
}
|
||||
else if (cnst->Type->IsA(RUNTIME_CLASS(PBool)))
|
||||
else if (cnst->Type == TypeBool)
|
||||
{
|
||||
return new FxConstant(!!cnst->IntVal, *ast);
|
||||
}
|
||||
else if (cnst->Type->IsA(RUNTIME_CLASS(PFloat)))
|
||||
else if (cnst->Type->isFloat())
|
||||
{
|
||||
return new FxConstant(cnst->DoubleVal, *ast);
|
||||
}
|
||||
else if (cnst->Type->IsA(RUNTIME_CLASS(PString)))
|
||||
else if (cnst->Type == TypeString)
|
||||
{
|
||||
return new FxConstant(*cnst->StringVal, *ast);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue