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

Support for matching interface conformance in distinct build options

This commit is contained in:
Brian Fiete 2020-09-16 04:37:28 -07:00
parent 6cb1235fd6
commit 0b20ef867b
6 changed files with 87 additions and 25 deletions

View file

@ -267,10 +267,20 @@ namespace IDE.ui
else else
{ {
bool isValid = true; bool isValid = true;
for (let typeName in typeNames.Split(';')) for (var typeName in typeNames.Split(';'))
{ {
if ((!typeNames.StartsWith("@")) && (!gApp.mBfResolveCompiler.VerifyTypeName(scope String(typeName), -1))) if (!typeNames.StartsWith("@"))
isValid = false; {
while (!typeName.IsEmpty)
{
if ((typeName[0] != ':') && (!typeName[0].IsWhiteSpace))
break;
typeName.RemoveFromStart(1);
}
if (!gApp.mBfResolveCompiler.VerifyTypeName(scope String(typeName), -1))
isValid = false;
}
} }
subItem.mTextColor = isValid ? 0xFFFFFFFF : 0xFFFF8080; subItem.mTextColor = isValid ? 0xFFFFFFFF : 0xFFFF8080;
propEntry.mColorOverride = subItem.mTextColor; propEntry.mColorOverride = subItem.mTextColor;

View file

@ -34,6 +34,14 @@ namespace IDE.ui
editOffset = semiPos + 1; editOffset = semiPos + 1;
} }
while (editOffset < editText.Length)
{
char8 c = editText[editOffset];
if ((c != ':') && (!c.IsWhiteSpace))
break;
editOffset++;
}
editText.Remove(0, editOffset); editText.Remove(0, editOffset);
cursorPos -= editOffset; cursorPos -= editOffset;
// //
@ -47,7 +55,9 @@ namespace IDE.ui
if (editText.StartsWith("@")) if (editText.StartsWith("@"))
isValid = true; isValid = true;
else else
{
isValid = gApp.mBfResolveCompiler.VerifyTypeName(editText, cursorPos); isValid = gApp.mBfResolveCompiler.VerifyTypeName(editText, cursorPos);
}
for (int ofs < editText.Length) for (int ofs < editText.Length)
{ {
@ -82,14 +92,23 @@ namespace IDE.ui
text[i].mDisplayTypeId = 0; text[i].mDisplayTypeId = 0;
} }
for (let typeName in editText.Split(';')) for (var typeName in editText.Split(';'))
{ {
int startOfs = 0;
while (!typeName.IsEmpty)
{
if ((typeName[0] != ':') && (!typeName[0].IsWhiteSpace))
break;
typeName.RemoveFromStart(1);
startOfs++;
}
bool isValid = gApp.mBfResolveCompiler.VerifyTypeName(scope String(typeName), -1); bool isValid = gApp.mBfResolveCompiler.VerifyTypeName(scope String(typeName), -1);
if (!isValid) if (!isValid)
{ {
for (int ofs < typeName.Length) for (int ofs < typeName.Length)
{ {
text[@typeName.Pos + ofs].mDisplayTypeId = 1; text[@typeName.Pos + startOfs + ofs].mDisplayTypeId = 1;
} }
} }
} }

View file

@ -13051,8 +13051,14 @@ BfTypedValue BfExprEvaluator::MakeCallableTarget(BfAstNode* targetSrc, BfTypedVa
} }
else if (primStructType->IsSplattable()) else if (primStructType->IsSplattable())
{ {
BF_ASSERT(target.IsSplat()); BF_ASSERT(target.IsSplat() || target.mValue.IsFake());
target.mKind = BfTypedValueKind_SplatHead; if (target.IsSplat())
target.mKind = BfTypedValueKind_SplatHead;
else
{
if (!target.mValue.IsFake())
mModule->FailInternal("MakeCallableTarget splat fail", targetSrc);
}
} }
} }

View file

