浏览代码

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

git-svn-id: branches/jvmbackend@18653 -
Jonas Maebe 14 年之前
父节点
当前提交
40fdc62e74
共有 2 个文件被更改,包括 26 次插入3 次删除
  1. 7 1
      compiler/defcmp.pas
  2. 19 2
      compiler/jvm/njvmcnv.pas

+ 7 - 1
compiler/defcmp.pas

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

+ 19 - 2
compiler/jvm/njvmcnv.pas

@@ -32,6 +32,7 @@ interface
        tjvmtypeconvnode = class(tcgtypeconvnode)
        tjvmtypeconvnode = class(tcgtypeconvnode)
           function typecheck_dynarray_to_openarray: tnode; override;
           function typecheck_dynarray_to_openarray: tnode; override;
           function typecheck_string_to_chararray: tnode; override;
           function typecheck_string_to_chararray: tnode; override;
+          function typecheck_char_to_string: tnode; override;
           function pass_1: tnode; override;
           function pass_1: tnode; override;
           function simplify(forinline: boolean): tnode; override;
           function simplify(forinline: boolean): tnode; override;
 
 
@@ -169,6 +170,21 @@ implementation
      end;
      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
                              FirstTypeConv
 *****************************************************************************}
 *****************************************************************************}
@@ -205,8 +221,9 @@ implementation
           exit;
           exit;
         { string constants passed to java.lang.String must be converted to
         { string constants passed to java.lang.String must be converted to
           widestring }
           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
            (maybe_find_real_class_definition(resultdef,false)=java_jlstring) then
           inserttypeconv(left,cunicodestringtype);
           inserttypeconv(left,cunicodestringtype);
       end;
       end;