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

Added Obsolete support for moved collections

This commit is contained in:
Brian Fiete 2020-04-29 09:53:48 -07:00
parent dbd9b32e3f
commit 842a6a8898
16 changed files with 232 additions and 109 deletions

View file

@ -4623,6 +4623,16 @@ void BfCompiler::MarkStringPool(BfModule* module)
MarkStringPool(specModulePair.mValue);
}
void BfCompiler::MarkStringPool(BfIRConstHolder* constHolder, BfIRValue irValue)
{
auto constant = constHolder->GetConstant(irValue);
if ((constant != NULL) && (constant->mTypeCode == BfTypeCode_StringId))
{
BfStringPoolEntry& stringPoolEntry = mContext->mStringObjectIdMap[constant->mInt32];
stringPoolEntry.mLastUsedRevision = mRevision;
}
}
void BfCompiler::ClearUnusedStringPoolEntries()
{
BF_ASSERT(!IsHotCompile());
@ -4630,6 +4640,24 @@ void BfCompiler::ClearUnusedStringPoolEntries()
for (auto module : mContext->mModules)
{
MarkStringPool(module);
}
for (auto type : mContext->mResolvedTypes)
{
auto typeInstance = type->ToTypeInstance();
if (typeInstance == NULL)
continue;
if (typeInstance->mCustomAttributes == NULL)
continue;
for (auto& attribute : typeInstance->mCustomAttributes->mAttributes)
{
for (auto arg : attribute.mCtorArgs)
MarkStringPool(typeInstance->mConstHolder, arg);
for (auto setValue : attribute.mSetProperties)
MarkStringPool(typeInstance->mConstHolder, setValue.mParam.mValue);
for (auto setValue : attribute.mSetField)
MarkStringPool(typeInstance->mConstHolder, setValue.mParam.mValue);
}
}
for (auto itr = mContext->mStringObjectIdMap.begin(); itr != mContext->mStringObjectIdMap.end(); )

View file

@ -437,6 +437,7 @@ public:
BfTypeDef* GetArrayTypeDef(int dimensions);
void GenerateAutocompleteInfo();
void MarkStringPool(BfModule* module);
void MarkStringPool(BfIRConstHolder* constHolder, BfIRValue irValue);
void ClearUnusedStringPoolEntries();
void ClearBuildCache();
int GetDynCastVDataCount();

View file

@ -4134,77 +4134,8 @@ void BfExprEvaluator::ResolveArgValues(BfResolvedArgs& resolvedArgs, BfResolveAr
void BfExprEvaluator::PerformCallChecks(BfMethodInstance* methodInstance, BfAstNode* targetSrc)
{
BfCustomAttributes* customAttributes = methodInstance->GetCustomAttributes();
if (customAttributes != NULL)
{
auto _AddMethodDeclarationMoreInfo = [&]()
{
if (methodInstance->mMethodDef->mMethodDeclaration != NULL)
mModule->mCompiler->mPassInstance->MoreInfo(
StrFormat("See method declaration '%s'", mModule->MethodToString(methodInstance).c_str()),
methodInstance->mMethodDef->GetRefNode());
};
BfIRConstHolder* constHolder = methodInstance->GetOwner()->mConstHolder;
auto customAttribute = customAttributes->Get(mModule->mCompiler->mObsoleteAttributeTypeDef);
if ((customAttribute != NULL) && (!customAttribute->mCtorArgs.IsEmpty()))
{
String err;
err = StrFormat("'%s' is obsolete", mModule->MethodToString(methodInstance).c_str());
bool isError = false;
auto constant = constHolder->GetConstant(customAttribute->mCtorArgs[0]);
if (constant->mTypeCode == BfTypeCode_Boolean)
{
isError = constant->mBool;
}
else if (customAttribute->mCtorArgs.size() >= 2)
{
String* str = mModule->GetStringPoolString(customAttribute->mCtorArgs[0], constHolder);
if (str != NULL)
{
err += ":\n '";
err += *str;
err += "'";
}
constant = constHolder->GetConstant(customAttribute->mCtorArgs[1]);
isError = constant->mBool;
}
BfError* error = NULL;
if (isError)
error = mModule->Fail(err, targetSrc);
else
error = mModule->Warn(0, err, targetSrc);
if (error != NULL)
_AddMethodDeclarationMoreInfo();
}
customAttribute = customAttributes->Get(mModule->mCompiler->mErrorAttributeTypeDef);
if ((customAttribute != NULL) && (!customAttribute->mCtorArgs.IsEmpty()))
{
String err = StrFormat("Method error: '", mModule->MethodToString(methodInstance).c_str());
String* str = mModule->GetStringPoolString(customAttribute->mCtorArgs[0], constHolder);
if (str != NULL)
err += *str;
err += "'";
if (mModule->Fail(err, targetSrc) != NULL)
_AddMethodDeclarationMoreInfo();
}
customAttribute = customAttributes->Get(mModule->mCompiler->mWarnAttributeTypeDef);
if ((customAttribute != NULL) && (!customAttribute->mCtorArgs.IsEmpty()))
{
String err = StrFormat("Method warning: '", mModule->MethodToString(methodInstance).c_str());
String* str = mModule->GetStringPoolString(customAttribute->mCtorArgs[0], constHolder);
if (str != NULL)
err += *str;
err += "'";
if (mModule->Warn(0, err, targetSrc) != NULL)
_AddMethodDeclarationMoreInfo();
}
}
if (customAttributes != NULL)
mModule->CheckErrorAttributes(methodInstance->GetOwner(), methodInstance, customAttributes, targetSrc);
}
BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRValue func, bool bypassVirtual, SizedArrayImpl<BfIRValue>& irArgs, BfTypedValue* sret, bool isTailCall)

View file

@ -1557,7 +1557,7 @@ String* BfModule::GetStringPoolString(BfIRValue constantStr, BfIRConstHolder * c
{
auto& entry = mContext->mStringObjectIdMap[strId];
return &entry.mString;
}
}
return NULL;
}
@ -2747,6 +2747,98 @@ BfError* BfModule::Warn(int warningNum, const StringImpl& warning, BfAstNode* re
return bfError;
}
void BfModule::CheckErrorAttributes(BfTypeInstance* typeInstance, BfMethodInstance* methodInstance, BfCustomAttributes* customAttributes, BfAstNode* targetSrc)
{
auto _AddDeclarationMoreInfo = [&]()
{
if (methodInstance != NULL)
{
if (methodInstance->mMethodDef->mMethodDeclaration != NULL)
mCompiler->mPassInstance->MoreInfo(
StrFormat("See method declaration '%s'", MethodToString(methodInstance).c_str()),
methodInstance->mMethodDef->GetRefNode());
}
else
{
mCompiler->mPassInstance->MoreInfo(
StrFormat("See type declaration '%s'", TypeToString(typeInstance, BfTypeNameFlag_UseUnspecializedGenericParamNames).c_str()),
typeInstance->mTypeDef->GetRefNode());
}
};
BfIRConstHolder* constHolder = typeInstance->mConstHolder;
auto customAttribute = customAttributes->Get(mCompiler->mObsoleteAttributeTypeDef);
if ((customAttribute != NULL) && (!customAttribute->mCtorArgs.IsEmpty()))
{
String err;
if (methodInstance != NULL)
err = StrFormat("'%s' is obsolete", MethodToString(methodInstance).c_str());
else
err = StrFormat("'%s' is obsolete", TypeToString(typeInstance, BfTypeNameFlag_UseUnspecializedGenericParamNames).c_str());
bool isError = false;
auto constant = constHolder->GetConstant(customAttribute->mCtorArgs[0]);
if (constant->mTypeCode == BfTypeCode_Boolean)
{
isError = constant->mBool;
}
else if (customAttribute->mCtorArgs.size() >= 2)
{
String* str = GetStringPoolString(customAttribute->mCtorArgs[0], constHolder);
if (str != NULL)
{
err += ":\n '";
err += *str;
err += "'";
}
constant = constHolder->GetConstant(customAttribute->mCtorArgs[1]);
isError = constant->mBool;
}
BfError* error = NULL;
if (isError)
error = Fail(err, targetSrc);
else
error = Warn(0, err, targetSrc);
if (error != NULL)
_AddDeclarationMoreInfo();
}
customAttribute = customAttributes->Get(mCompiler->mErrorAttributeTypeDef);
if ((customAttribute != NULL) && (!customAttribute->mCtorArgs.IsEmpty()))
{
String err;
if (methodInstance != NULL)
StrFormat("Method error: '", MethodToString(methodInstance).c_str());
else
StrFormat("Type error: '", TypeToString(typeInstance, BfTypeNameFlag_UseUnspecializedGenericParamNames).c_str());
String* str = GetStringPoolString(customAttribute->mCtorArgs[0], constHolder);
if (str != NULL)
err += *str;
err += "'";
if (Fail(err, targetSrc) != NULL)
_AddDeclarationMoreInfo();
}
customAttribute = customAttributes->Get(mCompiler->mWarnAttributeTypeDef);
if ((customAttribute != NULL) && (!customAttribute->mCtorArgs.IsEmpty()))
{
String err;
if (methodInstance != NULL)
StrFormat("Method warning: '", MethodToString(methodInstance).c_str());
else
StrFormat("Type warning: '", TypeToString(typeInstance, BfTypeNameFlag_UseUnspecializedGenericParamNames).c_str());
String* str = GetStringPoolString(customAttribute->mCtorArgs[0], constHolder);
if (str != NULL)
err += *str;
err += "'";
if (Warn(0, err, targetSrc) != NULL)
_AddDeclarationMoreInfo();
}
}
void BfModule::CheckRangeError(BfType* type, BfAstNode* refNode)
{
if (mBfIRBuilder->mOpFailed)
@ -9351,6 +9443,7 @@ static String GetAttributesTargetListString(BfAttributeTargets attrTarget)
AddAttributeTargetName(flagsLeft, BfAttributeTargets_Invocation, resultStr, "invocations");
AddAttributeTargetName(flagsLeft, BfAttributeTargets_MemberAccess, resultStr, "member access");
AddAttributeTargetName(flagsLeft, BfAttributeTargets_Alloc, resultStr, "allocations");
AddAttributeTargetName(flagsLeft, BfAttributeTargets_Alias, resultStr, "aliases");
if (resultStr.IsEmpty())
return "<nothing>";
return resultStr;

View file

@ -1413,6 +1413,7 @@ public:
BfError* FailInternal(const StringImpl& error, BfAstNode* refNode = NULL);
BfError* FailAfter(const StringImpl& error, BfAstNode* refNode);
BfError* Warn(int warningNum, const StringImpl& warning, BfAstNode* refNode = NULL, bool isPersistent = false);
void CheckErrorAttributes(BfTypeInstance* typeInstance, BfMethodInstance* methodInstance, BfCustomAttributes* customAttributes, BfAstNode* targetSrc);
void CheckRangeError(BfType* type, BfAstNode* refNode);
bool CheckCircularDataError();
BfFileInstance* GetFileFromNode(BfAstNode* astNode);

View file

@ -949,6 +949,7 @@ bool BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType
}
resolvedTypeRef->mDefineState = BfTypeDefineState_DefinedAndMethodsSlotted;
resolvedTypeRef->mRebuildFlags = BfTypeRebuildFlag_None;
typeAlias->mCustomAttributes = GetCustomAttributes(typeDef->mTypeDeclaration->mAttributes, BfAttributeTargets_Alias);
return true;
}
@ -6046,10 +6047,9 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
}
}
BfGenericTypeInstance* genericTypeInstance = NULL;
if (resolvedTypeRef != NULL)
genericTypeInstance = resolvedTypeRef->ToGenericTypeInstance();
BfTypeInstance* typeInstance = resolvedTypeRef->ToTypeInstance();
BfGenericTypeInstance* genericTypeInstance = resolvedTypeRef->ToGenericTypeInstance();
bool hadError = false;
hadError = !PopulateType(resolvedTypeRef, populateType);
@ -6064,13 +6064,25 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
if (populateType != BfPopulateType_IdentityNoRemapAlias)
{
while ((resolvedTypeRef != NULL) && (resolvedTypeRef->IsTypeAlias()))
{
{
if (mCurTypeInstance != NULL)
AddDependency(resolvedTypeRef, mCurTypeInstance, BfDependencyMap::DependencyFlag_NameReference);
if ((typeInstance->mCustomAttributes != NULL) && (!typeRef->IsTemporary()))
CheckErrorAttributes(typeInstance, NULL, typeInstance->mCustomAttributes, typeRef);
resolvedTypeRef = resolvedTypeRef->GetUnderlyingType();
if (resolvedTypeRef != NULL)
typeInstance = resolvedTypeRef->ToTypeInstance();
else
typeInstance = NULL;
}
}
if (typeInstance != NULL)
{
if ((typeInstance->mCustomAttributes != NULL) && (!typeRef->IsTemporary()))
CheckErrorAttributes(typeInstance, NULL, typeInstance->mCustomAttributes, typeRef);
}
return resolvedTypeRef;
}
@ -10416,6 +10428,12 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
// We don't want the param names, just the commas (this is an unspecialized type reference)
if (i > prevGenericParamCount)
str += ',';
if ((typeNameFlags & BfTypeNameFlag_UseUnspecializedGenericParamNames) != 0)
{
str += checkTypeDef->mGenericParamDefs[i]->mName;
}
continue;
}
}

