LCOV - code coverage report
Current view: top level - process/include/mcrl2/process/detail - match_action_parameters.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 32 34 94.1 %
Date: 2020-09-22 00:46:14 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Wieger Wesselink (2016)
       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             : /// \file mcrl2/process/detail/match_action_parameters.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_PROCESS_DETAIL_MATCH_ACTION_PARAMETERS_H
      13             : #define MCRL2_PROCESS_DETAIL_MATCH_ACTION_PARAMETERS_H
      14             : 
      15             : #include "mcrl2/core/detail/print_utility.h"
      16             : #include "mcrl2/data/detail/data_utility.h"
      17             : #include "mcrl2/data/typecheck.h"
      18             : 
      19             : namespace mcrl2 {
      20             : 
      21             : namespace process {
      22             : 
      23             : namespace detail {
      24             : 
      25             : inline
      26        5635 : std::tuple<bool, data::data_expression_vector, std::string> match_action_parameters(const data::data_expression_list& parameters,
      27             :                                                                                     const data::sort_expression_list& expected_sorts,
      28             :                                                                                     const data::detail::variable_context& variable_context,
      29             :                                                                                     data::data_type_checker& typechecker
      30             :                                                                                    )
      31             : {
      32       11270 :   data::data_expression_vector result;
      33        5635 :   auto i = parameters.begin();
      34        5635 :   auto j = expected_sorts.begin();
      35       14095 :   for (; i != parameters.end(); ++i, ++j)
      36             :   {
      37             :     try
      38             :     {
      39        4534 :       result.push_back(typechecker.typecheck_data_expression(*i, *j, variable_context));
      40             :     }
      41         608 :     catch (mcrl2::runtime_error& e)
      42             :     {
      43         304 :       return std::make_tuple(false, data::data_expression_vector(), std::string(e.what()));
      44             :     }
      45             :   }
      46        5331 :   return std::make_tuple(true, result, std::string(""));
      47             : }
      48             : 
      49             : inline
      50        5332 : std::pair<data::data_expression_list, data::sort_expression_list> match_action_parameters(const data::data_expression_list& parameters,
      51             :                                                                                           const data::sorts_list& possible_parameter_sorts,
      52             :                                                                                           const data::detail::variable_context& variable_context,
      53             :                                                                                           const core::identifier_string& name,
      54             :                                                                                           const std::string& msg,
      55             :                                                                                           data::data_type_checker& typechecker
      56             :                                                                                          )
      57             : {
      58       10664 :   std::vector<data::data_expression_vector> matches;
      59       10664 :   std::vector<std::string> match_errors;
      60       10967 :   for (const data::sort_expression_list& sorts: possible_parameter_sorts)
      61             :   {
      62       11270 :     auto p = match_action_parameters(parameters, sorts, variable_context, typechecker);
      63        5635 :     if (std::get<0>(p))
      64             :     {
      65        5331 :       matches.push_back(std::get<1>(p));
      66             :     }
      67             :     else
      68             :     {
      69         304 :       match_errors.push_back(std::get<2>(p));
      70             :     }
      71             :   }
      72        5332 :   if (matches.empty())
      73             :   {
      74           2 :     std::ostringstream out;
      75           1 :     out << "Could not find a matching " << msg << " declaration for " << name << core::detail::print_arguments(parameters) << ".";
      76           1 :     auto i = possible_parameter_sorts.begin();
      77           1 :     auto j = match_errors.begin();
      78           3 :     for (; i != possible_parameter_sorts.end(); ++i, ++j)
      79             :     {
      80           1 :       out << "\n" << name << ": ";
      81           2 :       for (auto k = i->begin(); k != i->end(); ++k)
      82             :       {
      83           1 :         if (k != i->begin())
      84             :         {
      85           0 :           out << " # ";
      86             :         }
      87           1 :         out << *k;
      88             :       }
      89           1 :       out << " does not match.\n" << *j;
      90             :     }
      91           1 :     throw mcrl2::runtime_error(out.str());
      92             :   }
      93        5331 :   if (matches.size() > 1)
      94             :   {
      95           0 :     throw mcrl2::runtime_error("Multiple matching " + msg + " declarations for " + core::pp(name) + core::detail::print_arguments(parameters) + ".");
      96             :   }
      97        5331 :   const data::data_expression_vector& typechecked_parameters = matches.front();
      98       10662 :   return { data::data_expression_list(typechecked_parameters.begin(), typechecked_parameters.end()), data::detail::parameter_sorts(typechecked_parameters) };
      99             : }
     100             : 
     101             : } // namespace detail
     102             : 
     103             : } // namespace process
     104             : 
     105             : } // namespace mcrl2
     106             : 
     107             : #endif // MCRL2_PROCESS_DETAIL_MATCH_ACTION_PARAMETERS_H

Generated by: LCOV version 1.13