GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/strings/sequences_rewriter.h Lines: 1 1 100.0 %
Date: 2021-08-01 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Andres Noetzli, Yoni Zohar
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Rewriter for the theory of strings and sequences.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__STRINGS__SEQUENCES_REWRITER_H
19
#define CVC5__THEORY__STRINGS__SEQUENCES_REWRITER_H
20
21
#include <vector>
22
23
#include "expr/node.h"
24
#include "theory/strings/rewrites.h"
25
#include "theory/strings/sequences_stats.h"
26
#include "theory/strings/strings_entail.h"
27
#include "theory/theory_rewriter.h"
28
29
namespace cvc5 {
30
namespace theory {
31
namespace strings {
32
33
10027
class SequencesRewriter : public TheoryRewriter
34
{
35
 public:
36
  SequencesRewriter(HistogramStat<Rewrite>* statistics);
37
38
 protected:
39
  /** rewrite regular expression concatenation
40
   *
41
   * This is the entry point for post-rewriting applications of re.++.
42
   * Returns the rewritten form of node.
43
   */
44
  Node rewriteConcatRegExp(TNode node);
45
  /** rewrite regular expression star
46
   *
47
   * This is the entry point for post-rewriting applications of re.*.
48
   * Returns the rewritten form of node.
49
   */
50
  Node rewriteStarRegExp(TNode node);
51
  /** rewrite regular expression intersection/union
52
   *
53
   * This is the entry point for post-rewriting applications of re.inter and
54
   * re.union. Returns the rewritten form of node.
55
   */
56
  Node rewriteAndOrRegExp(TNode node);
57
  /** rewrite regular expression loop
58
   *
59
   * This is the entry point for post-rewriting applications of re.loop.
60
   * Returns the rewritten form of node.
61
   */
62
  Node rewriteLoopRegExp(TNode node);
63
  /** rewrite regular expression repeat
64
   *
65
   * This is the entry point for post-rewriting applications of re.repeat.
66
   * Returns the rewritten form of node.
67
   */
68
  Node rewriteRepeatRegExp(TNode node);
69
  /** rewrite regular expression option
70
   *
71
   * This is the entry point for post-rewriting applications of re.opt.
72
   * Returns the rewritten form of node.
73
   */
74
  Node rewriteOptionRegExp(TNode node);
75
  /** rewrite regular expression plus
76
   *
77
   * This is the entry point for post-rewriting applications of re.+.
78
   * Returns the rewritten form of node.
79
   */
80
  Node rewritePlusRegExp(TNode node);
81
  /** rewrite regular expression difference
82
   *
83
   * This is the entry point for post-rewriting applications of re.diff.
84
   * Returns the rewritten form of node.
85
   */
86
  Node rewriteDifferenceRegExp(TNode node);
87
  /** rewrite regular expression range
88
   *
89
   * This is the entry point for post-rewriting applications of re.range.
90
   * Returns the rewritten form of node.
91
   */
92
  Node rewriteRangeRegExp(TNode node);
93
94
  /** rewrite regular expression membership
95
   *
96
   * This is the entry point for post-rewriting applications of str.in.re
97
   * Returns the rewritten form of node.
98
   */
99
  Node rewriteMembership(TNode node);
100
101
  /** rewrite string equality extended
102
   *
103
   * This method returns a formula that is equivalent to the equality between
104
   * two strings s = t, given by node. It is called by rewriteEqualityExt.
105
   */
106
  Node rewriteStrEqualityExt(Node node);
107
  /** rewrite arithmetic equality extended
108
   *
109
   * This method returns a formula that is equivalent to the equality between
110
   * two arithmetic string terms s = t, given by node. t is called by
111
   * rewriteEqualityExt.
112
   */
113
  Node rewriteArithEqualityExt(Node node);
114
  /**
115
   * Called when node rewrites to ret.
116
   *
117
   * The rewrite r indicates the justification for the rewrite, which is printed
118
   * by this function for debugging.
119
   *
120
   * If node is not an equality (or rewriteEq is true) and ret is an equality,
121
   * this method applies an additional rewrite step (rewriteEqualityExt) that
122
   * performs additional rewrites on ret, after which we return the result of
123
   * this call. Otherwise, this method simply returns ret.
124
   */
125
  Node returnRewrite(Node node,
126
                     Node ret,
127
                     Rewrite r,
128
                     bool rewriteEqAgain = false);
129
130
 public:
131
  RewriteResponse postRewrite(TNode node) override;
132
  RewriteResponse preRewrite(TNode node) override;
133
  /** Expand definition */
134
  TrustNode expandDefinition(Node n) override;
135
136
  /** rewrite equality
137
   *
138
   * This method returns a formula that is equivalent to the equality between
139
   * two strings s = t, given by node. The result of rewrite is one of
140
   * { s = t, t = s, true, false }.
141
   */
142
  Node rewriteEquality(Node node);
143
  /** rewrite equality extended
144
   *
145
   * This method returns a formula that is equivalent to the equality between
146
   * two terms s = t, given by node, where s and t are terms in the signature
147
   * of the theory of strings. Notice that s and t may be of string type or
148
   * of Int type.
149
   *
150
   * Specifically, this function performs rewrites whose conclusion is not
151
   * necessarily one of { s = t, t = s, true, false }.
152
   */
153
  Node rewriteEqualityExt(Node node) override;
154
  /** rewrite string length
155
   * This is the entry point for post-rewriting terms node of the form
156
   *   str.len( t )
157
   * Returns the rewritten form of node.
158
   */
159
  Node rewriteLength(Node node);
160
  /** rewrite concat
161
   * This is the entry point for post-rewriting terms node of the form
162
   *   str.++( t1, .., tn )
163
   * Returns the rewritten form of node.
164
   */
165
  Node rewriteConcat(Node node);
166
  /** rewrite character at
167
   * This is the entry point for post-rewriting terms node of the form
168
   *   str.charat( s, i1 )
169
   * Returns the rewritten form of node.
170
   */
171
  Node rewriteCharAt(Node node);
172
  /** rewrite substr
173
   * This is the entry point for post-rewriting terms node of the form
174
   *   str.substr( s, i1, i2 )
175
   * Returns the rewritten form of node.
176
   */
177
  Node rewriteSubstr(Node node);
178
  /** rewrite update
179
   * This is the entry point for post-rewriting terms node of the form
180
   *   str.update( s, i1, i2 )
181
   * Returns the rewritten form of node.
182
   */
183
  Node rewriteUpdate(Node node);
184
  /** rewrite contains
185
   * This is the entry point for post-rewriting terms node of the form
186
   *   str.contains( t, s )
187
   * Returns the rewritten form of node.
188
   *
189
   * For details on some of the basic rewrites done in this function, see Figure
190
   * 7 of Reynolds et al "Scaling Up DPLL(T) String Solvers Using
191
   * Context-Dependent Rewriting", CAV 2017.
192
   */
193
  Node rewriteContains(Node node);
194
  /** rewrite indexof
195
   * This is the entry point for post-rewriting terms n of the form
196
   *   str.indexof( s, t, n )
197
   * Returns the rewritten form of node.
198
   */
199
  Node rewriteIndexof(Node node);
200
  /** rewrite indexof regular expression match
201
   * This is the entry point for post-rewriting terms n of the form
202
   *   str.indexof_re( s, r, n )
203
   * Returns the rewritten form of node.
204
   */
205
  Node rewriteIndexofRe(Node node);
206
  /** rewrite replace
207
   * This is the entry point for post-rewriting terms n of the form
208
   *   str.replace( s, t, r )
209
   * Returns the rewritten form of node.
210
   */
211
  Node rewriteReplace(Node node);
212
  /** rewrite replace all
213
   * This is the entry point for post-rewriting terms n of the form
214
   *   str.replaceall( s, t, r )
215
   * Returns the rewritten form of node.
216
   */
217
  Node rewriteReplaceAll(Node node);
218
  /** rewrite replace internal
219
   *
220
   * This method implements rewrite rules that apply to both str.replace and
221
   * str.replaceall. If it returns a non-null ret, then node rewrites to ret.
222
   */
223
  Node rewriteReplaceInternal(Node node);
224
  /** rewrite regular expression replace
225
   *
226
   * This method implements rewrite rules that apply to terms of the form
227
   * str.replace_re(s, r, t).
228
   *
229
   * @param node The node to rewrite
230
   * @return The rewritten node
231
   */
232
  Node rewriteReplaceRe(Node node);
233
  /** rewrite regular expression replace
234
   *
235
   * This method implements rewrite rules that apply to terms of the form
236
   * str.replace_re_all(s, r, t).
237
   *
238
   * @param node The node to rewrite
239
   * @return The rewritten node
240
   */
241
  Node rewriteReplaceReAll(Node node);
242
  /**
243
   * Returns the first, shortest sequence in n that matches r.
244
   *
245
   * @param n The constant string or sequence to search in.
246
   * @param r The regular expression to search for.
247
   * @return A pair holding the start position and the end position of the
248
   *         match or a pair of string::npos if r does not appear in n.
249
   */
250
  std::pair<size_t, size_t> firstMatch(Node n, Node r);
251
  /** rewrite string reverse
252
   *
253
   * This is the entry point for post-rewriting terms n of the form
254
   *   str.rev( s )
255
   * Returns the rewritten form of node.
256
   */
257
  Node rewriteStrReverse(Node node);
258
  /** rewrite prefix/suffix
259
   * This is the entry point for post-rewriting terms n of the form
260
   *   str.prefixof( s, t ) / str.suffixof( s, t )
261
   * Returns the rewritten form of node.
262
   */
263
  Node rewritePrefixSuffix(Node node);
264
265
  /** rewrite str.to_code
266
   * This is the entry point for post-rewriting terms n of the form
267
   *   str.to_code( t )
268
   * Returns the rewritten form of node.
269
   */
270
  Node rewriteStringToCode(Node node);
271
  /** rewrite seq.unit
272
   * This is the entry point for post-rewriting terms n of the form
273
   *   seq.unit( t )
274
   * Returns the rewritten form of node.
275
   */
276
  Node rewriteSeqUnit(Node node);
277
278
  /** rewrite seq.nth
279
   * This is the entry point for post-rewriting terms n of the form
280
   *   seq.nth(s, i)
281
   * Returns the rewritten form of node.
282
   */
283
  Node rewriteSeqNth(Node node);
284
285
  /** length preserving rewrite
286
   *
287
   * Given input n, this returns a string n' whose length is equivalent to n.
288
   * We apply certain normalizations to n', such as replacing all constants
289
   * that are not relevant to length by "A".
290
   */
291
  static Node lengthPreserveRewrite(Node n);
292
293
  /**
294
   * Given a symbolic length n, returns the canonical string (of type stype)
295
   * for that length. For example if n is constant, this function returns a
296
   * string consisting of "A" repeated n times. Returns the null node if no such
297
   * string exists.
298
   */
299
  static Node canonicalStrForSymbolicLength(Node n, TypeNode stype);
300
301
  /** Reference to the rewriter statistics. */
302
  HistogramStat<Rewrite>* d_statistics;
303
304
  /** Instance of the entailment checker for strings. */
305
  StringsEntail d_stringsEntail;
306
}; /* class SequencesRewriter */
307
308
}  // namespace strings
309
}  // namespace theory
310
}  // namespace cvc5
311
312
#endif /* CVC5__THEORY__STRINGS__SEQUENCES_REWRITER_H */