Ver código fonte

Add a modeswitch for type helpers as discussed in core on 24th October 2013. It is disabled by default in all modes (afterall type helper support in Delphi started only beginning with XE3)

+ globtype.pas: add new modeswitch to modeswitch enum and name array
* ptype.pas & pdecobj.pas: check for new modeswitch instead of modeswitch class
* ppu.pas: increase ppu version as we've added a new modeswitch which requires correctly compiled units

* adjusted tests to enabled the modeswitch when necessary
+ added three new tests that check for correct functionality of modeswitch typehelpers

git-svn-id: trunk@26796 -
svenbarth 11 anos atrás
pai
commit
ddb78fefdc

+ 3 - 0
.gitattributes

@@ -12038,6 +12038,9 @@ tests/test/tthlp17.pp svneol=native#text/pascal
 tests/test/tthlp18.pp svneol=native#text/pascal
 tests/test/tthlp19.pp svneol=native#text/pascal
 tests/test/tthlp2.pp svneol=native#text/pascal
+tests/test/tthlp20.pp svneol=native#text/pascal
+tests/test/tthlp21.pp svneol=native#text/pascal
+tests/test/tthlp22.pp svneol=native#text/pascal
 tests/test/tthlp3.pp svneol=native#text/pascal
 tests/test/tthlp4.pp svneol=native#text/pascal
 tests/test/tthlp5.pp svneol=native#text/pascal

+ 6 - 3
compiler/globtype.pas

@@ -389,8 +389,10 @@ interface
          m_final_fields,        { allows declaring fields as "final", which means they must be initialised
                                   in the (class) constructor and are constant from then on (same as final
                                   fields in Java) }
-         m_default_unicodestring { makes the default string type in $h+ mode unicodestring rather than
-                                   ansistring; similarly, char becomes unicodechar rather than ansichar }
+         m_default_unicodestring, { makes the default string type in $h+ mode unicodestring rather than
+                                    ansistring; similarly, char becomes unicodechar rather than ansichar }
+         m_type_helpers         { allows the declaration of "type helper" (non-Delphi) or "record helper"
+                                  (Delphi) for primitive types }
        );
        tmodeswitches = set of tmodeswitch;
 
@@ -554,7 +556,8 @@ interface
          'ISOUNARYMINUS',
          'SYSTEMCODEPAGE',
          'FINALFIELDS',
-         'UNICODESTRINGS');
+         'UNICODESTRINGS',
+         'TYPEHELPERS');
 
 
      type

+ 1 - 1
compiler/pdecobj.pas

@@ -767,7 +767,7 @@ implementation
                       { primitive types are allowed for record helpers in mode
                         delphi }
                       (hdef.typ<>recorddef) and
-                      not (m_delphi in current_settings.modeswitches)
+                      not (m_type_helpers in current_settings.modeswitches)
                     ) then
                   Message1(type_e_record_type_expected,hdef.typename)
                 else

+ 1 - 1
compiler/ppu.pas

@@ -43,7 +43,7 @@ type
 {$endif Test_Double_checksum}
 
 const
-  CurrentPPUVersion = 164;
+  CurrentPPUVersion = 165;
 
 { buffer sizes }
   maxentrysize = 1024;

+ 2 - 2
compiler/ptype.pas

@@ -1745,8 +1745,8 @@ implementation
                 end
               else
                 if hadtypetoken and
-                    { don't allow "type helper" in mode delphi and require modeswitch class }
-                    ([m_delphi,m_class]*current_settings.modeswitches=[m_class]) and
+                    { don't allow "type helper" in mode delphi and require modeswitch typehelpers }
+                    ([m_delphi,m_type_helpers]*current_settings.modeswitches=[m_type_helpers]) and
                     (token=_ID) and (idtoken=_HELPER) then
                   begin
                     consume(_HELPER);

+ 1 - 0
tests/test/tthlp1.pp

@@ -5,6 +5,7 @@
 program tthlp1;
 
 {$mode objfpc}{$H+}
+{$modeswitch typehelpers}
 
 type
   TTest = type helper for LongInt

+ 1 - 0
tests/test/tthlp10.pp

@@ -5,6 +5,7 @@
 program tthlp10;
 
 {$mode objfpc}
+{$modeswitch typehelpers}
 
 type
   TProcedure = procedure;

+ 1 - 0
tests/test/tthlp11.pp

@@ -5,6 +5,7 @@
 program tthlp11;
 
 {$mode delphi}
+{$modeswitch typehelpers}
 
 type
   TProcedure = procedure;

+ 1 - 0
tests/test/tthlp12.pp

@@ -3,6 +3,7 @@
 program tthlp12;
 
 {$mode objfpc}
+{$modeswitch typehelpers}
 
 type
   TLongIntHelper = type helper for LongInt

+ 1 - 0
tests/test/tthlp13.pp

@@ -5,6 +5,7 @@
 program tthlp13;
 
 {$mode objfpc}
+{$modeswitch typehelpers}
 
 type
   TLongIntHelper = type helper for LongInt

+ 1 - 0
tests/test/tthlp15.pp

@@ -5,6 +5,7 @@
 program tthlp15;
 
 {$mode objfpc}
+{$modeswitch typehelpers}
 
 type
   TLongIntHelper = type helper for LongInt

+ 1 - 0
tests/test/tthlp16.pp

@@ -5,6 +5,7 @@
 program tthlp16;
 
 {$mode objfpc}
+{$modeswitch typehelpers}
 
 type
   TLongIntHelper = type helper for LongInt

+ 1 - 0
tests/test/tthlp2.pp

@@ -5,6 +5,7 @@
 program tthlp2;
 
 {$mode delphi}{$H+}
+{$modeswitch typehelpers}
 
 type
   TTest = record helper for LongInt

+ 14 - 0
tests/test/tthlp20.pp

@@ -0,0 +1,14 @@
+{ %NORUN }
+
+{ test that "type helper" is parsed as "type alias" + "type name" if modeswitch typehelpers is not set }
+
+program tthlp20;
+
+type
+  helper = LongInt;
+
+  TTest = type helper;
+
+begin
+
+end.

+ 13 - 0
tests/test/tthlp21.pp

@@ -0,0 +1,13 @@
+{ %FAIL }
+
+{ type helpers are not parsed if modeswitch typehelpers is not set }
+
+program tthlp20;
+
+type
+  TTest = type helper for LongInt
+  end;
+
+begin
+
+end.

+ 15 - 0
tests/test/tthlp22.pp

@@ -0,0 +1,15 @@
+{ %FAIL }
+
+{ type helpers are not parsed if modeswitch typehelpers is not set (mode Delphi) }
+
+program tthlp20;
+
+{$mode delphi}
+
+type
+  TTest = record helper for LongInt
+  end;
+
+begin
+
+end.

+ 1 - 0
tests/test/tthlp9.pp

@@ -3,6 +3,7 @@
 program tthlp9;
 
 {$mode objfpc}
+{$modeswitch typehelpers}
 {$apptype console}
 
 type

+ 1 - 0
tests/test/uthlp.pp

@@ -2,6 +2,7 @@ unit uthlp;
 
 {$ifdef fpc}
   {$mode delphi}{$H+}
+  {$modeswitch typehelpers}
 {$endif}
 
 interface