@@ -598,29 +598,43 @@ bool ps_visit_type_reference_subrange(ps_interpreter *interpreter, ps_interprete
598598bool ps_visit_type_reference_array (ps_interpreter * interpreter , ps_interpreter_mode mode , ps_symbol * * type_symbol ,
599599 const char * type_name )
600600{
601- // interpreter->debug = DEBUG_VERBOSE;
602601 VISIT_BEGIN ("TYPE_REFERENCE_ARRAY" , "" );
603602
604- ps_symbol * subrange = NULL ;
603+ ps_symbol * subranges [8 ] = {0 };
604+ int dimensions = 0 ;
605605 ps_symbol * item_type = NULL ;
606+ ps_symbol * subrange = NULL ;
606607
607- // ARRAY
608+ // ' ARRAY'
608609 if (lexer -> current_token .type != PS_TOKEN_ARRAY )
609610 RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
610611 READ_NEXT_TOKEN
611612 // '['
612613 if (lexer -> current_token .type != PS_TOKEN_LEFT_BRACKET )
613614 RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
614615 READ_NEXT_TOKEN
615- // SUBRANGE (LOW '..' HIGH)
616- if (!ps_visit_type_reference (interpreter , mode , & subrange , NULL ))
617- TRACE_ERROR ("DIMENSION ")
618- // Dimension *must* be a subrange
619- if (subrange - > kind != PS_SYMBOL_KIND_TYPE_DEFINITION || subrange - > value - > data .t - > type != PS_TYPE_SUBRANGE )
620- RETURN_ERROR (PS_ERROR_EXPECTED_SUBRANGE )
621- // ']'
622- if (lexer - > current_token .type != PS_TOKEN_RIGHT_BRACKET )
616+ do
617+ {
618+ // SUBRANGE (LOW '..' HIGH)
619+ if (!ps_visit_type_reference (interpreter , mode , & subrange , NULL ))
620+ TRACE_ERROR ("DIMENSION" )
621+ // Dimension *must* be a subrange
622+ if (subrange -> kind != PS_SYMBOL_KIND_TYPE_DEFINITION || subrange -> value -> data .t -> type != PS_TYPE_SUBRANGE )
623+ RETURN_ERROR (PS_ERROR_EXPECTED_SUBRANGE )
624+ subranges [dimensions ] = subrange ;
625+ dimensions += 1 ;
626+ // ',' ?
627+ if (lexer -> current_token .type == PS_TOKEN_COMMA )
628+ {
629+ if (dimensions == 8 )
630+ RETURN_ERROR (PS_ERROR_TOO_MANY_DIMENSIONS )
631+ continue ;
632+ }
633+ // ']'
634+ if (lexer -> current_token .type == PS_TOKEN_RIGHT_BRACKET )
635+ break ;
623636 RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
637+ } while (true);
624638 READ_NEXT_TOKEN
625639 // 'OF'
626640 if (lexer -> current_token .type != PS_TOKEN_OF )
@@ -641,8 +655,15 @@ bool ps_visit_type_reference_array(ps_interpreter *interpreter, ps_interpreter_m
641655 type_def = ps_type_definition_alloc (PS_TYPE_ARRAY , PS_TYPE_ARRAY );
642656 if (type_def == NULL )
643657 RETURN_ERROR (PS_ERROR_OUT_OF_MEMORY )
644- type_def -> def .a .subrange = subrange ;
658+ type_def -> def .a .subranges = ps_memory_calloc (PS_MEMORY_TYPE , dimensions , sizeof (ps_symbol * ));
659+ if (type_def -> def .a .subranges == NULL )
660+ {
661+ ps_type_definition_free (type_def );
662+ RETURN_ERROR (PS_ERROR_OUT_OF_MEMORY );
663+ }
664+ memccpy (type_def -> def .a .subranges , subranges , dimensions * sizeof (ps_symbol * ));
645665 type_def -> def .a .item_type = item_type ;
666+ type_def -> def .a .dimensions = dimensions ;
646667 // Register new type definition in symbol table
647668 if (!ps_type_definition_register (interpreter , mode , name , type_def , type_symbol ))
648669 RETURN_ERROR (interpreter -> error )
0 commit comments