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

          Line data    Source code
       1             : // Author(s): Wieger Wesselink
       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/action_context.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_PROCESS_DETAIL_ACTION_CONTEXT_H
      13             : #define MCRL2_PROCESS_DETAIL_ACTION_CONTEXT_H
      14             : 
      15             : #include "mcrl2/data/typecheck.h"
      16             : #include "mcrl2/process/action_label.h"
      17             : 
      18             : namespace mcrl2 {
      19             : 
      20             : namespace process {
      21             : 
      22             : namespace detail {
      23             : 
      24        2322 : class action_context
      25             : {
      26             :   private:
      27             :     std::multimap<core::identifier_string, action_label> m_actions;
      28             : 
      29             :   public:
      30        7568 :     bool is_declared(const core::identifier_string& name) const
      31             :     {
      32        7568 :       return m_actions.find(name) != m_actions.end();
      33             :     }
      34             : 
      35             :     // Adds the elements of actions to action_map
      36             :     // Throws an exception if the sorts of the actions are not declared
      37             :     template <typename ActionLabelContainer>
      38        1145 :     void add_context_action_labels(const ActionLabelContainer& actions, const data::sort_type_checker& sort_typechecker)
      39             :     {
      40        5558 :       for (const process::action_label& a: actions)
      41             :       {
      42        8357 :         for (const data::sort_expression& s: a.sorts())
      43             :         {
      44        3944 :           sort_typechecker(s);
      45             :         }
      46             : 
      47             :         // Insert a in m_action_context; N.B. Before that check if it already exists
      48        4413 :         auto range = m_actions.equal_range(a.name());
      49        4413 :         if (range.first != m_actions.end())
      50             :         {
      51        1773 :           for (auto i = range.first; i != range.second; ++i)
      52             :           {
      53         732 :             if (i->second == a)
      54             :             {
      55           0 :               throw mcrl2::runtime_error("double declaration of action " + process::pp(a));
      56             :             }
      57             :           }
      58             :         }
      59        4413 :         m_actions.insert(range.first, std::make_pair(a.name(), a));
      60             :       }
      61        1145 :     }
      62             : 
      63         855 :     data::sorts_list matching_action_sorts(const core::identifier_string& name) const
      64             :     {
      65         855 :       auto range = m_actions.equal_range(name);
      66         855 :       assert(range.first != m_actions.end());
      67        1710 :       data::sorts_list result;
      68        2016 :       for (auto k = range.first; k != range.second; ++k)
      69             :       {
      70        1161 :         const action_label& a = k->second;
      71        1161 :         result.push_front(a.sorts());
      72             :       }
      73        1710 :       return atermpp::reverse(result);
      74             :     }
      75             : 
      76        3278 :     data::sorts_list matching_action_sorts(const core::identifier_string& name, const data::data_expression_list& parameters) const
      77             :     {
      78        6556 :       data::sorts_list result;
      79        3278 :       auto range = m_actions.equal_range(name);
      80        7162 :       for (auto k = range.first; k != range.second; ++k)
      81             :       {
      82        3884 :         const action_label& a = k->second;
      83        3884 :         if (a.sorts().size() == parameters.size())
      84             :         {
      85        3581 :           result.push_front(a.sorts());
      86             :         }
      87             :       }
      88        6556 :       return atermpp::reverse(result);
      89             :     }
      90             : 
      91         958 :     void clear()
      92             :     {
      93         958 :       m_actions.clear();
      94         958 :     }
      95             : };
      96             : 
      97             : } // namespace detail
      98             : 
      99             : } // namespace process
     100             : 
     101             : } // namespace mcrl2
     102             : 
     103             : #endif // MCRL2_PROCESS_DETAIL_ACTION_CONTEXT_H

Generated by: LCOV version 1.13