@@ -444,6 +444,57 @@ bool ps_visit_type_reference_enum(ps_interpreter *interpreter, ps_interpreter_mo
444444 return false;
445445}
446446
447+ bool ps_visit_type_reference_subrange_min_or_max (ps_interpreter * interpreter , ps_interpreter_mode mode , ps_value * value ,
448+ ps_value_type * base , ps_type_definition_subrange_char * c ,
449+ ps_type_definition_subrange_integer * i ,
450+ ps_type_definition_subrange_unsigned * u ,
451+ ps_type_definition_subrange_enum * e , bool is_for_min )
452+ {
453+ VISIT_BEGIN ("TYPE_REFERENCE_SUBRANGE" , "" )
454+
455+ * base = ps_value_get_type (value );
456+ if (* base == PS_TYPE_CHAR )
457+ {
458+ if (ps_value_get_type (value ) != PS_TYPE_CHAR )
459+ RETURN_ERROR (PS_ERROR_EXPECTED_CHAR )
460+ if (is_for_min )
461+ c -> min = value -> data .c ;
462+ else
463+ c -> max = value -> data .c ;
464+ }
465+ else if (* base == PS_TYPE_INTEGER )
466+ {
467+ if (ps_value_get_type (value ) != PS_TYPE_INTEGER )
468+ RETURN_ERROR (PS_ERROR_EXPECTED_INTEGER )
469+ if (is_for_min )
470+ i -> min = value -> data .i ;
471+ else
472+ i -> max = value -> data .i ;
473+ }
474+ else if (* base == PS_TYPE_UNSIGNED )
475+ {
476+ if (ps_value_get_type (value ) != PS_TYPE_UNSIGNED )
477+ RETURN_ERROR (PS_ERROR_EXPECTED_UNSIGNED )
478+ if (is_for_min )
479+ u -> min = value -> data .u ;
480+ else
481+ u -> max = value -> data .u ;
482+ }
483+ else if (base == PS_TYPE_ENUM )
484+ {
485+ if (ps_value_get_type (value ) != PS_TYPE_ENUM )
486+ RETURN_ERROR (PS_ERROR_EXPECTED_ENUM )
487+ if (is_for_min )
488+ e -> min = value -> data .u ;
489+ else
490+ e -> max = value -> data .u ;
491+ }
492+ else
493+ RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
494+
495+ VISIT_END ("OK" )
496+ }
497+
447498bool ps_visit_type_reference_subrange (ps_interpreter * interpreter , ps_interpreter_mode mode , ps_symbol * * type_symbol ,
448499 const char * type_name )
449500{
@@ -461,46 +512,21 @@ bool ps_visit_type_reference_subrange(ps_interpreter *interpreter, ps_interprete
461512 ps_value_type max_base = PS_TYPE_NONE ;
462513
463514 // Parse min value of subrange as a constant expression
464- // can't be an enum for now
465515 if (!ps_visit_constant_expression (interpreter , mode , & min_value ))
466- TRACE_ERROR ("MIN" )
467- // ps_value_debug(stderr, "==> MIN_VALUE: ", &min_value);
468- min_base = ps_value_get_type (& min_value );
469- if (min_base == PS_TYPE_CHAR )
470- {
471- if (ps_value_get_type (& min_value ) != PS_TYPE_CHAR )
472- RETURN_ERROR (PS_ERROR_EXPECTED_CHAR )
473- c .min = min_value .data .c ;
474- }
475- else if (min_base == PS_TYPE_INTEGER )
476- {
477- if (ps_value_get_type (& min_value ) != PS_TYPE_INTEGER )
478- RETURN_ERROR (PS_ERROR_EXPECTED_INTEGER )
479- i .min = min_value .data .i ;
480- }
481- else if (min_base == PS_TYPE_UNSIGNED )
482- {
483- if (ps_value_get_type (& min_value ) != PS_TYPE_UNSIGNED )
484- RETURN_ERROR (PS_ERROR_EXPECTED_UNSIGNED )
485- u .min = min_value .data .u ;
486- }
487- else if (min_base == PS_TYPE_ENUM )
488- {
489- if (ps_value_get_type (& min_value ) != PS_TYPE_ENUM )
490- RETURN_ERROR (PS_ERROR_EXPECTED_ENUM )
491- e .min = min_value .data .u ;
492- }
493- else
494- RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
516+ TRACE_ERROR ("MIN1" )
517+ if (!ps_visit_type_reference_subrange_min_or_max (interpreter , mode , & min_value , & min_base , & c , & i , & u , & e , true))
518+ TRACE_ERROR ("MIN2" )
495519
496520 // Parse '..'
497521 EXPECT_TOKEN (PS_TOKEN_RANGE )
498522 READ_NEXT_TOKEN
499523
500524 // Parse max value of subrange as a constant expression
501525 if (!ps_visit_constant_expression (interpreter , mode , & tmp_value ))
502- TRACE_ERROR ("MAX" );
503- // ps_value_debug(stderr, "==> TMP_VALUE: ", &tmp_value);
526+ TRACE_ERROR ("MAX1" );
527+ if (!ps_visit_type_reference_subrange_min_or_max (interpreter , mode , & max_value , & max_base , & c , & i , & u , & e , false))
528+ TRACE_ERROR ("MAX2" )
529+
504530 max_value .type = min_value .type ;
505531 if (!ps_interpreter_copy_value (interpreter , & tmp_value , & max_value ))
506532 TRACE_ERROR ("COPY" )
0 commit comments