Skip to content

Commit 7511a53

Browse files
author
Joel Allred
committed
Extract equation_symbol_mapping to its own files
Because we can.
1 parent 9bbd8b1 commit 7511a53

5 files changed

+68
-44
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************\
2+
3+
Module: String solver
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include "equation_symbol_mapping.h"
10+
11+
void equation_symbol_mappingt::add(const std::size_t i, const exprt &expr)
12+
{
13+
equations_containing[expr].push_back(i);
14+
strings_in_equation[i].push_back(expr);
15+
}
16+
17+
std::vector<exprt>
18+
equation_symbol_mappingt::find_expressions(const std::size_t i)
19+
{
20+
return strings_in_equation[i];
21+
}
22+
23+
std::vector<std::size_t>
24+
equation_symbol_mappingt::find_equations(const exprt &expr)
25+
{
26+
return equations_containing[expr];
27+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*******************************************************************\
2+
3+
Module: String solver
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_SOLVERS_STRINGS_EQUATION_SYMBOL_MAPPING_H
10+
#define CPROVER_SOLVERS_STRINGS_EQUATION_SYMBOL_MAPPING_H
11+
12+
#include <util/expr.h>
13+
14+
/// Maps equation to expressions contained in them and conversely expressions to
15+
/// equations that contain them. This can be used on a subset of expressions
16+
/// which interests us, in particular strings. Equations are identified by an
17+
/// index of type `std::size_t` for more efficient insertion and lookup.
18+
class equation_symbol_mappingt
19+
{
20+
public:
21+
/// Record the fact that equation `i` contains expression `expr`
22+
void add(const std::size_t i, const exprt &expr);
23+
24+
/// \param i: index corresponding to an equation
25+
/// \return vector of expressions contained in the equation with the given
26+
/// index `i`
27+
std::vector<exprt> find_expressions(const std::size_t i);
28+
29+
/// \param expr: an expression
30+
/// \return vector of equations containing the given expression `expr`
31+
std::vector<std::size_t> find_equations(const exprt &expr);
32+
33+
private:
34+
/// Record index of the equations that contain a given expression
35+
std::map<exprt, std::vector<std::size_t>> equations_containing;
36+
/// Record expressions that are contained in the equation with the given index
37+
std::unordered_map<std::size_t, std::vector<exprt>> strings_in_equation;
38+
};
39+
40+
#endif // CPROVER_SOLVERS_STRINGS_EQUATION_SYMBOL_MAPPING_H

src/solvers/strings/string_refinement.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Author: Alberto Griggio, [email protected]
2929
#include <util/magic.h>
3030
#include <util/simplify_expr.h>
3131

32+
#include "equation_symbol_mapping.h"
3233
#include "string_constraint_instantiation.h"
3334

3435
static bool is_valid_string_constraint(

src/solvers/strings/string_refinement_util.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,6 @@ array_exprt interval_sparse_arrayt::concretize(
183183
return array;
184184
}
185185

186-
void equation_symbol_mappingt::add(const std::size_t i, const exprt &expr)
187-
{
188-
equations_containing[expr].push_back(i);
189-
strings_in_equation[i].push_back(expr);
190-
}
191-
192-
std::vector<exprt>
193-
equation_symbol_mappingt::find_expressions(const std::size_t i)
194-
{
195-
return strings_in_equation[i];
196-
}
197-
198-
std::vector<std::size_t>
199-
equation_symbol_mappingt::find_equations(const exprt &expr)
200-
{
201-
return equations_containing[expr];
202-
}
203-
204186
/// Construct a string_builtin_functiont object from a function application
205187
/// \return a unique pointer to the created object
206188
static std::unique_ptr<string_builtin_functiont> to_string_builtin_function(

src/solvers/strings/string_refinement_util.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,32 +132,6 @@ class interval_sparse_arrayt final : public sparse_arrayt
132132
}
133133
};
134134

135-
/// Maps equation to expressions contained in them and conversely expressions to
136-
/// equations that contain them. This can be used on a subset of expressions
137-
/// which interests us, in particular strings. Equations are identified by an
138-
/// index of type `std::size_t` for more efficient insertion and lookup.
139-
class equation_symbol_mappingt
140-
{
141-
public:
142-
/// Record the fact that equation `i` contains expression `expr`
143-
void add(const std::size_t i, const exprt &expr);
144-
145-
/// \param i: index corresponding to an equation
146-
/// \return vector of expressions contained in the equation with the given
147-
/// index `i`
148-
std::vector<exprt> find_expressions(const std::size_t i);
149-
150-
/// \param expr: an expression
151-
/// \return vector of equations containing the given expression `expr`
152-
std::vector<std::size_t> find_equations(const exprt &expr);
153-
154-
private:
155-
/// Record index of the equations that contain a given expression
156-
std::map<exprt, std::vector<std::size_t>> equations_containing;
157-
/// Record expressions that are contained in the equation with the given index
158-
std::unordered_map<std::size_t, std::vector<exprt>> strings_in_equation;
159-
};
160-
161135
/// Keep track of dependencies between strings.
162136
/// Each string points to the builtin_function calls on which it depends.
163137
/// Each builtin_function points to the strings on which the result depends.

0 commit comments

Comments
 (0)