- 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());
}
retval = ResolveUserType(btype, outertype? &outertype->Symbols : nullptr, true);
retval = ResolveUserType(btype, btype->UserType, outertype? &outertype->Symbols : nullptr, true);
break;
case ZCC_UserType:
@ -1837,7 +1837,7 @@ PType *ZCCCompiler::DetermineType(PType *outertype, ZCC_TreeNode *field, FName n
break;
default:
retval = ResolveUserType(btype, outertype ? &outertype->Symbols : nullptr, false);
retval = ResolveUserType(btype, btype->UserType, outertype ? &outertype->Symbols : nullptr, false);
break;
}
break;
@ -1936,18 +1936,25 @@ PType *ZCCCompiler::DetermineType(PType *outertype, ZCC_TreeNode *field, FName n
//
// 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.
PSymbol *sym = nullptr;
// 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 (sym == nullptr) sym = OutNamespace->Symbols.FindSymbol(type->UserType->Id, true);
if (symt != nullptr) sym = symt->FindSymbol(id->Id, true);
if (sym == nullptr && type->UserType == id) sym = OutNamespace->Symbols.FindSymbol(id->Id, true);
if (sym != nullptr && sym->IsKindOf(RUNTIME_CLASS(PSymbolType)))
{
auto ptype = static_cast<PSymbolType *>(sym)->Type;
@ -1957,6 +1964,21 @@ PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, PSymbolTable *symt, boo
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 (!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;
}
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;
}
//==========================================================================
//
// 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
@ -2318,7 +2365,11 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
}
if (type->GetRegType() == REGT_NIL && type != TypeVector2 && type != TypeVector3 && type != TypeFVector2 && type != TypeFVector3)
{
Error(p, "Invalid type %s for function parameter", type->DescriptiveName());
// If it's TypeError, then an error was already given
if (type != TypeError)
{
Error(p, "Invalid type %s for function parameter", type->DescriptiveName());
}
}
else if (p->Default != nullptr)
{

View file

@ -134,7 +134,8 @@ protected:
FString FlagsToString(uint32_t flags);
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 *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();
void AddStruct(TArray<ZCC_StructWork *> &new_order, ZCC_StructWork *struct_def);
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);
}
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)
{
PARAM_PROLOGUE;