Ver Fonte

* Fix tbs/tb0540.

git-svn-id: trunk@7926 -
daniel há 18 anos atrás
pai
commit
4ed25e3a78
1 ficheiros alterados com 23 adições e 10 exclusões
  1. 23 10
      compiler/nmem.pas

+ 23 - 10
compiler/nmem.pas

@@ -128,7 +128,7 @@ interface
 implementation
 
     uses
-      globtype,systems,
+      globtype,systems,constexp,
       cutils,verbose,globals,
       symconst,symbase,defutil,defcmp,
       nbas,nutils,
@@ -719,15 +719,28 @@ implementation
          { maybe type conversion for the index value, but
            do not convert enums,booleans,char
            and do not convert range nodes }
-         if (right.nodetype<>rangen) and (
-             ((right.resultdef.typ<>enumdef) and
-               not(is_char(right.resultdef) or is_widechar(right.resultdef)) and
-               not(is_boolean(right.resultdef))
-             ) or
-             (left.resultdef.typ <> arraydef)
-            ) then
-           begin
-             inserttypeconv(right,sinttype);
+         if ((right.nodetype<>rangen) and is_integer(right.resultdef)) or (left.resultdef.typ<>arraydef) then
+           case left.resultdef.typ of
+             arraydef:
+               if ado_IsDynamicArray in Tarraydef(left.resultdef).arrayoptions then 
+                 {Convert indexes into dynamic arrays to aword.}
+                 inserttypeconv(right,uinttype)
+               else
+                 {Convert array indexes to low_bound..high_bound.}
+                 inserttypeconv(right,Torddef.create(Torddef(sinttype).ordtype,
+                                                     int64(Tarraydef(left.resultdef).lowrange),
+                                                     int64(Tarraydef(left.resultdef).highrange)
+                                                    ));
+             stringdef:
+               if Tstringdef(left.resultdef).stringtype=st_shortstring then
+                 {Convert shortstring indexes to 0..length.}
+                 inserttypeconv(right,Torddef.create(u8bit,0,int64(Tstringdef(left.resultdef).len)))
+               else
+                 {Convert indexes into dynamically allocated strings to aword.}
+                 inserttypeconv(right,uinttype);
+             else
+               {Others, i.e. pointer indexes to aint.}
+               inserttypeconv(right,sinttype);
            end;
 
          case left.resultdef.typ of