Browse Source

+ changes precedence of unary minus operator in mac and iso mode, resolves #17710

git-svn-id: trunk@17489 -
florian 14 years ago
parent
commit
6ea8eb7dc2
5 changed files with 29 additions and 6 deletions
  1. 1 0
      .gitattributes
  2. 2 2
      compiler/globals.pas
  3. 4 2
      compiler/globtype.pas
  4. 6 2
      compiler/pexpr.pas
  5. 16 0
      tests/webtbs/tw17710.pp

+ 1 - 0
.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

+ 2 - 2
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;

+ 4 - 2
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

+ 6 - 2
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;

+ 16 - 0
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.