GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/logic_info.h Lines: 23 23 100.0 %
Date: 2021-05-22 Branches: 15 18 83.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Morgan Deters, Andrew Reynolds, Tim King
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
 * A class giving information about a logic (group of theory modules and
14
 * configuration information).
15
 */
16
17
#include "cvc5_public.h"
18
19
#ifndef CVC5__LOGIC_INFO_H
20
#define CVC5__LOGIC_INFO_H
21
22
#include <string>
23
#include <vector>
24
25
#include "cvc5_export.h"
26
#include "theory/theory_id.h"
27
28
namespace cvc5 {
29
30
/**
31
 * A LogicInfo instance describes a collection of theory modules and some
32
 * basic configuration about them.  Conceptually, it provides a background
33
 * context for all operations in cvc5.  Typically, when cvc5's SmtEngine
34
 * is created, it is issued a setLogic() command indicating features of the
35
 * assertions and queries to follow---for example, whether quantifiers are
36
 * used, whether integers or reals (or both) will be used, etc.
37
 *
38
 * Most places in cvc5 will only ever need to access a const reference to an
39
 * instance of this class.  Such an instance is generally set by the SmtEngine
40
 * when setLogic() is called.  However, mutating member functions are also
41
 * provided by this class so that it can be used as a more general mechanism
42
 * (e.g., for communicating to the SmtEngine which theories should be used,
43
 * rather than having to provide an SMT-LIB string).
44
 */
45
463827
class CVC5_EXPORT LogicInfo
46
{
47
  mutable std::string d_logicString; /**< an SMT-LIB-like logic string */
48
  std::vector<bool> d_theories; /**< set of active theories */
49
  size_t d_sharingTheories; /**< count of theories that need sharing */
50
51
  /** are integers used in this logic? */
52
  bool d_integers;
53
  /** are reals used in this logic? */
54
  bool d_reals;
55
  /** transcendentals in this logic? */
56
  bool d_transcendentals;
57
  /** linear-only arithmetic in this logic? */
58
  bool d_linear;
59
  /** difference-only arithmetic in this logic? */
60
  bool d_differenceLogic;
61
  /** cardinality constraints in this logic? */
62
  bool d_cardinalityConstraints;
63
  /** higher-order constraints in this logic? */
64
  bool d_higherOrder;
65
66
  bool d_locked; /**< is this LogicInfo instance locked (and thus immutable)? */
67
68
  /**
69
   * Returns true iff this is a "true" theory (one that must be worried
70
   * about for sharing
71
   */
72
906468
  static inline bool isTrueTheory(theory::TheoryId theory) {
73
906468
    switch(theory) {
74
239266
    case theory::THEORY_BUILTIN:
75
    case theory::THEORY_BOOL:
76
    case theory::THEORY_QUANTIFIERS:
77
239266
      return false;
78
667202
    default:
79
667202
      return true;
80
    }
81
  }
82
83
public:
84
85
  /**
86
   * Constructs a LogicInfo for the most general logic (quantifiers, all
87
   * background theory modules, ...).
88
   */
89
  LogicInfo();
90
91
  /**
92
   * Construct a LogicInfo from an SMT-LIB-like logic string.
93
   * Throws an IllegalArgumentException if the logic string cannot
94
   * be interpreted.
95
   */
96
  LogicInfo(std::string logicString);
97
98
  /**
99
   * Construct a LogicInfo from an SMT-LIB-like logic string.
100
   * Throws an IllegalArgumentException if the logic string cannot
101
   * be interpreted.
102
   */
103
  LogicInfo(const char* logicString);
104
105
  // ACCESSORS
106
107
  /**
108
   * Get an SMT-LIB-like logic string.  These are only guaranteed to
109
   * be SMT-LIB-compliant if an SMT-LIB-compliant string was used in
110
   * the constructor and no mutating functions were called.
111
   */
112
  std::string getLogicString() const;
113
114
  /** Is sharing enabled for this logic? */
115
  bool isSharingEnabled() const;
116
117
  /** Is the given theory module active in this logic? */
118
  bool isTheoryEnabled(theory::TheoryId theory) const;
119
120
  /** Is this a quantified logic? */
121
  bool isQuantified() const;
122
123
  /** Is this the all-inclusive logic? */
124
  bool hasEverything() const;
125
126
  /** Is this the all-exclusive logic?  (Here, that means propositional logic) */
127
  bool hasNothing() const;
128
129
  /**
130
   * Is this a pure logic (only one "true" background theory).  Quantifiers
131
   * can exist in such logics though; to test for quantifier-free purity,
132
   * use "isPure(theory) && !isQuantified()".
133
   */
134
  bool isPure(theory::TheoryId theory) const;
135
136
  // these are for arithmetic
137
138
  /** Are integers in this logic? */
139
  bool areIntegersUsed() const;
140
141
  /** Are reals in this logic? */
142
  bool areRealsUsed() const;
143
144
  /** Are transcendentals in this logic? */
145
  bool areTranscendentalsUsed() const;
146
147
  /** Does this logic only linear arithmetic? */
148
  bool isLinear() const;
149
150
  /** Does this logic only permit difference reasoning? (implies linear) */
151
  bool isDifferenceLogic() const;
152
153
  /** Does this logic allow cardinality constraints? */
154
  bool hasCardinalityConstraints() const;
155
156
  /** Is this a higher order logic? */
157
  bool isHigherOrder() const;
158
159
  // MUTATORS
160
161
  /**
162
   * Initialize the LogicInfo with an SMT-LIB-like logic string.
163
   * Throws an IllegalArgumentException if the string can't be
164
   * interpreted.
165
   */
166
  void setLogicString(std::string logicString);
167
168
  /**
169
   * Enable all functionality.  All theories, plus quantifiers, will be
170
   * enabled.
171
   */
172
  void enableEverything();
173
174
  /**
175
   * Disable all functionality.  The result will be a LogicInfo with
176
   * the BUILTIN and BOOLEAN theories enabled only ("QF_SAT").
177
   */
178
  void disableEverything();
179
180
  /**
181
   * Enable the given theory module.
182
   */
183
  void enableTheory(theory::TheoryId theory);
184
185
  /**
186
   * Disable the given theory module.  THEORY_BUILTIN and THEORY_BOOL cannot
187
   * be disabled (and if given here, the request will be silently ignored).
188
   */
189
  void disableTheory(theory::TheoryId theory);
190
191
  /**
192
   * Quantifiers are a special case, since two theory modules handle them.
193
   */
194
6684
  void enableQuantifiers() {
195
6684
    enableTheory(theory::THEORY_QUANTIFIERS);
196
6684
  }
197
198
  /**
199
   * Quantifiers are a special case, since two theory modules handle them.
200
   */
201
19829
  void disableQuantifiers() {
202
19829
    disableTheory(theory::THEORY_QUANTIFIERS);
203
19827
  }
204
205
  /**
206
   * Enable everything that is needed for sygus with respect to this logic info.
207
   * This means enabling quantifiers, datatypes, UF, integers, and higher order.
208
   */
209
  void enableSygus();
210
  /**
211
   * Enable everything that is needed for separation logic. This means enabling
212
   * the theories of separation logic, UF and sets.
213
   */
214
  void enableSeparationLogic();
215
216
  // these are for arithmetic
217
218
  /** Enable the use of integers in this logic. */
219
  void enableIntegers();
220
  /** Disable the use of integers in this logic. */
221
  void disableIntegers();
222
  /** Enable the use of reals in this logic. */
223
  void enableReals();
224
  /** Disable the use of reals in this logic. */
225
  void disableReals();
226
  /** Enable the use of transcendentals in this logic. */
227
  void arithTranscendentals();
228
  /** Only permit difference arithmetic in this logic. */
229
  void arithOnlyDifference();
230
  /** Only permit linear arithmetic in this logic. */
231
  void arithOnlyLinear();
232
  /** Permit nonlinear arithmetic in this logic. */
233
  void arithNonLinear();
234
235
  // for cardinality constraints
236
237
  /** Enable the use of cardinality constraints in this logic. */
238
  void enableCardinalityConstraints();
239
  /** Disable the use of cardinality constraints in this logic. */
240
  void disableCardinalityConstraints();
241
242
  // for higher-order
243
244
  /** Enable the use of higher-order in this logic. */
245
  void enableHigherOrder();
246
  /** Disable the use of higher-order in this logic. */
247
  void disableHigherOrder();
248
249
  // LOCKING FUNCTIONALITY
250
251
  /** Lock this LogicInfo, disabling further mutation and allowing queries */
252
81747
  void lock() { d_locked = true; }
253
  /** Check whether this LogicInfo is locked, disallowing further mutation */
254
139341
  bool isLocked() const { return d_locked; }
255
  /** Get a copy of this LogicInfo that is identical, but unlocked */
256
  LogicInfo getUnlockedCopy() const;
257
258
  // COMPARISON
259
260
  /** Are these two LogicInfos equal? */
261
  bool operator==(const LogicInfo& other) const;
262
263
  /** Are these two LogicInfos disequal? */
264
3416
  bool operator!=(const LogicInfo& other) const {
265
3416
    return !(*this == other);
266
  }
267
268
  /** Is this LogicInfo "greater than" (does it contain everything and more) the other? */
269
2348
  bool operator>(const LogicInfo& other) const {
270
2348
    return *this >= other && *this != other;
271
  }
272
273
  /** Is this LogicInfo "less than" (does it contain strictly less) the other? */
274
2348
  bool operator<(const LogicInfo& other) const {
275
2348
    return *this <= other && *this != other;
276
  }
277
  /** Is this LogicInfo "less than or equal" the other? */
278
  bool operator<=(const LogicInfo& other) const;
279
280
  /** Is this LogicInfo "greater than or equal" the other? */
281
  bool operator>=(const LogicInfo& other) const;
282
283
  /** Are two LogicInfos comparable?  That is, is one of <= or > true? */
284
2348
  bool isComparableTo(const LogicInfo& other) const {
285
2348
    return *this <= other || *this >= other;
286
  }
287
288
}; /* class LogicInfo */
289
290
std::ostream& operator<<(std::ostream& out, const LogicInfo& logic);
291
292
}  // namespace cvc5
293
294
#endif /* CVC5__LOGIC_INFO_H */