From 4f7b4a2735aee929817e78687f711f28b17c631e Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Wed, 28 Oct 2015 18:06:27 +0000 Subject: [PATCH] * changed {$ifdef x86} code in defcmp into virtual methods git-svn-id: trunk@32180 - --- compiler/defcmp.pas | 18 ++++---------- compiler/symdef.pas | 14 +++++++++++ compiler/x86/symi86.pas | 6 ++--- compiler/x86/symx86.pas | 48 ++++++++++++++++++++++++++++++++++++++ compiler/x86_64/symcpu.pas | 4 ++-- 5 files changed, 71 insertions(+), 19 deletions(-) diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas index a04861c761..7d40ae4f45 100644 --- a/compiler/defcmp.pas +++ b/compiler/defcmp.pas @@ -1339,18 +1339,16 @@ implementation end; pointerdef : begin -{$ifdef x86} { check for far pointers } - if (tcpupointerdef(def_from).x86pointertyp<>tcpupointerdef(def_to).x86pointertyp) then + if not tpointerdef(def_from).compatible_with_pointerdef_size(tpointerdef(def_to)) then begin if fromtreetype=niln then eq:=te_equal else eq:=te_incompatible; end + { the types can be forward type, handle before normal type check !! } else -{$endif x86} - { the types can be forward type, handle before normal type check !! } if assigned(def_to.typesym) and ((tpointerdef(def_to).pointeddef.typ=forwarddef) or (tpointerdef(def_from).pointeddef.typ=forwarddef)) then @@ -1422,11 +1420,7 @@ implementation this is not allowed for complex procvars } if (is_void(tpointerdef(def_to).pointeddef) or (m_mac_procvar in current_settings.modeswitches)) and - tprocvardef(def_from).is_addressonly -{$ifdef x86} - and (tcpupointerdef(voidcodepointertype).x86pointertyp=tcpupointerdef(def_to).x86pointertyp) -{$endif x86} - then + tprocvardef(def_from).compatible_with_pointerdef_size(tpointerdef(def_to)) then begin doconv:=tc_equal; eq:=te_convert_l1; @@ -1437,11 +1431,7 @@ implementation { procedure variable can be assigned to an void pointer, this not allowed for methodpointers } if (m_mac_procvar in current_settings.modeswitches) and - tprocdef(def_from).is_addressonly -{$ifdef x86} - and (tcpupointerdef(voidcodepointertype).x86pointertyp=tcpupointerdef(def_to).x86pointertyp) -{$endif x86} - then + tprocdef(def_from).compatible_with_pointerdef_size(tpointerdef(def_to)) then begin doconv:=tc_proc_2_procvar; eq:=te_convert_l2; diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 112ad1223a..094a81a42d 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -242,6 +242,7 @@ interface 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; + function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual; end; tpointerdefclass = class of tpointerdef; @@ -598,6 +599,7 @@ interface function no_self_node:boolean; { get either a copy as a procdef or procvardef } function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef; virtual; + function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual; procedure check_mark_as_nested; procedure init_paraloc_info(side: tcallercallee); function stack_tainting_parameter(side: tcallercallee): boolean; @@ -3285,6 +3287,12 @@ implementation end; + function tpointerdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean; + begin + result:=true; + end; + + {**************************************************************************** TCLASSREFDEF ****************************************************************************} @@ -4906,6 +4914,12 @@ implementation end; + function tabstractprocdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean; + begin + result:=is_addressonly; + end; + + procedure tabstractprocdef.check_mark_as_nested; begin { nested procvars require that nested functions use the Delphi-style diff --git a/compiler/x86/symi86.pas b/compiler/x86/symi86.pas index 37fdd34dba..45b9a4fae6 100644 --- a/compiler/x86/symi86.pas +++ b/compiler/x86/symi86.pas @@ -26,19 +26,19 @@ unit symi86; interface uses - symtype,symdef,symsym; + symtype,symdef,symsym,symx86; type { ti86procvardef } - ti86procvardef = class(tprocvardef) + ti86procvardef = class(tx86procvardef) function is_pushleftright: boolean; override; end; { ti86procdef } - ti86procdef = class(tprocdef) + ti86procdef = class(tx86procdef) function is_pushleftright: boolean; override; end; diff --git a/compiler/x86/symx86.pas b/compiler/x86/symx86.pas index a1fbdb0fee..e7a9b51895 100644 --- a/compiler/x86/symx86.pas +++ b/compiler/x86/symx86.pas @@ -44,15 +44,28 @@ type function getcopy: tstoreddef; override; function GetTypeName: string; override; class function default_x86_data_pointer_type: tx86pointertyp; virtual; + function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; override; end; tx86pointerdefclass = class of tx86pointerdef; + tx86procvardef = class(tprocvardef) + function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; override; + end; + tx86procvardefclass = class of tx86procvardef; + + tx86procdef = class(tprocdef) + function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; override; + end; + tx86procdefclass = class of tx86procdef; + + implementation uses globals, verbose, symbase, fmodule; + {**************************************************************************** tx86pointerdef ****************************************************************************} @@ -178,5 +191,40 @@ implementation result:=x86pt_near; end; + + function tx86pointerdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean; + begin + result:= + inherited and + (x86pointertyp=tx86pointerdef(ptr).x86pointertyp); + end; + + +{**************************************************************************** + tx86procvardef +****************************************************************************} + + + function tx86procvardef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean; + begin + result:= + inherited and + (tx86pointerdef(voidcodepointertype).x86pointertyp=tx86pointerdef(ptr).x86pointertyp); + end; + + + {**************************************************************************** + tx86procdef + ****************************************************************************} + + + function tx86procdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean; + begin + result:= + inherited and + (tx86pointerdef(voidcodepointertype).x86pointertyp=tx86pointerdef(ptr).x86pointertyp); + end; + + end. diff --git a/compiler/x86_64/symcpu.pas b/compiler/x86_64/symcpu.pas index 038726deef..e6d15ba87e 100644 --- a/compiler/x86_64/symcpu.pas +++ b/compiler/x86_64/symcpu.pas @@ -86,11 +86,11 @@ type end; tcpufloatdefclass = class of tcpufloatdef; - tcpuprocvardef = class(tprocvardef) + tcpuprocvardef = class(tx86procvardef) end; tcpuprocvardefclass = class of tcpuprocvardef; - tcpuprocdef = class(tprocdef) + tcpuprocdef = class(tx86procdef) procedure ppuload_platform(ppufile: tcompilerppufile); override; procedure ppuwrite_platform(ppufile: tcompilerppufile); override; public