Pārlūkot izejas kodu

* Introduce constwresourcestring - in unicode mode, resource strings are unicode strings, and must be streamed differently

Michaël Van Canneyt 1 gadu atpakaļ
vecāks
revīzija
fe62b3ace8

+ 2 - 1
compiler/aasmcnst.pas

@@ -2208,12 +2208,13 @@ implementation
      var
        resourcestrrec: trecorddef;
      begin
-       if cs.consttyp<>constresourcestring then
+       if not (cs.consttyp in [constresourcestring,constwresourcestring]) then
          internalerror(2014062102);
        if fqueue_offset<>0 then
          internalerror(2014062103);
        { warning: update if/when the type of resource strings changes }
        case cs.consttyp of
+         constwresourcestring,
          constresourcestring:
            begin
              resourcestrrec:=trecorddef(search_system_type('TRESOURCESTRINGRECORD').typedef);

+ 1 - 1
compiler/cresstr.pas

@@ -338,7 +338,7 @@ uses
     procedure Tresourcestrings.ConstSym_Register(p:TObject;arg:pointer);
       begin
         if (tsym(p).typ=constsym) and
-           (tconstsym(p).consttyp=constresourcestring) then
+           (tconstsym(p).consttyp in [constresourcestring,constwresourcestring]) then
           List.Concat(TResourceStringItem.Create(TConstsym(p)));
       end;
 

+ 2 - 0
compiler/dbgdwarf.pas

@@ -2703,6 +2703,7 @@ implementation
                 usedef:=clongstringtype;
             end;
           constresourcestring,
+          constwresourcestring,
           constwstring:
             usedef:=nil;
           else
@@ -2753,6 +2754,7 @@ implementation
                 end;
             end;
           constwstring,
+          constwresourcestring,
           constresourcestring:
             begin
               { write dummy for now }

+ 1 - 1
compiler/htypechk.pas

@@ -1939,7 +1939,7 @@ implementation
                      end;
                    constsym:
                      begin
-                       if (tconstsym(tloadnode(hp).symtableentry).consttyp=constresourcestring) and
+                       if (tconstsym(tloadnode(hp).symtableentry).consttyp in [constresourcestring,constwresourcestring]) and
                          (valid_addr in opts) then
                          result:=true
                        else

+ 1 - 1
compiler/ncal.pas

@@ -5511,7 +5511,7 @@ implementation
                 if FindUnitSymtable(tloadnode(n).symtable).moduleid<>current_module.moduleid then
                   current_module.addimportedsym(sym);
               end
-            else if (sym.typ=constsym) and (tconstsym(sym).consttyp=constresourcestring) then
+            else if (sym.typ=constsym) and (tconstsym(sym).consttyp in [constwresourcestring,constresourcestring]) then
               begin
                 if tloadnode(n).symtableentry.owner.moduleid<>current_module.moduleid then
                   current_module.addimportedsym(sym);

+ 1 - 1
compiler/ncgld.pas

@@ -441,7 +441,7 @@ implementation
               end;
            constsym:
              begin
-                if tconstsym(symtableentry).consttyp=constresourcestring then
+                if tconstsym(symtableentry).consttyp in [constresourcestring,constwresourcestring] then
                   begin
                      location_reset_ref(location,LOC_CREFERENCE,def_cgsize(cansistringtype),cansistringtype.size,[]);
                      indirect:=(tf_supports_packages in target_info.flags) and

+ 1 - 1
compiler/ncon.pas

@@ -305,7 +305,7 @@ implementation
       begin
         is_constresourcestringnode:=(p.nodetype=loadn) and
           (tloadnode(p).symtableentry.typ=constsym) and
-          (tconstsym(tloadnode(p).symtableentry).consttyp=constresourcestring);
+          (tconstsym(tloadnode(p).symtableentry).consttyp in [constresourcestring,constwresourcestring]);
       end;
 
 

+ 1 - 1
compiler/ngtcon.pas

@@ -1022,7 +1022,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                     labelsym :
                       ftcb.queue_emit_label(tlabelsym(srsym));
                     constsym :
-                      if tconstsym(srsym).consttyp=constresourcestring then
+                      if tconstsym(srsym).consttyp in [constresourcestring,constwresourcestring] then
                         ftcb.queue_emit_const(tconstsym(srsym))
                       else
                         Message(type_e_constant_expr_expected);

