1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-11 04:52:21 +02:00

Improved ClassView search for methods (ie: 'Parse(', or 'Par ( style')

This commit is contained in:
Brian Fiete 2022-01-08 08:16:53 -05:00
parent 59ba0dd0d4
commit d89c63290d

View file

@ -8357,7 +8357,7 @@ public:
} }
} }
void AddParams(BfMethodDef* methodDef) void AddParams(BfMethodDef* methodDef, StringImpl& result)
{ {
int visParamIdx = 0; int visParamIdx = 0;
for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++) for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++)
@ -8366,15 +8366,15 @@ public:
if ((paramDef->mParamKind == BfParamKind_AppendIdx) || (paramDef->mParamKind == BfParamKind_ImplicitCapture)) if ((paramDef->mParamKind == BfParamKind_AppendIdx) || (paramDef->mParamKind == BfParamKind_ImplicitCapture))
continue; continue;
if (visParamIdx > 0) if (visParamIdx > 0)
mResult += ", "; result += ", ";
StringT<64> refName; StringT<64> refName;
paramDef->mTypeRef->ToString(refName); paramDef->mTypeRef->ToString(refName);
Sanitize(refName); Sanitize(refName);
mResult += refName; result += refName;
mResult += " "; result += " ";
mResult += paramDef->mName; result += paramDef->mName;
visParamIdx++; visParamIdx++;
} }
} }
@ -8412,7 +8412,7 @@ public:
{ {
if (methodDef->mMethodType == BfMethodType_PropertyGetter) if (methodDef->mMethodType == BfMethodType_PropertyGetter)
{ {
AddParams(methodDef); AddParams(methodDef, mResult);
break; break;
} }
} }
@ -8429,30 +8429,37 @@ public:
mResult += "\n"; mResult += "\n";
} }
void AddMethodDef(BfMethodDef* methodDef) void GetMethodDefString(BfMethodDef* methodDef, StringImpl& result)
{ {
if (methodDef->mMethodType == BfMethodType_Ctor) if (methodDef->mMethodType == BfMethodType_Ctor)
{ {
if (methodDef->mIsStatic) if (methodDef->mIsStatic)
mResult += "static "; result += "static ";
mResult += "this"; result += "this";
} }
else if (methodDef->mMethodType == BfMethodType_Dtor) else if (methodDef->mMethodType == BfMethodType_Dtor)
{ {
if (methodDef->mIsStatic) if (methodDef->mIsStatic)
mResult += "static "; result += "static ";
mResult += "~this"; result += "~this";
} }
else else
mResult += methodDef->mName; result += methodDef->mName;
if (methodDef->mMethodType == BfMethodType_Mixin) if (methodDef->mMethodType == BfMethodType_Mixin)
mResult += "!"; result += "!";
mResult += "("; result += "(";
AddParams(methodDef); AddParams(methodDef, result);
mResult += ")"; result += ")";
}
void AddMethodDef(BfMethodDef* methodDef, StringImpl* methodDefString = NULL)
{
if (methodDefString != NULL)
mResult += *methodDefString;
else
GetMethodDefString(methodDef, mResult);
mResult += "\t"; mResult += "\t";
AddLocation(methodDef->GetRefNode()); AddLocation(methodDef->GetRefNode());
mResult += "\n"; mResult += "\n";
} }
@ -8479,10 +8486,10 @@ public:
return mFoundCount == mSearch.mSize; return mFoundCount == mSearch.mSize;
} }
uint32 CheckMatch(const StringView& str) uint32 CheckMatch(const StringView& str, int startIdx = 0)
{ {
uint32 matchFlags = 0; uint32 matchFlags = 0;
for (int i = 0; i < mSearch.mSize; i++) for (int i = startIdx; i < mSearch.mSize; i++)
{ {
auto& search = mSearch[i]; auto& search = mSearch[i];
if (((mFoundFlags & (1 << i)) == 0) && (str.IndexOf(search.mStr, true) != -1)) if (((mFoundFlags & (1 << i)) == 0) && (str.IndexOf(search.mStr, true) != -1))
@ -8555,6 +8562,9 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
String result; String result;
TypeDefMatchHelper matchHelper(result); TypeDefMatchHelper matchHelper(result);
int openParenIdx = -1;
bool parenHasDot = false;
// //
{ {
int searchIdx = 0; int searchIdx = 0;
@ -8587,6 +8597,14 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
if (searchEntry.mStr.IsEmpty()) if (searchEntry.mStr.IsEmpty())
searchEntry.mStr = str; searchEntry.mStr = str;
if (str.Contains('('))
{
if (str.Contains('.'))
parenHasDot = true;
if (openParenIdx == -1)
openParenIdx = matchHelper.mSearch.mSize;
}
if (!searchEntry.mStr.IsEmpty()) if (!searchEntry.mStr.IsEmpty())
matchHelper.mSearch.Add(searchEntry); matchHelper.mSearch.Add(searchEntry);
if (str.Contains('.')) if (str.Contains('.'))
@ -8643,6 +8661,8 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
int matchIdx = -1; int matchIdx = -1;
String tempStr;
if (!fullyMatchesName) if (!fullyMatchesName)
{ {
for (auto fieldDef : typeDef->mFields) for (auto fieldDef : typeDef->mFields)
@ -8674,7 +8694,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
matchHelper.AddPropertyDef(typeDef, propDef); matchHelper.AddPropertyDef(typeDef, propDef);
} }
} }
for (auto methodDef : typeDef->mMethods) for (auto methodDef : typeDef->mMethods)
{ {
if ((methodDef->mMethodType != BfMethodType_Normal) && if ((methodDef->mMethodType != BfMethodType_Normal) &&
@ -8687,15 +8707,40 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
continue; continue;
matchHelper.ClearResults(); matchHelper.ClearResults();
if (matchHelper.CheckMemberMatch(typeDef, methodDef->mName)) bool matches = matchHelper.CheckMemberMatch(typeDef, methodDef->mName);
bool hasTypeString = false;
bool hasMethodString = false;
if ((!matches) && (openParenIdx != -1))
{
hasMethodString = true;
tempStr.Clear();
if (parenHasDot)
{
hasTypeString = true;
if (BfTypeUtils::TypeToString(tempStr, typeDef, (BfTypeNameFlags)(BfTypeNameFlag_HideGlobalName | BfTypeNameFlag_InternalName)))
tempStr += ".";
}
matchHelper.GetMethodDefString(methodDef, tempStr);
matchHelper.CheckMatch(tempStr, openParenIdx);
matches = matchHelper.IsFullMatch();
}
if (matches)
{ {
if (methodDef->mIsOverride) if (methodDef->mIsOverride)
result += "o"; result += "o";
else else
result += "M"; result += "M";
if (BfTypeUtils::TypeToString(result, typeDef, (BfTypeNameFlags)(BfTypeNameFlag_HideGlobalName | BfTypeNameFlag_InternalName))) if (!hasTypeString)
result += "."; {
matchHelper.AddMethodDef(methodDef); if (BfTypeUtils::TypeToString(result, typeDef, (BfTypeNameFlags)(BfTypeNameFlag_HideGlobalName | BfTypeNameFlag_InternalName)))
result += ".";
}
if (hasMethodString)
matchHelper.AddMethodDef(methodDef, &tempStr);
else
matchHelper.AddMethodDef(methodDef);
} }
} }