Skip to content

Extract equation_symbol_mapping to its own files #4692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/solvers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ SRC = $(BOOLEFORCE_SRC) \
refinement/refine_arithmetic.cpp \
refinement/refine_arrays.cpp \
strings/array_pool.cpp \
strings/equation_symbol_mapping.cpp \
strings/string_builtin_function.cpp \
strings/string_refinement.cpp \
strings/string_refinement_util.cpp \
Expand Down
27 changes: 27 additions & 0 deletions src/solvers/strings/equation_symbol_mapping.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************\
Module: String solver
Author: Diffblue Ltd.
\*******************************************************************/

#include "equation_symbol_mapping.h"

void equation_symbol_mappingt::add(const std::size_t i, const exprt &expr)
{
equations_containing[expr].push_back(i);
strings_in_equation[i].push_back(expr);
}

std::vector<exprt>
equation_symbol_mappingt::find_expressions(const std::size_t i)
{
return strings_in_equation[i];
}

std::vector<std::size_t>
equation_symbol_mappingt::find_equations(const exprt &expr)
{
return equations_containing[expr];
}
43 changes: 43 additions & 0 deletions src/solvers/strings/equation_symbol_mapping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************\

Module: String solver

Author: Diffblue Ltd.

\*******************************************************************/

#ifndef CPROVER_SOLVERS_STRINGS_EQUATION_SYMBOL_MAPPING_H
#define CPROVER_SOLVERS_STRINGS_EQUATION_SYMBOL_MAPPING_H

#include <map>
#include <unordered_map>

#include <util/expr.h>

/// Maps equation to expressions contained in them and conversely expressions to
/// equations that contain them. This can be used on a subset of expressions
/// which interests us, in particular strings. Equations are identified by an
/// index of type `std::size_t` for more efficient insertion and lookup.
class equation_symbol_mappingt
{
public:
/// Record the fact that equation `i` contains expression `expr`
void add(const std::size_t i, const exprt &expr);

/// \param i: index corresponding to an equation
/// \return vector of expressions contained in the equation with the given
/// index `i`
std::vector<exprt> find_expressions(const std::size_t i);

/// \param expr: an expression
/// \return vector of equations containing the given expression `expr`
std::vector<std::size_t> find_equations(const exprt &expr);

private:
/// Record index of the equations that contain a given expression
std::map<exprt, std::vector<std::size_t>> equations_containing;
/// Record expressions that are contained in the equation with the given index
std::unordered_map<std::size_t, std::vector<exprt>> strings_in_equation;
};

#endif // CPROVER_SOLVERS_STRINGS_EQUATION_SYMBOL_MAPPING_H
4 changes: 3 additions & 1 deletion src/solvers/strings/string_refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Author: Alberto Griggio, [email protected]
/// Ghosh.

#include "string_refinement.h"
#include "string_constraint_instantiation.h"

#include <iomanip>
#include <numeric>
Expand All @@ -30,6 +29,9 @@ Author: Alberto Griggio, [email protected]
#include <util/magic.h>
#include <util/simplify_expr.h>

#include "equation_symbol_mapping.h"
#include "string_constraint_instantiation.h"

static bool is_valid_string_constraint(
messaget::mstreamt &stream,
const namespacet &ns,
Expand Down
18 changes: 0 additions & 18 deletions src/solvers/strings/string_refinement_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,6 @@ array_exprt interval_sparse_arrayt::concretize(
return array;
}

void equation_symbol_mappingt::add(const std::size_t i, const exprt &expr)
{
equations_containing[expr].push_back(i);
strings_in_equation[i].push_back(expr);
}

std::vector<exprt>
equation_symbol_mappingt::find_expressions(const std::size_t i)
{
return strings_in_equation[i];
}

std::vector<std::size_t>
equation_symbol_mappingt::find_equations(const exprt &expr)
{
return equations_containing[expr];
}

/// Construct a string_builtin_functiont object from a function application
/// \return a unique pointer to the created object
static std::unique_ptr<string_builtin_functiont> to_string_builtin_function(
Expand Down
26 changes: 0 additions & 26 deletions src/solvers/strings/string_refinement_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,32 +132,6 @@ class interval_sparse_arrayt final : public sparse_arrayt
}
};

/// Maps equation to expressions contained in them and conversely expressions to
/// equations that contain them. This can be used on a subset of expressions
/// which interests us, in particular strings. Equations are identified by an
/// index of type `std::size_t` for more efficient insertion and lookup.
class equation_symbol_mappingt
{
public:
/// Record the fact that equation `i` contains expression `expr`
void add(const std::size_t i, const exprt &expr);

/// \param i: index corresponding to an equation
/// \return vector of expressions contained in the equation with the given
/// index `i`
std::vector<exprt> find_expressions(const std::size_t i);

/// \param expr: an expression
/// \return vector of equations containing the given expression `expr`
std::vector<std::size_t> find_equations(const exprt &expr);

private:
/// Record index of the equations that contain a given expression
std::map<exprt, std::vector<std::size_t>> equations_containing;
/// Record expressions that are contained in the equation with the given index
std::unordered_map<std::size_t, std::vector<exprt>> strings_in_equation;
};

/// Keep track of dependencies between strings.
/// Each string points to the builtin_function calls on which it depends.
/// Each builtin_function points to the strings on which the result depends.
Expand Down