+ 3 - 1
compiler/nld.pas

@@ -350,6 +350,8 @@ implementation
              begin
                if tconstsym(symtableentry).consttyp=constresourcestring then
                  resultdef:=getansistringdef
+               else if tconstsym(symtableentry).consttyp=constwresourcestring then
+                 resultdef:=cunicodestringtype
                else
                  internalerror(22799);
              end;
@@ -481,7 +483,7 @@ implementation
               ;
             constsym:
               begin
-                if tconstsym(symtableentry).consttyp=constresourcestring then
+                if tconstsym(symtableentry).consttyp in [constresourcestring,constwresourcestring] then
                   expectloc:=LOC_CREFERENCE;
               end;
             staticvarsym,

+ 1 - 1
compiler/pdecl.pas

@@ -1362,7 +1362,7 @@ implementation
                                  changestringtype(cunicodestringtype);
                                initwidestring(pw);
                                copywidestring(pcompilerwidestring(value_str),pw);
-                               sym:=cconstsym.create_wstring(orgname,constresourcestring,pw);
+                               sym:=cconstsym.create_wstring(orgname,constwresourcestring,pw);
                                end;
                           end;
                       else

+ 1 - 1
compiler/pexpr.pas

@@ -3121,7 +3121,7 @@ implementation
 
           constsym :
             begin
-              if tconstsym(srsym).consttyp=constresourcestring then
+              if tconstsym(srsym).consttyp in [constresourcestring,constwresourcestring]then
                 begin
                   result:=cloadnode.create(srsym,srsymtable);
                   do_typecheckpass(result);

+ 1 - 1
compiler/ppu.pas

