summaryrefslogtreecommitdiff
path: root/src/util/result.h
blob: e76e5605b22ea7dcdaea6c4f18d420364413d26e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*********************                                                        */
/*! \file result.h
 ** \verbatim
 ** Original author: mdeters
 ** Major contributors: none
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief Encapsulation of the result of a query.
 **
 ** Encapsulation of the result of a query.
 **/

#include "cvc4_public.h"

#ifndef __CVC4__RESULT_H
#define __CVC4__RESULT_H

#include "util/Assert.h"

namespace CVC4 {

// TODO: perhaps best to templatize Result on its Kind (SAT/Validity),
// but this requires doing the same for Prover and needs discussion.

// TODO: subclass to provide models, etc.  This is really just
// intended as a three-valued response code.

/**
 * Three-valued, immutable SMT result, with optional explanation.
 */
class CVC4_PUBLIC Result {
public:
  enum SAT {
    UNSAT = 0,
    SAT = 1,
    SAT_UNKNOWN = 2
  };

  enum Validity {
    INVALID = 0,
    VALID = 1,
    VALIDITY_UNKNOWN = 2
  };

  enum UnknownExplanation {
    REQUIRES_FULL_CHECK,
    INCOMPLETE,
    TIMEOUT,
    BAIL,
    OTHER
  };

private:
  enum SAT      d_sat;
  enum Validity d_validity;
  enum { TYPE_SAT, TYPE_VALIDITY, TYPE_NONE } d_which;

  friend std::ostream& CVC4::operator<<(std::ostream& out, Result r);

public:
  Result() :
    d_sat(SAT_UNKNOWN),
    d_validity(VALIDITY_UNKNOWN),
    d_which(TYPE_NONE) {
  }
  Result(enum SAT s) :
    d_sat(s),
    d_validity(VALIDITY_UNKNOWN),
    d_which(TYPE_SAT) {
  }
  Result(enum Validity v) :
    d_sat(SAT_UNKNOWN),
    d_validity(v),
    d_which(TYPE_VALIDITY) {
  }

  enum SAT isSAT() {
    return d_which == TYPE_SAT ? d_sat : SAT_UNKNOWN;
  }
  enum Validity isValid() {
    return d_which == TYPE_VALIDITY ? d_validity : VALIDITY_UNKNOWN;
  }
  enum UnknownExplanation whyUnknown();

  inline Result asSatisfiabilityResult() const;
  inline Result asValidityResult() const;

};/* class Result */

inline Result Result::asSatisfiabilityResult() const {
  if(d_which == TYPE_SAT) {
    return *this;
  }

  switch(d_validity) {

  case INVALID:
    return Result(SAT);

  case VALID:
    return Result(UNSAT);

  case VALIDITY_UNKNOWN:
    return Result(SAT_UNKNOWN);

  default:
    Unhandled(d_validity);
  }
}

inline Result Result::asValidityResult() const {
  if(d_which == TYPE_VALIDITY) {
    return *this;
  }

  switch(d_sat) {

  case SAT:
    return Result(INVALID);

  case UNSAT:
    return Result(VALID);

  case SAT_UNKNOWN:
    return Result(VALIDITY_UNKNOWN);

  default:
    Unhandled(d_sat);
  }
}

inline std::ostream& operator<<(std::ostream& out, Result r) {
  if(r.d_which == Result::TYPE_SAT) {
    switch(r.d_sat) {
    case Result::UNSAT: out << "UNSAT"; break;
    case Result::SAT: out << "SAT"; break;
    case Result::SAT_UNKNOWN: out << "SAT_UNKNOWN"; break;
    }
  } else {
    switch(r.d_validity) {
    case Result::INVALID: out << "INVALID"; break;
    case Result::VALID: out << "VALID"; break;
    case Result::VALIDITY_UNKNOWN: out << "VALIDITY_UNKNOWN"; break;
    }
  }

  return out;
}

}/* CVC4 namespace */

#endif /* __CVC4__RESULT_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback