1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Fixed autocomplete doc crash for generic methods

This commit is contained in:
Brian Fiete 2020-10-10 06:12:29 -07:00
parent 0f9ae6ab8c
commit 42a361a8c0
2 changed files with 36 additions and 27 deletions

View file

@ -483,7 +483,11 @@ void BfAutoComplete::AddMethod(BfTypeInstance* typeInstance, BfMethodDef* method
if ((methodInstance == NULL) && (methodDef != NULL)) if ((methodInstance == NULL) && (methodDef != NULL))
methodInstance = mModule->GetRawMethodInstance(typeInstance, methodDef); methodInstance = mModule->GetRawMethodInstance(typeInstance, methodDef);
if (methodInstance != NULL) if (methodInstance != NULL)
str = mModule->MethodToString(methodInstance, BfMethodNameFlag_IncludeReturnType); {
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mModule->mCurTypeInstance, typeInstance);
SetAndRestoreValue<BfMethodInstance*> prevCurMethodInstance(mModule->mCurMethodInstance, methodInstance);
str = mModule->MethodToString(methodInstance, (BfMethodNameFlags)(BfMethodNameFlag_IncludeReturnType | BfMethodNameFlag_ResolveGenericParamNames));
}
if (entryAdded->mDocumentation != NULL) if (entryAdded->mDocumentation != NULL)
{ {

View file

@ -9857,11 +9857,11 @@ bool BfModule::HasMixin(BfTypeInstance* typeInstance, const StringImpl& methodNa
StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags, BfTypeVector* methodGenericArgs) StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags, BfTypeVector* methodGenericArgs)
{ {
auto methodDef = methodInst->mMethodDef; auto methodDef = methodInst->mMethodDef;
bool allowResolveGenericParamNames = ((methodNameFlags & BfMethodNameFlag_ResolveGenericParamNames) != 0); bool allowResolveGenericParamNames = ((methodNameFlags & BfMethodNameFlag_ResolveGenericParamNames) != 0);
BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None; BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None;
BfType* type = methodInst->mMethodInstanceGroup->mOwner; BfType* type = methodInst->mMethodInstanceGroup->mOwner;
if ((methodGenericArgs != NULL) && (type->IsUnspecializedType())) if ((methodGenericArgs != NULL) && (type->IsUnspecializedType()))
type = ResolveGenericType(type, NULL, methodGenericArgs); type = ResolveGenericType(type, NULL, methodGenericArgs);
@ -9869,12 +9869,22 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames; typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
if (allowResolveGenericParamNames) if (allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames; typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
StringT<128> methodName; StringT<128> methodName;
auto _AddTypeName = [&](BfType* type)
{
auto typeNameFlags = BfTypeNameFlags_None;
if (allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
if ((methodGenericArgs != NULL) && (type->IsUnspecializedType()))
type = ResolveGenericType(type, NULL, methodGenericArgs);
methodName += TypeToString(type, typeNameFlags);
};
if ((methodNameFlags & BfMethodNameFlag_IncludeReturnType) != 0) if ((methodNameFlags & BfMethodNameFlag_IncludeReturnType) != 0)
{ {
methodName += TypeToString(methodInst->mReturnType); _AddTypeName(methodInst->mReturnType);
methodName += " "; methodName += " ";
} }
@ -9911,24 +9921,24 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
} }
if ((methodInst->mMethodInfoEx != NULL) && (methodInst->mMethodInfoEx->mForeignType != NULL)) if ((methodInst->mMethodInfoEx != NULL) && (methodInst->mMethodInfoEx->mForeignType != NULL))
{ {
BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None; BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None;
if (!methodInst->mIsUnspecializedVariation && allowResolveGenericParamNames) if (!methodInst->mIsUnspecializedVariation && allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames; typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
methodName += TypeToString(methodInst->mMethodInfoEx->mForeignType, typeNameFlags); methodName += TypeToString(methodInst->mMethodInfoEx->mForeignType, typeNameFlags);
methodName += "."; methodName += ".";
} }
if ((methodInst->mMethodInfoEx != NULL) && (methodInst->mMethodInfoEx->mExplicitInterface != NULL)) if ((methodInst->mMethodInfoEx != NULL) && (methodInst->mMethodInfoEx->mExplicitInterface != NULL))
{ {
BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None; BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None;
if (!methodInst->mIsUnspecializedVariation && allowResolveGenericParamNames) if (!methodInst->mIsUnspecializedVariation && allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames; typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
methodName += "["; methodName += "[";
methodName += TypeToString(methodInst->mMethodInfoEx->mExplicitInterface, typeNameFlags); methodName += TypeToString(methodInst->mMethodInfoEx->mExplicitInterface, typeNameFlags);
methodName += "]."; methodName += "].";
} }
if (methodDef->mMethodType == BfMethodType_Operator) if (methodDef->mMethodType == BfMethodType_Operator)
{ {
BfOperatorDef* operatorDef = (BfOperatorDef*)methodDef; BfOperatorDef* operatorDef = (BfOperatorDef*)methodDef;
@ -9960,7 +9970,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
else else
methodName += "this"; methodName += "this";
accessorString = ""; accessorString = "";
} }
else if (methodDef->mMethodType == BfMethodType_PropertyGetter) else if (methodDef->mMethodType == BfMethodType_PropertyGetter)
{ {
auto propertyDecl = methodDef->GetPropertyDeclaration(); auto propertyDecl = methodDef->GetPropertyDeclaration();
@ -9992,16 +10002,16 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
} }
} }
else else
methodName += methodDefName; methodName += methodDefName;
if (methodDef->mMethodType == BfMethodType_Mixin) if (methodDef->mMethodType == BfMethodType_Mixin)
methodName += "!"; methodName += "!";
BfTypeVector newMethodGenericArgs; BfTypeVector newMethodGenericArgs;
if ((methodInst->mMethodInfoEx != NULL) && (methodInst->mMethodInfoEx->mMethodGenericArguments.size() != 0)) if ((methodInst->mMethodInfoEx != NULL) && (methodInst->mMethodInfoEx->mMethodGenericArguments.size() != 0))
{ {
methodName += "<"; methodName += "<";
for (int i = 0; i < (int) methodInst->mMethodInfoEx->mMethodGenericArguments.size(); i++) for (int i = 0; i < (int)methodInst->mMethodInfoEx->mMethodGenericArguments.size(); i++)
{ {
if (i > 0) if (i > 0)
methodName += ", "; methodName += ", ";
@ -10020,7 +10030,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
hasEmpty = true; hasEmpty = true;
} }
if (hasEmpty) if (hasEmpty)
{ {
for (int genericIdx = 0; genericIdx < (int)methodGenericArgs->size(); genericIdx++) for (int genericIdx = 0; genericIdx < (int)methodGenericArgs->size(); genericIdx++)
{ {
auto arg = (*methodGenericArgs)[genericIdx]; auto arg = (*methodGenericArgs)[genericIdx];
@ -10035,7 +10045,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
newMethodGenericArgs.push_back(mContext->mBfObjectType); // Default newMethodGenericArgs.push_back(mContext->mBfObjectType); // Default
} }
} }
methodGenericArgs = &newMethodGenericArgs; methodGenericArgs = &newMethodGenericArgs;
} }
if (type->IsUnspecializedType()) if (type->IsUnspecializedType())
@ -10051,31 +10061,26 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
else else
methodName += TypeToString(type, typeNameFlags); methodName += TypeToString(type, typeNameFlags);
} }
methodName += ">"; methodName += ">";
} }
if (accessorString.length() == 0) if (accessorString.length() == 0)
{ {
int dispParamIdx = 0; int dispParamIdx = 0;
methodName += "("; methodName += "(";
for (int paramIdx = 0; paramIdx < (int) methodInst->GetParamCount(); paramIdx++) for (int paramIdx = 0; paramIdx < (int)methodInst->GetParamCount(); paramIdx++)
{ {
int paramKind = methodInst->GetParamKind(paramIdx); int paramKind = methodInst->GetParamKind(paramIdx);
if (paramKind == BfParamKind_ImplicitCapture) if (paramKind == BfParamKind_ImplicitCapture)
continue; continue;
if (dispParamIdx > 0) if (dispParamIdx > 0)
methodName += ", "; methodName += ", ";
if (paramKind == BfParamKind_Params) if (paramKind == BfParamKind_Params)
methodName += "params "; methodName += "params ";
typeNameFlags = BfTypeNameFlags_None;
if (allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
BfType* type = methodInst->GetParamType(paramIdx); BfType* type = methodInst->GetParamType(paramIdx);
if ((methodGenericArgs != NULL) && (type->IsUnspecializedType())) _AddTypeName(type);
type = ResolveGenericType(type, NULL, methodGenericArgs);
methodName += TypeToString(type, typeNameFlags);
methodName += " "; methodName += " ";
methodName += methodInst->GetParamName(paramIdx); methodName += methodInst->GetParamName(paramIdx);
@ -10091,7 +10096,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
} }
methodName += ")"; methodName += ")";
} }
if (accessorString.length() != 0) if (accessorString.length() != 0)
{ {
methodName += " " + accessorString; methodName += " " + accessorString;