Quellcode durchsuchen

* handle widechar constants directly in the scanner, instead of in the
overload selection (where you can't even know whether the string is
a valid widechar constant) (mantis #33875)

git-svn-id: trunk@40009 -

Jonas Maebe vor 6 Jahren
Ursprung
Commit
2c7c0d1144
5 geänderte Dateien mit 27 neuen und 10 gelöschten Zeilen
  1. 1 0
      .gitattributes
  2. 2 3
      compiler/defcmp.pas
  3. 0 6
      compiler/ncnv.pas
  4. 4 1
      compiler/pexpr.pas
  5. 20 0
      tests/webtbs/tw33875.pp

+ 1 - 0
.gitattributes

@@ -16387,6 +16387,7 @@ tests/webtbs/tw33818.pp svneol=native#text/pascal
 tests/webtbs/tw33839a.pp -text svneol=native#text/pascal
 tests/webtbs/tw33839b.pp -text svneol=native#text/pascal
 tests/webtbs/tw33840.pp -text svneol=native#text/pascal
+tests/webtbs/tw33875.pp svneol=native#text/plain
 tests/webtbs/tw33898.pp -text svneol=native#text/pascal
 tests/webtbs/tw3402.pp svneol=native#text/plain
 tests/webtbs/tw34021.pp -text svneol=native#text/pascal

+ 2 - 3
compiler/defcmp.pas

@@ -492,9 +492,8 @@ implementation
                    end;
                  arraydef :
                    begin
-                     if (((m_mac in current_settings.modeswitches) and
-                          is_integer(def_to)) or
-                         is_widechar(def_to)) and
+                     if (m_mac in current_settings.modeswitches) and
+                        is_integer(def_to) and
                         (fromtreetype=stringconstn) then
                        begin
                          eq:=te_convert_l3;

+ 0 - 6
compiler/ncnv.pas

@@ -1635,12 +1635,6 @@ implementation
              fcc:=(pb[0] shl 24) or (pb[1] shl 16) or (pb[2] shl 8) or pb[3];
              result:=cordconstnode.create(fcc,u32inttype,false);
            end
-         else if is_widechar(resultdef) and
-            (tstringconstnode(left).cst_type=cst_unicodestring) and
-            (pcompilerwidestring(tstringconstnode(left).value_str)^.len=1) then
-           begin
-             result:=cordconstnode.create(pcompilerwidestring(tstringconstnode(left).value_str)^.data[0], resultdef, false);
-           end
          else
            CGMessage2(type_e_illegal_type_conversion,left.resultdef.typename,resultdef.typename);
       end;

+ 4 - 1
compiler/pexpr.pas

@@ -3800,7 +3800,10 @@ implementation
 
              _CWSTRING:
                begin
-                 p1:=cstringconstnode.createunistr(patternw);
+                 if getlengthwidestring(patternw)=1 then
+                   p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true)
+                 else
+                   p1:=cstringconstnode.createunistr(patternw);
                  consume(_CWSTRING);
                  if token in postfixoperator_tokens then
                    begin

+ 20 - 0
tests/webtbs/tw33875.pp

@@ -0,0 +1,20 @@
+{$MODE DELPHI}
+
+program CharOverload;
+
+uses
+  SysUtils;
+
+procedure Foo(const aArg: UnicodeString); overload;
+begin
+  WriteLn('WideString: ', aArg);
+end;
+
+procedure Foo(c: WideChar); overload;
+begin
+  WriteLn('Char: ', c);
+end;
+
+begin
+  Foo('abc');
+end.