Browse Source

* fixed length(char) when char is a variable

peter 27 years ago
parent
commit
cd9ec74eb5
2 changed files with 26 additions and 11 deletions
  1. 13 2
      compiler/cg386inl.pas
  2. 13 9
      compiler/tcinl.pas

+ 13 - 2
compiler/cg386inl.pas

@@ -688,7 +688,15 @@ implementation
                  set_location(p^.location,p^.left^.location);
                  set_location(p^.location,p^.left^.location);
                  { length in ansi strings is at offset -8 }
                  { length in ansi strings is at offset -8 }
                  if is_ansistring(p^.left^.resulttype) then
                  if is_ansistring(p^.left^.resulttype) then
-                   dec(p^.location.reference.offset,8);
+                   dec(p^.location.reference.offset,8)
+                 { char is always 1, so make it a constant value }
+                 else if is_char(p^.left^.resulttype) then
+                   begin
+                     clear_location(p^.location);
+                     p^.location.loc:=LOC_MEM;
+                     p^.location.reference.isintvalue:=true;
+                     p^.location.reference.offset:=1;
+                   end;
               end;
               end;
             in_pred_x,
             in_pred_x,
             in_succ_x:
             in_succ_x:
@@ -962,7 +970,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.17  1998-11-05 12:02:33  peter
+  Revision 1.18  1998-11-24 17:04:27  peter
+    * fixed length(char) when char is a variable
+
+  Revision 1.17  1998/11/05 12:02:33  peter
     * released useansistring
     * released useansistring
     * removed -Sv, its now available in fpc modes
     * removed -Sv, its now available in fpc modes
 
 

+ 13 - 9
compiler/tcinl.pas

@@ -370,7 +370,7 @@ implementation
                     p^.resulttype:=s32bitdef
                     p^.resulttype:=s32bitdef
                   else
                   else
                     p^.resulttype:=u8bitdef;
                     p^.resulttype:=u8bitdef;
-                  { wer don't need string conversations here }
+                  { we don't need string conversations here }
                   if (p^.left^.treetype=typeconvn) and
                   if (p^.left^.treetype=typeconvn) and
                      (p^.left^.left^.resulttype^.deftype=stringdef) then
                      (p^.left^.left^.resulttype^.deftype=stringdef) then
                     begin
                     begin
@@ -379,6 +379,11 @@ implementation
                        p^.left:=hp;
                        p^.left:=hp;
                     end;
                     end;
 
 
+                  { check the type, must be string or char }
+                  if (p^.left^.resulttype^.deftype<>stringdef) and
+                     (not is_char(p^.left^.resulttype)) then
+                    CGMessage(type_e_mismatch);
+
                   { evaluates length of constant strings direct }
                   { evaluates length of constant strings direct }
                   if (p^.left^.treetype=stringconstn) then
                   if (p^.left^.treetype=stringconstn) then
                     begin
                     begin
@@ -388,17 +393,13 @@ implementation
                        p:=hp;
                        p:=hp;
                     end
                     end
                   { length of char is one allways }
                   { length of char is one allways }
-                  else if (p^.left^.treetype=ordconstn) then
-                    if (porddef(p^.left^.resulttype)^.typ=uchar) then
-                      begin
+                  else if is_constcharnode(p^.left) then
+                    begin
                        hp:=genordinalconstnode(1,s32bitdef);
                        hp:=genordinalconstnode(1,s32bitdef);
                        disposetree(p);
                        disposetree(p);
                        firstpass(hp);
                        firstpass(hp);
                        p:=hp;
                        p:=hp;
-                      end
-                    else
-                      CGMessage(type_e_mismatch);
-                    ;
+                    end;
                end;
                end;
              in_assigned_x:
              in_assigned_x:
                begin
                begin
@@ -862,7 +863,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.8  1998-11-14 10:51:33  peter
+  Revision 1.9  1998-11-24 17:04:28  peter
+    * fixed length(char) when char is a variable
+
+  Revision 1.8  1998/11/14 10:51:33  peter
     * fixed low/high for record.field
     * fixed low/high for record.field
 
 
   Revision 1.7  1998/11/13 10:15:52  peter
   Revision 1.7  1998/11/13 10:15:52  peter