- Backend update from GZDoom.

* ZScript compiler fixes for type promotion
* FileSystem.FindLumpFullName
* Statusbar text scaling fixes.
* removed scalar addition operators from vectors.
This commit is contained in:
Christoph Oelckers 2022-08-11 22:28:40 +02:00
parent 9c107049fd
commit 77bc5999ce
8 changed files with 117 additions and 50 deletions

View file

@ -1813,7 +1813,7 @@ PType *ZCCCompiler::DetermineType(PType *outertype, ZCC_TreeNode *field, FName n
{ {
Error(field, "%s: @ not allowed for user scripts", name.GetChars()); Error(field, "%s: @ not allowed for user scripts", name.GetChars());
} }
retval = ResolveUserType(btype, outertype? &outertype->Symbols : nullptr, true); retval = ResolveUserType(btype, btype->UserType, outertype? &outertype->Symbols : nullptr, true);
break; break;
case ZCC_UserType: case ZCC_UserType:
@ -1837,7 +1837,7 @@ PType *ZCCCompiler::DetermineType(PType *outertype, ZCC_TreeNode *field, FName n
break; break;
default: default:
retval = ResolveUserType(btype, outertype ? &outertype->Symbols : nullptr, false); retval = ResolveUserType(btype, btype->UserType, outertype ? &outertype->Symbols : nullptr, false);
break; break;
} }
break; break;
@ -1936,18 +1936,25 @@ PType *ZCCCompiler::DetermineType(PType *outertype, ZCC_TreeNode *field, FName n
// //
// ZCCCompiler :: ResolveUserType // ZCCCompiler :: ResolveUserType
// //
// resolves a user type and returns a matching PType
//
//========================================================================== //==========================================================================
PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, PSymbolTable *symt, bool nativetype) /**
* Resolves a user type and returns a matching PType.
*
* @param type The tree node with the identifiers to look for.
* @param type The current identifier being looked for. This must be in type's UserType list.
* @param symt The symbol table to search in. If id is the first identifier and not found in symt, then OutNamespace will also be searched.
* @param nativetype Distinguishes between searching for a native type or a user type.
* @returns the PType found for this user type
*/
PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, ZCC_Identifier *id, PSymbolTable *symt, bool nativetype)
{ {
// Check the symbol table for the identifier. // Check the symbol table for the identifier.
PSymbol *sym = nullptr; PSymbol *sym = nullptr;
// We first look in the current class and its parents, and then in the current namespace and its parents. // We first look in the current class and its parents, and then in the current namespace and its parents.
if (symt != nullptr) sym = symt->FindSymbol(type->UserType->Id, true); if (symt != nullptr) sym = symt->FindSymbol(id->Id, true);
if (sym == nullptr) sym = OutNamespace->Symbols.FindSymbol(type->UserType->Id, true); if (sym == nullptr && type->UserType == id) sym = OutNamespace->Symbols.FindSymbol(id->Id, true);
if (sym != nullptr && sym->IsKindOf(RUNTIME_CLASS(PSymbolType))) if (sym != nullptr && sym->IsKindOf(RUNTIME_CLASS(PSymbolType)))
{ {
auto ptype = static_cast<PSymbolType *>(sym)->Type; auto ptype = static_cast<PSymbolType *>(sym)->Type;
@ -1957,6 +1964,21 @@ PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, PSymbolTable *symt, boo
return TypeError; return TypeError;
} }
if (id->SiblingNext != type->UserType)
{
assert(id->SiblingNext->NodeType == AST_Identifier);
ptype = ResolveUserType(
type,
static_cast<ZCC_Identifier *>(id->SiblingNext),
&ptype->Symbols,
nativetype
);
if (ptype == TypeError)
{
return ptype;
}
}
if (ptype->isEnum()) if (ptype->isEnum())
{ {
if (!nativetype) return TypeSInt32; // hack this to an integer until we can resolve the enum mess. if (!nativetype) return TypeSInt32; // hack this to an integer until we can resolve the enum mess.
@ -1972,11 +1994,36 @@ PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, PSymbolTable *symt, boo
} }
if (!nativetype) return ptype; if (!nativetype) return ptype;
} }
Error(type, "Unable to resolve %s%s as type.", nativetype? "@" : "", FName(type->UserType->Id).GetChars()); Error(type, "Unable to resolve %s%s as a type.", nativetype? "@" : "", UserTypeName(type).GetChars());
return TypeError; return TypeError;
} }
//==========================================================================
//
// ZCCCompiler :: UserTypeName STATIC
//
// Returns the full name for a UserType node.
//
//==========================================================================
FString ZCCCompiler::UserTypeName(ZCC_BasicType *type)
{
FString out;
ZCC_Identifier *id = type->UserType;
do
{
assert(id->NodeType == AST_Identifier);
if (out.Len() > 0)
{
out += '.';
}
out += FName(id->Id).GetChars();
} while ((id = static_cast<ZCC_Identifier *>(id->SiblingNext)) != type->UserType);
return out;
}
//========================================================================== //==========================================================================
// //
// ZCCCompiler :: ResolveArraySize // ZCCCompiler :: ResolveArraySize
@ -2317,9 +2364,13 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
} }
} }
if (type->GetRegType() == REGT_NIL && type != TypeVector2 && type != TypeVector3 && type != TypeFVector2 && type != TypeFVector3) if (type->GetRegType() == REGT_NIL && type != TypeVector2 && type != TypeVector3 && type != TypeFVector2 && type != TypeFVector3)
{
// If it's TypeError, then an error was already given
if (type != TypeError)
{ {
Error(p, "Invalid type %s for function parameter", type->DescriptiveName()); Error(p, "Invalid type %s for function parameter", type->DescriptiveName());
} }
}
else if (p->Default != nullptr) else if (p->Default != nullptr)
{ {
if (flags & VARF_Out) if (flags & VARF_Out)

View file

@ -134,7 +134,8 @@ protected:
FString FlagsToString(uint32_t flags); FString FlagsToString(uint32_t flags);
PType *DetermineType(PType *outertype, ZCC_TreeNode *field, FName name, ZCC_Type *ztype, bool allowarraytypes, bool formember); PType *DetermineType(PType *outertype, ZCC_TreeNode *field, FName name, ZCC_Type *ztype, bool allowarraytypes, bool formember);
PType *ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, PContainerType *cls, bool *nosize); PType *ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, PContainerType *cls, bool *nosize);
PType *ResolveUserType(ZCC_BasicType *type, PSymbolTable *sym, bool nativetype); PType *ResolveUserType(ZCC_BasicType *type, ZCC_Identifier *id, PSymbolTable *sym, bool nativetype);
static FString UserTypeName(ZCC_BasicType *type);
TArray<ZCC_StructWork *> OrderStructs(); TArray<ZCC_StructWork *> OrderStructs();
void AddStruct(TArray<ZCC_StructWork *> &new_order, ZCC_StructWork *struct_def); void AddStruct(TArray<ZCC_StructWork *> &new_order, ZCC_StructWork *struct_def);
ZCC_StructWork *StructTypeToWork(const PStruct *type) const; ZCC_StructWork *StructTypeToWork(const PStruct *type) const;

