@@ -381,7 +381,7 @@ string_dependenciest::get_node(const array_string_exprt &e)
381
381
if (!entry_inserted.second )
382
382
return string_nodes[entry_inserted.first ->second ];
383
383
384
- string_nodes.emplace_back ();
384
+ string_nodes.emplace_back (e, entry_inserted. first -> second );
385
385
return string_nodes.back ();
386
386
}
387
387
@@ -485,54 +485,6 @@ static void add_dependency_to_string_subexprs(
485
485
}
486
486
}
487
487
488
- string_dependenciest::node_indext string_dependenciest::size () const
489
- {
490
- return builtin_function_nodes.size () + string_nodes.size ();
491
- }
492
-
493
- // / Convert an index of a string node in `string_nodes` to the node_indext for
494
- // / the same node
495
- static std::size_t string_index_to_node_index (const std::size_t string_index)
496
- {
497
- return 2 * string_index + 1 ;
498
- }
499
-
500
- // / Convert an index of a builtin function node to the node_indext for
501
- // / the same node
502
- static std::size_t
503
- builtin_function_index_to_node_index (const std::size_t builtin_index)
504
- {
505
- return 2 * builtin_index;
506
- }
507
-
508
- string_dependenciest::node_indext
509
- string_dependenciest::node_index (const builtin_function_nodet &n) const
510
- {
511
- return builtin_function_index_to_node_index (n.index );
512
- }
513
-
514
- string_dependenciest::node_indext
515
- string_dependenciest::node_index (const array_string_exprt &s) const
516
- {
517
- return string_index_to_node_index (node_index_pool.at (s));
518
- }
519
-
520
- optionalt<string_dependenciest::builtin_function_nodet>
521
- string_dependenciest::get_builtin_function_node (node_indext i) const
522
- {
523
- if (i % 2 == 0 )
524
- return builtin_function_nodet (i / 2 );
525
- return {};
526
- }
527
-
528
- optionalt<string_dependenciest::string_nodet>
529
- string_dependenciest::get_string_node (node_indext i) const
530
- {
531
- if (i % 2 == 1 && i / 2 < string_nodes.size ())
532
- return string_nodes[i / 2 ];
533
- return {};
534
- }
535
-
536
488
optionalt<exprt> string_dependenciest::eval (
537
489
const array_string_exprt &s,
538
490
const std::function<exprt(const exprt &)> &get_value) const
@@ -601,50 +553,58 @@ bool add_node(
601
553
}
602
554
603
555
void string_dependenciest::for_each_successor (
604
- const std:: size_t &i ,
605
- const std::function<void (const std:: size_t &)> &f) const
556
+ const nodet &node ,
557
+ const std::function<void (const nodet &)> &f) const
606
558
{
607
- if (const auto &builtin_function_node = get_builtin_function_node (i) )
559
+ if (node. kind == nodet::BUILTIN )
608
560
{
609
- const string_builtin_functiont &p =
610
- get_builtin_function (*builtin_function_node);
611
- std::for_each (
612
- p. string_arguments (). begin (),
613
- p. string_arguments (). end (),
614
- [&]( const array_string_exprt &s) { f ( node_index (s)); });
561
+ const auto &builtin = builtin_function_nodes[node. index ];
562
+ for ( const auto &s : builtin-> string_arguments ())
563
+ {
564
+ if ( const auto node = node_at (s))
565
+ f ( nodet (*node));
566
+ }
615
567
}
616
- else if (const auto &s = get_string_node (i) )
568
+ else if (node. kind == nodet::STRING )
617
569
{
570
+ const auto &s_node = string_nodes[node.index ];
618
571
std::for_each (
619
- s-> dependencies .begin (),
620
- s-> dependencies .end (),
621
- [&](const builtin_function_nodet &p) { f (node_index (p)); });
572
+ s_node. dependencies .begin (),
573
+ s_node. dependencies .end (),
574
+ [&](const builtin_function_nodet &p) { f (nodet (p)); });
622
575
}
623
576
else
624
577
UNREACHABLE;
625
578
}
626
579
580
+ void string_dependenciest::for_each_node (
581
+ const std::function<void (const nodet &)> &f) const
582
+ {
583
+ for (const auto string_node : string_nodes)
584
+ f (nodet (string_node));
585
+ for (std::size_t i = 0 ; i < builtin_function_nodes.size (); ++i)
586
+ f (nodet (builtin_function_nodet (i)));
587
+ }
588
+
627
589
void string_dependenciest::output_dot (std::ostream &stream) const
628
590
{
629
- const auto for_each_node =
630
- [&](const std::function<void (const std::size_t &)> &f) { // NOLINT
631
- for (std::size_t i = 0 ; i < string_nodes.size (); ++i)
632
- f (string_index_to_node_index (i));
633
- for (std::size_t i = 0 ; i < builtin_function_nodes.size (); ++i)
634
- f (builtin_function_index_to_node_index (i));
591
+ const auto for_each =
592
+ [&](const std::function<void (const nodet &)> &f) { // NOLINT
593
+ for_each_node (f);
635
594
};
636
-
637
- const auto for_each_succ = [&](
638
- const std::size_t &i,
639
- const std::function<void (const std::size_t &)> &f) { // NOLINT
640
- for_each_successor (i, f);
641
- };
642
-
643
- const auto node_to_string = [&](const std::size_t &i) { // NOLINT
644
- return std::to_string (i);
595
+ const auto for_each_succ =
596
+ [&](const nodet &n, const std::function<void (const nodet &)> &f) { // NOLINT
597
+ for_each_successor (n, f);
598
+ };
599
+ const auto node_to_string = [&](const nodet &n) { // NOLINT
600
+ std::stringstream ostream;
601
+ if (n.kind == nodet::BUILTIN)
602
+ ostream << " builtin_" << n.index ;
603
+ else
604
+ ostream << ' "' << format (string_nodes[n.index ].expr ) << ' "' ;
605
+ return ostream.str ();
645
606
};
646
607
stream << " digraph dependencies {\n " ;
647
- output_dot_generic<std::size_t >(
648
- stream, for_each_node, for_each_succ, node_to_string);
608
+ output_dot_generic<nodet>(stream, for_each, for_each_succ, node_to_string);
649
609
stream << ' }' << std::endl;
650
610
}
0 commit comments