renaming method and adding comments (#3312)

This commit is contained in:
samuraiGH 2025-07-03 20:39:09 +03:00 committed by GitHub
parent 9d57c427ac
commit ef795bbb64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 11 deletions

View file

@ -5,6 +5,7 @@ using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections;
using System.Linq;
namespace PascalABCCompiler.NETGenerator {
@ -836,16 +837,21 @@ namespace PascalABCCompiler.NETGenerator {
return null;
}
public bool IsConstructedGenericType(Type t)
/// <summary>
/// До вызова <c>.CreateType()</c> позволяет определить, был ли тип объявлен в коде, а не в готовой сборке.
/// Generic типы инстанцированные Pascal типами также считаются Pascal типами (пример: <c>IEnumerable&lt;PascalType&gt;</c>)
/// </summary>
public bool IsPascalType(Type t)
{
if (t is TypeBuilder || t is GenericTypeParameterBuilder || t is EnumBuilder || t.GetType().FullName == "System.Reflection.Emit.TypeBuilderInstantiation")
return true;
if (t.IsGenericType)
foreach (Type gt in t.GetGenericArguments())
if (IsConstructedGenericType(gt))
return true;
if ( t.IsGenericType && t.GetGenericArguments().Any(IsPascalType) )
return true;
if (t.IsArray)
return IsConstructedGenericType(t.GetElementType());
return IsPascalType(t.GetElementType());
return false;
}

View file

@ -3922,7 +3922,7 @@ namespace PascalABCCompiler.NETGenerator
PushIntConst(il, i - 2 - rank);
ILGenerator ilb = this.il;
if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && (helper.IsConstructedGenericType(ti.tp) || ti.tp.IsGenericType || !ti.tp.IsEnum))
if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && (helper.IsPascalType(ti.tp) || ti.tp.IsGenericType || !ti.tp.IsEnum))
if (!(ti.tp is EnumBuilder))
il.Emit(OpCodes.Ldelema, ti.tp);
if (_arr_type.is_nullable_type && exprs[i] is INullConstantNode)
@ -4643,7 +4643,7 @@ namespace PascalABCCompiler.NETGenerator
this.il = ilb;
}
if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && lb.LocalType.GetElementType().IsValueType && (helper.IsConstructedGenericType(ti.tp) || ti.tp.IsGenericType || !ti.tp.IsEnum))
if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && lb.LocalType.GetElementType().IsValueType && (helper.IsPascalType(ti.tp) || ti.tp.IsGenericType || !ti.tp.IsEnum))
{
if (!(ti.tp is EnumBuilder))
il.Emit(OpCodes.Ldelema, ti.tp);
@ -11663,7 +11663,7 @@ namespace PascalABCCompiler.NETGenerator
// если элемент перечисления объявлен в коде
// или типоаргумент элемента перечисления объявлен в коде
// например IEnumerable<MyType>, array of MyType
if (helper.IsConstructedGenericType(elementType))
if (helper.IsPascalType(elementType))
{
enumer_mi = TypeBuilder.GetMethod(
TypeFactory.IEnumerableGenericType.MakeGenericType(elementType),
@ -11712,7 +11712,7 @@ namespace PascalABCCompiler.NETGenerator
MethodInfo get_current_meth = enumer_mi.ReturnType.GetMethod("get_Current");
if (enumer_mi.ReturnType.IsGenericType && !enumer_mi.ReturnType.IsGenericTypeDefinition)
{
if (helper.IsConstructedGenericType(return_type))
if (helper.IsPascalType(return_type))
get_current_meth = TypeBuilder.GetMethod(return_type, enumer_mi.ReturnType.GetGenericTypeDefinition().GetMethod("get_Current"));
else
get_current_meth = return_type.GetMethod("get_Current");
@ -11781,7 +11781,7 @@ namespace PascalABCCompiler.NETGenerator
il.BeginFinallyBlock();
//il.MarkLabel(br_lbl);
bool is_disposable = false;
if (helper.IsConstructedGenericType(return_type))
if (helper.IsPascalType(return_type))
{
if (enumer_mi.ReturnType.GetGenericTypeDefinition().GetMethod("Dispose") != null)
is_disposable = true;