Fixed comparison of class names for functions and fields

https://mantis.zdoom.org/view.php?id=426
This commit is contained in:
alexey.lysiuk 2017-03-14 14:40:20 +02:00 committed by Christoph Oelckers
parent 44a087554f
commit 6b8ea7ead3
1 changed files with 28 additions and 6 deletions

View File

@ -624,6 +624,30 @@ FPropertyInfo *FindProperty(const char * string)
return NULL;
}
//==========================================================================
//
//
//
//==========================================================================
template <typename Desc>
static int CompareClassNames(const char* const aname, const Desc& b)
{
// ++ to get past the prefix letter of the native class name, which gets omitted by the FName for the class.
const char* bname = b.ClassName;
if ('\0' != *bname) ++bname;
return stricmp(aname, bname);
}
template <typename Desc>
static int CompareClassNames(const Desc& a, const Desc& b)
{
// ++ to get past the prefix letter of the native class name, which gets omitted by the FName for the class.
const char* aname = a.ClassName;
if ('\0' != *aname) ++aname;
return CompareClassNames(aname, b);
}
//==========================================================================
//
// Find a function by name using a binary search
@ -637,7 +661,7 @@ AFuncDesc *FindFunction(PStruct *cls, const char * string)
while (min <= max)
{
int mid = (min + max) / 2;
int lexval = stricmp(cls->TypeName.GetChars(), AFTable[mid].ClassName + 1);
int lexval = CompareClassNames(cls->TypeName.GetChars(), AFTable[mid]);
if (lexval == 0) lexval = stricmp(string, AFTable[mid].FuncName);
if (lexval == 0)
{
@ -669,7 +693,7 @@ FieldDesc *FindField(PStruct *cls, const char * string)
while (min <= max)
{
int mid = (min + max) / 2;
int lexval = stricmp(cname, FieldTable[mid].ClassName + 1);
int lexval = CompareClassNames(cname, FieldTable[mid]);
if (lexval == 0) lexval = stricmp(string, FieldTable[mid].FieldName);
if (lexval == 0)
{
@ -719,16 +743,14 @@ static int propcmp(const void * a, const void * b)
static int funccmp(const void * a, const void * b)
{
// +1 to get past the prefix letter of the native class name, which gets omitted by the FName for the class.
int res = stricmp(((AFuncDesc*)a)->ClassName + 1, ((AFuncDesc*)b)->ClassName + 1);
int res = CompareClassNames(*(AFuncDesc*)a, *(AFuncDesc*)b);
if (res == 0) res = stricmp(((AFuncDesc*)a)->FuncName, ((AFuncDesc*)b)->FuncName);
return res;
}
static int fieldcmp(const void * a, const void * b)
{
// +1 to get past the prefix letter of the native class name, which gets omitted by the FName for the class.
int res = stricmp(((FieldDesc*)a)->ClassName + 1, ((FieldDesc*)b)->ClassName + 1);
int res = CompareClassNames(*(FieldDesc*)a, *(FieldDesc*)b);
if (res == 0) res = stricmp(((FieldDesc*)a)->FieldName, ((FieldDesc*)b)->FieldName);
return res;
}