Browse Source

* defutil.get_int_type_for_pointer_arithmetic replaced with a virtual method
tpointerdef.pointer_arithmetic_int_type

git-svn-id: trunk@28258 -

nickysn 11 years ago
parent
commit
33dac14554
4 changed files with 27 additions and 23 deletions
  1. 0 18
      compiler/defutil.pas
  2. 10 0
      compiler/i8086/symcpu.pas
  3. 5 5
      compiler/nadd.pas
  4. 12 0
      compiler/symdef.pas

+ 0 - 18
compiler/defutil.pas

@@ -331,13 +331,6 @@ interface
     { returns true of def is a methodpointer }
     { returns true of def is a methodpointer }
     function is_methodpointer(def : tdef) : boolean;
     function is_methodpointer(def : tdef) : boolean;
 
 
-    {# returns the appropriate int type for pointer arithmetic with the given pointer type.
-       When adding or subtracting a number to/from a pointer, this function returns the
-       int type to which that number has to be converted, before the operation can be performed.
-       Normally, this is sinttype, except on i8086, where it takes into account the
-       special i8086 pointer types (near, far, huge). }
-    function get_int_type_for_pointer_arithmetic(p : tdef) : tdef;
-
 {$ifdef i8086}
 {$ifdef i8086}
     {# Returns true if p is a far pointer def }
     {# Returns true if p is a far pointer def }
     function is_farpointer(p : tdef) : boolean;
     function is_farpointer(p : tdef) : boolean;
@@ -1440,17 +1433,6 @@ implementation
         result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
         result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
       end;
       end;
 
 
-
-    function get_int_type_for_pointer_arithmetic(p : tdef) : tdef;
-      begin
-{$ifdef i8086}
-        if is_hugepointer(p) then
-          result:=s32inttype
-        else
-{$endif i8086}
-          result:=sinttype;
-      end;
-
 {$ifdef i8086}
 {$ifdef i8086}
     { true if p is a far pointer def }
     { true if p is a far pointer def }
     function is_farpointer(p : tdef) : boolean;
     function is_farpointer(p : tdef) : boolean;

+ 10 - 0
compiler/i8086/symcpu.pas

@@ -57,6 +57,7 @@ type
 
 
   tcpupointerdef = class(tx86pointerdef)
   tcpupointerdef = class(tx86pointerdef)
     class function default_x86_data_pointer_type: tx86pointertyp; override;
     class function default_x86_data_pointer_type: tx86pointertyp; override;
+    function pointer_arithmetic_int_type:tdef; override;
     function pointer_subtraction_result_type:tdef; override;
     function pointer_subtraction_result_type:tdef; override;
   end;
   end;
   tcpupointerdefclass = class of tcpupointerdef;
   tcpupointerdefclass = class of tcpupointerdef;
@@ -312,6 +313,15 @@ implementation
       end;
       end;
 
 
 
 
+    function tcpupointerdef.pointer_arithmetic_int_type:tdef;
+      begin
+        if x86pointertyp=x86pt_huge then
+          result:=s32inttype
+        else
+          result:=inherited;
+      end;
+
+
     function tcpupointerdef.pointer_subtraction_result_type:tdef;
     function tcpupointerdef.pointer_subtraction_result_type:tdef;
       begin
       begin
         case x86pointertyp of
         case x86pointertyp of

+ 5 - 5
compiler/nadd.pas

@@ -1967,7 +1967,7 @@ implementation
               end
               end
             else
             else
               resultdef:=right.resultdef;
               resultdef:=right.resultdef;
-            inserttypeconv(left,get_int_type_for_pointer_arithmetic(right.resultdef));
+            inserttypeconv(left,tpointerdef(right.resultdef).pointer_arithmetic_int_type);
             if nodetype=addn then
             if nodetype=addn then
               begin
               begin
                 if (rt=niln) then
                 if (rt=niln) then
@@ -1981,7 +1981,7 @@ implementation
                    (tpointerdef(rd).pointeddef.size>1) then
                    (tpointerdef(rd).pointeddef.size>1) then
                    begin
                    begin
                      left:=caddnode.create(muln,left,
                      left:=caddnode.create(muln,left,
-                       cordconstnode.create(tpointerdef(rd).pointeddef.size,get_int_type_for_pointer_arithmetic(right.resultdef),true));
+                       cordconstnode.create(tpointerdef(rd).pointeddef.size,tpointerdef(right.resultdef).pointer_arithmetic_int_type,true));
                      typecheckpass(left);
                      typecheckpass(left);
                    end;
                    end;
               end
               end
@@ -2000,7 +2000,7 @@ implementation
              else
              else
                resultdef:=left.resultdef;
                resultdef:=left.resultdef;
 
 
-             inserttypeconv(right,get_int_type_for_pointer_arithmetic(left.resultdef));
+             inserttypeconv(right,tpointerdef(left.resultdef).pointer_arithmetic_int_type);
              if nodetype in [addn,subn] then
              if nodetype in [addn,subn] then
                begin
                begin
                  if (lt=niln) then
                  if (lt=niln) then
@@ -2017,7 +2017,7 @@ implementation
                    if (tpointerdef(ld).pointeddef.size>1) then
                    if (tpointerdef(ld).pointeddef.size>1) then
                    begin
                    begin
                      right:=caddnode.create(muln,right,
                      right:=caddnode.create(muln,right,
-                       cordconstnode.create(tpointerdef(ld).pointeddef.size,get_int_type_for_pointer_arithmetic(left.resultdef),true));
+                       cordconstnode.create(tpointerdef(ld).pointeddef.size,tpointerdef(left.resultdef).pointer_arithmetic_int_type,true));
                      typecheckpass(right);
                      typecheckpass(right);
                    end
                    end
                  end else
                  end else
@@ -2025,7 +2025,7 @@ implementation
                       (tarraydef(ld).elementdef.size>1) then
                       (tarraydef(ld).elementdef.size>1) then
                      begin
                      begin
                        right:=caddnode.create(muln,right,
                        right:=caddnode.create(muln,right,
-                         cordconstnode.create(tarraydef(ld).elementdef.size,get_int_type_for_pointer_arithmetic(left.resultdef),true));
+                         cordconstnode.create(tarraydef(ld).elementdef.size,tpointerdef(left.resultdef).pointer_arithmetic_int_type,true));
                        typecheckpass(right);
                        typecheckpass(right);
                      end;
                      end;
                end
                end

+ 12 - 0
compiler/symdef.pas

@@ -227,6 +227,12 @@ interface
             override ppuwrite_platform instead }
             override ppuwrite_platform instead }
           procedure ppuwrite(ppufile:tcompilerppufile);override;final;
           procedure ppuwrite(ppufile:tcompilerppufile);override;final;
           function  GetTypeName:string;override;
           function  GetTypeName:string;override;
+          {# returns the appropriate int type for pointer arithmetic with the given pointer type.
+             When adding or subtracting a number to/from a pointer, this function returns the
+             int type to which that number has to be converted, before the operation can be performed.
+             Normally, this is sinttype, except on i8086, where it takes into account the
+             special i8086 pointer types (near, far, huge). }
+          function pointer_arithmetic_int_type:tdef;virtual;
           {# returns the int type produced when subtracting two pointers of the given type.
           {# returns the int type produced when subtracting two pointers of the given type.
              Normally, this is sinttype, except on i8086, where it takes into account the
              Normally, this is sinttype, except on i8086, where it takes into account the
              special i8086 pointer types (near, far, huge). }
              special i8086 pointer types (near, far, huge). }
@@ -3170,6 +3176,12 @@ implementation
       end;
       end;
 
 
 
 
+    function tpointerdef.pointer_arithmetic_int_type:tdef;
+      begin
+        result:=sinttype;
+      end;
+
+
     function tpointerdef.pointer_subtraction_result_type:tdef;
     function tpointerdef.pointer_subtraction_result_type:tdef;
       begin
       begin
         result:=ptrsinttype;
         result:=ptrsinttype;