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: 37 39 94.9 %
Date: 2024-04-19 03:43:27 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        5350 : 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        5350 :   data::data_expression_vector result;
      33        5350 :   auto i = parameters.begin();
      34        5350 :   auto j = expected_sorts.begin();
      35        8994 :   for (; i != parameters.end(); ++i, ++j)
      36             :   {
      37             :     try
      38             :     {
      39        3781 :       result.push_back(typechecker.typecheck_data_expression(*i, *j, variable_context));
      40             :     }
      41         137 :     catch (mcrl2::runtime_error& e)
      42             :     {
      43         274 :       return std::make_tuple(false, data::data_expression_vector(), std::string(e.what()));
      44         137 :     }
      45             :   }
      46       10426 :   return std::make_tuple(true, result, std::string(""));
      47        5350 : }
      48             : 
      49             : inline
      50        5214 : 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        5214 :   std::vector<data::data_expression_vector> matches;
      59        5214 :   std::vector<std::string> match_errors;
      60       10564 :   for (const data::sort_expression_list& sorts: possible_parameter_sorts)
      61             :   {
      62        5350 :     auto p = match_action_parameters(parameters, sorts, variable_context, typechecker);
      63        5350 :     if (std::get<0>(p))
      64             :     {
      65        5213 :       matches.push_back(std::get<1>(p));
      66             :     }
      67             :     else
      68             :     {
      69         137 :       match_errors.push_back(std::get<2>(p));
      70             :     }
      71        5350 :   }
      72        5214 :   if (matches.empty())
      73             :   {
      74           1 :     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           2 :     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           1 :   }
      93        5213 :   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        5213 :   const data::data_expression_vector& typechecked_parameters = matches.front();
      98       10426 :   return { data::data_expression_list(typechecked_parameters.begin(), typechecked_parameters.end()), data::detail::parameter_sorts(typechecked_parameters) };
      99        5215 : }
     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.14