瀏覽代碼

* constant string conversion fixed, it's now equal to both
shortstring, ansistring and the typeconvnode will return
te_equal but still return convtype to change the constnode

peter 22 年之前
父節點
當前提交
90473fa87f
共有 2 個文件被更改,包括 37 次插入20 次删除
  1. 21 15
      compiler/defcmp.pas
  2. 16 5
      compiler/ncnv.pas

+ 21 - 15
compiler/defcmp.pas

@@ -34,17 +34,6 @@ interface
        symconst,symbase,symtype,symdef;
        symconst,symbase,symtype,symdef;
 
 
      type
      type
-       { The order is from low priority to high priority,
-         Note: the operators > and < are used on this list }
-       tequaltype = (
-         te_incompatible,
-         te_convert_operator,
-         te_convert_l2,     { compatible conversion with possible loss of data }
-         te_convert_l1,     { compatible conversion     }
-         te_equal,          { the definitions are equal }
-         te_exact
-       );
-
        { if acp is cp_all the var const or nothing are considered equal }
        { if acp is cp_all the var const or nothing are considered equal }
        compare_type = ( cp_none, cp_value_equal_const, cp_all,cp_procvar);
        compare_type = ( cp_none, cp_value_equal_const, cp_all,cp_procvar);
 
 
@@ -286,10 +275,15 @@ implementation
                            doconv:=tc_string_2_string;
                            doconv:=tc_string_2_string;
                            { Don't prefer conversions from widestring to a
                            { Don't prefer conversions from widestring to a
                              normal string as we can loose information }
                              normal string as we can loose information }
-                           if is_widestring(def_from) then
-                            eq:=te_convert_l1
+                           if tstringdef(def_from).string_typ=st_widestring then
+                             eq:=te_convert_l1
                            else
                            else
-                            eq:=te_convert_l2;
+                             begin
+                               if tstringdef(def_to).string_typ=st_widestring then
+                                 eq:=te_convert_l1
+                               else
+                                 eq:=te_equal; { we can change the stringconst node }
+                             end;
                          end;
                          end;
                       end
                       end
                      else
                      else
@@ -958,6 +952,7 @@ implementation
 
 
            formaldef :
            formaldef :
              begin
              begin
+               doconv:=tc_equal;
                if (def_from.deftype=formaldef) then
                if (def_from.deftype=formaldef) then
                  eq:=te_equal
                  eq:=te_equal
                else
                else
@@ -978,6 +973,12 @@ implementation
             if assigned(operatorpd) then
             if assigned(operatorpd) then
              eq:=te_convert_operator;
              eq:=te_convert_operator;
           end;
           end;
+
+        { update convtype for te_equal when it is not yet set }
+        if (eq=te_equal) and
+           (doconv=tc_not_possible) then
+          doconv:=tc_equal;
+
         compare_defs_ext:=eq;
         compare_defs_ext:=eq;
       end;
       end;
 
 
@@ -1187,7 +1188,12 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.16  2003-01-05 22:42:13  peter
+  Revision 1.17  2003-01-09 21:43:39  peter
+    * constant string conversion fixed, it's now equal to both
+      shortstring, ansistring and the typeconvnode will return
+      te_equal but still return convtype to change the constnode
+
+  Revision 1.16  2003/01/05 22:42:13  peter
     * use int_to_int conversion for pointer/procvar/classref to int
     * use int_to_int conversion for pointer/procvar/classref to int
 
 
   Revision 1.15  2003/01/05 15:54:15  florian
   Revision 1.15  2003/01/05 15:54:15  florian

+ 16 - 5
compiler/ncnv.pas

@@ -1054,10 +1054,16 @@ implementation
                 end
                 end
               else
               else
                begin
                begin
-                 left.resulttype:=resulttype;
-                 result:=left;
-                 left:=nil;
-                 exit;
+                 { Only leave when there is no conversion to do.
+                   We can still need to call a conversion routine,
+                   like the routine to convert a stringconstnode }
+                 if convtype in [tc_equal,tc_not_possible] then
+                  begin
+                    left.resulttype:=resulttype;
+                    result:=left;
+                    left:=nil;
+                    exit;
+                  end;
                end;
                end;
             end;
             end;
 
 
@@ -2018,7 +2024,12 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.98  2003-01-05 22:41:40  peter
+  Revision 1.99  2003-01-09 21:43:39  peter
+    * constant string conversion fixed, it's now equal to both
+      shortstring, ansistring and the typeconvnode will return
+      te_equal but still return convtype to change the constnode
+
+  Revision 1.98  2003/01/05 22:41:40  peter
     * move code that checks for longint-pointer conversion hint
     * move code that checks for longint-pointer conversion hint
 
 
   Revision 1.97  2003/01/03 12:15:56  daniel
   Revision 1.97  2003/01/03 12:15:56  daniel