Merge branch 'master' of github.com:pascalabcnet/pascalabcnet

This commit is contained in:
SunSerega 2020-12-09 23:20:19 +02:00
commit a37dab39f1
21 changed files with 306 additions and 18 deletions

View file

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

View file

@ -1,4 +1,4 @@
%COREVERSION%=1
%REVISION%=2764
%REVISION%=2768
%MINOR%=7
%MAJOR%=3

View file

@ -0,0 +1,19 @@
// Сериализация объектов
// Можно сериализовать только объекты, помеченные атрибутом [Serializable]
// Внешние Serialize, Deserialize позволяют сохранить в файле - восстановить
// один объект (один граф объектов с данным корнем)
type
[Serializable]
Node = auto class
x: integer;
next: Node;
end;
const fname = 'a.dat';
begin
var m := new Node(5,new Node(3,new Node(4,nil)));
Serialize(fname,m); // Сериализуем объект в файл
var m1 := Deserialize(fname) as Node; // Десериализуем из файла
Print(m1);
end.

View file

@ -0,0 +1,28 @@
// Сериализация объектов
// Можно сериализовать только объекты, помеченные атрибутом [Serializable]
// Внешние Serialize, Deserialize позволяют сохранить в файле - восстановить
// один объект (один граф объектов с данным корнем)
type
[Serializable]
My = auto class
x,y: integer;
end;
IntArray = array of integer;
const fname = 'a.dat';
begin
var f := CreateBinary(fname);
f.Serialize(new My(444,555));
f.Serialize(|1,2,3|);
f.Serialize(Lst(1..9));
f.Close;
f := OpenBinary(fname);
var m: My := f.Deserialize as My;
var a: array of integer := f.Deserialize as IntArray;
var l: List<integer> := f.Deserialize as List<integer>;
f.Close;
Print(m,a,l);
end.

View file

@ -0,0 +1,18 @@
// Сериализация объектов
// Можно сериализовать только объекты, помеченные атрибутом [Serializable]
// Внешние Serialize, Deserialize позволяют сохранить в файле - восстановить
// один объект (один граф объектов с данным корнем)
type
[Serializable]
My = auto class
x,y: integer;
end;
const fname = 'a.dat';
begin
var m := new My(2,3);
Serialize(fname,m); // Сериализуем объект в файл
var m1 := Deserialize(fname) as My; // Десериализуем из файла
Print(m1);
end.

View file

@ -1 +1 @@
3.7.1.2764
3.7.1.2768

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1 +1 @@
!define VERSION '3.7.1.2764'
!define VERSION '3.7.1.2768'

View file

