@@ -331,7 +331,12 @@ struct action<semicolon>
331
331
{ \
332
332
std::cout << " load_type_action: " << typeid (Rule).name () << " " \
333
333
<< in.string () << std::endl; \
334
+ \
334
335
state[" type" ] = std::string (#id); \
336
+ if (state[" type" ] == " string" || state[" type" ] == " wstring" ) \
337
+ { \
338
+ state.erase (" parsing_string" ); \
339
+ } \
335
340
} \
336
341
};
337
342
@@ -424,57 +429,53 @@ struct action<open_bracket>
424
429
};
425
430
426
431
template <>
427
- struct action <positive_int_const >
432
+ struct action <fixed_array_size >
428
433
{
429
434
template <typename Input>
430
435
static void apply (
431
- const Input& in ,
432
- Context* ctx,
436
+ const Input& /* in */ ,
437
+ Context* /* ctx*/ ,
433
438
std::map<std::string, std::string>& state,
434
439
std::vector<traits<DynamicData>::ref_type>& operands)
435
440
{
436
- Module& module = ctx->module ();
437
- std::string const_value = in.string ();
438
-
439
- if (state.count (" arithmetic_expr" ))
441
+ DynamicData::_ref_type xdata;
442
+ if (!operands.empty ())
440
443
{
441
- DynamicData::_ref_type xdata;
444
+ xdata = operands.back ();
445
+ operands.pop_back ();
442
446
if (!operands.empty ())
443
447
{
444
- xdata = operands.back ();
445
- operands.pop_back ();
446
- if (!operands.empty ())
447
- {
448
- throw std::runtime_error (" Finished const expression parsing with non-empty operands stack." );
449
- }
448
+ throw std::runtime_error (" Finished array size parsing with non-empty operands stack." );
450
449
}
451
- else if (module.has_constant (const_value))
450
+
451
+ int64_t value;
452
+ xdata->get_int64_value (value, MEMBER_ID_INVALID);
453
+ if (value <= 0 )
452
454
{
453
- xdata = module. constant (const_value );
455
+ throw std::runtime_error ( " Array size is non-positive: " + std::to_string (value) );
454
456
}
455
- else
457
+
458
+ // Append the current array size to `current_array_sizes`, separating multiple dimensions with commas
459
+ if (state[" current_array_sizes" ].empty ())
456
460
{
457
- throw std::runtime_error ( " Unknown const expression: " + const_value );
461
+ state[ " current_array_sizes " ] = std::to_string (value );
458
462
}
459
-
460
- int64_t value;
461
- xdata->get_int64_value (value, MEMBER_ID_INVALID);
462
- if (value < 0 )
463
+ else
463
464
{
464
- throw std::runtime_error ( " Size value is negative: " + std::to_string (value) );
465
+ state[ " current_array_sizes " ] += " , " + std::to_string (value);
465
466
}
466
- state[" positive_int_const" ] = std::to_string (value);
467
467
}
468
468
else
469
469
{
470
- state[ " positive_int_const " ] = const_value ;
470
+ throw std::runtime_error ( " Empty operands stack while parsing fixed_array_size " ) ;
471
471
}
472
+ state.erase (" arithmetic_expr" );
472
473
}
473
474
474
475
};
475
476
476
477
template <>
477
- struct action <fixed_array_size >
478
+ struct action <kw_string >
478
479
{
479
480
template <typename Input>
480
481
static void apply (
@@ -483,19 +484,40 @@ struct action<fixed_array_size>
483
484
std::map<std::string, std::string>& state,
484
485
std::vector<traits<DynamicData>::ref_type>& /* operands*/ )
485
486
{
486
- if (state.count (" positive_int_const" ))
487
+ state[" parsing_string" ] = " true" ;
488
+ }
489
+
490
+ };
491
+
492
+ template <>
493
+ struct action <kw_wstring>
494
+ {
495
+ template <typename Input>
496
+ static void apply (
497
+ const Input& /* in*/ ,
498
+ Context* /* ctx*/ ,
499
+ std::map<std::string, std::string>& state,
500
+ std::vector<traits<DynamicData>::ref_type>& /* operands*/ )
501
+ {
502
+ state[" parsing_string" ] = " true" ;
503
+ }
504
+
505
+ };
506
+
507
+ template <>
508
+ struct action <open_ang_bracket>
509
+ {
510
+ template <typename Input>
511
+ static void apply (
512
+ const Input& /* in*/ ,
513
+ Context* /* ctx*/ ,
514
+ std::map<std::string, std::string>& state,
515
+ std::vector<traits<DynamicData>::ref_type>& /* operands*/ )
516
+ {
517
+ if (state.count (" parsing_string" ) && state[" parsing_string" ] == " true" )
487
518
{
488
- // Append the current array size to `current_array_sizes`, separating multiple dimensions with commas
489
- if (state[" current_array_sizes" ].empty ())
490
- {
491
- state[" current_array_sizes" ] = state[" positive_int_const" ];
492
- }
493
- else
494
- {
495
- state[" current_array_sizes" ] += " ," + state[" positive_int_const" ];
496
- }
519
+ state[" arithmetic_expr" ] = " " ;
497
520
}
498
- state.erase (" arithmetic_expr" );
499
521
}
500
522
501
523
};
@@ -509,14 +531,32 @@ struct action<fixed_array_size>
509
531
const Input& in, \
510
532
Context* /* ctx*/ , \
511
533
std::map<std::string, std::string>& state, \
512
- std::vector<traits<DynamicData>::ref_type>& /* operands*/ ) \
534
+ std::vector<traits<DynamicData>::ref_type>& operands) \
513
535
{ \
514
536
std::cout << " load_stringsize_action: " << typeid (Rule).name () << " " \
515
537
<< in.string () << std::endl; \
516
- if (state.count (" positive_int_const" )) \
538
+ \
539
+ DynamicData::_ref_type xdata; \
540
+ if (!operands.empty ()) \
541
+ { \
542
+ xdata = operands.back (); \
543
+ operands.pop_back (); \
544
+ if (!operands.empty ()) \
545
+ { \
546
+ throw std::runtime_error (" Finished string size parsing with non-empty operands stack." ); \
547
+ } \
548
+ \
549
+ int64_t value; \
550
+ xdata->get_int64_value (value, MEMBER_ID_INVALID); \
551
+ if (value <= 0 ) \
552
+ { \
553
+ throw std::runtime_error (" String size is non-positive: " + std::to_string (value)); \
554
+ } \
555
+ state[#id] = std::to_string (value); \
556
+ } \
557
+ else \
517
558
{ \
518
- state[#id] = state[" positive_int_const" ]; \
519
- state.erase (" positive_int_const" ); \
559
+ throw std::runtime_error (" Empty operands stack while parsing string size" ); \
520
560
} \
521
561
} \
522
562
};
0 commit comments