@ -1673,9 +1673,10 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn
int typeOptionsCount = (int)mContext->mSystem->mTypeOptions.size(); int typeOptionsCount = (int)mContext->mSystem->mTypeOptions.size();
if (checkTypeName) if (checkTypeName)
{ {
auto _CheckTypeName = [&](const StringImpl& typeName) auto _CheckType = [&](BfType* type)
{ {
StringImpl typeName = TypeToString(type);
for (int optionIdx = 0; optionIdx < (int)mContext->mSystem->mTypeOptions.size(); optionIdx++) for (int optionIdx = 0; optionIdx < (int)mContext->mSystem->mTypeOptions.size(); optionIdx++)
{ {
auto& typeOptions = mContext->mSystem->mTypeOptions[optionIdx]; auto& typeOptions = mContext->mSystem->mTypeOptions[optionIdx];
@ -1686,7 +1687,35 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn
int filterIdx = 0; int filterIdx = 0;
int typeNameIdx = 0; int typeNameIdx = 0;
if (BfCheckWildcard(filter, typeName)) if (filter.StartsWith(':'))
{
BfTypeInstance* typeInst = type->ToTypeInstance();
if (typeInst != NULL)
{
int startPos = 1;
for (; startPos < (int)filter.length(); startPos++)
if (filter[startPos] != ' ')
break;
String checkFilter;
checkFilter.Reference(filter.c_str() + startPos, filter.mLength - startPos);
BfTypeInstance* checkTypeInst = typeInst;
while (checkTypeInst != NULL)
{
for (auto& iface : checkTypeInst->mInterfaces)
{
StringT<128> ifaceName = TypeToString(iface.mInterfaceType);
if (BfCheckWildcard(checkFilter, ifaceName))
matched = true;
break;
}
checkTypeInst = checkTypeInst->mBaseType;
}
if (matched)
break;
}
}
else if (BfCheckWildcard(filter, typeName))
{ {
matched = true; matched = true;
break; break;
@ -1702,9 +1731,8 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn
{ {
auto underlyingType = typeInstance->GetUnderlyingType(); auto underlyingType = typeInstance->GetUnderlyingType();
if (underlyingType != NULL) if (underlyingType != NULL)
{ {
String typeName = TypeToString(underlyingType); _CheckType(underlyingType);
_CheckTypeName(typeName);
} }
else else
{ {
@ -1716,13 +1744,11 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn
{ {
BF_ASSERT(typeInstance->IsGenericTypeInstance()); BF_ASSERT(typeInstance->IsGenericTypeInstance());
auto innerType = typeInstance->mGenericTypeInfo->mTypeGenericArguments[0]; auto innerType = typeInstance->mGenericTypeInfo->mTypeGenericArguments[0];
auto ptrType = CreatePointerType(innerType); auto ptrType = CreatePointerType(innerType);
String typeName = TypeToString(ptrType); _CheckType(ptrType);
_CheckTypeName(typeName);
} }
String typeName = TypeToString(typeInstance); _CheckType(typeInstance);
_CheckTypeName(typeName);
} }
int matchedIdx = -1; int matchedIdx = -1;

View file

@ -1978,10 +1978,11 @@ bool BfTypeInstance::IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProje
bool BfTypeInstance::WantsGCMarking() bool BfTypeInstance::WantsGCMarking()
{ {
BF_ASSERT(mTypeDef->mTypeCode != BfTypeCode_Extension);
if (IsObjectOrInterface()) if (IsObjectOrInterface())
return true; return true;
if ((IsEnum()) && (!IsPayloadEnum())) if ((IsEnum()) && (!IsPayloadEnum()))
return false; return false;
BF_ASSERT(mDefineState >= BfTypeDefineState_Defined); BF_ASSERT(mDefineState >= BfTypeDefineState_Defined);
return mWantsGCMarking; return mWantsGCMarking;
} }
@ -2198,13 +2199,14 @@ BfType* BfTypeInstance::GetUnderlyingType()
bool BfTypeInstance::IsValuelessType() bool BfTypeInstance::IsValuelessType()
{ {
BF_ASSERT(mTypeDef->mTypeCode != BfTypeCode_Extension);
if ((mTypeDef->mTypeCode == BfTypeCode_Object) || (mTypeDef->mTypeCode == BfTypeCode_Interface)) if ((mTypeDef->mTypeCode == BfTypeCode_Object) || (mTypeDef->mTypeCode == BfTypeCode_Interface))
{ {
return false; return false;
} }
if (mTypeDef->mIsOpaque) if (mTypeDef->mIsOpaque)
return false; return false;
BF_ASSERT(mDefineState >= BfTypeDefineState_Defined); BF_ASSERT(mDefineState >= BfTypeDefineState_Defined);
BF_ASSERT(mInstSize >= 0); BF_ASSERT(mInstSize >= 0);
if (mInstSize == 0) if (mInstSize == 0)

View file

@ -2617,12 +2617,11 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef)
BF_ASSERT(typeDef->mFullNameEx == nextTypeDef->mFullNameEx); BF_ASSERT(typeDef->mFullNameEx == nextTypeDef->mFullNameEx);
typeDef->mProtection = nextTypeDef->mProtection; typeDef->mProtection = nextTypeDef->mProtection;
if ((typeDef->mTypeCode != BfTypeCode_Extension) && (!typeDef->mIsCombinedPartial))
BF_ASSERT(nextTypeDef->mTypeCode != BfTypeCode_Extension);
BF_ASSERT(typeDef->mTypeCode == nextTypeDef->mTypeCode); BF_ASSERT(typeDef->mTypeCode == nextTypeDef->mTypeCode);
typeDef->mTypeCode = nextTypeDef->mTypeCode; typeDef->mTypeCode = nextTypeDef->mTypeCode;
typeDef->mIsAlwaysInclude = nextTypeDef->mIsAlwaysInclude; typeDef->mIsAlwaysInclude = nextTypeDef->mIsAlwaysInclude;
typeDef->mIsNoDiscard = nextTypeDef->mIsNoDiscard; typeDef->mIsNoDiscard = nextTypeDef->mIsNoDiscard;
typeDef->mIsPartial = nextTypeDef->mIsPartial; typeDef->mIsPartial = nextTypeDef->mIsPartial;