@ -39,6 +39,15 @@ namespace SyntaxVisitors.SugarVisitors
DefaultVisit(ne);
}
public override void visit(labeled_statement ls)
{
var sl = new List<statement>();
sl.Add(new labeled_statement(ls.label_name, new empty_statement(), ls.source_context));
sl.Add(ls.to_statement);
ReplaceStatementUsingParent(ls, sl);
ProcessNode(ls.to_statement);
}
public override void visit(assign_var_tuple assvartup)
{
if (assvartup.expr is tuple_node tn && tn.el.expressions.All(ex => ex is const_node) && !tn.el.expressions.Any(ex => ex is nil_const))

14
TestSuite/2363.pas Normal file
View file

@ -0,0 +1,14 @@
procedure p0<T>(o: T);
begin
//Print(1);
end;
procedure p1<T>; where T: record;
begin
//Ошибка: Возможны два преобразования типов
p0&<T?>(nil);
end;
begin
Assert(1=1)
end.

View file

@ -253,6 +253,9 @@ type
/// Предоставляет методы для точного измерения затраченного времени
Stopwatch = System.Diagnostics.Stopwatch;
/// Указывает на возможность сериализации класса
Serializable = System.SerializableAttribute;
/// Представляет тип короткой строки фиксированной длины 255 символов
ShortString = string[255];
@ -586,6 +589,10 @@ type
function ReadReal: real;
/// Считывает строку из бестипового файла
function ReadString: string;
/// Сериализует объект в файл (объект должен иметь атрибут [Serializable])
procedure Serialize(obj: object);
/// Десериализует объект из файла
function Deserialize: object;
end;
type
@ -1183,6 +1190,12 @@ procedure Println(params args: array of object);
/// Выводит значения a,b,... в текстовый файл f, после каждого значения выводит пробел и переходит на новую строку
procedure Println(f: Text; params args: array of object);
/// Сериализует объект в файл (объект должен иметь атрибут [Serializable])
procedure Serialize(filename: string; obj: object);
/// Десериализует объект из файла
function Deserialize(filename: string): object;
// -----------------------------------------------------
//>> Общие подпрограммы для работы с файлами # Common subroutines for files
// -----------------------------------------------------
@ -2818,6 +2831,9 @@ function WINAPI_AllocConsole: longword; external 'kernel32.dll' name 'AllocConso
var
console_alloc: boolean := false;
type
BinaryFormatter = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter;
// -----------------------------------------------------
// Internal functions
@ -6677,6 +6693,18 @@ begin
Result := Self.br.ReadString;
end;
procedure BinaryFile.Serialize(obj: object);
begin
var formatter := new BinaryFormatter;
formatter.Serialize(fs,obj);
end;
function BinaryFile.Deserialize: object;
begin
var formatter := new BinaryFormatter;
Result := formatter.Deserialize(fs);
end;
// -----------------------------------------------------
// Eoln - Eof
// -----------------------------------------------------
@ -6997,6 +7025,23 @@ begin
Print(f, args);
Writeln(f);
end;
procedure Serialize(filename: string; obj: object);
begin
var fs := new System.IO.FileStream(filename,System.IO.FileMode.Create);
var formatter := new BinaryFormatter;
formatter.Serialize(fs,obj);
fs.Close;
end;
function Deserialize(filename: string): object;
begin
var fs := new System.IO.FileStream(filename,System.IO.FileMode.Open);
var formatter := new BinaryFormatter;
Result := formatter.Deserialize(fs);
fs.Close;
end;
// -----------------------------------------------------
// Text files
// -----------------------------------------------------

View file

@ -38,6 +38,12 @@ function MinMax(s: sequence of int64): (int64, int64);
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of integer): (integer, integer);
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of real): (real, real);
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of BigInteger): (BigInteger, BigInteger);
/// Возвращает НОД
function НОД(a, b: int64): int64;
@ -276,10 +282,12 @@ function MinMax(s: sequence of int64): (int64, int64);
begin
var (min, max) := (int64.MaxValue, int64.MinValue);
foreach var m in s do
begin
if m < min then
min := m
else if m > max then
max := m;
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
@ -288,10 +296,44 @@ function MinMax(s: sequence of integer): (integer, integer);
begin
var (min, max) := (integer.MaxValue, integer.MinValue);
foreach var m in s do
begin
if m < min then
min := m
else if m > max then
max := m;
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of real): (real, real);
begin
var (min, max) := (real.MaxValue, -real.MaxValue);
foreach var m in s do
begin
if m < min then
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of BigInteger): (BigInteger, BigInteger);
begin
var min, max: BigInteger;
var FirstValue := True;
foreach var m in s do
if FirstValue then
(min, max, FirstValue) := (m, m, False)
else
begin
if m < min then
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
@ -302,7 +344,15 @@ MinMax(Self);
/// Возвращает кортеж из минимума и максимума последовательности
function MinMax(Self: sequence of integer): (integer, integer);
extensionmethod :=
MinMax(Self);
MinMax(Self);
/// Возвращает кортеж из минимума и максимума последовательности
function MinMax(Self: sequence of real): (real, real); extensionmethod :=
MinMax(Self);
/// Возвращает кортеж из минимума и максимума последовательности
function MinMax(Self: sequence of BigInteger): (BigInteger, BigInteger);
extensionmethod := MinMax(Self);
{$endregion}

View file

@ -0,0 +1,8 @@
label 1;
begin
var c := 1;
1:
var (a,b) := (1,1);
b := 1;
Assert(b=1);
end.

View file

@ -1667,6 +1667,8 @@ namespace PascalABCCompiler.TreeConverter
{
if (ptc.second!=null)
{
if (ptc.first.from is null_type_node || ptc.second.from is null_type_node)
continue; // SSM 9/12/20 fix 2363
AddError(new PossibleTwoTypeConversionsInFunctionCall(loc,ptc.first,ptc.second));
}

View file

@ -253,6 +253,9 @@ type
/// Предоставляет методы для точного измерения затраченного времени
Stopwatch = System.Diagnostics.Stopwatch;
/// Указывает на возможность сериализации класса
Serializable = System.SerializableAttribute;
/// Представляет тип короткой строки фиксированной длины 255 символов
ShortString = string[255];
@ -586,6 +589,10 @@ type
function ReadReal: real;
/// Считывает строку из бестипового файла
function ReadString: string;
/// Сериализует объект в файл (объект должен иметь атрибут [Serializable])
procedure Serialize(obj: object);
/// Десериализует объект из файла
function Deserialize: object;
end;
type
@ -1183,6 +1190,12 @@ procedure Println(params args: array of object);
/// Выводит значения a,b,... в текстовый файл f, после каждого значения выводит пробел и переходит на новую строку
procedure Println(f: Text; params args: array of object);
/// Сериализует объект в файл (объект должен иметь атрибут [Serializable])
procedure Serialize(filename: string; obj: object);
/// Десериализует объект из файла
function Deserialize(filename: string): object;
// -----------------------------------------------------
//>> Общие подпрограммы для работы с файлами # Common subroutines for files
// -----------------------------------------------------
@ -2818,6 +2831,9 @@ function WINAPI_AllocConsole: longword; external 'kernel32.dll' name 'AllocConso
var
console_alloc: boolean := false;
type
BinaryFormatter = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter;
// -----------------------------------------------------
// Internal functions
@ -6677,6 +6693,18 @@ begin
Result := Self.br.ReadString;
end;
procedure BinaryFile.Serialize(obj: object);
begin
var formatter := new BinaryFormatter;
formatter.Serialize(fs,obj);
end;
function BinaryFile.Deserialize: object;
begin
var formatter := new BinaryFormatter;
Result := formatter.Deserialize(fs);
end;
// -----------------------------------------------------
// Eoln - Eof
// -----------------------------------------------------
@ -6997,6 +7025,23 @@ begin
Print(f, args);
Writeln(f);
end;
procedure Serialize(filename: string; obj: object);
begin
var fs := new System.IO.FileStream(filename,System.IO.FileMode.Create);
var formatter := new BinaryFormatter;
formatter.Serialize(fs,obj);
fs.Close;
end;
function Deserialize(filename: string): object;
begin
var fs := new System.IO.FileStream(filename,System.IO.FileMode.Open);
var formatter := new BinaryFormatter;
Result := formatter.Deserialize(fs);
fs.Close;
end;
// -----------------------------------------------------
// Text files
// -----------------------------------------------------

View file

@ -38,6 +38,12 @@ function MinMax(s: sequence of int64): (int64, int64);
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of integer): (integer, integer);
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of real): (real, real);
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of BigInteger): (BigInteger, BigInteger);
/// Возвращает НОД
function НОД(a, b: int64): int64;
@ -276,10 +282,12 @@ function MinMax(s: sequence of int64): (int64, int64);
begin
var (min, max) := (int64.MaxValue, int64.MinValue);
foreach var m in s do
begin
if m < min then
min := m
else if m > max then
max := m;
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
@ -288,10 +296,44 @@ function MinMax(s: sequence of integer): (integer, integer);
begin
var (min, max) := (integer.MaxValue, integer.MinValue);
foreach var m in s do
begin
if m < min then
min := m
else if m > max then
max := m;
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of real): (real, real);
begin
var (min, max) := (real.MaxValue, -real.MaxValue);
foreach var m in s do
begin
if m < min then
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
/// Возвращает кортеж из минимума и максимума последовательности s
function MinMax(s: sequence of BigInteger): (BigInteger, BigInteger);
begin
var min, max: BigInteger;
var FirstValue := True;
foreach var m in s do
if FirstValue then
(min, max, FirstValue) := (m, m, False)
else
begin
if m < min then
min := m;
if m > max then
max := m
end;
Result := (min, max)
end;
@ -302,7 +344,15 @@ MinMax(Self);
/// Возвращает кортеж из минимума и максимума последовательности
function MinMax(Self: sequence of integer): (integer, integer);
extensionmethod :=
MinMax(Self);
MinMax(Self);
/// Возвращает кортеж из минимума и максимума последовательности
function MinMax(Self: sequence of real): (real, real); extensionmethod :=
MinMax(Self);
/// Возвращает кортеж из минимума и максимума последовательности
function MinMax(Self: sequence of BigInteger): (BigInteger, BigInteger);
extensionmethod := MinMax(Self);
{$endregion}