Browse Source

* 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 -

Jonas Maebe 13 years ago
parent
commit
3589f90cf8

+ 2 - 2
compiler/defutil.pas

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

+ 5 - 1
compiler/msg/errore.msg

@@ -1413,7 +1413,7 @@ parser_e_invalid_codepage=03314_E_Invalid codepage
 % \end{description}
 % \end{description}
 # Type Checking
 # Type Checking
 #
 #
-# 04108 is the last used one
+# 04110 is the last used one
 #
 #
 % \section{Type checking errors}
 % \section{Type checking errors}
 % This section lists all errors that can occur when type checking is
 % 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
 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
 % Conversion from a WideChar to AnsiChar can lose data since now all unicode characters may be represented in the current
 % system codepage
 % 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}
 % \end{description}
 #
 #
 # Symtable
 # Symtable

+ 4 - 2
compiler/msgidx.inc

@@ -506,6 +506,8 @@ const
   type_w_explicit_string_cast=04106;
   type_w_explicit_string_cast=04106;
   type_w_explicit_string_cast_loss=04107;
   type_w_explicit_string_cast_loss=04107;
   type_w_unicode_data_loss=04108;
   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_e_id_not_found=05000;
   sym_f_internal_error_in_symtablestack=05001;
   sym_f_internal_error_in_symtablestack=05001;
   sym_e_duplicate_id=05002;
   sym_e_duplicate_id=05002;
@@ -921,9 +923,9 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 62838;
+  MsgTxtSize = 63006;
 
 
   MsgIdxMax : array[1..20] of longint=(
   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
     52,20,1,1,1,1,1,1,1,1
   );
   );

File diff suppressed because it is too large
+ 293 - 288
compiler/msgtxt.inc


+ 3 - 3
compiler/ninl.pas

@@ -1917,9 +1917,9 @@ implementation
                   if left.nodetype in [ordconstn,realconstn] then
                   if left.nodetype in [ordconstn,realconstn] then
                     begin
                     begin
                       vr:=getconstrealvalue;
                       vr:=getconstrealvalue;
-                      if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
+                      if (vr>=9223372036854775807.99) or (vr<=-9223372036854775808.0) then
                         begin
                         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)
                           result:=cordconstnode.create(1,s64inttype,false)
                         end
                         end
                       else
                       else
@@ -1935,7 +1935,7 @@ implementation
                       vr:=getconstrealvalue;
                       vr:=getconstrealvalue;
                       if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
                       if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
                         begin
                         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)
                           result:=cordconstnode.create(1,s64inttype,false)
                         end
                         end
                       else
                       else

+ 5 - 5
compiler/pdecsub.pas

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

+ 5 - 5
compiler/pdecvar.pas

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

+ 1 - 1
compiler/pexports.pas

@@ -142,7 +142,7 @@ implementation
                            (Tordconstnode(pt).value>int64(high(index))) then
                            (Tordconstnode(pt).value>int64(high(index))) then
                           begin
                           begin
                             index:=0;
                             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
                           end
                         else
                         else
                           index:=Tordconstnode(pt).value.svalue
                           index:=Tordconstnode(pt).value.svalue

+ 3 - 3
compiler/ptconst.pas

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

Some files were not shown because too many files changed in this diff