1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 |
|
* Implementation of method identifier |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "proof/method_id.h" |
17 |
|
|
18 |
|
#include "proof/proof_checker.h" |
19 |
|
#include "util/rational.h" |
20 |
|
|
21 |
|
namespace cvc5 { |
22 |
|
|
23 |
10 |
const char* toString(MethodId id) |
24 |
|
{ |
25 |
10 |
switch (id) |
26 |
|
{ |
27 |
|
case MethodId::RW_REWRITE: return "RW_REWRITE"; |
28 |
|
case MethodId::RW_EXT_REWRITE: return "RW_EXT_REWRITE"; |
29 |
|
case MethodId::RW_REWRITE_EQ_EXT: return "RW_REWRITE_EQ_EXT"; |
30 |
|
case MethodId::RW_EVALUATE: return "RW_EVALUATE"; |
31 |
|
case MethodId::RW_IDENTITY: return "RW_IDENTITY"; |
32 |
5 |
case MethodId::RW_REWRITE_THEORY_PRE: return "RW_REWRITE_THEORY_PRE"; |
33 |
5 |
case MethodId::RW_REWRITE_THEORY_POST: return "RW_REWRITE_THEORY_POST"; |
34 |
|
case MethodId::SB_DEFAULT: return "SB_DEFAULT"; |
35 |
|
case MethodId::SB_LITERAL: return "SB_LITERAL"; |
36 |
|
case MethodId::SB_FORMULA: return "SB_FORMULA"; |
37 |
|
case MethodId::SBA_SEQUENTIAL: return "SBA_SEQUENTIAL"; |
38 |
|
case MethodId::SBA_SIMUL: return "SBA_SIMUL"; |
39 |
|
case MethodId::SBA_FIXPOINT: return "SBA_FIXPOINT"; |
40 |
|
default: return "MethodId::Unknown"; |
41 |
|
}; |
42 |
|
} |
43 |
|
|
44 |
10 |
std::ostream& operator<<(std::ostream& out, MethodId id) |
45 |
|
{ |
46 |
10 |
out << toString(id); |
47 |
10 |
return out; |
48 |
|
} |
49 |
|
|
50 |
277478 |
Node mkMethodId(MethodId id) |
51 |
|
{ |
52 |
277478 |
return NodeManager::currentNM()->mkConst(Rational(static_cast<uint32_t>(id))); |
53 |
|
} |
54 |
|
|
55 |
73062 |
bool getMethodId(TNode n, MethodId& i) |
56 |
|
{ |
57 |
|
uint32_t index; |
58 |
73062 |
if (!ProofRuleChecker::getUInt32(n, index)) |
59 |
|
{ |
60 |
|
return false; |
61 |
|
} |
62 |
73062 |
i = static_cast<MethodId>(index); |
63 |
73062 |
return true; |
64 |
|
} |
65 |
|
|
66 |
762237 |
bool getMethodIds(const std::vector<Node>& args, |
67 |
|
MethodId& ids, |
68 |
|
MethodId& ida, |
69 |
|
MethodId& idr, |
70 |
|
size_t index) |
71 |
|
{ |
72 |
762237 |
ids = MethodId::SB_DEFAULT; |
73 |
762237 |
ida = MethodId::SBA_SEQUENTIAL; |
74 |
762237 |
idr = MethodId::RW_REWRITE; |
75 |
813003 |
for (size_t offset = 0; offset <= 2; offset++) |
76 |
|
{ |
77 |
812965 |
if (args.size() > index + offset) |
78 |
|
{ |
79 |
50766 |
MethodId& id = offset == 0 ? ids : (offset == 1 ? ida : idr); |
80 |
50766 |
if (!getMethodId(args[index + offset], id)) |
81 |
|
{ |
82 |
|
Trace("builtin-pfcheck") |
83 |
|
<< "Failed to get id from " << args[index + offset] << std::endl; |
84 |
|
return false; |
85 |
|
} |
86 |
|
} |
87 |
|
else |
88 |
|
{ |
89 |
762199 |
break; |
90 |
|
} |
91 |
|
} |
92 |
1524474 |
Trace("builtin-pfcheck") << "Got MethodIds ids/ida/idr: " << ids << " / " |
93 |
762237 |
<< ida << " / " << idr << "\n"; |
94 |
762237 |
return true; |
95 |
|
} |
96 |
|
|
97 |
13651 |
void addMethodIds(std::vector<Node>& args, |
98 |
|
MethodId ids, |
99 |
|
MethodId ida, |
100 |
|
MethodId idr) |
101 |
|
{ |
102 |
13651 |
bool ndefRewriter = (idr != MethodId::RW_REWRITE); |
103 |
13651 |
bool ndefApply = (ida != MethodId::SBA_SEQUENTIAL); |
104 |
13651 |
if (ids != MethodId::SB_DEFAULT || ndefRewriter || ndefApply) |
105 |
|
{ |
106 |
11834 |
args.push_back(mkMethodId(ids)); |
107 |
|
} |
108 |
13651 |
if (ndefApply || ndefRewriter) |
109 |
|
{ |
110 |
11834 |
args.push_back(mkMethodId(ida)); |
111 |
|
} |
112 |
13651 |
if (ndefRewriter) |
113 |
|
{ |
114 |
37 |
args.push_back(mkMethodId(idr)); |
115 |
|
} |
116 |
13651 |
} |
117 |
|
|
118 |
29574 |
} // namespace cvc5 |