Quellcode durchsuchen

* support for widestrings in tconstsym
* fix widestring writing for stringconstn

git-svn-id: trunk@646 -

peter vor 20 Jahren
Ursprung
Commit
9cda65c4b0
7 geänderte Dateien mit 94 neuen und 11 gelöschten Zeilen
  1. 1 0
      .gitattributes
  2. 19 4
      compiler/ncon.pas
  3. 15 5
      compiler/pdecl.pas
  4. 4 0
      compiler/pexpr.pas
  5. 1 1
      compiler/ppu.pas
  6. 29 1
      compiler/symsym.pas
  7. 25 0
      tests/webtbs/tw4199.pp

+ 1 - 0
.gitattributes

@@ -6144,6 +6144,7 @@ tests/webtbs/tw4152.pp svneol=native#text/plain
 tests/webtbs/tw4155.pp svneol=native#text/plain
 tests/webtbs/tw4162.pp svneol=native#text/plain
 tests/webtbs/tw4188.pp svneol=native#text/plain
+tests/webtbs/tw4199.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 19 - 4
compiler/ncon.pas

@@ -611,13 +611,25 @@ implementation
 
 
     constructor tstringconstnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
+      var
+        pw : pcompilerwidestring;
       begin
         inherited ppuload(t,ppufile);
         st_type:=tstringtype(ppufile.getbyte);
         len:=ppufile.getlongint;
-        getmem(value_str,len+1);
-        ppufile.getdata(value_str^,len);
-        value_str[len]:=#0;
+        if st_type=st_widestring then
+          begin
+            initwidestring(pw);
+            setlengthwidestring(pw,len);
+            ppufile.getdata(pw^.data,pw^.len*sizeof(tcompilerwidechar));
+            pcompilerwidestring(value_str):=pw
+          end
+        else
+          begin
+            getmem(value_str,len+1);
+            ppufile.getdata(value_str^,len);
+            value_str[len]:=#0;
+          end;
         lab_str:=tasmlabel(ppufile.getasmsymbol);
       end;
 
@@ -627,7 +639,10 @@ implementation
         inherited ppuwrite(ppufile);
         ppufile.putbyte(byte(st_type));
         ppufile.putlongint(len);
-        ppufile.putdata(value_str^,len);
+        if st_type=st_widestring then
+          ppufile.putdata(pcompilerwidestring(value_str)^.data,len*sizeof(tcompilerwidechar))
+        else
+          ppufile.putdata(value_str^,len);
         ppufile.putasmsymbol(lab_str);
       end;
 

+ 15 - 5
compiler/pdecl.pas

@@ -49,12 +49,12 @@ implementation
        { common }
        cutils,cclasses,
        { global }
-       globtype,tokens,verbose,
+       globtype,tokens,verbose,widestr,
        systems,
        { aasm }
        aasmbase,aasmtai,fmodule,
        { symtable }
-       symconst,symbase,symtype,symdef,symtable,paramgr,
+       symconst,symbase,symtype,symdef,symtable,paramgr,defutil,
        { pass 1 }
        nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,nobj,
        { codegen }
@@ -75,6 +75,7 @@ implementation
         pd : pbestreal;
         pg : pguid;
         sp : pchar;
+        pw : pcompilerwidestring;
         storetokenpos : tfileposinfo;
       begin
         readconstant:=nil;
@@ -94,9 +95,18 @@ implementation
              end;
            stringconstn:
              begin
-                getmem(sp,tstringconstnode(p).len+1);
-                move(tstringconstnode(p).value_str^,sp^,tstringconstnode(p).len+1);
-                hp:=tconstsym.create_string(orgname,conststring,sp,tstringconstnode(p).len);
+               if is_widestring(p.resulttype.def) then
+                 begin
+                   initwidestring(pw);
+                   copywidestring(pcompilerwidestring(tstringconstnode(p).value_str),pw);
+                   hp:=tconstsym.create_wstring(orgname,constwstring,pw);
+                 end
+               else
+                 begin
+                   getmem(sp,tstringconstnode(p).len+1);
+                   move(tstringconstnode(p).value_str^,sp^,tstringconstnode(p).len+1);
+                   hp:=tconstsym.create_string(orgname,conststring,sp,tstringconstnode(p).len);
+                 end;
              end;
            realconstn :
              begin