View file

@ -758,6 +758,16 @@ DEFINE_ACTION_FUNCTION(_Wads, FindLump)
ACTION_RETURN_INT(isLumpValid ? fileSystem.FindLump(name, &startlump, 0 != ns) : -1); ACTION_RETURN_INT(isLumpValid ? fileSystem.FindLump(name, &startlump, 0 != ns) : -1);
} }
DEFINE_ACTION_FUNCTION(_Wads, FindLumpFullName)
{
PARAM_PROLOGUE;
PARAM_STRING(name);
PARAM_INT(startlump);
PARAM_BOOL(noext);
const bool isLumpValid = startlump >= 0 && startlump < fileSystem.GetNumEntries();
ACTION_RETURN_INT(isLumpValid ? fileSystem.FindLumpFullName(name, &startlump, noext) : -1);
}
DEFINE_ACTION_FUNCTION(_Wads, GetLumpName) DEFINE_ACTION_FUNCTION(_Wads, GetLumpName)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;

View file

@ -745,7 +745,7 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d
{ {
if (ch == ' ') if (ch == ' ')
{ {
x += monospaced ? spacing : font->GetSpaceWidth() + spacing; x += (monospaced ? spacing : font->GetSpaceWidth() + spacing) * scaleX;
continue; continue;
} }
else if (ch == TEXTCOLOR_ESCAPE) else if (ch == TEXTCOLOR_ESCAPE)
@ -765,7 +765,7 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d
width += font->GetDefaultKerning(); width += font->GetDefaultKerning();
if (!monospaced) //If we are monospaced lets use the offset if (!monospaced) //If we are monospaced lets use the offset
x += (c->GetDisplayLeftOffset() + 1); //ignore x offsets since we adapt to character size x += (c->GetDisplayLeftOffset() * scaleX + 1); //ignore x offsets since we adapt to character size
double rx, ry, rw, rh; double rx, ry, rw, rh;
rx = x + drawOffset.X; rx = x + drawOffset.X;
@ -816,12 +816,12 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d
DTA_LegacyRenderStyle, ERenderStyle(style), DTA_LegacyRenderStyle, ERenderStyle(style),
TAG_DONE); TAG_DONE);
dx = monospaced
? spacing
: width + spacing - (c->GetDisplayLeftOffset() + 1);
// Take text scale into account // Take text scale into account
x += dx * scaleX; dx = monospaced
? spacing * scaleX
: (double(width) + spacing - c->GetDisplayLeftOffset()) * scaleX - 1;
x += dx;
} }
} }

