Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pascalabcnet/pascalabcnet
Browse files Browse the repository at this point in the history
…into test
  • Loading branch information
BH_build_bot authored and BH_build_bot committed Jul 8, 2024
2 parents 8a4594f + acfce9b commit 3f52aaf
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 65 deletions.
134 changes: 70 additions & 64 deletions NETGenerator/NETGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3885,7 +3885,11 @@ private void InitializeUnsizedArray(ILGenerator il, TypeInfo ti, ITypeNode _arr_
if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && (helper.IsConstructedGenericType(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)
{
il.Emit(OpCodes.Initobj, helper.GetTypeReference(_arr_type).tp);
continue;
}
this.il = il;
exprs[i].visit(this);
bool box = EmitBox(exprs[i], arr_type.GetElementType());
Expand Down Expand Up @@ -4548,81 +4552,83 @@ private void GenerateArrayInitCode(ILGenerator il, LocalBuilder lb, IArrayInitia
}
else
if (ElementValues.Length > 0 && (ElementValues[0] is IRecordConstantNode || ElementValues[0] is IRecordInitializer))
{
TypeInfo ti = helper.GetTypeReference(ElementValues[0].type);
LocalBuilder llb = il.DeclareLocal(ti.tp.MakePointerType());
for (int i = 0; i < ElementValues.Length; i++)
{
TypeInfo ti = helper.GetTypeReference(ElementValues[0].type);
LocalBuilder llb = il.DeclareLocal(ti.tp.MakePointerType());
for (int i = 0; i < ElementValues.Length; i++)
{
il.Emit(OpCodes.Ldloc, lb);
PushIntConst(il, i);
il.Emit(OpCodes.Ldelema, ti.tp);
il.Emit(OpCodes.Stloc, llb);
if (ElementValues[i] is IRecordConstantNode)
GenerateRecordInitCode(il, llb, ElementValues[i] as IRecordConstantNode);
else GenerateRecordInitCode(il, llb, ElementValues[i] as IRecordInitializer, true);
}
il.Emit(OpCodes.Ldloc, lb);
PushIntConst(il, i);
il.Emit(OpCodes.Ldelema, ti.tp);
il.Emit(OpCodes.Stloc, llb);
if (ElementValues[i] is IRecordConstantNode)
GenerateRecordInitCode(il, llb, ElementValues[i] as IRecordConstantNode);
else GenerateRecordInitCode(il, llb, ElementValues[i] as IRecordInitializer, true);
}
else
for (int i = 0; i < ElementValues.Length; i++)
{
il.Emit(OpCodes.Ldloc, lb);
PushIntConst(il, i);
ILGenerator ilb = this.il;
TypeInfo ti = helper.GetTypeReference(ElementValues[i].type);
}
else
for (int i = 0; i < ElementValues.Length; i++)
{
il.Emit(OpCodes.Ldloc, lb);
PushIntConst(il, i);
ILGenerator ilb = this.il;
TypeInfo ti = helper.GetTypeReference(ElementValues[i].type);

if (ti != null && ti.is_set)
if (ti != null && ti.is_set)
{
this.il = il;
IConstantNode cn1 = null;
IConstantNode cn2 = null;
if (ArrayType != null && ArrayType.element_type.element_type is ICommonTypeNode)
{
this.il = il;
IConstantNode cn1 = null;
IConstantNode cn2 = null;
if (ArrayType != null && ArrayType.element_type.element_type is ICommonTypeNode)
{
cn1 = (ArrayType.element_type.element_type as ICommonTypeNode).lower_value;
cn2 = (ArrayType.element_type.element_type as ICommonTypeNode).upper_value;
}
if (cn1 != null && cn2 != null)
{
cn1.visit(this);
il.Emit(OpCodes.Box, helper.GetTypeReference(cn1.type).tp);
cn2.visit(this);
il.Emit(OpCodes.Box, helper.GetTypeReference(cn2.type).tp);
}
else
{
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Ldnull);
}
il.Emit(OpCodes.Newobj, ti.def_cnstr);
il.Emit(OpCodes.Stelem_Ref);
il.Emit(OpCodes.Ldloc, lb);
PushIntConst(il, i);
this.il = ilb;
cn1 = (ArrayType.element_type.element_type as ICommonTypeNode).lower_value;
cn2 = (ArrayType.element_type.element_type as ICommonTypeNode).upper_value;
}

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 (cn1 != null && cn2 != null)
{
if (!(ti.tp is EnumBuilder))
il.Emit(OpCodes.Ldelema, ti.tp);
cn1.visit(this);
il.Emit(OpCodes.Box, helper.GetTypeReference(cn1.type).tp);
cn2.visit(this);
il.Emit(OpCodes.Box, helper.GetTypeReference(cn2.type).tp);
}
else
if (ti != null && ti.assign_meth != null && lb.LocalType.GetElementType() != TypeFactory.ObjectType)
il.Emit(OpCodes.Ldelem_Ref);

this.il = il;
ElementValues[i].visit(this);
if (ti != null && ti.assign_meth != null && lb.LocalType.GetElementType() != TypeFactory.ObjectType)
{
il.Emit(OpCodes.Call, ti.assign_meth);
this.il = ilb;
continue;
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Ldnull);
}
bool box = EmitBox(ElementValues[i], lb.LocalType.GetElementType());
il.Emit(OpCodes.Newobj, ti.def_cnstr);
il.Emit(OpCodes.Stelem_Ref);
il.Emit(OpCodes.Ldloc, lb);
PushIntConst(il, i);
this.il = ilb;
if (ti != null && !box)
NETGeneratorTools.PushStelem(il, ti.tp);
else
il.Emit(OpCodes.Stelem_Ref);
}

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.tp is EnumBuilder))
il.Emit(OpCodes.Ldelema, ti.tp);

}
else
if (ti != null && ti.assign_meth != null && lb.LocalType.GetElementType() != TypeFactory.ObjectType)
il.Emit(OpCodes.Ldelem_Ref);

