From 6ea8eb7dc23e37c295d7dc64048511d96c8b8aed Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 17 May 2011 19:53:55 +0000 Subject: [PATCH] + changes precedence of unary minus operator in mac and iso mode, resolves #17710 git-svn-id: trunk@17489 - --- .gitattributes | 1 + compiler/globals.pas | 4 ++-- compiler/globtype.pas | 6 ++++-- compiler/pexpr.pas | 8 ++++++-- tests/webtbs/tw17710.pp | 16 ++++++++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 tests/webtbs/tw17710.pp diff --git a/.gitattributes b/.gitattributes index 9329203d7a..611df64132 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11422,6 +11422,7 @@ tests/webtbs/tw17646.pp svneol=native#text/plain tests/webtbs/tw1765.pp svneol=native#text/plain tests/webtbs/tw17675.pp svneol=native#text/plain tests/webtbs/tw17675a.pp svneol=native#text/plain +tests/webtbs/tw17710.pp svneol=native#text/pascal tests/webtbs/tw17714.pp svneol=native#text/plain tests/webtbs/tw17715.pp svneol=native#text/plain tests/webtbs/tw1779.pp svneol=native#text/plain diff --git a/compiler/globals.pas b/compiler/globals.pas index f19ee8fa39..df5abe6105 100644 --- a/compiler/globals.pas +++ b/compiler/globals.pas @@ -68,9 +68,9 @@ interface [m_gpc,m_all,m_tp_procvar]; {$endif} macmodeswitches = - [m_mac,m_all,m_cvar_support,m_mac_procvar,m_nested_procvars,m_non_local_goto]; + [m_mac,m_all,m_cvar_support,m_mac_procvar,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus]; isomodeswitches = - [m_iso,m_all,m_tp_procvar,m_duplicate_names,m_nested_procvars,m_non_local_goto]; + [m_iso,m_all,m_tp_procvar,m_duplicate_names,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus]; { maximum nesting of routines } maxnesting = 32; diff --git a/compiler/globtype.pas b/compiler/globtype.pas index d7300d2bff..1d40edc5c0 100644 --- a/compiler/globtype.pas +++ b/compiler/globtype.pas @@ -287,7 +287,8 @@ interface m_objectivec2, { support interfacing with Objective-C (2.0) } m_nested_procvars, { support nested procedural variables } m_non_local_goto, { support non local gotos (like iso pascal) } - m_advanced_records { advanced record syntax with visibility sections, methods and properties } + m_advanced_records, { advanced record syntax with visibility sections, methods and properties } + m_isolike_unary_minus { unary minus like in iso pascal: same precedence level as binary minus/plus } ); tmodeswitches = set of tmodeswitch; @@ -418,7 +419,8 @@ interface 'OBJECTIVEC2', 'NESTEDPROCVARS', 'NONLOCALGOTO', - 'ADVANCEDRECORDS'); + 'ADVANCEDRECORDS', + 'ISOUNARYMINUS'); type diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 2ef96b7bff..c1190a7abe 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -2698,7 +2698,7 @@ implementation _MINUS : begin consume(_MINUS); - if (token = _INTCONST) then + if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then begin { ugly hack, but necessary to be able to parse } { -9223372036854775808 as int64 (JM) } @@ -2726,7 +2726,11 @@ implementation end else begin - p1:=sub_expr(oppower,false,false); + if m_isolike_unary_minus in current_settings.modeswitches then + p1:=sub_expr(opmultiply,false,false) + else + p1:=sub_expr(oppower,false,false); + p1:=cunaryminusnode.create(p1); end; end; diff --git a/tests/webtbs/tw17710.pp b/tests/webtbs/tw17710.pp new file mode 100644 index 0000000000..878dbfacc6 --- /dev/null +++ b/tests/webtbs/tw17710.pp @@ -0,0 +1,16 @@ +{$mode macpas} +program unary; +var + i : longint; +begin + if -2 shr 1<>-1 then + halt(1); + if -2-2<>-4 then + halt(1); + i:=2; + if -i shr 1<>-1 then + halt(1); + if -i-i<>-4 then + halt(1); + writeln('ok'); +end.