@@ -363,7 +363,7 @@ string_dependenciest::get_node(const array_string_exprt &e)
363363 if (!entry_inserted.second )
364364 return string_nodes[entry_inserted.first ->second ];
365365
366- string_nodes.emplace_back ();
366+ string_nodes.emplace_back (e, entry_inserted. first -> second );
367367 return string_nodes.back ();
368368}
369369
@@ -467,54 +467,6 @@ static void add_dependency_to_string_subexprs(
467467 }
468468}
469469
470- string_dependenciest::node_indext string_dependenciest::size () const
471- {
472- return builtin_function_nodes.size () + string_nodes.size ();
473- }
474-
475- // / Convert an index of a string node in `string_nodes` to the node_indext for
476- // / the same node
477- static std::size_t string_index_to_node_index (const std::size_t string_index)
478- {
479- return 2 * string_index + 1 ;
480- }
481-
482- // / Convert an index of a builtin function node to the node_indext for
483- // / the same node
484- static std::size_t
485- builtin_function_index_to_node_index (const std::size_t builtin_index)
486- {
487- return 2 * builtin_index;
488- }
489-
490- string_dependenciest::node_indext
491- string_dependenciest::node_index (const builtin_function_nodet &n) const
492- {
493- return builtin_function_index_to_node_index (n.index );
494- }
495-
496- string_dependenciest::node_indext
497- string_dependenciest::node_index (const array_string_exprt &s) const
498- {
499- return string_index_to_node_index (node_index_pool.at (s));
500- }
501-
502- optionalt<string_dependenciest::builtin_function_nodet>
503- string_dependenciest::get_builtin_function_node (node_indext i) const
504- {
505- if (i % 2 == 0 )
506- return builtin_function_nodet (i / 2 );
507- return {};
508- }
509-
510- optionalt<string_dependenciest::string_nodet>
511- string_dependenciest::get_string_node (node_indext i) const
512- {
513- if (i % 2 == 1 && i / 2 < string_nodes.size ())
514- return string_nodes[i / 2 ];
515- return {};
516- }
517-
518470optionalt<exprt> string_dependenciest::eval (
519471 const array_string_exprt &s,
520472 const std::function<exprt(const exprt &)> &get_value) const
@@ -583,50 +535,57 @@ bool add_node(
583535}
584536
585537void string_dependenciest::for_each_successor (
586- const std:: size_t &i ,
587- const std::function<void (const std:: size_t &)> &f) const
538+ const nodet &node ,
539+ const std::function<void (const nodet &)> &f) const
588540{
589- if (const auto &builtin_function_node = get_builtin_function_node (i) )
541+ if (node. kind == nodet::BUILTIN )
590542 {
591- const string_builtin_functiont &p =
592- get_builtin_function (*builtin_function_node);
593- std::for_each (
594- p. string_arguments (). begin (),
595- p. string_arguments (). end (),
596- [&]( const array_string_exprt &s) { f ( node_index (s)); });
543+ const auto &builtin = builtin_function_nodes[node. index ];
544+ for ( const auto &s : builtin-> string_arguments ())
545+ {
546+ if ( const auto node = node_at (s))
547+ f ( nodet (*node));
548+ }
597549 }
598- else if (const auto &s = get_string_node (i) )
550+ else if (node. kind == nodet::STRING )
599551 {
552+ const auto &s_node = string_nodes[node.index ];
600553 std::for_each (
601- s-> dependencies .begin (),
602- s-> dependencies .end (),
603- [&](const builtin_function_nodet &p) { f (node_index (p)); });
554+ s_node. dependencies .begin (),
555+ s_node. dependencies .end (),
556+ [&](const builtin_function_nodet &p) { f (nodet (p)); });
604557 }
605558 else
606559 UNREACHABLE;
607560}
608561
562+ void string_dependenciest::for_each_node (
563+ const std::function<void (const nodet &)> &f) const
564+ {
565+ for (const auto string_node : string_nodes)
566+ f (nodet (string_node));
567+ for (std::size_t i = 0 ; i < builtin_function_nodes.size (); ++i)
568+ f (nodet (builtin_function_nodet (i)));
569+ }
570+
609571void string_dependenciest::output_dot (std::ostream &stream) const
610572{
611- const auto for_each_node =
612- [&](const std::function<void (const std::size_t &)> &f) { // NOLINT
613- for (std::size_t i = 0 ; i < string_nodes.size (); ++i)
614- f (string_index_to_node_index (i));
615- for (std::size_t i = 0 ; i < builtin_function_nodes.size (); ++i)
616- f (builtin_function_index_to_node_index (i));
573+ const auto for_each = [&](const std::function<void (const nodet &)> &f) { // NOLINT
574+ for_each_node (f);
617575 };
618-
619- const auto for_each_succ = [&](
620- const std::size_t &i,
621- const std::function<void (const std::size_t &)> &f) { // NOLINT
622- for_each_successor (i, f);
623- };
624-
625- const auto node_to_string = [&](const std::size_t &i) { // NOLINT
626- return std::to_string (i);
576+ const auto for_each_succ =
577+ [&](const nodet &n, const std::function<void (const nodet &)> &f) { // NOLINT
578+ for_each_successor (n, f);
579+ };
580+ const auto node_to_string = [&](const nodet &n) { // NOLINT
581+ std::stringstream ostream;
582+ if (n.kind == nodet::BUILTIN)
583+ ostream << " builtin_" << n.index ;
584+ else
585+ ostream << ' "' << format (string_nodes[n.index ].expr ) << ' "' ;
586+ return ostream.str ();
627587 };
628588 stream << " digraph dependencies {\n " ;
629- output_dot_generic<std::size_t >(
630- stream, for_each_node, for_each_succ, node_to_string);
589+ output_dot_generic<nodet>(stream, for_each, for_each_succ, node_to_string);
631590 stream << ' }' << std::endl;
632591}
0 commit comments