From 454001cba94bf048fbc2530f1150d4c392a46255 Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Fri, 7 Feb 2020 09:31:40 +0300 Subject: [PATCH] MAP -= KEY --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 2 +- NETGenerator/NETGenerator.cs | 30 ++++++++--- Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- TestSuite/BigIntegerDivMod.pas | 6 +++ TestSuite/CompilationSamples/PABCSystem.pas | 56 ++++++++++++++++++++- TestSuite/MapME.pas | 10 ++++ TreeConverter/TreeRealization/generics.cs | 9 +++- bin/Lib/PABCSystem.pas | 13 ++++- bin/Lib/SF.pas | 30 +++++++++++ 11 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 TestSuite/BigIntegerDivMod.pas create mode 100644 TestSuite/MapME.pas diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 2b5889bb6..74c8068d5 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "6"; public const string Build = "0"; - public const string Revision = "2340"; + public const string Revision = "2344"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 9b7669194..5726ce611 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ %COREVERSION%=0 -%REVISION%=2340 +%REVISION%=2344 %MINOR%=6 %MAJOR%=3 diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 25013f5a3..379440177 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -534,8 +534,12 @@ namespace PascalABCCompiler.NETGenerator cur_unit = Path.GetFileNameWithoutExtension(SourceFileName); string entry_cur_unit = cur_unit; - entry_type = mb.DefineType(cur_unit + ".Program", TypeAttributes.Public);//определяем синтетический статический класс основной программы - cur_type = entry_type; + // SSM 07.02.20 + if (comp_opt.target != TargetType.Dll) + entry_type = mb.DefineType(cur_unit + ".Program", TypeAttributes.Public);//определяем синтетический статический класс основной программы + // SSM 07.02.20 + if (entry_type != null) + cur_type = entry_type; //точка входа в приложение if (p.main_function != null) { @@ -591,7 +595,9 @@ namespace PascalABCCompiler.NETGenerator if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name]; bool is_main_namespace = cnns[iii].namespace_name == "" && comp_opt.target != TargetType.Dll || comp_opt.target == TargetType.Dll && cnns[iii].namespace_name == ""; ICommonNamespaceNode cnn = cnns[iii]; - cur_type = entry_type; + // SSM 07.02.20 + if (entry_type != null) + cur_type = entry_type; if (!is_main_namespace) { cur_unit = cnn.namespace_name; // SSM 05.02.20 here change @@ -644,7 +650,9 @@ namespace PascalABCCompiler.NETGenerator } else { - NamespacesTypes.Add(cnns[iii], entry_type); + // SSM 07.02.20 + if (entry_type != null) + NamespacesTypes.Add(cnns[iii], entry_type); } } @@ -798,7 +806,9 @@ namespace PascalABCCompiler.NETGenerator } il = tmp_il; } - cur_type = entry_type; + // SSM 07.02.20 + if (entry_type != null) + cur_type = entry_type; //is_in_unit = false; //переводим реализации for (int iii = 0; iii < cnns.Length; iii++) @@ -841,10 +851,13 @@ namespace PascalABCCompiler.NETGenerator MakeAttribute(cnns[iii]); } doc = first_doc; - cur_type = entry_type; + // SSM 07.02.20 + if (entry_type != null) + cur_type = entry_type; CloseTypes();//закрываем типы - entry_type.CreateType(); + // SSM 07.02.20 ? + entry_type?.CreateType(); switch (comp_opt.target) { case TargetType.Exe: ab.SetEntryPoint(entry_meth, PEFileKinds.ConsoleApplication); break; @@ -909,7 +922,8 @@ namespace PascalABCCompiler.NETGenerator bytes[6] = (byte)(0x80 | ((sb.Length & 0xFF00) >> 8)); } } - entry_type.SetCustomAttribute(attr_ci, bytes); + // SSM 07.02.20 ? + entry_type?.SetCustomAttribute(attr_ci, bytes); attr_class.CreateType(); } } diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index 95850e573..040e4a5b0 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.6.0.2340 +3.6.0.2344 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index ce159c6e1..d3906868a 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.6.0.2340' +!define VERSION '3.6.0.2344' diff --git a/TestSuite/BigIntegerDivMod.pas b/TestSuite/BigIntegerDivMod.pas new file mode 100644 index 000000000..3b28be357 --- /dev/null +++ b/TestSuite/BigIntegerDivMod.pas @@ -0,0 +1,6 @@ +begin + var a: BigInteger := 11; + Assert(a div 2 = 5); + Assert(a mod 2 = 1); + Assert(a mod BigInteger(2) = 1); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 6cc79ebc2..fbec79e8c 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -307,6 +307,7 @@ type procedure read(var x: uint64); procedure read(var x: single); procedure read(var x: boolean); + procedure read(var x: BigInteger); procedure readln; function ReadLine: string; function ReadLexem: string; @@ -341,6 +342,7 @@ type procedure read(var x: uint64); virtual; procedure read(var x: single); virtual; procedure read(var x: boolean); virtual; + procedure read(var x: BigInteger); virtual; procedure readln; virtual; function ReadLine: string; virtual; function ReadLexem: string; virtual; @@ -618,6 +620,8 @@ procedure Read(var x: uint64); procedure Read(var x: single); ///-- procedure Read(var x: boolean); +///-- +procedure Read(var x: BigInteger); ///- procedure Readln(a,b,...); /// Вводит значения a,b,... с клавиатуры и осуществляет переход на следующую строку procedure Readln; @@ -642,6 +646,8 @@ function TryRead(var x: int64): boolean; function TryRead(var x: uint64): boolean; ///-- function TryRead(var x: single): boolean; +///-- +function TryRead(var x: BigInteger): boolean; /// Возвращает значение типа integer, введенное с клавиатуры function ReadInteger: integer; @@ -655,6 +661,8 @@ function ReadChar: char; function ReadString: string; /// Возвращает значение типа boolean, введенное с клавиатуры function ReadBoolean: boolean; +/// Возвращает значение типа BigInteger, введенное с клавиатуры +function ReadBigInteger: BigInteger; /// Возвращает следующую лексему function ReadLexem: string; @@ -670,6 +678,9 @@ function ReadlnChar: char; function ReadlnString: string; /// Возвращает значение типа boolean, введенное с клавиатуры, и переходит на следующую строку ввода function ReadlnBoolean: boolean; +/// Возвращает значение типа BigInteger, введенное с клавиатуры, и переходит на следующую строку ввода +function ReadlnBigInteger: BigInteger; + /// Возвращает кортеж из двух значений типа integer, введенных с клавиатуры function ReadInteger2: (integer, integer); @@ -2344,7 +2355,7 @@ type end; -type +{type ///-- __TypeclassRestrictedFunctionAttribute = class(Attribute) public @@ -2384,7 +2395,7 @@ type constructor(instanceName: string); begin end; - end; + end;} type // Смысл полей Num, Width и Fmt соответствует @@ -4114,6 +4125,10 @@ procedure BigInteger.operator*=(var p: BigInteger; q: BigInteger) := p := p * q; procedure BigInteger.operator-=(var p: BigInteger; q: BigInteger) := p := p - q; +function BigInteger.operator div(p: BigInteger; q: integer) := BigInteger.Divide(p,q); + +function BigInteger.operator mod(p: BigInteger; q: integer) := BigInteger.Remainder(p,q); + //function BigInteger.operator div(p,q: BigInteger) := BigInteger.Divide(p,q); //function BigInteger.operator mod(p,q: BigInteger) := BigInteger.Remainder(p,q); @@ -5232,6 +5247,11 @@ begin else raise new System.FormatException('Входная строка имела неверный формат'); end; +procedure IOStandardSystem.read(var x: BigInteger); +begin + x := Biginteger.Parse(ReadLexem) +end; + procedure IOStandardSystem.readln; begin // while CurrentIOSystem.read_symbol <> END_OF_LINE_SYMBOL do; // было @@ -5360,6 +5380,11 @@ begin CurrentIOSystem.read(x) end; +procedure Read(var x: BigInteger); +begin + CurrentIOSystem.read(x) +end; + function TryRead(var x: integer): boolean; begin Result := True; @@ -5370,6 +5395,16 @@ begin end end; +function TryRead(var x: BigInteger): boolean; +begin + Result := True; + try + Read(x) + except + Result := False; + end +end; + function TryRead(var x: real): boolean; begin Result := True; @@ -5490,6 +5525,11 @@ begin Read(Result); end; +function ReadBigInteger: BigInteger; +begin + Read(Result); +end; + function ReadlnInteger: integer; begin Result := ReadInteger; @@ -5525,6 +5565,13 @@ begin Readln(); end; +function ReadlnBigInteger: BigInteger; +begin + Result := ReadBigInteger; + Readln(); +end; + + function ReadInteger2 := (ReadInteger, ReadInteger); function ReadReal2 := (ReadReal, ReadReal); @@ -11537,6 +11584,11 @@ begin Result := Self.ToDictionary(g -> g.Key, g -> grOperation(g)); end; +/// Операция удаления из словаря пары с указанным значением ключа +procedure operator-=(Self: IDictionary; k: Key); extensionmethod; +begin + Self.Remove(k); +end; //{{{--doc: Конец методов расширения }}} diff --git a/TestSuite/MapME.pas b/TestSuite/MapME.pas new file mode 100644 index 000000000..a4fd8a530 --- /dev/null +++ b/TestSuite/MapME.pas @@ -0,0 +1,10 @@ +{procedure operator-=(Self: IDictionary; k: Key); extensionmethod; +begin + Self.Remove(k); +end;} + +begin + var d := Dict(KV(1,2),KV(2,3)); + d -= 1; d -= 4; + Assert(d.Count = 1); +end. \ No newline at end of file diff --git a/TreeConverter/TreeRealization/generics.cs b/TreeConverter/TreeRealization/generics.cs index 7a859480c..30a888c06 100644 --- a/TreeConverter/TreeRealization/generics.cs +++ b/TreeConverter/TreeRealization/generics.cs @@ -396,7 +396,14 @@ namespace PascalABCCompiler.TreeRealization //generic-типе. if (method_param_types == (t.DeclaringMethod != null)) { - return param_types[t.GenericParameterPosition]; + try + { + return param_types[t.GenericParameterPosition]; + } + catch(Exception e) + { + e = e; + } } else { diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index ddb49bddd..fbec79e8c 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -2355,7 +2355,7 @@ type end; -type +{type ///-- __TypeclassRestrictedFunctionAttribute = class(Attribute) public @@ -2395,7 +2395,7 @@ type constructor(instanceName: string); begin end; - end; + end;} type // Смысл полей Num, Width и Fmt соответствует @@ -4125,6 +4125,10 @@ procedure BigInteger.operator*=(var p: BigInteger; q: BigInteger) := p := p * q; procedure BigInteger.operator-=(var p: BigInteger; q: BigInteger) := p := p - q; +function BigInteger.operator div(p: BigInteger; q: integer) := BigInteger.Divide(p,q); + +function BigInteger.operator mod(p: BigInteger; q: integer) := BigInteger.Remainder(p,q); + //function BigInteger.operator div(p,q: BigInteger) := BigInteger.Divide(p,q); //function BigInteger.operator mod(p,q: BigInteger) := BigInteger.Remainder(p,q); @@ -11580,6 +11584,11 @@ begin Result := Self.ToDictionary(g -> g.Key, g -> grOperation(g)); end; +/// Операция удаления из словаря пары с указанным значением ключа +procedure operator-=(Self: IDictionary; k: Key); extensionmethod; +begin + Self.Remove(k); +end; //{{{--doc: Конец методов расширения }}} diff --git a/bin/Lib/SF.pas b/bin/Lib/SF.pas index 45e187c8c..c1cf79d19 100644 --- a/bin/Lib/SF.pas +++ b/bin/Lib/SF.pas @@ -37,6 +37,36 @@ function RlnR3 := ReadlnReal3; function RlnC3 := ReadlnChar3; function RlnS3 := ReadlnString3; +procedure ReMin(var min: integer; x: integer); +begin + if x < min then + min := x +end; +procedure ReMax(var max: integer; x: integer); +begin + if x > max then + max := x +end; + +procedure ReMin(var min: real; x: real); +begin + if x < min then + min := x +end; + +procedure ReMax(var max: real; x: real); +begin + if x > max then + max := x +end; + +function ToI(Self: string); extensionmethod := Self.ToInteger; + +function ToR(Self: string); extensionmethod := Self.ToReal; + +function operator-(c,c1: char): integer; extensionmethod := Ord(c) - Ord(c1); + +function Len(Self: string): integer; extensionmethod := Self.Length; end. \ No newline at end of file