/src/solidity/libsolidity/formal/ArraySlicePredicate.h
Line | Count | Source |
1 | | /* |
2 | | This file is part of solidity. |
3 | | |
4 | | solidity is free software: you can redistribute it and/or modify |
5 | | it under the terms of the GNU General Public License as published by |
6 | | the Free Software Foundation, either version 3 of the License, or |
7 | | (at your option) any later version. |
8 | | |
9 | | solidity is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | GNU General Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU General Public License |
15 | | along with solidity. If not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | // SPDX-License-Identifier: GPL-3.0 |
18 | | |
19 | | #include <libsolidity/formal/EncodingContext.h> |
20 | | #include <libsolidity/formal/Predicate.h> |
21 | | #include <libsolidity/formal/SymbolicVariables.h> |
22 | | |
23 | | #include <libsmtutil/Sorts.h> |
24 | | |
25 | | #include <vector> |
26 | | |
27 | | namespace solidity::frontend |
28 | | { |
29 | | |
30 | | /** |
31 | | * Contains the set of rules to compute an array slice. |
32 | | * Rules: |
33 | | * 1. end > start => ArraySliceHeader(a, b, start, end, 0) |
34 | | * 2. ArraySliceHeader(a, b, start, end, i) && i >= (end - start) => ArraySlice(a, b, start, end) |
35 | | * 3. ArraySliceHeader(a, b, start, end, i) && i >= 0 && i < (end - start) => ArraySliceLoop(a, b, start, end, i) |
36 | | * 4. ArraySliceLoop(a, b, start, end, i) && b[i] = a[start + i] => ArraySliceHeader(a, b, start, end, i + 1) |
37 | | * |
38 | | * The rule to be used by CHC is ArraySlice(a, b, start, end). |
39 | | */ |
40 | | |
41 | | struct ArraySlicePredicate |
42 | | { |
43 | | /// Contains the predicates and rules created to compute |
44 | | /// array slices for a given sort. |
45 | | struct SliceData |
46 | | { |
47 | | std::vector<Predicate const*> predicates; |
48 | | std::vector<smtutil::Expression> rules; |
49 | | }; |
50 | | |
51 | | /// @returns a flag representing whether the array slice predicates had already been created before for this sort, |
52 | | /// and the corresponding slice data. |
53 | | static std::pair<bool, SliceData const&> create(smtutil::SortPointer _sort, smt::EncodingContext& _context); |
54 | | |
55 | 10.9k | static void reset() { m_slicePredicates.clear(); } |
56 | | |
57 | | private: |
58 | | /// Maps a unique sort name to its slice data. |
59 | | static std::map<std::string, SliceData> m_slicePredicates; |
60 | | }; |
61 | | |
62 | | } |