View file

@ -20,14 +20,15 @@ enum BfTypeNameFlags : uint16
{
BfTypeNameFlags_None = 0,
BfTypeNameFlag_ResolveGenericParamNames = 1,
BfTypeNameFlag_OmitNamespace = 2,
BfTypeNameFlag_OmitOuterType = 4,
BfTypeNameFlag_ReduceName = 8,
BfTypeNameFlag_UseArrayImplType = 0x10,
BfTypeNameFlag_DisambiguateDups = 0x20, // Add a disambiguation if mDupDetectedRevision is set
BfTypeNameFlag_AddGlobalContainerName = 0x40,
BfTypeNameFlag_InternalName = 0x80, // Use special delimiters to remove ambiguities (ie: '+' for inner types)
BfTypeNameFlag_HideGlobalName = 0x100
BfTypeNameFlag_UseUnspecializedGenericParamNames = 2,
BfTypeNameFlag_OmitNamespace = 4,
BfTypeNameFlag_OmitOuterType = 8,
BfTypeNameFlag_ReduceName = 0x10,
BfTypeNameFlag_UseArrayImplType = 0x20,
BfTypeNameFlag_DisambiguateDups = 0x40, // Add a disambiguation if mDupDetectedRevision is set
BfTypeNameFlag_AddGlobalContainerName = 0x80,
BfTypeNameFlag_InternalName = 0x100, // Use special delimiters to remove ambiguities (ie: '+' for inner types)
BfTypeNameFlag_HideGlobalName = 0x200,
};
enum BfMethodNameFlags : uint8
@ -1401,28 +1402,29 @@ enum BfAttributeTargets : int32
{
BfAttributeTargets_SkipValidate = -1,
BfAttributeTargets_None = 0,
BfAttributeTargets_Assembly = 0x0001,
BfAttributeTargets_Module = 0x0002,
BfAttributeTargets_Class = 0x0004,
BfAttributeTargets_Struct = 0x0008,
BfAttributeTargets_Enum = 0x0010,
BfAttributeTargets_Constructor = 0x0020,
BfAttributeTargets_Method = 0x0040,
BfAttributeTargets_Property = 0x0080,
BfAttributeTargets_Field = 0x0100,
BfAttributeTargets_StaticField = 0x0200,
BfAttributeTargets_Interface = 0x0400,
BfAttributeTargets_Parameter = 0x0800,
BfAttributeTargets_Delegate = 0x1000,
BfAttributeTargets_Function = 0x2000,
BfAttributeTargets_ReturnValue = 0x4000,
BfAttributeTargets_None = 0,
BfAttributeTargets_Assembly = 0x0001,
BfAttributeTargets_Module = 0x0002,
BfAttributeTargets_Class = 0x0004,
BfAttributeTargets_Struct = 0x0008,
BfAttributeTargets_Enum = 0x0010,
BfAttributeTargets_Constructor = 0x0020,
BfAttributeTargets_Method = 0x0040,
BfAttributeTargets_Property = 0x0080,
BfAttributeTargets_Field = 0x0100,
BfAttributeTargets_StaticField = 0x0200,
BfAttributeTargets_Interface = 0x0400,
BfAttributeTargets_Parameter = 0x0800,
BfAttributeTargets_Delegate = 0x1000,
BfAttributeTargets_Function = 0x2000,
BfAttributeTargets_ReturnValue = 0x4000,
BfAttributeTargets_GenericParameter = 0x8000,
BfAttributeTargets_Invocation = 0x10000,
BfAttributeTargets_Invocation = 0x10000,
BfAttributeTargets_MemberAccess = 0x20000,
BfAttributeTargets_Alloc = 0x40000,
BfAttributeTargets_Delete = 0x80000,
BfAttributeTargets_All = 0xFFFFF
BfAttributeTargets_Alloc = 0x40000,
BfAttributeTargets_Delete = 0x80000,
BfAttributeTargets_Alias = 0x100000,
BfAttributeTargets_All = 0x1FFFFF
};
class BfAttributeData