+ 4 - 0
compiler/pexpr.pas

@@ -1389,6 +1389,8 @@ implementation
                           pc[len]:=#0;
                           p1:=cstringconstnode.createpchar(pc,len);
                         end;
+                      constwstring :
+                        p1:=cstringconstnode.createwstr(pcompilerwidestring(tconstsym(srsym).value.valueptr));
                       constreal :
                         p1:=crealconstnode.create(pbestreal(tconstsym(srsym).value.valueptr)^,pbestrealtype^);
                       constset :
@@ -1416,6 +1418,8 @@ implementation
                         end;
                       constguid :
                         p1:=cguidconstnode.create(pguid(tconstsym(srsym).value.valueptr)^);
+                      else
+                        internalerror(200507181);
                     end;
                   end;
 

+ 1 - 1
compiler/ppu.pas

@@ -43,7 +43,7 @@ type
 {$endif Test_Double_checksum}
 
 const
-  CurrentPPUVersion=49;
+  CurrentPPUVersion=50;
 
 { buffer sizes }
   maxentrysize = 1024;

+ 29 - 1
compiler/symsym.pas

@@ -28,7 +28,7 @@ interface
        { common }
        cutils,
        { target }
-       globtype,globals,
+       globtype,globals,widestr,
        { symtable }
        symconst,symbase,symtype,symdef,defcmp,
        { ppu }
@@ -317,6 +317,7 @@ interface
           constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
           constructor create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
           constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
+          constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
           constructor ppuload(ppufile:tcompilerppufile);
           destructor  destroy;override;
           procedure buildderef;override;
@@ -2164,11 +2165,24 @@ implementation
       end;
 
 
+    constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
+      begin
+         inherited create(n);
+         fillchar(value, sizeof(value), #0);
+         typ:=constsym;
+         consttyp:=t;
+         pcompilerwidestring(value.valueptr):=pw;
+         consttype.reset;
+         value.len:=getlengthwidestring(pw);
+      end;
+
+
     constructor tconstsym.ppuload(ppufile:tcompilerppufile);
       var
          pd : pbestreal;
          ps : pnormalset;
          pc : pchar;
+         pw : pcompilerwidestring;
       begin
          inherited ppuload(ppufile);
          typ:=constsym;
@@ -2186,6 +2200,13 @@ implementation
                ppufile.gettype(consttype);
                value.valueordptr:=ppufile.getptruint;
              end;
+           constwstring :
+             begin
+               initwidestring(pw);
+               setlengthwidestring(pw,ppufile.getlongint);
+               ppufile.getdata(pw^.data,pw^.len*sizeof(tcompilerwidechar));
+               pcompilerwidestring(value.valueptr):=pw;
+             end;
            conststring,
            constresourcestring :
              begin
@@ -2227,6 +2248,8 @@ implementation
           conststring,
           constresourcestring :
             freemem(pchar(value.valueptr),value.len+1);
+          constwstring :
+            donewidestring(pcompilerwidestring(value.valueptr));
           constreal :
             dispose(pbestreal(value.valueptr));
           constset :
@@ -2268,6 +2291,11 @@ implementation
                ppufile.puttype(consttype);
                ppufile.putptruint(value.valueordptr);
              end;
+           constwstring :
+             begin
+               ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
+               ppufile.putdata(pcompilerwidestring(value.valueptr)^.data,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
+             end;
            conststring,
            constresourcestring :
              begin

+ 25 - 0
tests/webtbs/tw4199.pp

@@ -0,0 +1,25 @@
+{$ifdef fpc}
+{$mode objfpc}{$H+}
+{$endif}
+uses
+  Classes, SysUtils;
+const
+ stringconst = 'abc';
+ widestringconst = widestring('abc');
+var
+ str1,str2 : widestring;
+begin
+ writeln('1 ',stringconst);             //ok
+ writeln('2 ',widestring(stringconst)); //ok
+ writeln('3 ',widestringconst);         //bad
+ str1:= widestringconst;
+ writeln('4 ',str1);                    //bad
+ str2:= copy(widestringconst,1,3);
+ writeln('5 ',str2);                    //bad
+ if widestringconst<>stringconst then
+   halt(1);
+ if str1<>stringconst then
+   halt(2);
+ if str2<>stringconst then
+   halt(3);
+end.