+ support for automatically converting char/widechar to java.lang.String

git-svn-id: branches/jvmbackend@18653 -
This commit is contained in:
Jonas Maebe 2011-08-20 08:21:34 +00:00
parent 4af73c0c51
commit 40fdc62e74
2 changed files with 26 additions and 3 deletions

View File

@ -1289,7 +1289,7 @@ implementation
here }
eq:=te_convert_l3;
end
{ java.lang.string -> unicodestring }
{ unicodestring -> java.lang.string }
else if (def_to=java_jlstring) and
(is_wide_or_unicode_string(def_from) or
(fromtreetype=stringconstn)) then
@ -1300,6 +1300,12 @@ implementation
else
eq:=te_convert_l2;
end
else if (def_to=java_jlstring) and
is_anychar(def_from) then
begin
doconv:=tc_char_2_string;
eq:=te_convert_l2
end
else
{ specific to implicit pointer object types }
if is_implicit_pointer_object_type(def_to) then

View File

@ -32,6 +32,7 @@ interface
tjvmtypeconvnode = class(tcgtypeconvnode)
function typecheck_dynarray_to_openarray: tnode; override;
function typecheck_string_to_chararray: tnode; override;
function typecheck_char_to_string: tnode; override;
function pass_1: tnode; override;
function simplify(forinline: boolean): tnode; override;
@ -169,6 +170,21 @@ implementation
end;
function tjvmtypeconvnode.typecheck_char_to_string: tnode;
begin
{ make sure the generic code gets a stringdef }
if self.totypedef=java_jlstring then
begin
inserttypeconv(left,cunicodestringtype);
inserttypeconv(left,totypedef);
result:=left;
left:=nil;
exit;
end;
result:=inherited;
end;
{*****************************************************************************
FirstTypeConv
*****************************************************************************}
@ -205,8 +221,9 @@ implementation
exit;
{ string constants passed to java.lang.String must be converted to
widestring }
if (left.nodetype=stringconstn) and
not(tstringconstnode(left).cst_type in [cst_unicodestring,cst_widestring]) and
if ((is_conststringnode(left) and
not(tstringconstnode(left).cst_type in [cst_unicodestring,cst_widestring])) or
is_constcharnode(left)) and
(maybe_find_real_class_definition(resultdef,false)=java_jlstring) then
inserttypeconv(left,cunicodestringtype);
end;