this.il = il;

ElementValues[i].visit(this);
if (ti != null && ti.assign_meth != null && lb.LocalType.GetElementType() != TypeFactory.ObjectType)
{
il.Emit(OpCodes.Call, ti.assign_meth);
this.il = ilb;
continue;
}
bool box = EmitBox(ElementValues[i], lb.LocalType.GetElementType());
this.il = ilb;
if (ti != null && !box)
NETGeneratorTools.PushStelem(il, ti.tp);
else
il.Emit(OpCodes.Stelem_Ref);
}
}

private void GenerateArrayInitCode(ILGenerator il, LocalBuilder lb, IArrayConstantNode InitalValue)
Expand Down
4 changes: 4 additions & 0 deletions TestSuite/nullable15.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
begin
var a := new System.Nullable<integer>[](nil);
assert(a[0] = nil);
end.
4 changes: 4 additions & 0 deletions TestSuite/nullable16.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var a := new System.Nullable<integer>[](nil);
begin
assert(a[0] = nil);
end.
8 changes: 8 additions & 0 deletions TestSuite/nullable17.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
procedure test(params a: array of System.Nullable<integer>);
begin
assert(a[0] = nil);
assert(a[1] = 1);
end;
begin
test(nil, 1);
end.
2 changes: 1 addition & 1 deletion bin/Lng/Rus/SemanticErrors_nv.dat
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ CAN_NOT_EXPLICITLY_CONVERT_TYPE_{0}_TO_TYPE_{1}=Невозможно явно п
ONLY_ONE_PARAMETER_OF_TYPE_CONVERSION_ALLOWED=У операции преобразования типов допустим только один параметр
REAL_TYPE_IN_DOUBLE_COLON_EXPRESSION_EXPECTED=Данный формат вывода может быть применен только к вещественному типу
ONLY_ONE_PARAMS_PARAMETER_ALLOWED=Допустим только один параметр с ключевым словом params
ONLY_UNSIZED_ARRAY_PARAMS_PARAMETER_ALLOWED=Только динамический массив может описываться с ключевым словом params
ONLY_UNSIZED_ARRAY_PARAMS_PARAMETER_ALLOWED=Только одномерный динамический массив может описываться с ключевым словом params
{0}_DIMENSIONAL_ARRAY_CAN_NOT_HAVE_{1}_AND_MORE_INDEXING=Неверное количество индексов. Должно быть {0}
TUPLE_CAN_HAVE_ONLY_ONE_INDEX=Кортеж может иметь только один индекс
TUPLE_INDEX_OUT_OF_RANGE_{0}=Индекс кортежа должен быть ≥0 и ≤{0}
Expand Down

0 comments on commit 3f52aaf

Please sign in to comment.