1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +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

@ -116,3 +116,9 @@ namespace System.Collections
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias BinaryHeap<T> = System.Collections.BinaryHeap<T>;
}

View file

@ -940,3 +940,9 @@ namespace System.Collections
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias Dictionary<TKey, TValue> = System.Collections.Dictionary<TKey, TValue>;
}

View file

@ -1164,3 +1164,9 @@ namespace System.Collections
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias HashSet<T> = System.Collections.HashSet<T>;
}

View file

@ -37,3 +37,9 @@ namespace System.Collections
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias KeyValuePair<TKey, TValue> = System.Collections.KeyValuePair<TKey, TValue>;
}

View file

@ -798,3 +798,9 @@ namespace System.Collections
}*/
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias List<T> = System.Collections.List<T>;
}

View file

@ -460,3 +460,9 @@ namespace System.Collections
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias Queue<T> = System.Collections.Queue<T>;
}

View file

@ -299,3 +299,9 @@ namespace System.Collections
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias Sorter<T, T2> = System.Collections.Sorter<T, T2>;
}

View file

@ -27,11 +27,12 @@ namespace System
MemberAccess = 0x20000,
Alloc = 0x40000,
Delete = 0x80000,
Alias = 0x100000,
All = Assembly | Module | Class | Struct | Enum | Constructor |
Method | Property | Field | StaticField | Interface | Parameter |
Delegate | Function | ReturnValue | GenericParameter | Invocation | MemberAccess |
Alloc | Delete,
Alloc | Delete | Alias,
}
public enum ReflectKind
@ -350,7 +351,7 @@ namespace System
{
}
[AttributeUsage(.Method | .Constructor)]
[AttributeUsage(.Method | .Constructor | .Class | .Struct | .Alias)]
public struct ObsoleteAttribute : Attribute
{
public this(bool isError)
@ -370,7 +371,7 @@ namespace System
}
[AttributeUsage(.Method | .Constructor)]
[AttributeUsage(.Method | .Constructor | .Class | .Struct | .Alias)]
public struct ErrorAttribute : Attribute
{
public this(String error)
@ -379,7 +380,7 @@ namespace System
}
}
[AttributeUsage(.Method | .Constructor)]
[AttributeUsage(.Method | .Constructor | .Class | .Struct | .Alias)]
public struct WarnAttribute : Attribute
{
public this(String error)

View file

@ -654,3 +654,9 @@ namespace System.Collections
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic containers have been moved into System.Collections", false)]
typealias List<T> = System.Collections.List<T>;
}

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());
@ -4632,6 +4642,24 @@ void BfCompiler::ClearUnusedStringPoolEntries()
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(); )
{
int strId = itr->mKey;

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

@ -4135,76 +4135,7 @@ void BfExprEvaluator::PerformCallChecks(BfMethodInstance* methodInstance, BfAstN
{
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();
}
}
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

@ -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,9 +6047,8 @@ 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);
@ -6067,10 +6067,22 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
{
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