@@ -48,7 +48,7 @@ const
   CurrentPPUVersion = 208;
   { for any other changes to the ppu format, increase this version number
     (it's a cardinal) }
-  CurrentPPULongVersion = 21;
+  CurrentPPULongVersion = 22;
 
 { unit flags }
   uf_big_endian          = $000004;

+ 4 - 2
compiler/scanner.pas

@@ -1064,7 +1064,8 @@ type
             getmem(value.valueptr,value.len+1);
             move(c.value.valueptr^,value.valueptr^,value.len+1);
           end;
-        constwstring:
+        constwstring,
+        constwresourcestring:
           begin
             initwidestring(value.valueptr);
             copywidestring(c.value.valueptr,value.valueptr);
@@ -1519,7 +1520,8 @@ type
         conststring,
         constresourcestring :
           freemem(value.valueptr,value.len+1);
-        constwstring :
+        constwstring,
+        constwresourcestring:
           donewidestring(pcompilerwidestring(value.valueptr));
         constreal :
           dispose(pbestreal(value.valueptr));

+ 2 - 1
compiler/symconst.pas

@@ -765,7 +765,8 @@ type
   tconsttyp = (constnone,
     constord,conststring,constreal,
     constset,constpointer,constnil,
-    constresourcestring,constwstring,constguid
+    constresourcestring,constwstring,
+    constguid,constwresourcestring
   );
 
   { RTTI information to store }

+ 1 - 0
compiler/symdef.pas

@@ -5892,6 +5892,7 @@ implementation
                   hpc:=tconstsym(hp.defaultconstsym);
                   hs:='';
                   case hpc.consttyp of
+                    constwresourcestring,
                     constwstring:
                       begin
                         if pcompilerwidestring(hpc.value.valueptr)^.len>0 then

+ 57 - 30
compiler/symsym.pas

@@ -573,6 +573,7 @@ implementation
           constreal,
           constset,
           constresourcestring,
+          constwresourcestring,
           constwstring,
           constguid: begin
             if value1.len<>value2.len then
@@ -2675,6 +2676,28 @@ implementation
          pc : pchar;
          pw : pcompilerwidestring;
          i  : longint;
+
+         procedure do_widestring_const;
+         var
+            i  : longint;
+         begin
+           initwidestring(pw);
+           setlengthwidestring(pw,ppufile.getlongint);
+           { don't use getdata, because the compilerwidechars may have to
+             be byteswapped
+           }
+{$if sizeof(tcompilerwidechar) = 2}
+           for i:=0 to pw^.len-1 do
+             pw^.data[i]:=ppufile.getword;
+{$elseif sizeof(tcompilerwidechar) = 4}
+           for i:=0 to pw^.len-1 do
+             pw^.data[i]:=cardinal(ppufile.getlongint);
+{$else}
+          {$error Unsupported tcompilerwidechar size}
+{$endif}
+           pcompilerwidestring(value.valueptr):=pw;
+         end;
+
       begin
          inherited ppuload(constsym,ppufile);
          constdef:=nil;
@@ -2693,31 +2716,22 @@ implementation
              end;
            constwstring :
              begin
-               initwidestring(pw);
-               setlengthwidestring(pw,ppufile.getlongint);
-               { don't use getdata, because the compilerwidechars may have to
-                 be byteswapped
-               }
-{$if sizeof(tcompilerwidechar) = 2}
-               for i:=0 to pw^.len-1 do
-                 pw^.data[i]:=ppufile.getword;
-{$elseif sizeof(tcompilerwidechar) = 4}
-               for i:=0 to pw^.len-1 do
-                 pw^.data[i]:=cardinal(ppufile.getlongint);
-{$else}
-              {$error Unsupported tcompilerwidechar size}
-{$endif}
-               pcompilerwidestring(value.valueptr):=pw;
+               do_widestring_const;
              end;
            conststring,
            constresourcestring :
+              begin
+              ppufile.getderef(constdefderef);
+              value.len:=ppufile.getlongint;
+              getmem(pc,value.len+1);
+              ppufile.getdata(pc^,value.len);
+              pc[value.len]:=#0;
+              value.valueptr:=pc;
+              end;
+           constwresourcestring :
              begin
                ppufile.getderef(constdefderef);
-               value.len:=ppufile.getlongint;
-               getmem(pc,value.len+1);
-               ppufile.getdata(pc^,value.len);
-               pc[value.len]:=#0;
-               value.valueptr:=pc;
+               do_widestring_const;
              end;
            constreal :
              begin
@@ -2759,7 +2773,8 @@ implementation
           conststring,
           constresourcestring :
             freemem(pchar(value.valueptr),value.len+1);
-          constwstring :
+          constwstring,
+          constwresourcestring:
             donewidestring(pcompilerwidestring(value.valueptr));
           constreal :
             dispose(pbestreal(value.valueptr));
@@ -2776,7 +2791,7 @@ implementation
       begin
         inherited;
         case consttyp  of
-          constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constguid:
+          constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constwresourcestring,constguid:
             constdefderef.build(constdef);
           constwstring:
             ;
@@ -2789,7 +2804,7 @@ implementation
     procedure tconstsym.deref;
       begin
         case consttyp of
-          constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constguid:
+          constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constwresourcestring,constguid:
             constdef:=tdef(constdefderef.resolve);
           constwstring:
             constdef:=carraydef.getreusable(cwidechartype,getlengthwidestring(pcompilerwidestring(value.valueptr)));
@@ -2800,6 +2815,15 @@ implementation
 
 
     procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
+
+      procedure do_widestring_const;
+
+      begin
+        ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
+        ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
+      end;
+
+
       begin
          inherited ppuwrite(ppufile);
          ppufile.putbyte(byte(consttyp));
@@ -2819,15 +2843,18 @@ implementation
            constwstring :
              begin
                { no need to store the def, we can reconstruct it }
-               ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
-               ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
+               do_widestring_const;
              end;
-           conststring,
-           constresourcestring :
+           conststring,constresourcestring:
+             begin
+             ppufile.putderef(constdefderef);
+             ppufile.putlongint(value.len);
+             ppufile.putdata(pchar(value.valueptr)^,value.len);
+             end;
+            constwresourcestring:
              begin
                ppufile.putderef(constdefderef);
-               ppufile.putlongint(value.len);
-               ppufile.putdata(pchar(value.valueptr)^,value.len);
+               do_widestring_const
              end;
            constreal :
              begin
@@ -2883,7 +2910,7 @@ implementation
 
         WriteLn(T, PrintNodeIndention, '<visibility>', visibility, '</visibility>');
 
-        if not (consttyp in [conststring, constresourcestring, constwstring]) then
+        if not (consttyp in [conststring, constresourcestring, constwresourcestring, constwstring]) then
           { constdef.size will return an internal error for string
             constants because constdef is an open array internally }
           WriteLn(T, PrintNodeIndention, '<size>', constdef.size, '</size>');