Browse Source

* widechararray patch from Peter

florian 20 years ago
parent
commit
7aa53f09cc
3 changed files with 50 additions and 18 deletions
  1. 22 8
      compiler/defcmp.pas
  2. 22 9
      compiler/ncnv.pas
  3. 6 1
      compiler/pdecvar.pas

+ 22 - 8
compiler/defcmp.pas

@@ -268,7 +268,7 @@ implementation
                end;
              end;
 
-          stringdef :
+           stringdef :
              begin
                case def_from.deftype of
                  stringdef :
@@ -323,7 +323,7 @@ implementation
                    end;
                  arraydef :
                    begin
-                   { array of char to string, the length check is done by the firstpass of this node }
+                     { array of char to string, the length check is done by the firstpass of this node }
                      if is_chararray(def_from) or
                         (is_char(tarraydef(def_from).elementtype.def) and
                          is_open_array(def_from)) then
@@ -337,7 +337,19 @@ implementation
                          eq:=te_convert_l1
                         else
                          eq:=te_convert_l2;
-                      end;
+                      end
+                     else
+                     { array of widechar to string, the length check is done by the firstpass of this node }
+                      if is_widechararray(def_from) or
+                         (is_widechar(tarraydef(def_from).elementtype.def) and
+                          is_open_array(def_from)) then
+                       begin
+                         doconv:=tc_chararray_2_string;
+                         if is_widestring(def_to) then
+                          eq:=te_convert_l1
+                         else
+                          eq:=te_convert_l3;
+                       end;
                    end;
                  pointerdef :
                    begin
@@ -361,8 +373,6 @@ implementation
                           else if is_pwidechar(def_from) then
                            begin
                              doconv:=tc_pwchar_2_string;
-                             { prefer ansistrings because pchars can overflow shortstrings, }
-                             { but only if ansistrings are the default (JM)                 }
                              if is_widestring(def_to) then
                                eq:=te_convert_l1
                              else
@@ -596,7 +606,8 @@ implementation
                       begin
                         { string to char array }
                         if (not is_special_array(def_to)) and
-                           is_char(tarraydef(def_to).elementtype.def) then
+                           (is_char(tarraydef(def_to).elementtype.def)or
+                            is_widechar(tarraydef(def_to).elementtype.def)) then
                          begin
                            doconv:=tc_string_2_chararray;
                            eq:=te_convert_l1;
@@ -678,7 +689,7 @@ implementation
                             eq:=te_convert_l1;
                           end
                          else
-                          { pwidechar(ansistring) }
+                          { pwidechar(widestring) }
                           if is_pwidechar(def_to) and
                              is_widestring(def_from) then
                            begin
@@ -1323,7 +1334,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.63  2005-01-03 17:55:57  florian
+  Revision 1.64  2005-01-06 13:30:40  florian
+    * widechararray patch from Peter
+
+  Revision 1.63  2005/01/03 17:55:57  florian
     + first batch of patches to support tdef.getcopy fully
 
   Revision 1.62  2004/12/05 12:28:10  peter

+ 22 - 9
compiler/ncnv.pas

@@ -655,25 +655,31 @@ implementation
           internalerror(200104023);
       end;
 
-    function ttypeconvnode.resulttype_chararray_to_string : tnode;
 
+    function ttypeconvnode.resulttype_chararray_to_string : tnode;
+      var
+        chartype : string[8];
       begin
+        if is_widechar(tarraydef(left.resulttype).elementtype.def) then
+          chartype:='widechar'
+        else
+          chartype:='char';
         result := ccallnode.createinternres(
-          'fpc_chararray_to_'+tstringdef(resulttype.def).stringtypname,
-          ccallparanode.create(left,nil),resulttype);
+           'fpc_'+chartype+'array_to_'+tstringdef(resulttype.def).stringtypname,
+           ccallparanode.create(left,nil),resulttype);
         left := nil;
       end;
 
-    function ttypeconvnode.resulttype_string_to_chararray : tnode;
 
+    function ttypeconvnode.resulttype_string_to_chararray : tnode;
       var
-        arrsize : aint;
-
+        arrsize  : aint;
+        chartype : string[8];
       begin
          with tarraydef(resulttype.def) do
           begin
             if highrange<lowrange then
-             internalerror(75432653);
+             internalerror(200501051);
             arrsize := highrange-lowrange+1;
           end;
          if (left.nodetype = stringconstn) and
@@ -685,9 +691,13 @@ implementation
              result := nil;
              exit;
            end;
+        if is_widechar(tarraydef(resulttype).elementtype.def) then
+          chartype:='widechar'
+        else
+          chartype:='char';
         result := ccallnode.createinternres(
           'fpc_'+tstringdef(left.resulttype.def).stringtypname+
-          '_to_chararray',ccallparanode.create(left,ccallparanode.create(
+          '_to_'+chartype+'array',ccallparanode.create(left,ccallparanode.create(
           cordconstnode.create(arrsize,s32inttype,true),nil)),resulttype);
         left := nil;
       end;
@@ -2541,7 +2551,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.170  2005-01-03 17:55:57  florian
+  Revision 1.171  2005-01-06 13:30:41  florian
+    * widechararray patch from Peter
+
+  Revision 1.170  2005/01/03 17:55:57  florian
     + first batch of patches to support tdef.getcopy fully
 
   Revision 1.169  2004/12/27 16:54:29  peter

+ 6 - 1
compiler/pdecvar.pas

@@ -654,6 +654,8 @@ implementation
               symtablestack.insert(tcsym);
               insertconstdata(tcsym);
               readtypedconst(tt,tcsym,false);
+              { The variable has a value assigned }
+              vs.varstate:=vs_assigned;
             end
           else
             begin
@@ -1311,7 +1313,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.90  2005-01-04 16:52:07  peter
+  Revision 1.91  2005-01-06 13:30:41  florian
+    * widechararray patch from Peter
+
+  Revision 1.90  2005/01/04 16:52:07  peter
     * don't typecast index of indexed properties
 
   Revision 1.89  2005/01/04 16:37:38  peter