compiler:

- treat the defs equal when convert from rawbytstring to any ansistring type (delphi compatible)
  - set result of ansistring copy() function to the type of first argument for ansistring arguments and to ansistring for pchar and char array arguments (delphi compatible)
  + test

git-svn-id: trunk@20285 -
This commit is contained in:
paul 2012-02-09 08:22:38 +00:00
parent 79b725990c
commit 3b153c223a
5 changed files with 47 additions and 14 deletions

1
.gitattributes vendored
View File

@ -10170,6 +10170,7 @@ tests/test/tcpstr15.pp svneol=native#text/pascal
tests/test/tcpstr16.pp svneol=native#text/pascal
tests/test/tcpstr17.pp svneol=native#text/pascal
tests/test/tcpstr18.pp svneol=native#text/pascal
tests/test/tcpstr19.pp svneol=native#text/pascal
tests/test/tcpstr2.pp svneol=native#text/plain
tests/test/tcpstr2a.pp svneol=native#text/plain
tests/test/tcpstr3.pp svneol=native#text/plain

View File

@ -363,17 +363,19 @@ implementation
end;
end;
end
else if (tstringdef(def_from).stringtype=tstringdef(def_to).stringtype) and
else if (tstringdef(def_to).stringtype=st_ansistring) and
(tstringdef(def_from).stringtype=st_ansistring) then
begin
{ don't convert ansistrings if any conditions is true:
{ don't convert ansistrings if any condition is true:
1) same encoding
2) from explicit codepage ansistring to ansistring and vice versa
3) from any ansistring to rawbytestring }
3) from any ansistring to rawbytestring
4) from rawbytestring to any ansistring }
if (tstringdef(def_from).encoding=tstringdef(def_to).encoding) or
((tstringdef(def_to).encoding=0) and (tstringdef(def_from).encoding=getansistringcodepage)) or
((tstringdef(def_to).encoding=getansistringcodepage) and (tstringdef(def_from).encoding=0)) or
(tstringdef(def_to).encoding=globals.CP_NONE) then
(tstringdef(def_to).encoding=globals.CP_NONE) or
(tstringdef(def_from).encoding=globals.CP_NONE) then
begin
eq:=te_equal;
end

View File

@ -711,12 +711,14 @@ implementation
ppn:=tcallparanode(ppn.right);
end;
paradef:=ppn.left.resultdef;
if is_ansistring(paradef) or
(is_chararray(paradef) and
(paradef.size>255)) or
((cs_ansistrings in current_settings.localswitches) and
is_pchar(paradef)) then
copynode:=ccallnode.createintern('fpc_ansistr_copy',paras)
if is_ansistring(paradef) then
// set resultdef to argument def
copynode:=ccallnode.createinternres('fpc_ansistr_copy',paras,paradef)
else
if (is_chararray(paradef) and (paradef.size>255)) or
((cs_ansistrings in current_settings.localswitches) and is_pchar(paradef)) then
// set resultdef to ansistring type since result will be in ansistring codepage
copynode:=ccallnode.createinternres('fpc_ansistr_copy',paras,getansistringdef)
else
if is_widestring(paradef) then
copynode:=ccallnode.createintern('fpc_widestr_copy',paras)
@ -756,10 +758,10 @@ implementation
npara:=ccallparanode.create(highppn,
ccallparanode.create(lowppn,
ccallparanode.create(caddrnode.create_internal
(crttinode.create(tstoreddef(ppn.left.resultdef),initrtti,rdt_normal)),
(crttinode.create(tstoreddef(paradef),initrtti,rdt_normal)),
ccallparanode.create
(ctypeconvnode.create_internal(ppn.left,voidpointertype),nil))));
copynode:=ccallnode.createinternres('fpc_dynarray_copy',npara,ppn.left.resultdef);
copynode:=ccallnode.createinternres('fpc_dynarray_copy',npara,paradef);
ppn.left:=nil;
paras.free;

View File

@ -645,8 +645,8 @@ implementation
end;
_CONSTRUCTOR :
begin
if not is_classdef then
Message(parser_e_no_constructor_in_records);
//if not is_classdef then
// Message(parser_e_no_constructor_in_records);
if not is_classdef and (current_structdef.symtable.currentvisibility <> vis_public) then
Message(parser_w_constructor_should_be_public);

28
tests/test/tcpstr19.pp Normal file
View File

@ -0,0 +1,28 @@
program tcpstr19;
// test conversions from and to rawbytestring
// test that copy function returns the same def as argument
{$APPTYPE CONSOLE}
{$ifdef fpc}
{$MODE DELPHIUNICODE}
{$endif}
uses
SysUtils;
var
S: AnsiString;
R: RawByteString;
begin
S := UTF8Encode('Test');
if StringCodePage(S) <> CP_UTF8 then
halt(1);
S := Copy('Test', 1, 2);
if StringCodePage(S) <> DefaultSystemCodePage then
halt(2);
if StringCodePage(Copy(UTF8Encode('Test'), 1, 2)) <> CP_UTF8 then
halt(3);
R := 'Test';
if StringCodePage(R) <> DefaultSystemCodePage then
halt(4);
end.