@@ -365,18 +365,69 @@ Function: smv_typecheckt::check_type
365365
366366void smv_typecheckt::check_type (typet &type)
367367{
368- if (type.id () == ID_range )
368+ if (type.id () == ID_smv_array )
369369 {
370- auto range = smv_ranget::from_type (to_range_type (type));
370+ auto from = numeric_cast_v<mp_integer>(
371+ to_constant_expr (static_cast <const exprt &>(type.find (ID_from))));
372+ auto to = numeric_cast_v<mp_integer>(
373+ to_constant_expr (static_cast <const exprt &>(type.find (ID_to))));
371374
372- if (range.from > range.to )
373- throw errort ().with_location (type.source_location ()) << " range is empty" ;
375+ if (to < from)
376+ throw errort ().with_location (type.source_location ())
377+ << " array must end with number >= `" << from << ' \' ' ;
378+
379+ type.id (ID_array);
380+ type.remove (ID_from);
381+ type.remove (ID_to);
382+ type.set (ID_size, integer2string (to - from + 1 ));
383+ type.set (ID_offset, integer2string (from));
384+
385+ // recursive call
386+ check_type (to_type_with_subtype (type).subtype ());
374387 }
375388 else if (type.id () == ID_smv_enumeration)
376389 {
377390 // normalize the ordering of elements
378391 to_smv_enumeration_type (type).normalize ();
379392 }
393+ else if (type.id () == ID_smv_range)
394+ {
395+ auto from = numeric_cast_v<mp_integer>(
396+ to_constant_expr (static_cast <const exprt &>(type.find (ID_from))));
397+ auto to = numeric_cast_v<mp_integer>(
398+ to_constant_expr (static_cast <const exprt &>(type.find (ID_to))));
399+
400+ if (from > to)
401+ throw errort ().with_location (type.source_location ()) << " range is empty" ;
402+
403+ type.id (ID_range);
404+ type.set (ID_from, integer2string (from));
405+ type.set (ID_to, integer2string (to));
406+ }
407+ else if (type.id () == ID_smv_signed_word)
408+ {
409+ auto width = numeric_cast_v<mp_integer>(
410+ to_constant_expr (static_cast <const exprt &>(type.find (ID_width))));
411+
412+ if (width < 1 )
413+ throw errort ().with_location (type.source_location ())
414+ << " word width must be 1 or larger" ;
415+
416+ type.id (ID_signedbv);
417+ type.set (ID_width, integer2string (width));
418+ }
419+ else if (type.id () == ID_smv_word || type.id () == ID_smv_unsigned_word)
420+ {
421+ auto width = numeric_cast_v<mp_integer>(
422+ to_constant_expr (static_cast <const exprt &>(type.find (ID_width))));
423+
424+ if (width < 1 )
425+ throw errort ().with_location (type.source_location ())
426+ << " word width must be 1 or larger" ;
427+
428+ type.id (ID_unsignedbv);
429+ type.set (ID_width, integer2string (width));
430+ }
380431}
381432
382433/* ******************************************************************\
0 commit comments