View file

@ -141,11 +141,13 @@ struct TVector2
} }
// Scalar addition // Scalar addition
#if 0
TVector2 &operator+= (double scalar) TVector2 &operator+= (double scalar)
{ {
X += scalar, Y += scalar; X += scalar, Y += scalar;
return *this; return *this;
} }
#endif
friend TVector2 operator+ (const TVector2 &v, vec_t scalar) friend TVector2 operator+ (const TVector2 &v, vec_t scalar)
{ {
@ -385,11 +387,13 @@ struct TVector3
} }
// Scalar addition // Scalar addition
#if 0
TVector3 &operator+= (vec_t scalar) TVector3 &operator+= (vec_t scalar)
{ {
X += scalar, Y += scalar, Z += scalar; X += scalar, Y += scalar, Z += scalar;
return *this; return *this;
} }
#endif
friend TVector3 operator+ (const TVector3 &v, vec_t scalar) friend TVector3 operator+ (const TVector3 &v, vec_t scalar)
{ {

View file

@ -830,6 +830,7 @@ struct Wads // todo: make FileSystem an alias to 'Wads'
native static int CheckNumForName(string name, int ns, int wadnum = -1, bool exact = false); native static int CheckNumForName(string name, int ns, int wadnum = -1, bool exact = false);
native static int CheckNumForFullName(string name); native static int CheckNumForFullName(string name);
native static int FindLump(string name, int startlump = 0, FindLumpNamespace ns = GlobalNamespace); native static int FindLump(string name, int startlump = 0, FindLumpNamespace ns = GlobalNamespace);
native static int FindLumpFullName(string name, int startlump = 0, bool noext = false);
native static string ReadLump(int lump); native static string ReadLump(int lump);
native static int GetNumLumps(); native static int GetNumLumps();

View file

@ -8,16 +8,16 @@ struct DynArray_I8 native
native void Copy(DynArray_I8 other); native void Copy(DynArray_I8 other);
native void Move(DynArray_I8 other); native void Move(DynArray_I8 other);
native void Append (DynArray_I8 other); native void Append (DynArray_I8 other);
native uint Find(int item) const; native int Find(int item) const;
native uint Push (int item); native int Push(int item);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
native void Insert (uint index, int item); native void Insert (uint index, int item);
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }
@ -28,16 +28,16 @@ struct DynArray_I16 native
native void Copy(DynArray_I16 other); native void Copy(DynArray_I16 other);
native void Move(DynArray_I16 other); native void Move(DynArray_I16 other);
native void Append (DynArray_I16 other); native void Append (DynArray_I16 other);
native uint Find(int item) const; native int Find(int item) const;
native uint Push (int item); native int Push(int item);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
native void Insert (uint index, int item); native void Insert (uint index, int item);
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }
@ -48,8 +48,8 @@ struct DynArray_I32 native
native void Copy(DynArray_I32 other); native void Copy(DynArray_I32 other);
native void Move(DynArray_I32 other); native void Move(DynArray_I32 other);
native void Append (DynArray_I32 other); native void Append (DynArray_I32 other);
native uint Find(int item) const; native int Find(int item) const;
native uint Push (int item); native int Push(int item);
native vararg uint PushV (int item, ...); native vararg uint PushV (int item, ...);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
@ -57,8 +57,8 @@ struct DynArray_I32 native
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }
@ -69,16 +69,16 @@ struct DynArray_F32 native
native void Copy(DynArray_F32 other); native void Copy(DynArray_F32 other);
native void Move(DynArray_F32 other); native void Move(DynArray_F32 other);
native void Append (DynArray_F32 other); native void Append (DynArray_F32 other);
native uint Find(double item) const; native int Find(double item) const;
native uint Push (double item); native int Push(double item);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
native void Insert (uint index, double item); native void Insert (uint index, double item);
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }
@ -89,16 +89,16 @@ struct DynArray_F64 native
native void Copy(DynArray_F64 other); native void Copy(DynArray_F64 other);
native void Move(DynArray_F64 other); native void Move(DynArray_F64 other);
native void Append (DynArray_F64 other); native void Append (DynArray_F64 other);
native uint Find(double item) const; native int Find(double item) const;
native uint Push (double item); native int Push(double item);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
native void Insert (uint index, double item); native void Insert (uint index, double item);
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }
@ -109,16 +109,16 @@ struct DynArray_Ptr native
native void Copy(DynArray_Ptr other); native void Copy(DynArray_Ptr other);
native void Move(DynArray_Ptr other); native void Move(DynArray_Ptr other);
native void Append (DynArray_Ptr other); native void Append (DynArray_Ptr other);
native uint Find(voidptr item) const; native int Find(voidptr item) const;
native uint Push (voidptr item); native int Push(voidptr item);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
native void Insert (uint index, voidptr item); native void Insert (uint index, voidptr item);
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }
@ -129,16 +129,16 @@ struct DynArray_Obj native
native void Copy(DynArray_Obj other); native void Copy(DynArray_Obj other);
native void Move(DynArray_Obj other); native void Move(DynArray_Obj other);
native void Append (DynArray_Obj other); native void Append (DynArray_Obj other);
native uint Find(Object item) const; native int Find(Object item) const;
native uint Push (Object item); native int Push(Object item);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
native void Insert (uint index, Object item); native void Insert (uint index, Object item);
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }
@ -149,8 +149,8 @@ struct DynArray_String native
native void Copy(DynArray_String other); native void Copy(DynArray_String other);
native void Move(DynArray_String other); native void Move(DynArray_String other);
native void Append (DynArray_String other); native void Append (DynArray_String other);
native uint Find(String item) const; native int Find(String item) const;
native uint Push (String item); native int Push(String item);
native vararg uint PushV(String item, ...); native vararg uint PushV(String item, ...);
native bool Pop (); native bool Pop ();
native void Delete (uint index, int deletecount = 1); native void Delete (uint index, int deletecount = 1);
@ -158,7 +158,7 @@ struct DynArray_String native
native void ShrinkToFit (); native void ShrinkToFit ();
native void Grow (uint amount); native void Grow (uint amount);
native void Resize (uint amount); native void Resize (uint amount);
native uint Reserve (uint amount); native int Reserve(uint amount);
native uint Max () const; native int Max() const;
native void Clear (); native void Clear ();
} }

View file

@ -304,7 +304,7 @@ class OptionMenuItemOptionBase : OptionMenuItem
int Selection = GetSelection(); int Selection = GetSelection();
String text = StringTable.Localize(OptionValues.GetText(mValues, Selection)); String text = StringTable.Localize(OptionValues.GetText(mValues, Selection));
if (text.Length() == 0) text = "Unknown"; if (text.Length() == 0) text = StringTable.Localize("$TXT_UNKNOWN");
drawValue(indent, y, OptionMenuSettings.mFontColorValue, text, isGrayed()); drawValue(indent, y, OptionMenuSettings.mFontColorValue, text, isGrayed());
return indent; return indent;
} }