From 3396fddd6b1192f5ccc26a1d0a2e80ab2e6bf58b Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Sat, 4 Sep 2021 17:59:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20s[^1]=20=D0=B2=20zerobasedstrings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 ++-- Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- TestSuite/CompilationSamples/PABCSystem.pas | 5 +++++ TestSuite/zerobased_with_index_fromend.pas | 8 ++++++++ .../TreeConversion/syntax_tree_visitor.cs | 19 ++++++++++++++++--- bin/Lib/PABCSystem.pas | 5 +++++ 8 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 TestSuite/zerobased_with_index_fromend.pas diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 797b5cd9b..36d12bf51 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 = "8"; public const string Build = "1"; - public const string Revision = "2979"; + public const string Revision = "2980"; 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 4b24d738c..03cc80c26 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%MINOR%=8 -%REVISION%=2979 %COREVERSION%=1 +%REVISION%=2980 +%MINOR%=8 %MAJOR%=3 diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index efde7c4a0..01e018071 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.8.1.2979 +3.8.1.2980 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 71bfe13e4..f69ef052a 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.8.1.2979' +!define VERSION '3.8.1.2980' diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 77a491343..a298298e7 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -820,6 +820,11 @@ type Result := str.Length - IndexValue + 1; end; + function Reverse0(str: string): integer; + begin + Result := str.Length - IndexValue; + end; + function Reverse(arr: System.Array; dim: integer): integer; begin Result := arr.GetLength(dim) - IndexValue; diff --git a/TestSuite/zerobased_with_index_fromend.pas b/TestSuite/zerobased_with_index_fromend.pas new file mode 100644 index 000000000..5ec856ec8 --- /dev/null +++ b/TestSuite/zerobased_with_index_fromend.pas @@ -0,0 +1,8 @@ +{$zerobasedstrings} +begin + var s := 'ABCD'; + Assert(s[^1]='D'); + Assert(s[^2]='C'); + Assert(s[^3]='B'); + Assert(s[^4]='A'); +end. diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 489d130ee..5bdda7835 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -5417,7 +5417,6 @@ namespace PascalABCCompiler.TreeConverter semantic_node sn = convert_semantic_strong(_dot_node.left); // SSM 17/07/21 учёт ZeroBasedStrings в семантике срезов строк - // Пока не получилось if (SemanticRules.ZeroBasedStrings && (sn as expression_node)?.type is compiled_type_node ctn && ctn.compiled_type == typeof(string) && _dot_node.right is ident id0 @@ -5427,11 +5426,25 @@ namespace PascalABCCompiler.TreeConverter || id0.name.ToLower() == "systemslicequestion" || id0.name.ToLower() == "systemsliceassignment" ) - id0.name += "0"; + id0.name += "0"; // SystemSlice0 + } + + // SSM 04/09/21 учёт ZeroBasedStrings в s[^1] + if (SemanticRules.ZeroBasedStrings + && (sn as expression_node)?.type.BaseFullName == "PABCSystem.SystemIndex" + && _dot_node.right is ident id1 + && id1.name.ToLower() == "reverse" + && _method_call.parameters.Count == 1) + { + var strtn = convert_strong(_method_call.parameters.expressions[0]); + if (strtn.type is compiled_type_node strtnc && strtnc.compiled_type == typeof(string)) // Уф + { + id1.name += "0"; // Reverse0 + } } //SyntaxTree.ident id_right = ConvertOperatorNameToIdent(_dot_node.right as SyntaxTree.ident); - SyntaxTree.ident id_right = _dot_node.right as SyntaxTree.ident; + SyntaxTree.ident id_right = _dot_node.right as SyntaxTree.ident; switch (sn.general_node_type) { case general_node_type.expression: diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 77a491343..a298298e7 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -820,6 +820,11 @@ type Result := str.Length - IndexValue + 1; end; + function Reverse0(str: string): integer; + begin + Result := str.Length - IndexValue; + end; + function Reverse(arr: System.Array; dim: integer): integer; begin Result := arr.GetLength(dim) - IndexValue;