diff --git a/compiler/pdecl.pas b/compiler/pdecl.pas index 499c46c855..2bf4b1a47c 100644 --- a/compiler/pdecl.pas +++ b/compiler/pdecl.pas @@ -408,6 +408,7 @@ implementation generictypelist : TFPObjectList; generictokenbuf : tdynamicarray; vmtbuilder : TVMTBuilder; + p:tnode; begin old_block_type:=block_type; { save unit container of forward declarations - @@ -536,6 +537,28 @@ implementation hdef:=tstoreddef(hdef).getcopy; + { check if it is an ansistirng(codepage) declaration } + if is_ansistring(hdef) and try_to_consume(_LKLAMMER) then + begin + p:=comp_expr(true,false); + consume(_RKLAMMER); + if not is_constintnode(p) then + begin + Message(parser_e_illegal_expression); + { error recovery } + end + else + begin + if (tordconstnode(p).value<0) or (tordconstnode(p).value>65535) then + begin + Message(parser_e_invalid_codepage); + tordconstnode(p).value:=0; + end; + tstringdef(hdef).encoding:=int64(tordconstnode(p).value); + end; + p.free; + end; + { fix name, it is used e.g. for tables } if is_class_or_interface_or_dispinterface(hdef) then with tobjectdef(hdef) do diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 8ab9a25060..bd771ad149 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -130,35 +130,6 @@ implementation end; p.free; end - else if token=_LSHARPBRACKET then - begin - if not(allowtypedef) then - Message(parser_e_no_local_para_def); - consume(_LSHARPBRACKET); - p:=comp_expr(true,false); - if not is_constintnode(p) then - begin - Message(parser_e_illegal_expression); - { error recovery } - end - else - begin - if (tordconstnode(p).value<0) or (tordconstnode(p).value>65535) then - begin - Message(parser_e_invalid_codepage); - tordconstnode(p).value:=0; - end; - if tordconstnode(p).value=CP_UTF16 then - def:=tstringdef.createunicode - else - begin - def:=tstringdef.createansi; - tstringdef(def).encoding:=int64(tordconstnode(p).value); - end; - consume(_RSHARPBRACKET); - end; - p.free; - end else begin if cs_ansistrings in current_settings.localswitches then @@ -1522,7 +1493,7 @@ implementation (token=_LT) and (m_delphi in current_settings.modeswitches) then generate_specialization(hdef,false,''); - if try_to_consume(_LKLAMMER) then + if not typeonly and try_to_consume(_LKLAMMER) then begin p1:=comp_expr(true,false); consume(_RKLAMMER); diff --git a/compiler/pp.lpi b/compiler/pp.lpi index 148060d8e8..8485cb2a9b 100644 --- a/compiler/pp.lpi +++ b/compiler/pp.lpi @@ -25,7 +25,7 @@ - + @@ -64,6 +64,7 @@ + diff --git a/rtl/inc/systemh.inc b/rtl/inc/systemh.inc index 581762a975..922462d7bc 100644 --- a/rtl/inc/systemh.inc +++ b/rtl/inc/systemh.inc @@ -291,14 +291,14 @@ Type UCS4String = array of UCS4Char; {$ifdef FPC_HAS_CPSTRING} - UTF8String = String<65001>; + UTF8String = type AnsiString(65001); {$else FPC_HAS_CPSTRING} UTF8String = type ansistring; {$endif FPC_HAS_CPSTRING} PUTF8String = ^UTF8String; {$ifdef FPC_HAS_CPSTRING} - RawByteString = String<$ffff>; + RawByteString = type AnsiString($ffff); {$else FPC_HAS_CPSTRING} RawByteString = ansistring; {$endif FPC_HAS_CPSTRING} diff --git a/tests/test/tcpstr1.pp b/tests/test/tcpstr1.pp index 374be2565a..83348abfe6 100644 --- a/tests/test/tcpstr1.pp +++ b/tests/test/tcpstr1.pp @@ -1,7 +1,7 @@ {$CODEPAGE cp437} type - tcpstr437 = string<437>; - tcpstr850 = string<850>; + tcpstr437 = type AnsiString(437); + tcpstr850 = type AnsiString(850); var a1 : tcpstr437; a2 : utf8string; diff --git a/tests/test/tcpstr6.pp b/tests/test/tcpstr6.pp index aee57b1e98..2afb962efe 100644 --- a/tests/test/tcpstr6.pp +++ b/tests/test/tcpstr6.pp @@ -1,8 +1,8 @@ {$CODEPAGE cp1251} // file encoding is cp1251 type - Cp866String = string<866>; - Cp1251String = string<1251>; + Cp866String = type AnsiString(866); + Cp1251String = type AnsiString(1251); procedure WriteString(const s: RawByteString); begin diff --git a/tests/test/tcpstr8.pp b/tests/test/tcpstr8.pp index 3841654051..5074e23de9 100644 --- a/tests/test/tcpstr8.pp +++ b/tests/test/tcpstr8.pp @@ -2,8 +2,8 @@ program test; {$CODEPAGE UTF8} // file encoding is UTF8 type - CP866String = string<866>; - CP1251String = string<1251>; + CP866String = type AnsiString(866); + CP1251String = type AnsiString(1251); procedure WriteString(const s: RawByteString); begin diff --git a/tests/test/tcpstransistr2shortstring.pp b/tests/test/tcpstransistr2shortstring.pp index 6f6de58779..8c6ae5b6ea 100644 --- a/tests/test/tcpstransistr2shortstring.pp +++ b/tests/test/tcpstransistr2shortstring.pp @@ -6,7 +6,7 @@ uses sysutils; type - ts866 = type string<866>; + ts866 = type AnsiString(866); procedure doerror(ANumber : Integer); begin diff --git a/tests/test/tcpstransistr2widechararray.pp b/tests/test/tcpstransistr2widechararray.pp index 624c7778a9..467eb97f6a 100644 --- a/tests/test/tcpstransistr2widechararray.pp +++ b/tests/test/tcpstransistr2widechararray.pp @@ -5,7 +5,7 @@ sysutils; type - ts850 = type string<850>; + ts850 = type AnsiString(850); procedure doerror(ANumber : Integer); begin diff --git a/tests/test/tcpstransistrcompare.pp b/tests/test/tcpstransistrcompare.pp index 1ea24a1404..a326e6995e 100644 --- a/tests/test/tcpstransistrcompare.pp +++ b/tests/test/tcpstransistrcompare.pp @@ -5,8 +5,8 @@ uses SysUtils; type - ts850 = type string<850>; - ts1251 = type string<1251>; + ts850 = type AnsiString(850); + ts1251 = type AnsiString(1251); var a850:ts850; a1251 : ts1251; diff --git a/tests/test/tcpstransistrcompareequal.pp b/tests/test/tcpstransistrcompareequal.pp index 6dc16cde41..b46a351f92 100644 --- a/tests/test/tcpstransistrcompareequal.pp +++ b/tests/test/tcpstransistrcompareequal.pp @@ -5,8 +5,8 @@ uses SysUtils; type - ts850 = type string<850>; - ts1251 = type string<1251>; + ts850 = type AnsiString(850); + ts1251 = type AnsiString(1251); var a850:ts850; a1251 : ts1251; diff --git a/tests/test/tcpstransistrcopy.pp b/tests/test/tcpstransistrcopy.pp index ba33f284fd..834211e705 100644 --- a/tests/test/tcpstransistrcopy.pp +++ b/tests/test/tcpstransistrcopy.pp @@ -5,8 +5,8 @@ sysutils; type - ts850 = type string<850>; - ts1252 = type string<1252>; + ts850 = type AnsiString(850); + ts1252 = type AnsiString(1252); procedure doerror(ANumber : Integer); begin diff --git a/tests/test/tcpstrassignansistr.pp b/tests/test/tcpstrassignansistr.pp index f1965982fe..dde2d38b7a 100644 --- a/tests/test/tcpstrassignansistr.pp +++ b/tests/test/tcpstrassignansistr.pp @@ -1,7 +1,7 @@ {$CODEPAGE cp866} program tcpstrassignansistr; type - ts866 = type string<866>; + ts866 = type AnsiString(866); procedure doerror(ANumber : Integer); begin diff --git a/tests/test/tcpstrchar2ansistr.pp b/tests/test/tcpstrchar2ansistr.pp index cc32acca5e..1cce3958e2 100644 --- a/tests/test/tcpstrchar2ansistr.pp +++ b/tests/test/tcpstrchar2ansistr.pp @@ -5,7 +5,7 @@ sysutils; type - ts866 = type string<866>; + ts866 = type AnsiString(866); procedure doerror(ANumber : Integer); begin diff --git a/tests/test/tcpstrconcat.pp b/tests/test/tcpstrconcat.pp index 74d5bb20fa..66d67651fd 100644 --- a/tests/test/tcpstrconcat.pp +++ b/tests/test/tcpstrconcat.pp @@ -6,7 +6,7 @@ uses SysUtils; type - ts866 = type string<866>; + ts866 = type AnsiString(866); var a, b, c : ts866; begin diff --git a/tests/test/tcpstrconcat2.pp b/tests/test/tcpstrconcat2.pp index 2f62e6fbaf..5d52ef3a2b 100644 --- a/tests/test/tcpstrconcat2.pp +++ b/tests/test/tcpstrconcat2.pp @@ -6,7 +6,7 @@ uses SysUtils; type - ts866 = type string<866>; + ts866 = type AnsiString(866); var a, b, c : ts866; begin diff --git a/tests/test/tcpstrconcat3.pp b/tests/test/tcpstrconcat3.pp index b9773db19e..7ec1ebbc9e 100644 --- a/tests/test/tcpstrconcat3.pp +++ b/tests/test/tcpstrconcat3.pp @@ -6,9 +6,9 @@ uses SysUtils; type - ts866 = type string<866>; - ts850 = type string<850>; - ts1251 = type string<1251>; + ts866 = type AnsiString(866); + ts850 = type AnsiString(850); + ts1251 = type AnsiString(1251); var a : ts1251; b : ts850; diff --git a/tests/test/tcpstrconcatmulti.pp b/tests/test/tcpstrconcatmulti.pp index 681a119b50..b5497f84ff 100644 --- a/tests/test/tcpstrconcatmulti.pp +++ b/tests/test/tcpstrconcatmulti.pp @@ -7,7 +7,7 @@ uses SysUtils; type - ts866 = type string<866>; + ts866 = type AnsiString(866); var a, b, c, d : ts866; begin diff --git a/tests/test/tcpstrconcatmulti2.pp b/tests/test/tcpstrconcatmulti2.pp index 189d340501..f012116d4a 100644 --- a/tests/test/tcpstrconcatmulti2.pp +++ b/tests/test/tcpstrconcatmulti2.pp @@ -7,9 +7,9 @@ uses SysUtils; type - ts866 = type string<866>; - ts850 = type string<850>; - ts1251 = type string<1251>; + ts866 = type AnsiString(866); + ts850 = type AnsiString(850); + ts1251 = type AnsiString(1251); var a : ts1251; b : ts850; diff --git a/tests/test/tcpstrpchar2ansistr.pp b/tests/test/tcpstrpchar2ansistr.pp index 9d86cacae2..6bd2e8a215 100644 --- a/tests/test/tcpstrpchar2ansistr.pp +++ b/tests/test/tcpstrpchar2ansistr.pp @@ -5,8 +5,8 @@ sysutils; type - ts866 = type string<866>; - ts1252 = type string<1252>; + ts866 = type AnsiString(866); + ts1252 = type AnsiString(1252); procedure doerror(ANumber : Integer); begin diff --git a/tests/test/tcpstrsetlength.pp b/tests/test/tcpstrsetlength.pp index b44149d941..18217115ae 100644 --- a/tests/test/tcpstrsetlength.pp +++ b/tests/test/tcpstrsetlength.pp @@ -5,7 +5,7 @@ uses SysUtils; type - ts866 = type string<866>; + ts866 = type AnsiString(866); var a866 : ts866; begin diff --git a/tests/test/tcpstrsetlength2.pp b/tests/test/tcpstrsetlength2.pp index 9eef9cc6d0..44fc952b03 100644 --- a/tests/test/tcpstrsetlength2.pp +++ b/tests/test/tcpstrsetlength2.pp @@ -5,7 +5,7 @@ uses SysUtils; type - ts866 = type string<866>; + ts866 = type AnsiString(866); var a866 : ts866; begin diff --git a/tests/test/tcpstrshortstr2ansistr.pp b/tests/test/tcpstrshortstr2ansistr.pp index 11d3d13569..a3be8c73cb 100644 --- a/tests/test/tcpstrshortstr2ansistr.pp +++ b/tests/test/tcpstrshortstr2ansistr.pp @@ -6,8 +6,8 @@ uses sysutils; type - ts866 = type string<866>; - ts1252 = type string<1252>; + ts866 = type AnsiString(866) + ts1252 = type AnsiString(1252); procedure doerror(ANumber : Integer); begin diff --git a/tests/test/tcptypedconst.pp b/tests/test/tcptypedconst.pp index 7948d8a27c..5282b832a2 100644 --- a/tests/test/tcptypedconst.pp +++ b/tests/test/tcptypedconst.pp @@ -2,8 +2,8 @@ program tcptypedconst; type - Str_cp = string<1251>; - Str_cp850 = string<850>; + Str_cp = type AnsiString(1251); + Str_cp850 = type AnsiString(850); procedure printcontent(p : Pointer; l: integer); var