mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Added some alloctype(T) tests
This commit is contained in:
parent
9d5d5b4063
commit
4b80bcbbcf
3 changed files with 74 additions and 10 deletions
|
@ -6551,6 +6551,18 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
|
// Turn T* into a T, if we can
|
||||||
|
if ((target.mType->IsPointer()) && (target.mType->GetUnderlyingType()->IsGenericParam()))
|
||||||
|
{
|
||||||
|
auto underlyingType = target.mType->GetUnderlyingType();
|
||||||
|
auto genericParam = mModule->GetGenericParamInstance((BfGenericParamType*)underlyingType);
|
||||||
|
if (((genericParam->mTypeConstraint != NULL) && (genericParam->mTypeConstraint->IsValueType())) ||
|
||||||
|
((genericParam->mGenericParamFlags & (BfGenericParamFlag_Struct)) != 0))
|
||||||
|
{
|
||||||
|
target.mType = underlyingType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((!target.mType->IsGenericParam()) && (!target.IsSplat()) && (!target.mType->IsVar()))
|
if ((!target.mType->IsGenericParam()) && (!target.IsSplat()) && (!target.mType->IsVar()))
|
||||||
target = MakeCallableTarget(targetSrc, target);
|
target = MakeCallableTarget(targetSrc, target);
|
||||||
}
|
}
|
||||||
|
@ -6682,6 +6694,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
|
||||||
BfTypeDef* curTypeDef = NULL;
|
BfTypeDef* curTypeDef = NULL;
|
||||||
BfTypeInstance* targetTypeInst = NULL;
|
BfTypeInstance* targetTypeInst = NULL;
|
||||||
bool checkNonStatic = true;
|
bool checkNonStatic = true;
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
if (targetType->IsVar())
|
if (targetType->IsVar())
|
||||||
|
@ -12741,14 +12754,26 @@ BfAllocTarget BfExprEvaluator::ResolveAllocTarget(BfAstNode* allocNode, BfTokenN
|
||||||
|
|
||||||
BfTypedValue BfExprEvaluator::MakeCallableTarget(BfAstNode* targetSrc, BfTypedValue target)
|
BfTypedValue BfExprEvaluator::MakeCallableTarget(BfAstNode* targetSrc, BfTypedValue target)
|
||||||
{
|
{
|
||||||
if (((target.mType->IsRef()) || (target.mType->IsPointer())) &&
|
if ((target.mType->IsRef()) || (target.mType->IsPointer()))
|
||||||
(target.mType->GetUnderlyingType()->IsStruct()))
|
{
|
||||||
|
auto underlying = target.mType->GetUnderlyingType();
|
||||||
|
bool underlyingIsStruct = underlying->IsStruct();
|
||||||
|
// if (underlying->IsGenericParam())
|
||||||
|
// {
|
||||||
|
// auto genericParam = mModule->GetGenericParamInstance((BfGenericParamType*)underlying);
|
||||||
|
// if (((genericParam->mTypeConstraint != NULL) && (genericParam->mTypeConstraint->IsValueType())) ||
|
||||||
|
// ((genericParam->mGenericParamFlags & (BfGenericParamFlag_Struct)) != 0))
|
||||||
|
// underlyingIsStruct = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (underlyingIsStruct)
|
||||||
{
|
{
|
||||||
auto pointerType = (BfPointerType*)target.mType;
|
auto pointerType = (BfPointerType*)target.mType;
|
||||||
target = mModule->LoadValue(target);
|
target = mModule->LoadValue(target);
|
||||||
target.mType = pointerType->mElementType;
|
target.mType = pointerType->mElementType;
|
||||||
target.mKind = BfTypedValueKind_Addr;
|
target.mKind = BfTypedValueKind_Addr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((target.mType->IsStruct()) && (!target.IsAddr()))
|
if ((target.mType->IsStruct()) && (!target.IsAddr()))
|
||||||
{
|
{
|
||||||
|
|
|
@ -8130,7 +8130,21 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
||||||
if (resolvedType != NULL)
|
if (resolvedType != NULL)
|
||||||
{
|
{
|
||||||
if (resolvedType->IsGenericParam())
|
if (resolvedType->IsGenericParam())
|
||||||
|
{
|
||||||
|
auto genericParam = GetGenericParamInstance((BfGenericParamType*)resolvedType);
|
||||||
|
if (((genericParam->mTypeConstraint != NULL) && (genericParam->mTypeConstraint->IsValueType())) ||
|
||||||
|
((genericParam->mGenericParamFlags & (BfGenericParamFlag_Struct | BfGenericParamFlag_StructPtr)) != 0))
|
||||||
|
{
|
||||||
|
resolvedType = CreatePointerType(resolvedType);
|
||||||
|
}
|
||||||
|
else if (((genericParam->mTypeConstraint != NULL) && (!genericParam->mTypeConstraint->IsValueType())) ||
|
||||||
|
((genericParam->mGenericParamFlags & (BfGenericParamFlag_Class)) != 0))
|
||||||
|
{
|
||||||
|
// Leave as 'T'
|
||||||
|
}
|
||||||
|
else
|
||||||
resolvedType = CreateModifiedTypeType(resolvedType, BfToken_AllocType);
|
resolvedType = CreateModifiedTypeType(resolvedType, BfToken_AllocType);
|
||||||
|
}
|
||||||
else if (resolvedType->IsValueType())
|
else if (resolvedType->IsValueType())
|
||||||
resolvedType = CreatePointerType(resolvedType);
|
resolvedType = CreatePointerType(resolvedType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma warning disable 168
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
|
@ -124,6 +126,29 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Alloc0<T>() where T : new, delete, IDisposable
|
||||||
|
{
|
||||||
|
alloctype(T) val = new T();
|
||||||
|
val.Dispose();
|
||||||
|
delete val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Alloc1<T>() where T : new, delete, IDisposable, Object
|
||||||
|
{
|
||||||
|
alloctype(T) val = new T();
|
||||||
|
T val2 = val;
|
||||||
|
val.Dispose();
|
||||||
|
delete val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Alloc2<T>() where T : new, delete, IDisposable, struct
|
||||||
|
{
|
||||||
|
alloctype(T) val = new T();
|
||||||
|
T* val2 = val;
|
||||||
|
val2.Dispose();
|
||||||
|
delete val;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
|
@ -169,7 +194,7 @@ namespace Tests
|
||||||
Test.Assert(totals == 10+20+30+40+50);
|
Test.Assert(totals == 10+20+30+40+50);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static mixin TransformArray<Input, Output, InputSize>(Input[InputSize] array, delegate void(Input, ref Output) predicate) where InputSize : const int where Output : new
|
public static mixin TransformArray<Input, Output, InputSize>(Input[InputSize] array, delegate void(Input, ref Output) predicate) where InputSize : const int where Output : new, class
|
||||||
{
|
{
|
||||||
Output[2] output = default;
|
Output[2] output = default;
|
||||||
for (int i = 0; i < array.Count; i++)
|
for (int i = 0; i < array.Count; i++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue