From 02f150a99a23bcee7156ca39a099d605cbd0867e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 24 May 2020 18:07:51 +0200 Subject: [PATCH] fix #2102 --- TestSuite/CompilationSamples/PABCSystem.pas | 2 ++ .../CompilationSamples/__RedirectIOMode.pas | 3 +- TestSuite/operators1.pas | 30 +++++++++++++++++++ .../TreeConversion/compilation_context.cs | 20 ++++++++----- TreeConverter/TreeRealization/functions.cs | 5 ++++ 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 TestSuite/operators1.pas diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 51839eb5d..d94c17f1b 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -2700,6 +2700,8 @@ function InternalRange(l,r: char): CharRange; ///-- function InternalRange(l,r: real): RealRange; +///-- +function IsInputPipedOrRedirectedFromFile: boolean; // ----------------------------------------------------- // Internal procedures for PABCRTL.dll diff --git a/TestSuite/CompilationSamples/__RedirectIOMode.pas b/TestSuite/CompilationSamples/__RedirectIOMode.pas index 96916748a..e3abb0ee7 100644 --- a/TestSuite/CompilationSamples/__RedirectIOMode.pas +++ b/TestSuite/CompilationSamples/__RedirectIOMode.pas @@ -57,7 +57,8 @@ end; procedure SendReadlnRequest; begin ReadlnSignalSended := true; - WriteToProcessErrorStream(ReadlnSignalCommand); + if not IsInputPipedOrRedirectedFromFile then + WriteToProcessErrorStream(ReadlnSignalCommand); end; function __ReadSignalOISystem.peek: integer; diff --git a/TestSuite/operators1.pas b/TestSuite/operators1.pas new file mode 100644 index 000000000..2e040e8fe --- /dev/null +++ b/TestSuite/operators1.pas @@ -0,0 +1,30 @@ +var i: integer; + +type TRec = record + a, b: integer; + class function operator=(a, b: TRec): boolean; + begin + Result := false; + i := 2; + end; + +end; + +TRec2 = record + a, b: integer; + class function operator=(a, b: TRec2): boolean; + begin + Result := false; + i := 3; + end; + +end; +begin + var r1, r2: TRec; + assert(not (r1 = r2)); + assert(i = 2); + var r3, r4: TRec2; + assert(not (r3 = r4)); + assert(i = 3); + assert(not (r3 <> r4)); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/compilation_context.cs b/TreeConverter/TreeConversion/compilation_context.cs index 6149ccbb7..400994795 100644 --- a/TreeConverter/TreeConversion/compilation_context.cs +++ b/TreeConverter/TreeConversion/compilation_context.cs @@ -1019,10 +1019,12 @@ namespace PascalABCCompiler.TreeConverter private void add_notequal_operator_if_need() { - SymbolInfo si = _ctn.find_first_in_type(compiler_string_consts.noteq_name); - if (si.sym_info is common_method_node) - return; - SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.scope, _cmn.scope, null, si.ToString()); + List si_list = _ctn.find_in_type(compiler_string_consts.noteq_name); + foreach (SymbolInfo si2 in si_list) + if (si2.sym_info is common_method_node) + return; + SymbolInfo si = si_list[0]; + SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.scope, _cmn.scope, null, si.ToString()); common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.noteq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn, SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope); cmn.IsOperator = true; @@ -1053,10 +1055,12 @@ namespace PascalABCCompiler.TreeConverter private void add_equal_operator_if_need() { - SymbolInfo si = _ctn.find_first_in_type(compiler_string_consts.eq_name); - if (si.sym_info is common_method_node) - return; - SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope( _ctn.scope, _cmn.scope, null, si.ToString()); + List si_list = _ctn.find_in_type(compiler_string_consts.eq_name); + foreach (SymbolInfo si2 in si_list) + if (si2.sym_info is common_method_node) + return; + SymbolInfo si = si_list[0]; + SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope( _ctn.scope, _cmn.scope, null, si.ToString()); common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.eq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn, SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope); cmn.IsOperator = true; diff --git a/TreeConverter/TreeRealization/functions.cs b/TreeConverter/TreeRealization/functions.cs index 61bbebce9..aba3d4500 100644 --- a/TreeConverter/TreeRealization/functions.cs +++ b/TreeConverter/TreeRealization/functions.cs @@ -541,6 +541,11 @@ namespace PascalABCCompiler.TreeRealization } } + public void SetName(string name) + { + _name = name; + } + //TODO: Нужно ли is_overload для basic_function_node? public bool is_overload {