Ver código fonte

* better ansi string assignement

florian 27 anos atrás
pai
commit
814ae50075
3 arquivos alterados com 42 adições e 32 exclusões
  1. 28 23
      compiler/cg386con.pas
  2. 6 5
      compiler/pass_1.pas
  3. 8 4
      compiler/tree.pas

+ 28 - 23
compiler/cg386con.pas

@@ -202,28 +202,30 @@ implementation
 {$else UseAnsiString}
 
                    { generate an ansi string ? }
-                   if is_ansistring(p^.resulttype) then
-                     begin
-                        concat_constlabel(lastlabel,conststring);
-                        consts^.concat(new(pai_const,init_32bit(p^.length)));
-                        consts^.concat(new(pai_const,init_32bit(p^.length)));
-                        consts^.concat(new(pai_const,init_32bit(-1)));
-                        getmem(pc,p^.length+1);
-                        move(p^.values^,pc^,p^.length+1);
-                        { to overcome this problem we set the length explicitly }
-                        { with the ending null char }
-                        consts^.concat(new(pai_string,init_length_pchar(pc,p^.length+1)));
-                     end
-                   else
-                     begin
-                        getmem(pc,p^.length+3);
-                        move(p^.values^,pc[1],p^.length+1);
-                        pc[0]:=chr(p^.length);
-                        concat_constlabel(lastlabel,conststring);
-                        { to overcome this problem we set the length explicitly }
-                        { with the ending null char }
-                        consts^.concat(new(pai_string,init_length_pchar(pc,p^.length+2)));
-                     end;
+                   case p^.stringtype of
+                      st_ansistring:
+                        begin
+                           concat_constlabel(lastlabel,conststring);
+                           consts^.concat(new(pai_const,init_32bit(p^.length)));
+                           consts^.concat(new(pai_const,init_32bit(p^.length)));
+                           consts^.concat(new(pai_const,init_32bit(-1)));
+                           getmem(pc,p^.length+1);
+                           move(p^.values^,pc^,p^.length+1);
+                           { to overcome this problem we set the length explicitly }
+                           { with the ending null char }
+                           consts^.concat(new(pai_string,init_length_pchar(pc,p^.length+1)));
+                        end;
+                      st_shortstring:
+                        begin
+                           getmem(pc,p^.length+3);
+                           move(p^.values^,pc[1],p^.length+1);
+                           pc[0]:=chr(p^.length);
+                           concat_constlabel(lastlabel,conststring);
+                           { to overcome this problem we set the length explicitly }
+                           { with the ending null char }
+                           consts^.concat(new(pai_string,init_length_pchar(pc,p^.length+2)));
+                        end;
+                   end;
 {$endif UseAnsiString}
                 end;
            end;
@@ -344,7 +346,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.7  1998-07-18 22:54:25  florian
+  Revision 1.8  1998-07-20 10:23:00  florian
+    * better ansi string assignement
+
+  Revision 1.7  1998/07/18 22:54:25  florian
     * some ansi/wide/longstring support fixed:
        o parameter passing
        o returning as result from functions

+ 6 - 5
compiler/pass_1.pas

@@ -1826,7 +1826,7 @@ unit pass_1;
 
          { some string functions don't need conversion, so treat them separatly }
 
-         if (p^.left^.resulttype^.deftype=stringdef) and (assigned(p^.right^.resulttype)) then
+         if is_shortstring(p^.left^.resulttype) and (assigned(p^.right^.resulttype)) then
           begin
             if not ((p^.right^.resulttype^.deftype=stringdef) or
                     ((p^.right^.resulttype^.deftype=orddef) and (porddef(p^.right^.resulttype)^.typ=uchar))) then
@@ -2066,10 +2066,8 @@ unit pass_1;
          if pstringdef(p^.resulttype)^.string_typ<>
             pstringdef(p^.left^.resulttype)^.string_typ then
            begin
-              { trick: secondstringconstn generates a const entry depending on }
-              { the result type                                                }
               if p^.left^.treetype=stringconstn then
-                p^.left^.resulttype:=p^.resulttype
+                p^.left^.stringtype:=pstringdef(p^.resulttype)^.string_typ
               else
                 procinfo.flags:=procinfo.flags or pi_do_call;
            end;
@@ -5046,7 +5044,10 @@ unit pass_1;
 end.
 {
   $Log$
-  Revision 1.41  1998-07-18 22:54:27  florian
+  Revision 1.42  1998-07-20 10:23:01  florian
+    * better ansi string assignement
+
+  Revision 1.41  1998/07/18 22:54:27  florian
     * some ansi/wide/longstring support fixed:
        o parameter passing
        o returning as result from functions

+ 8 - 4
compiler/tree.pas

@@ -198,7 +198,7 @@ unit tree;
         firstpasscount : longint;
 {$endif extdebug}
           case treetype : ttreetyp of
-             addn : (use_strconcat : boolean;string_typ : stringtype);
+             addn : (use_strconcat : boolean;string_typ : tstringtype);
              callparan : (is_colon_para : boolean;exact_match_found : boolean);
              assignn : (assigntyp : tassigntyp;concat_string : boolean);
              loadn : (symtableentry : psym;symtable : psymtable;
@@ -218,9 +218,9 @@ unit tree;
              { stringconstn : (length : longint; values : pstring;labstrnumber : longint); }
              { string const can be longer then 255 with ansistring !! }
 {$ifdef UseAnsiString}
-             stringconstn : (values : pchar;length : longint; labstrnumber : longint);
+             stringconstn : (values : pchar;length : longint; labstrnumber : longint;stringtype : tstringtype);
 {$else UseAnsiString}
-             stringconstn : (values : pstring; labstrnumber : longint);
+             stringconstn : (values : pstring; labstrnumber : longint;stringtype : tstringtype);
 {$endif UseAnsiString}
              typeconvn : (convtyp : tconverttype;explizit : boolean);
              inlinen : (inlinenumber : longint);
@@ -823,6 +823,7 @@ unit tree;
          p^.values:=stringdup(s);
 {$endif UseAnsiString}
          p^.labstrnumber:=-1;
+         p^.stringtype:=st_shortstring;
          genstringconstnode:=p;
       end;
 
@@ -1595,7 +1596,10 @@ unit tree;
 end.
 {
   $Log$
-  Revision 1.21  1998-07-14 21:46:56  peter
+  Revision 1.22  1998-07-20 10:23:05  florian
+    * better ansi string assignement
+
+  Revision 1.21  1998/07/14 21:46:56  peter
     * updated messages file
 
   Revision 1.20  1998/07/14 14:47:11  peter