Merge branch 'master' into fix-2652

This commit is contained in:
Sun Serega 2022-04-15 07:24:57 +03:00
commit c7aa56bef9
49 changed files with 172 additions and 63 deletions

View file

@ -364,8 +364,9 @@ namespace CodeCompletion
{
/*if (ts is ArrayScope && !(ts as ArrayScope).is_dynamic_arr)
return new List<ProcScope>();*/
List<ProcScope> meths = GetExtensionMethods(ts);
List<ProcScope> meths = GetExtensionMethods(ts, name);
List<ProcScope> lst = new List<ProcScope>();
for (int i = 0; i < meths.Count; i++)
{
if (string.Compare(meths[i].si.name, name, true) == 0)
@ -376,12 +377,12 @@ namespace CodeCompletion
return lst;
}
public List<ProcScope> GetExtensionMethods(TypeScope ts)
public List<ProcScope> GetExtensionMethods(TypeScope ts, string name=null)
{
if (ts is TypeSynonim)
return GetExtensionMethods((ts as TypeSynonim).actType);
return GetExtensionMethods((ts as TypeSynonim).actType, name);
if (ts.original_type != null)
return GetExtensionMethods(ts.original_type);
return GetExtensionMethods(ts.original_type, name);
List<ProcScope> lst = new List<ProcScope>();
List<ProcScope> meths = null;
TypeScope tmp_ts = ts;
@ -396,7 +397,11 @@ namespace CodeCompletion
tmp_ts2 = TypeTable.get_compiled_type((tmp_ts as CompiledScope).CompiledType.GetGenericTypeDefinition());
if (extension_methods.TryGetValue(tmp_ts2, out meths))
{
lst.AddRange(meths);
foreach (var meth in meths)
{
if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0))
lst.Add(meth);
}
}
else
{
@ -411,7 +416,12 @@ namespace CodeCompletion
((t as FileScope).elementType == null) == ((tmp_ts2 as FileScope).elementType == null)
)
{
lst.AddRange(extension_methods[t]);
var meth_list = extension_methods[t];
foreach (var meth in meth_list)
{
if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0))
lst.Add(meth);
}
}
}
}
@ -433,7 +443,11 @@ namespace CodeCompletion
int_ts2 = TypeTable.get_compiled_type((int_ts as CompiledScope).CompiledType.GetGenericTypeDefinition());
if (extension_methods.TryGetValue(int_ts2, out meths))
{
lst.AddRange(meths);
foreach (var meth in meths)
{
if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0))
lst.Add(meth);
}
}
else
{
@ -445,7 +459,12 @@ namespace CodeCompletion
t is FileScope && int_ts2 is FileScope &&
((t as FileScope).elementType == null) == ((int_ts2 as FileScope).elementType == null))
{
lst.AddRange(extension_methods[t]);
var meth_list = extension_methods[t];
foreach (var meth in meth_list)
{
if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0))
lst.Add(meth);
}
//break;
}
}
@ -459,7 +478,15 @@ namespace CodeCompletion
for (int i = 0; i < this.used_units.Count; i++)
{
if (!hasUsesCycle(this))
lst.AddRange(this.used_units[i].GetExtensionMethods(ts));
{
var unit_meth_lst = this.used_units[i].GetExtensionMethods(ts, name);
foreach (var meth in unit_meth_lst)
{
if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0))
lst.Add(meth);
}
}
}
return lst;
}

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "8";
public const string Build = "3";
public const string Revision = "3093";
public const string Revision = "3101";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%MINOR%=8
%REVISION%=3093
%REVISION%=3101
%COREVERSION%=3
%MAJOR%=3

View file

@ -8964,14 +8964,40 @@ namespace PascalABCCompiler.NETGenerator
t1 = helper.GetTypeReference(real_parameters[0].type).tp;
if (real_parameters[1].type is ICompiledGenericTypeInstance)
t2 = helper.GetTypeReference(real_parameters[1].type).tp;
MethodInfo mi = ctn1.compiled_type.GetMethod("Equals");
MethodInfo mi = null;
MemberInfo[] eq_members = ctn1.compiled_type.GetMember("Equals", BindingFlags.Public | BindingFlags.Instance);
bool value_type_eq = false;
foreach (MemberInfo member in eq_members)
if (member is MethodInfo)
{
if (mi == null)
mi = member as MethodInfo;
else if ((member as MethodInfo).GetParameters()[0].ParameterType.IsValueType)
{
mi = member as MethodInfo;
value_type_eq = true;
}
}
if (mi != null)
{
real_parameters[0].visit(this);
il.Emit(OpCodes.Box, t1);
real_parameters[1].visit(this);
il.Emit(OpCodes.Box, t2);
il.Emit(OpCodes.Callvirt, mi);
if (value_type_eq)
{
var lb = il.DeclareLocal(t1);
il.Emit(OpCodes.Stloc, lb);
il.Emit(OpCodes.Ldloca, lb);
real_parameters[1].visit(this);
}
else
{
il.Emit(OpCodes.Box, t1);
real_parameters[1].visit(this);
il.Emit(OpCodes.Box, t2);
}
il.Emit(OpCodes.Call, mi);
if (ft == basic_function_type.objnoteq)
{
il.Emit(OpCodes.Ldc_I4_0);

View file

@ -1 +1 @@
3.8.3.3093
3.8.3.3101

View file

@ -1 +1 @@
!define VERSION '3.8.3.3093'
!define VERSION '3.8.3.3101'

View file

@ -8130,7 +8130,8 @@ end;
procedure Halt;
begin
Halt(ExitCode);
System.Diagnostics.Process.GetCurrentProcess.Kill;
//Halt(ExitCode);
end;
procedure Halt(exitCode: integer);
@ -10418,13 +10419,24 @@ end;
/// Разбивает последовательность на серии длины size
function Batch<T>(Self: sequence of T; size: integer): sequence of sequence of T; extensionmethod;
begin
Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size))
var buf := new List<T>;
foreach var elm in Self do begin
buf.Add(elm);
if buf.Count=size then begin
yield buf.ToArray;
buf.Clear
end;
end;
if buf.Count>0 then
yield buf.ToArray;
//Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size))
end;
/// Разбивает последовательность на серии длины size и применяет проекцию к каждой серии
function Batch<T, Res>(Self: sequence of T; size: integer; proj: Func<IEnumerable<T>, Res>): sequence of Res; extensionmethod;
begin
Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size)).Select(ss -> proj(ss));
//Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size)).Select(ss -> proj(ss));
Result := Self.Batch(size).Select(ss -> proj(ss));
end;
///--
@ -12568,7 +12580,7 @@ function NotDivs(Self,d: integer): boolean; extensionmethod := Self mod d <> 0;
function DivsAny(Self: integer; params a: array of integer): boolean; extensionmethod;
begin
Result := False;
for var i:=0 to a.High do
for var i:=0 to a.Length-1 do
if Self mod a[i] = 0 then
begin
Result := True;
@ -12580,7 +12592,7 @@ end;
function DivsAll(Self: integer; params a: array of integer): boolean; extensionmethod;
begin
Result := True;
for var i:=0 to a.High do
for var i:=0 to a.Length-1 do
if Self mod a[i] <> 0 then
begin
Result := False;

View file

@ -360,7 +360,7 @@ type
end;
procedure AnimRotateP(a,sec: real);
begin
var an := new DoubleAnimation(a, System.TimeSpan.FromSeconds(sec));
var an := new DoubleAnimation(a + rot.Angle, System.TimeSpan.FromSeconds(sec));
rot.BeginAnimation(RotateTransform.AngleProperty, an, HandoffBehavior.Compose);
end;
procedure AnimScaleP(a,sec: real);

7
TestSuite/generics63.pas Normal file
View file

@ -0,0 +1,7 @@
uses System;
begin
var t1 := new ValueTuple<integer>(1);
var t2 := new ValueTuple<integer>(1);
assert(t1 = t2);
end.

View file

@ -8130,7 +8130,8 @@ end;
procedure Halt;
begin
Halt(ExitCode);
System.Diagnostics.Process.GetCurrentProcess.Kill;
//Halt(ExitCode);
end;
procedure Halt(exitCode: integer);
@ -10418,13 +10419,24 @@ end;
/// Разбивает последовательность на серии длины size
function Batch<T>(Self: sequence of T; size: integer): sequence of sequence of T; extensionmethod;
begin
Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size))
var buf := new List<T>;
foreach var elm in Self do begin
buf.Add(elm);
if buf.Count=size then begin
yield buf.ToArray;
buf.Clear
end;
end;
if buf.Count>0 then
yield buf.ToArray;
//Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size))
end;
/// Разбивает последовательность на серии длины size и применяет проекцию к каждой серии
function Batch<T, Res>(Self: sequence of T; size: integer; proj: Func<IEnumerable<T>, Res>): sequence of Res; extensionmethod;
begin
Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size)).Select(ss -> proj(ss));
//Result := SeqWhile(Self, v -> v.Skip(size), v -> v.Count > 0).Select(v -> v.Take(size)).Select(ss -> proj(ss));
Result := Self.Batch(size).Select(ss -> proj(ss));
end;
///--

View file

@ -360,7 +360,7 @@ type
end;
procedure AnimRotateP(a,sec: real);
begin
var an := new DoubleAnimation(a, System.TimeSpan.FromSeconds(sec));
var an := new DoubleAnimation(a + rot.Angle, System.TimeSpan.FromSeconds(sec));
rot.BeginAnimation(RotateTransform.AngleProperty, an, HandoffBehavior.Compose);
end;
procedure AnimScaleP(a,sec: real);

View file

