LCOV - code coverage report
Current view: top level - data/source - data_io.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 7 32 21.9 %
Date: 2020-02-28 00:44:21 Functions: 3 7 42.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Maurice Laveaux
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : 
      10             : #include "mcrl2/data/data_io.h"
      11             : 
      12             : #include "mcrl2/atermpp/algorithm.h"
      13             : #include "mcrl2/data/data_specification.h"
      14             : 
      15             : using namespace mcrl2;
      16             : using namespace mcrl2::data;
      17             : 
      18           0 : atermpp::aterm_appl remove_index_impl(const atermpp::aterm_appl& x)
      19             : {
      20           0 :   if (x.function() == core::detail::function_symbol_DataVarId())
      21             :   {
      22           0 :     return atermpp::aterm_appl(core::detail::function_symbol_DataVarIdNoIndex(), x.begin(), --x.end());
      23             :   }
      24           0 :   else if (x.function() == core::detail::function_symbol_OpId())
      25             :   {
      26           0 :     return atermpp::aterm_appl(core::detail::function_symbol_OpIdNoIndex(), x.begin(), --x.end());
      27             :   }
      28           0 :   return x;
      29             : }
      30             : 
      31           0 : atermpp::aterm_appl add_index_impl(const atermpp::aterm_appl& x)
      32             : {
      33           0 :   if (x.function() == core::detail::function_symbol_DataVarIdNoIndex())
      34             :   {
      35           0 :     const data::variable& y = atermpp::down_cast<const data::variable>(x);
      36           0 :     std::size_t index = core::index_traits<data::variable, data::variable_key_type, 2>::insert(std::make_pair(y.name(), y.sort()));
      37           0 :     return atermpp::aterm_appl(core::detail::function_symbol_DataVarId(), x[0], x[1], atermpp::aterm_int(index));
      38             :   }
      39           0 :   else if (x.function() == core::detail::function_symbol_OpIdNoIndex())
      40             :   {
      41           0 :     const data::function_symbol& y = atermpp::down_cast<const data::function_symbol>(x);
      42           0 :     std::size_t index = core::index_traits<data::function_symbol, data::function_symbol_key_type, 2>::insert(std::make_pair(y.name(), y.sort()));
      43           0 :     return atermpp::aterm_appl(core::detail::function_symbol_OpId(), x[0], x[1], atermpp::aterm_int(index));
      44             :   }
      45           0 :   return x;
      46             : }
      47             : 
      48        1181 : atermpp::aterm_appl detail::data_specification_to_aterm(const data_specification& s)
      49             : {
      50             :   return atermpp::aterm_appl(core::detail::function_symbol_DataSpec(),
      51        2362 :            atermpp::aterm_appl(core::detail::function_symbol_SortSpec(), atermpp::aterm_list(s.user_defined_sorts().begin(),s.user_defined_sorts().end()) +
      52        2362 :                               atermpp::aterm_list(s.user_defined_aliases().begin(),s.user_defined_aliases().end())),
      53        2362 :            atermpp::aterm_appl(core::detail::function_symbol_ConsSpec(), atermpp::aterm_list(s.user_defined_constructors().begin(),s.user_defined_constructors().end())),
      54        2362 :            atermpp::aterm_appl(core::detail::function_symbol_MapSpec(), atermpp::aterm_list(s.user_defined_mappings().begin(),s.user_defined_mappings().end())),
      55        3543 :            atermpp::aterm_appl(core::detail::function_symbol_DataEqnSpec(), atermpp::aterm_list(s.user_defined_equations().begin(),s.user_defined_equations().end())));
      56             : }
      57             : 
      58             : inline
      59             : atermpp::aterm add_index(const atermpp::aterm& x)
      60             : {
      61             :   return atermpp::bottom_up_replace(x, add_index_impl);
      62             : }
      63             : 
      64             : inline
      65             : atermpp::aterm remove_index(const atermpp::aterm& x)
      66             : {
      67             :   return atermpp::bottom_up_replace(x, remove_index_impl);
      68             : }
      69             : 
      70           0 : atermpp::aterm_istream& data::operator>>(atermpp::aterm_istream& stream, data_specification& spec)
      71             : {
      72           0 :   atermpp::aterm t = stream.get();
      73             : 
      74           0 :   if (!t.type_is_appl() || !is_data_specification(atermpp::down_cast<const atermpp::aterm_appl>(t)))
      75             :   {
      76           0 :     throw mcrl2::runtime_error("Input stream does not contain a data specification");
      77             :   }
      78             : 
      79           0 :   spec = data_specification(atermpp::down_cast<atermpp::aterm_appl>(t));
      80           0 :   return stream;
      81             : }
      82             : 
      83           0 : atermpp::aterm_ostream& data::operator<<(atermpp::aterm_ostream& stream, const data_specification& spec)
      84             : {
      85           0 :   stream << remove_index_impl << detail::data_specification_to_aterm(spec);
      86           0 :   return stream;
      87         366 : }

Generated by: LCOV version 1.13