* also show the valid bounds in most cases when signalling a range check

warning/error while evaluating constants (mantis #21299)

git-svn-id: trunk@20507 -
This commit is contained in:
Jonas Maebe 2012-03-10 21:53:36 +00:00
parent 18866623cd
commit 3589f90cf8
9 changed files with 370 additions and 361 deletions

View File

@ -785,9 +785,9 @@ implementation
not(m_delphi in current_settings.modeswitches)) or
(cs_check_range in current_settings.localswitches) or
forcerangecheck then
Message(parser_e_range_check_error)
Message3(type_e_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv))
else
Message(parser_w_range_check_error);
Message3(type_w_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv));
end;
{ Fix the value to fit in the allocated space for this type of variable }
case longint(todef.size) of

View File

@ -1413,7 +1413,7 @@ parser_e_invalid_codepage=03314_E_Invalid codepage
% \end{description}
# Type Checking
#
# 04108 is the last used one
# 04110 is the last used one
#
% \section{Type checking errors}
% This section lists all errors that can occur when type checking is
@ -1795,6 +1795,10 @@ type_w_explicit_string_cast_loss=04107_-W_Explicit string typecast with potentia
type_w_unicode_data_loss=04108_W_Unicode constant cast with potential data loss
% Conversion from a WideChar to AnsiChar can lose data since now all unicode characters may be represented in the current
% system codepage
% You can nest function definitions only 31 levels deep.
type_e_range_check_error_bounds=04109_E_range check error while evaluating constants ($1 must be between $2 and $3)
type_w_range_check_error_bounds=04110_W_range check error while evaluating constants ($1 must be between $2 and $3)
% The constants are outside their allowed range.
% \end{description}
#
# Symtable

View File

@ -506,6 +506,8 @@ const
type_w_explicit_string_cast=04106;
type_w_explicit_string_cast_loss=04107;
type_w_unicode_data_loss=04108;
type_e_range_check_error_bounds=04109;
type_w_range_check_error_bounds=04110;
sym_e_id_not_found=05000;
sym_f_internal_error_in_symtablestack=05001;
sym_e_duplicate_id=05002;
@ -921,9 +923,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 62838;
MsgTxtSize = 63006;
MsgIdxMax : array[1..20] of longint=(
26,90,315,109,85,55,116,26,202,63,
26,90,315,111,85,55,116,26,202,63,
52,20,1,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -1917,9 +1917,9 @@ implementation
if left.nodetype in [ordconstn,realconstn] then
begin
vr:=getconstrealvalue;
if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
if (vr>=9223372036854775807.99) or (vr<=-9223372036854775808.0) then
begin
CGMessage(parser_e_range_check_error);
message3(type_e_range_check_error_bounds,realtostr(vr),'-9223372036854775808.0','9223372036854775807.99..');
result:=cordconstnode.create(1,s64inttype,false)
end
else
@ -1935,7 +1935,7 @@ implementation
vr:=getconstrealvalue;
if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
begin
CGMessage(parser_e_range_check_error);
message3(type_e_range_check_error_bounds,realtostr(vr),'-9223372036854775808.49..','9223372036854775807.49..');
result:=cordconstnode.create(1,s64inttype,false)
end
else

View File

@ -1602,7 +1602,7 @@ begin
consume(_COLON);
v:=get_intconst;
if (v<int64(low(longint))) or (v>int64(high(longint))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
else
Tprocdef(pd).extnumber:=longint(v.svalue);
end;
@ -1618,7 +1618,7 @@ begin
consume(_COLON);
v:=get_intconst;
if (v<int64(low(longint))) or (v>int64(high(longint))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
else
Tprocdef(pd).extnumber:=longint(v.svalue);
{ the proc is defined }
@ -1750,7 +1750,7 @@ begin
pt:=comp_expr(true,false);
if is_constintnode(pt) then
if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(longint)))
else
Tprocdef(pd).dispid:=Tordconstnode(pt).value.svalue
else
@ -1842,7 +1842,7 @@ begin
include(pd.procoptions,po_msgint);
if (Tordconstnode(pt).value<int64(low(Tprocdef(pd).messageinf.i))) or
(Tordconstnode(pt).value>int64(high(Tprocdef(pd).messageinf.i))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(Tprocdef(pd).messageinf.i)),tostr(high(Tprocdef(pd).messageinf.i)))
else
Tprocdef(pd).messageinf.i:=tordconstnode(pt).value.svalue;
end
@ -1914,7 +1914,7 @@ begin
v:=get_intconst;
if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(v),tostr(low(Tprocdef(pd).extnumber)),tostr(high(Tprocdef(pd).extnumber)))
else
Tprocdef(pd).extnumber:=v.uvalue;
end;

View File

@ -284,7 +284,7 @@ implementation
pt:=comp_expr(true,false);
if is_constintnode(pt) then
if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(longint)))
else
hdispid:=Tordconstnode(pt).value.svalue
else
@ -774,7 +774,7 @@ implementation
ordconstn :
if (Tordconstnode(pt).value<int64(low(longint))) or
(Tordconstnode(pt).value>int64(high(cardinal))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(cardinal)))
else
p.default:=longint(tordconstnode(pt).value.svalue);
niln :
@ -1206,8 +1206,8 @@ implementation
}
if (Tordconstnode(pt).value<int64(low(abssym.addroffset))) or
(Tordconstnode(pt).value>int64(high(abssym.addroffset))) then
message(parser_e_range_check_error)
else
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(abssym.addroffset)),tostr(high(abssym.addroffset)))
else
{$endif}
abssym.addroffset:=Tordconstnode(pt).value.svalue;
{$ifdef i386}
@ -1222,7 +1222,7 @@ implementation
tmpaddr:=abssym.addroffset shl 4+tordconstnode(pt).value.svalue;
if (tmpaddr<int64(low(abssym.addroffset))) or
(tmpaddr>int64(high(abssym.addroffset))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(abssym.addroffset)),tostr(high(abssym.addroffset)))
else
abssym.addroffset:=tmpaddr;
abssym.absseg:=true;

View File

@ -142,7 +142,7 @@ implementation
(Tordconstnode(pt).value>int64(high(index))) then
begin
index:=0;
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(index)),tostr(high(index)))
end
else
index:=Tordconstnode(pt).value.svalue

View File

@ -501,11 +501,11 @@ implementation
{Prevent overflow.}
v:=get_ordinal_value(tvecnode(hp).right)-base;
if (v<int64(low(offset))) or (v>int64(high(offset))) then
message(parser_e_range_check_error);
message3(type_e_range_check_error_bounds,tostr(v),tostr(low(offset)),tostr(high(offset)));
if high(offset)-offset div len>v then
inc(offset,len*v.svalue)
else
message(parser_e_range_check_error);
message3(type_e_range_check_error_bounds,tostr(v),'0',tostr(high(offset)-offset div len))
end
else
Message(parser_e_illegal_expression);
@ -799,7 +799,7 @@ implementation
exit;
end;
if (Tordconstnode(n).value<qword(low(Aword))) or (Tordconstnode(n).value>qword(high(Aword))) then
message(parser_e_range_check_error)
message3(type_e_range_check_error_bounds,tostr(Tordconstnode(n).value),tostr(low(Aword)),tostr(high(Aword)))
else
bitpackval(Tordconstnode(n).value.uvalue,bp);
if (bp.curbitoffset>=AIntBits) then