@ -2,8 +2,8 @@
interface
function ReadXLSX(fileName:string):Dictionary<string,array of array of string>;
function ToDate(Self:string):DateTime;
function ReadXLSX(fileName: string): Dictionary<string, array of array of string>;
function ToDate(Self: string): DateTime;
implementation
@ -16,21 +16,21 @@ uses System.Xml,sf;
var
numFmt := new List<int>;
arxiv : System.IO.Compression.ZipArchive;
arxiv: System.IO.Compression.ZipArchive;
shStr := new List<string>;
DateTypeId := |14,15,16,17,22,27,30,36,50,55,57|.ToHS;
DateTypeId := |14, 15, 16, 17, 22, 27, 30, 36, 50, 55, 57|.ToHS;
function ToDate(Self:string):DateTime;
function ToDate(Self: string): DateTime;
begin
Result := DateTime.Parse(Self);
end;
function ToCR(Self:string);extensionmethod
:= (self[2:].ToI-1, self[1]-'A'); // 'B3' -> [1,2]
function Load(path:string):XmlElement;
function ToCR(Self: string); extensionmethod
:= (self[2:].ToI - 1, self[1] - 'A'); // 'B3' -> [1,2]
function Load(path: string): XmlElement;
begin
if arxiv.Entries.Any(e->(e as ZipArchiveEntry).FullName = path) then begin
if arxiv.Entries.Any(e -> (e as ZipArchiveEntry).FullName = path) then begin
var stream := arxiv.GetEntry(path).Open;
var doc := new XmlDocument();
doc.Load(stream);
@ -38,59 +38,84 @@ begin
end;
end;
function LoadSheet(path:string):array of array of string;
function LoadSheet(path: string): array of array of string;
begin
var elms := Load(path);
var (LU,RD) := elms.Item['dimension'].GetAttribute('ref').Split(':').Sel(s->s.ToCR);
var (w,h) := (RD[1]-LU[1]+1,RD[0]-LU[0]+1);
var sheet : array of array of string;
setLength(sheet,h);
for var i:=0 to h-1 do sheet[i] := new string[w];
foreach var node:XmlNode in elms.Item['sheetData'].ChildNodes do begin
foreach var cell:XmlNode in node.ChildNodes do begin
var (i,j) := cell.Attributes.GetNamedItem('r').Value.ToCR;
var dim := elms.Item['dimension'];
var LU, RD: (int, int);
if dim = nil then begin // собираем габариты таблицы
var (l, u) := (maxint, maxint);
var (r, d) := (-1, -1);
foreach var node: XmlNode in elms.Item['sheetData'].ChildNodes do
begin
foreach var cell: XmlNode in node.ChildNodes do
begin
var (i, j) := cell.Attributes.GetNamedItem('r').Value.ToCR;
l := min(l, i);
u := min(u, j);
r := max(r, i);
d := max(d, j);
end
end;
LU := (l, u);
RD := (r, d);
end else // готовые габариты из таблицы
(LU, RD) := dim.GetAttribute('ref').Split(':').Sel(s -> s.ToCR);
var (w, h) := (RD[1] - LU[1] + 1, RD[0] - LU[0] + 1);
var sheet: array of array of string;
setLength(sheet, h);
for var i := 0 to h - 1 do sheet[i] := new string[w];
foreach var node: XmlNode in elms.Item['sheetData'].ChildNodes do
begin
foreach var cell: XmlNode in node.ChildNodes do
begin
var (i, j) := cell.Attributes.GetNamedItem('r').Value.ToCR;
i -= LU[0];
j -= LU[1];
var typ := cell.Attributes.GetNamedItem('t');
var st := cell.Attributes.GetNamedItem('s');
var shared := false;
if (typ<>nil) and (typ.Value='s') then
if (typ <> nil) and (typ.Value = 's') then
shared := true;
var value := '';
foreach var vl:XmlNode in cell.ChildNodes do
if vl.Name='v' then value := vl.InnerText;
foreach var vl: XmlNode in cell.ChildNodes do
if vl.Name = 'v' then value := vl.InnerText;
if shared then
sheet[i,j] := shStr[value.ToInteger]
else if (st<>nil)and(numFmt[st.Value.ToI] in DateTypeId) then
sheet[i,j] := (new DateTime(1900,1,1)).AddDays(value.ToI-2).ToString('dd.MM.yyyy')
sheet[i, j] := shStr[value.ToInteger]
else if (st <> nil) and (numFmt[st.Value.ToI] in DateTypeId) then
sheet[i, j] := (new DateTime(1900, 1, 1)).AddDays(value.ToI - 2).ToString('dd.MM.yyyy')
else
sheet[i,j] := value;
sheet[i, j] := value;
end;
end;
Result := sheet;
end;
function ReadXLSX(fileName:string):Dictionary<string,array of array of string>;
function ReadXLSX(fileName: string): Dictionary<string, array of array of string>;
begin
arxiv := ZipFile.OpenRead(fileName);
// общие строки
var elms := Load('xl/sharedStrings.xml');
if elms<>nil then
foreach var node:XmlNode in elms.ChildNodes do
if elms <> nil then
foreach var node: XmlNode in elms.ChildNodes do
shStr.Add(node.Item['t'].InnerText.Trim);
// стили
elms := Load('xl/styles.xml');
numFmt := new List<int>;
foreach var node:XmlNode in elms.Item['cellXfs'].ChildNodes do
foreach var node: XmlNode in elms.Item['cellXfs'].ChildNodes do
numFmt.Add(node.Attributes.GetNamedItem('numFmtId').Value.ToI);
elms := Load('xl/workbook.xml');
Result := new Dictionary<string,array of array of string>;
foreach var node:XmlNode in elms.Item['sheets'].ChildNodes do begin
Result := new Dictionary<string, array of array of string>;
foreach var node: XmlNode in elms.Item['sheets'].ChildNodes do
begin
var name := node.Attributes.GetNamedItem('name').Value;
var attrs := new List<string>;
foreach var attr:XmlAttribute in node.Attributes do
foreach var attr: XmlAttribute in node.Attributes do
attrs.Add(attr.Name);
var sheetId := node.Attributes.GetNamedItem('r:id').Value[4:];
Result[name] := LoadSheet($'xl/worksheets/sheet{sheetId}.xml');