浏览代码

* defutil.get_int_result_type_from_pointer_subtraction moved to a virtual
method tpointerdef.pointer_subtraction_result_type

git-svn-id: trunk@28219 -

nickysn 11 年之前
父节点
当前提交
d86a8ebc99
共有 4 个文件被更改,包括 26 次插入19 次删除
  1. 0 17
      compiler/defutil.pas
  2. 14 0
      compiler/i8086/symcpu.pas
  3. 2 2
      compiler/nadd.pas
  4. 10 0
      compiler/symdef.pas

+ 0 - 17
compiler/defutil.pas

@@ -338,11 +338,6 @@ interface
        special i8086 pointer types (near, far, huge). }
     function get_int_type_for_pointer_arithmetic(p : tdef) : tdef;
 
-    {# returns the int type produced when subtracting two pointers of the given type p.
-       Normally, this is sinttype, except on i8086, where it takes into account the
-       special i8086 pointer types (near, far, huge). }
-    function get_int_result_type_from_pointer_subtraction(p : tdef) : tdef;
-
 {$ifdef i8086}
     {# Returns true if p is a far pointer def }
     function is_farpointer(p : tdef) : boolean;
@@ -1456,18 +1451,6 @@ implementation
           result:=sinttype;
       end;
 
-    function get_int_result_type_from_pointer_subtraction(p : tdef) : tdef;
-      begin
-{$ifdef i8086}
-        if is_hugepointer(p) then
-          result:=s32inttype
-        else if is_farpointer(p) then
-          result:=u16inttype
-        else
-{$endif i8086}
-          result:=sinttype;
-      end;
-
 {$ifdef i8086}
     { true if p is a far pointer def }
     function is_farpointer(p : tdef) : boolean;

+ 14 - 0
compiler/i8086/symcpu.pas

@@ -57,6 +57,7 @@ type
 
   tcpupointerdef = class(tx86pointerdef)
     class function default_x86_data_pointer_type: tx86pointertyp; override;
+    function pointer_subtraction_result_type:tdef; override;
   end;
   tcpupointerdefclass = class of tcpupointerdef;
 
@@ -311,6 +312,19 @@ implementation
       end;
 
 
+    function tcpupointerdef.pointer_subtraction_result_type:tdef;
+      begin
+        case x86pointertyp of
+          x86pt_huge:
+            result:=s32inttype;
+          x86pt_far:
+            result:=u16inttype;
+          else
+            result:=inherited;
+        end;
+      end;
+
+
 {****************************************************************************
                              tcpuabsolutevarsym
 ****************************************************************************}

+ 2 - 2
compiler/nadd.pas

@@ -1698,9 +1698,9 @@ implementation
                         hp:=getcopy;
                         include(hp.flags,nf_has_pointerdiv);
                         result:=cmoddivnode.create(divn,hp,
-                          cordconstnode.create(tpointerdef(rd).pointeddef.size,get_int_result_type_from_pointer_subtraction(rd),false));
+                          cordconstnode.create(tpointerdef(rd).pointeddef.size,tpointerdef(rd).pointer_subtraction_result_type,false));
                       end;
-                    resultdef:=get_int_result_type_from_pointer_subtraction(rd);
+                    resultdef:=tpointerdef(rd).pointer_subtraction_result_type;
                     exit;
                  end;
                else

+ 10 - 0
compiler/symdef.pas

@@ -227,6 +227,10 @@ interface
             override ppuwrite_platform instead }
           procedure ppuwrite(ppufile:tcompilerppufile);override;final;
           function  GetTypeName:string;override;
+          {# 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
+             special i8086 pointer types (near, far, huge). }
+          function pointer_subtraction_result_type:tdef;virtual;
        end;
        tpointerdefclass = class of tpointerdef;
 
@@ -3166,6 +3170,12 @@ implementation
       end;
 
 
+    function tpointerdef.pointer_subtraction_result_type:tdef;
+      begin
+        result:=sinttype;
+      end;
+
+
 {****************************************************************************
                               TCLASSREFDEF
 ****************************************************************************}