|
@@ -893,8 +893,7 @@ implementation
|
|
|
begin
|
|
|
result:=nil;
|
|
|
if (left.nodetype=stringconstn) and
|
|
|
- ((not is_widechararray(left.resultdef) and
|
|
|
- not is_widestring(left.resultdef)) or
|
|
|
+ ((tstringdef(left.resultdef).stringtype<>st_widestring) or
|
|
|
(tstringdef(resultdef).stringtype=st_widestring) or
|
|
|
{ non-ascii chars would be replaced with '?' -> loses info }
|
|
|
not hasnonasciichars(pcompilerwidestring(tstringconstnode(left).value_str))) then
|
|
@@ -902,7 +901,7 @@ implementation
|
|
|
tstringconstnode(left).changestringtype(resultdef);
|
|
|
result:=left;
|
|
|
left:=nil;
|
|
|
- end
|
|
|
+ end
|
|
|
else
|
|
|
begin
|
|
|
{ get the correct procedure name }
|
|
@@ -935,7 +934,13 @@ implementation
|
|
|
|
|
|
begin
|
|
|
result:=nil;
|
|
|
- if left.nodetype=ordconstn then
|
|
|
+ { we can't do widechar to ansichar conversions at compile time, since }
|
|
|
+ { this maps all non-ascii chars to '?' -> loses information }
|
|
|
+ if (left.nodetype=ordconstn) and
|
|
|
+ ((tstringdef(resultdef).stringtype=st_widestring) or
|
|
|
+ (torddef(left.resultdef).ordtype=uchar) or
|
|
|
+ { >=128 is destroyed }
|
|
|
+ (tordconstnode(left).value<128)) then
|
|
|
begin
|
|
|
if tstringdef(resultdef).stringtype=st_widestring then
|
|
|
begin
|
|
@@ -949,22 +954,30 @@ implementation
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
- hp:=cstringconstnode.createstr(chr(tordconstnode(left).value));
|
|
|
+ if torddef(left.resultdef).ordtype=uwidechar then
|
|
|
+ hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value)))
|
|
|
+ else
|
|
|
+ hp:=cstringconstnode.createstr(chr(tordconstnode(left).value));
|
|
|
tstringconstnode(hp).changestringtype(resultdef);
|
|
|
end;
|
|
|
result:=hp;
|
|
|
end
|
|
|
else
|
|
|
- { shortstrings are handled 'inline' }
|
|
|
- if tstringdef(resultdef).stringtype <> st_shortstring then
|
|
|
+ { shortstrings are handled 'inline' (except for widechars) }
|
|
|
+ if (tstringdef(resultdef).stringtype <> st_shortstring) or
|
|
|
+ (torddef(left.resultdef).ordtype = uwidechar) then
|
|
|
begin
|
|
|
- { create the parameter }
|
|
|
+ { create the procname }
|
|
|
+ if torddef(left.resultdef).ordtype<>uwidechar then
|
|
|
+ procname := 'fpc_char_to_'
|
|
|
+ else
|
|
|
+ procname := 'fpc_wchar_to_';
|
|
|
+ procname:=procname+tstringdef(resultdef).stringtypname;
|
|
|
+
|
|
|
+ { and the parameter }
|
|
|
para := ccallparanode.create(left,nil);
|
|
|
left := nil;
|
|
|
|
|
|
- { and the procname }
|
|
|
- procname := 'fpc_char_to_' +tstringdef(resultdef).stringtypname;
|
|
|
-
|
|
|
{ and finally the call }
|
|
|
result := ccallnode.createinternres(procname,para,resultdef);
|
|
|
end
|
|
@@ -1009,7 +1022,11 @@ implementation
|
|
|
|
|
|
begin
|
|
|
result:=nil;
|
|
|
- if left.nodetype=ordconstn then
|
|
|
+ if (left.nodetype=ordconstn) and
|
|
|
+ ((torddef(resultdef).ordtype<>uchar) or
|
|
|
+ (torddef(left.resultdef).ordtype<>uwidechar) or
|
|
|
+ { >= 128 is replaced by '?' currently -> loses information }
|
|
|
+ (tordconstnode(left).value<128)) then
|
|
|
begin
|
|
|
if (torddef(resultdef).ordtype=uchar) and
|
|
|
(torddef(left.resultdef).ordtype=uwidechar) then
|
|
@@ -2291,9 +2308,21 @@ implementation
|
|
|
|
|
|
|
|
|
function ttypeconvnode.first_char_to_char : tnode;
|
|
|
+ var
|
|
|
+ fname: string[18];
|
|
|
+ begin
|
|
|
+ if (torddef(resultdef).ordtype=uchar) and
|
|
|
+ (torddef(left.resultdef).ordtype=uwidechar) then
|
|
|
+ fname := 'fpc_wchar_to_char'
|
|
|
+ else if (torddef(resultdef).ordtype=uwidechar) and
|
|
|
+ (torddef(left.resultdef).ordtype=uchar) then
|
|
|
+ fname := 'fpc_char_to_wchar'
|
|
|
+ else
|
|
|
+ internalerror(2007081201);
|
|
|
|
|
|
- begin
|
|
|
- first_char_to_char:=first_int_to_int;
|
|
|
+ result := ccallnode.createintern(fname,ccallparanode.create(left,nil));
|
|
|
+ left:=nil;
|
|
|
+ firstpass(result);
|
|
|
end;
|
|
|
|
|
|
|