diff options
author | svenbarth <svenbarth@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2014-02-16 12:58:24 +0000 |
---|---|---|
committer | svenbarth <svenbarth@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2014-02-16 12:58:24 +0000 |
commit | 12d0bfb6496b6ad7b0d4e46b9dce685b31bbcc37 (patch) | |
tree | fb12e89506c48f71319598f1307b91810d237e17 | |
parent | d4ceb89e3341f01e9f083f09ed83a50b0c14b5ae (diff) | |
download | fpc-12d0bfb6496b6ad7b0d4e46b9dce685b31bbcc37.tar.gz |
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: http://svn.freepascal.org/svn/fpc/trunk@26796 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r-- | compiler/globtype.pas | 9 | ||||
-rw-r--r-- | compiler/pdecobj.pas | 2 | ||||
-rw-r--r-- | compiler/ppu.pas | 2 | ||||
-rw-r--r-- | compiler/ptype.pas | 4 | ||||
-rw-r--r-- | tests/test/tthlp1.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp10.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp11.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp12.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp13.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp15.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp16.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp2.pp | 1 | ||||
-rw-r--r-- | tests/test/tthlp20.pp | 14 | ||||
-rw-r--r-- | tests/test/tthlp21.pp | 13 | ||||
-rw-r--r-- | tests/test/tthlp22.pp | 15 | ||||
-rw-r--r-- | tests/test/tthlp9.pp | 1 | ||||
-rw-r--r-- | tests/test/uthlp.pp | 1 |
17 files changed, 62 insertions, 7 deletions
diff --git a/compiler/globtype.pas b/compiler/globtype.pas index 32aafb4797..7daa06cc7b 100644 --- a/compiler/globtype.pas +++ b/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 diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 4c8fc7e989..2c85fb3785 100644 --- a/compiler/pdecobj.pas +++ b/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 diff --git a/compiler/ppu.pas b/compiler/ppu.pas index 2e0a1ccbe9..45f58a017d 100644 --- a/compiler/ppu.pas +++ b/compiler/ppu.pas @@ -43,7 +43,7 @@ type {$endif Test_Double_checksum} const - CurrentPPUVersion = 164; + CurrentPPUVersion = 165; { buffer sizes } maxentrysize = 1024; diff --git a/compiler/ptype.pas b/compiler/ptype.pas index 0253080113..fa74138d43 100644 --- a/compiler/ptype.pas +++ b/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); diff --git a/tests/test/tthlp1.pp b/tests/test/tthlp1.pp index c856b6b6f5..54cccb419c 100644 --- a/tests/test/tthlp1.pp +++ b/tests/test/tthlp1.pp @@ -5,6 +5,7 @@ program tthlp1; {$mode objfpc}{$H+} +{$modeswitch typehelpers} type TTest = type helper for LongInt diff --git a/tests/test/tthlp10.pp b/tests/test/tthlp10.pp index 223f7f1fd1..c420e2cadc 100644 --- a/tests/test/tthlp10.pp +++ b/tests/test/tthlp10.pp @@ -5,6 +5,7 @@ program tthlp10; {$mode objfpc} +{$modeswitch typehelpers} type TProcedure = procedure; diff --git a/tests/test/tthlp11.pp b/tests/test/tthlp11.pp index b4811d5f03..699fba8614 100644 --- a/tests/test/tthlp11.pp +++ b/tests/test/tthlp11.pp @@ -5,6 +5,7 @@ program tthlp11; {$mode delphi} +{$modeswitch typehelpers} type TProcedure = procedure; diff --git a/tests/test/tthlp12.pp b/tests/test/tthlp12.pp index 857527438f..b1ab65056d 100644 --- a/tests/test/tthlp12.pp +++ b/tests/test/tthlp12.pp @@ -3,6 +3,7 @@ program tthlp12; {$mode objfpc} +{$modeswitch typehelpers} type TLongIntHelper = type helper for LongInt diff --git a/tests/test/tthlp13.pp b/tests/test/tthlp13.pp index 41d3edfa57..e90ae31b6e 100644 --- a/tests/test/tthlp13.pp +++ b/tests/test/tthlp13.pp @@ -5,6 +5,7 @@ program tthlp13; {$mode objfpc} +{$modeswitch typehelpers} type TLongIntHelper = type helper for LongInt diff --git a/tests/test/tthlp15.pp b/tests/test/tthlp15.pp index afb20f1520..4d62cf9482 100644 --- a/tests/test/tthlp15.pp +++ b/tests/test/tthlp15.pp @@ -5,6 +5,7 @@ program tthlp15; {$mode objfpc} +{$modeswitch typehelpers} type TLongIntHelper = type helper for LongInt diff --git a/tests/test/tthlp16.pp b/tests/test/tthlp16.pp index 193067f139..6ec5b18fbf 100644 --- a/tests/test/tthlp16.pp +++ b/tests/test/tthlp16.pp @@ -5,6 +5,7 @@ program tthlp16; {$mode objfpc} +{$modeswitch typehelpers} type TLongIntHelper = type helper for LongInt diff --git a/tests/test/tthlp2.pp b/tests/test/tthlp2.pp index f8c07378ef..502af0afe3 100644 --- a/tests/test/tthlp2.pp +++ b/tests/test/tthlp2.pp @@ -5,6 +5,7 @@ program tthlp2; {$mode delphi}{$H+} +{$modeswitch typehelpers} type TTest = record helper for LongInt diff --git a/tests/test/tthlp20.pp b/tests/test/tthlp20.pp new file mode 100644 index 0000000000..e55d119ded --- /dev/null +++ b/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. diff --git a/tests/test/tthlp21.pp b/tests/test/tthlp21.pp new file mode 100644 index 0000000000..0e885eb056 --- /dev/null +++ b/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. diff --git a/tests/test/tthlp22.pp b/tests/test/tthlp22.pp new file mode 100644 index 0000000000..57f7bd4d26 --- /dev/null +++ b/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. diff --git a/tests/test/tthlp9.pp b/tests/test/tthlp9.pp index b775d0399d..d5b42b5463 100644 --- a/tests/test/tthlp9.pp +++ b/tests/test/tthlp9.pp @@ -3,6 +3,7 @@ program tthlp9; {$mode objfpc} +{$modeswitch typehelpers} {$apptype console} type diff --git a/tests/test/uthlp.pp b/tests/test/uthlp.pp index 730ad2e4aa..688598989f 100644 --- a/tests/test/uthlp.pp +++ b/tests/test/uthlp.pp @@ -2,6 +2,7 @@ unit uthlp; {$ifdef fpc} {$mode delphi}{$H+} + {$modeswitch typehelpers} {$endif} interface |