mCRL2
Loading...
Searching...
No Matches
resolve_name_clashes.h
Go to the documentation of this file.
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/pbes/resolve_name_clashes.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_PBES_RESOLVE_NAME_CLASHES_H
13#define MCRL2_PBES_RESOLVE_NAME_CLASHES_H
14
15#include "mcrl2/lps/resolve_name_clashes.h"
16#include "mcrl2/pbes/replace.h"
17#include "mcrl2/pbes/srf_pbes.h"
18
19
20
21namespace mcrl2::pbes_system {
22
23namespace detail {
24
25template<bool allow_ce>
26inline
27void resolve_summand_variable_name_clashes(pre_srf_summand<allow_ce>& summand, const std::set<core::identifier_string>& process_parameter_names, data::set_identifier_generator& generator)
28{
29 const data::variable_list& summation_variables = summand.parameters();
30 std::set<core::identifier_string> names = lps::detail::variable_name_clashes(summation_variables, process_parameter_names);
31 if (!names.empty())
32 {
33 data::mutable_map_substitution<> sigma;
34 for (const data::variable& v: summation_variables)
35 {
36 if (process_parameter_names.find(v.name()) != process_parameter_names.end())
37 {
38 sigma[v] = data::variable(generator(v.name()), v.sort());
39 }
40 }
41
42 summand.parameters() = lps::replace_all_variables(summand.parameters(), sigma);
43
44 if constexpr (allow_ce)
45 {
46 // Replace on pbes_expressions
47 summand.condition() = pbes_system::replace_all_variables(summand.condition(), sigma);
48 }
49 else
50 {
51 // Replace on data expressions.
52 summand.condition() = lps::replace_all_variables(summand.condition(), sigma);
53 }
54
55 summand.variable() = pbes_system::replace_all_variables(summand.variable(), sigma);
56 }
57}
58
59} // namespace detail
60
61/// \brief Renames summand variables such that there are no name clashes between summand variables and process parameters
62template<bool allow_ce>
63inline
64void resolve_summand_variable_name_clashes(detail::pre_srf_pbes<allow_ce>& pbesspec, const data::variable_list& process_parameters)
65{
66 std::set<core::identifier_string> process_parameter_names = lps::detail::variable_names(process_parameters);
67
69
70 // Here we cannot yet convert the full srf_pbes to pbes since it's not well typed, so instead find the identifiers separately.
71 for (const detail::pre_srf_equation<allow_ce>& eq : pbesspec.equations())
72 {
73 generator.add_identifiers(pbes_system::find_identifiers(eq.to_pbes()));
74 }
75 generator.add_identifiers(pbes_system::find_identifiers(pbesspec.initial_state()));
76 generator.add_identifiers(data::function_and_mapping_identifiers(pbesspec.data()));
77
78 for (auto& equation: pbesspec.equations())
79 {
80 for (auto& summand: equation.summands())
81 {
82 detail::resolve_summand_variable_name_clashes(summand, process_parameter_names, generator);
83 }
84 }
85}
86
87} // namespace mcrl2::pbes_system
88
89
90
91#endif // MCRL2_PBES_RESOLVE_NAME_CLASHES_H
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
void resolve_summand_variable_name_clashes(pre_srf_summand< allow_ce > &summand, const std::set< core::identifier_string > &process_parameter_names, data::set_identifier_generator &generator)
void resolve_summand_variable_name_clashes(detail::pre_srf_pbes< allow_ce > &pbesspec, const data::variable_list &process_parameters)
Renames summand variables such that there are no name clashes between summand variables and process p...