From e661df03ee13cc003f1d216d1a395fffc812493f Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 29 Mar 2004 14:44:10 +0000 Subject: [PATCH] * fixes to previous constant integer commit --- compiler/defutil.pas | 28 ++++++++++++++++++++-------- compiler/nadd.pas | 30 ++++++++++++++++-------------- compiler/nmat.pas | 11 +++++------ compiler/ptype.pas | 16 ++++++++++++++-- 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/compiler/defutil.pas b/compiler/defutil.pas index c7b9c93cad..69a1deaecc 100644 --- a/compiler/defutil.pas +++ b/compiler/defutil.pas @@ -50,6 +50,8 @@ interface {# Returns basetype of the specified integer range } function range_to_basetype(l,h:TConstExprInt):tbasetype; + procedure range_to_type(l,h:TConstExprInt;var tt:ttype); + procedure int_to_type(v:TConstExprInt;var tt:ttype); {# Returns true, if definition defines an integer type } @@ -266,25 +268,32 @@ implementation end; - procedure int_to_type(v:TConstExprInt;var tt:ttype); + procedure range_to_type(l,h:TConstExprInt;var tt:ttype); begin - if (v>=0) and (v<=255) then + { generate a unsigned range if high<0 and low>=0 } + if (l>=0) and (h<=255) then tt:=u8inttype - else if (v>=-128) and (v<=127) then + else if (l>=-128) and (h<=127) then tt:=s8inttype - else if (v>=0) and (v<=65535) then + else if (l>=0) and (h<=65535) then tt:=u16inttype - else if (v>=-32768) and (v<=32767) then + else if (l>=-32768) and (h<=32767) then tt:=s16inttype - else if (v>=low(longint)) and (v<=high(longint)) then + else if (l>=low(longint)) and (h<=high(longint)) then tt:=s32inttype - else if (v>=low(cardinal)) and (v<=high(cardinal)) then + else if (l>=low(cardinal)) and (h<=high(cardinal)) then tt:=u32inttype else tt:=s64inttype; end; + procedure int_to_type(v:TConstExprInt;var tt:ttype); + begin + range_to_type(v,v,tt); + end; + + { true if p is an ordinal } function is_ordinal(def : tdef) : boolean; var @@ -877,7 +886,10 @@ implementation end. { $Log$ - Revision 1.11 2004-03-23 22:34:49 peter + Revision 1.12 2004-03-29 14:44:10 peter + * fixes to previous constant integer commit + + Revision 1.11 2004/03/23 22:34:49 peter * constants ordinals now always have a type assigned * integer constants have the smallest type, unsigned prefered over signed diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 768fce5f18..37c8292aa6 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -283,16 +283,6 @@ implementation begin if not(equal_defs(ld,rd)) then inserttypeconv(right,left.resulttype); - end - else if (lt=ordconstn) and (rt=ordconstn) then - begin - { make left const type the biggest (u32bit is bigger than - s32bit for or,and,xor) } - if (rd.size>ld.size) or - ((torddef(rd).typ=torddef(uinttype.def).typ) and - (torddef(ld).typ=torddef(sinttype.def).typ) and - (nodetype in [orn,andn,xorn])) then - inserttypeconv(left,right.resulttype); end; { load values } @@ -340,11 +330,20 @@ implementation else t:=genintconstnode(int64(qword(lv)*qword(rv))); xorn : - t:=cordconstnode.create(lv xor rv,left.resulttype,false); + if is_integer(ld) then + t:=genintconstnode(lv xor rv) + else + t:=cordconstnode.create(lv xor rv,left.resulttype,true); orn : - t:=cordconstnode.create(lv or rv,left.resulttype,false); + if is_integer(ld) then + t:=genintconstnode(lv or rv) + else + t:=cordconstnode.create(lv or rv,left.resulttype,true); andn : - t:=cordconstnode.create(lv and rv,left.resulttype,false); + if is_integer(ld) then + t:=genintconstnode(lv and rv) + else + t:=cordconstnode.create(lv and rv,left.resulttype,true); ltn : t:=cordconstnode.create(ord(lv