Browse Source

* ansistring -> pchar fixed
* ansistring constants fixed
* ansistring constants are now written once

peter 27 years ago
parent
commit
df89c828e5
3 changed files with 86 additions and 15 deletions
  1. 20 6
      compiler/cg386cal.pas
  2. 51 5
      compiler/cg386cnv.pas
  3. 15 4
      compiler/cg386con.pas

+ 20 - 6
compiler/cg386cal.pas

@@ -55,6 +55,19 @@ implementation
     procedure secondcallparan(var p : ptree;defcoll : pdefcoll;
                 push_from_left_to_right,inlined : boolean;para_offset : longint);
 
+      function push_addr(p:ptree):boolean;
+        begin
+          push_addr:=(
+{$ifndef VALUEPARA}
+                      dont_copy_const_param(p^.resulttype) or
+{$else}
+                      push_addr_param(p^.resulttype) or
+{$endif}
+                      ((p^.treetype=stringconstn) and is_ansistring(p^.resulttype))
+                     );
+        end;
+
+
       procedure maybe_push_open_array_high;
         var
            r    : preference;
@@ -223,12 +236,8 @@ implementation
               tempdeftype:=p^.resulttype^.deftype;
               if tempdeftype=filedef then
                CGMessage(cg_e_file_must_call_by_reference);
-{$ifndef VALUEPARA}
               if (defcoll^.paratyp=vs_const) and
-                 dont_copy_const_param(p^.resulttype) then
-{$else}
-              if push_addr_param(p^.resulttype) then
-{$endif}
+                 push_addr(p^.left) then
                 begin
                    maybe_push_open_array_high;
                    inc(pushedparasize,4);
@@ -1563,7 +1572,12 @@ implementation
 end.
 {
   $Log$
-  Revision 1.45  1998-11-18 15:44:07  peter
+  Revision 1.46  1998-11-26 14:39:10  peter
+    * ansistring -> pchar fixed
+    * ansistring constants fixed
+    * ansistring constants are now written once
+
+  Revision 1.45  1998/11/18 15:44:07  peter
     * VALUEPARA for tp7 compatible value parameters
 
   Revision 1.44  1998/11/16 15:35:36  peter

+ 51 - 5
compiler/cg386cnv.pas

@@ -592,15 +592,55 @@ implementation
          clear_location(pto^.location);
          pto^.location.loc:=LOC_REGISTER;
          pto^.location.register:=getregister32;
-         inc(pfrom^.location.reference.offset);
-           exprasmlist^.concat(new(pai386,op_ref_reg(A_LEA,S_L,newreference(pfrom^.location.reference),
-             pto^.location.register)));
+         case pstringdef(pfrom^.resulttype)^.string_typ of
+           st_shortstring :
+             begin
+               inc(pfrom^.location.reference.offset);
+               exprasmlist^.concat(new(pai386,op_ref_reg(A_LEA,S_L,newreference(pfrom^.location.reference),
+                 pto^.location.register)));
+             end;
+           st_ansistring :
+             begin
+               exprasmlist^.concat(new(pai386,op_ref_reg(A_LEA,S_L,newreference(pfrom^.location.reference),
+                 pto^.location.register)));
+             end;
+           st_longstring:
+             begin
+               {!!!!!!!}
+               internalerror(8888);
+             end;
+           st_widestring:
+             begin
+               {!!!!!!!}
+               internalerror(8888);
+             end;
+         end;
       end;
 
 
     procedure second_string_to_chararray(pto,pfrom : ptree;convtyp : tconverttype);
       begin
-         inc(pto^.location.reference.offset);
+         case pstringdef(pfrom^.resulttype)^.string_typ of
+           st_shortstring :
+             begin
+               inc(pto^.location.reference.offset);
+             end;
+           st_ansistring :
+             begin
+               {!!!!!!!}
+               internalerror(8888);
+             end;
+           st_longstring:
+             begin
+               {!!!!!!!}
+               internalerror(8888);
+             end;
+           st_widestring:
+             begin
+               {!!!!!!!}
+               internalerror(8888);
+             end;
+         end;
       end;
 
 
@@ -1214,6 +1254,7 @@ implementation
          end;
       end;
 
+
     procedure second_nothing(pto,pfrom : ptree;convtyp : tconverttype);
       begin
       end;
@@ -1408,7 +1449,12 @@ implementation
 end.
 {
   $Log$
-  Revision 1.35  1998-11-26 13:10:39  peter
+  Revision 1.36  1998-11-26 14:39:11  peter
+    * ansistring -> pchar fixed
+    * ansistring constants fixed
+    * ansistring constants are now written once
+
+  Revision 1.35  1998/11/26 13:10:39  peter
     * new int - int conversion -dNEWCNV
     * some function renamings
 

+ 15 - 4
compiler/cg386con.pas

@@ -141,12 +141,16 @@ implementation
          lastlabel   : plabel;
          pc          : pchar;
          same_string : boolean;
-         i           : longint;
+         i,mylength  : longint;
       begin
          lastlabel:=nil;
          { const already used ? }
          if not assigned(p^.lab_str) then
            begin
+              if is_shortstring(p^.resulttype) then
+               mylength:=p^.length+2
+              else
+               mylength:=p^.length+1;
               { tries to found an old entry }
               hp1:=pai(consts^.first);
               while assigned(hp1) do
@@ -162,7 +166,7 @@ implementation
                         { typed consts have no leading length or   }
                         { they have no trailing zero               }
                         if (hp1^.typ=ait_string) and (lastlabel<>nil) and
-                          (pai_string(hp1)^.len=p^.length+2) then
+                           (pai_string(hp1)^.len=mylength) then
                           begin
                              same_string:=true;
                              for i:=0 to p^.length do
@@ -211,6 +215,8 @@ implementation
                                 { 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)));
+                                { return the offset of the real string }
+                                p^.lab_str:=l1;
                              end;
                         end;
                       st_shortstring:
@@ -257,7 +263,7 @@ implementation
            p^.location.loc:=LOC_MEM;
            p^.location.reference.isintvalue:=true;
            p^.location.reference.offset:=plongint(p^.value_set)^;
-	   exit;
+           exit;
          end;
 {$endif}
         if psetdef(p^.resulttype)^.settype=smallset then
@@ -356,7 +362,12 @@ implementation
 end.
 {
   $Log$
-  Revision 1.22  1998-11-24 13:40:59  peter
+  Revision 1.23  1998-11-26 14:39:12  peter
+    * ansistring -> pchar fixed
+    * ansistring constants fixed
+    * ansistring constants are now written once
+
+  Revision 1.22  1998/11/24 13:40:59  peter
     * release smallsetord, so small sets constant are handled like longints
 
   Revision 1.21  1998/11/24 12:52:41  peter