-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpred_format.h
59 lines (48 loc) · 1.44 KB
/
pred_format.h
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
#ifndef PRED_FORMAT_H_
#define PRED_FORMAT_H_
#include "pred.h"
#include "types.h"
#include "util/string.h"
namespace {
str show(Term t) {
switch(t.type()) {
case Term::VAR: return util::fmt("v%",Var(t).id());
case Term::FUN: {
Fun fun(t);
if(fun.fun()==u64(Fun::EXTRA_CONST)) return "c";
vec<str> args(fun.arg_count());
for(size_t i=0; i<fun.arg_count(); ++i) args[i] = show(fun.arg(i));
return util::fmt("f%(%)",Fun(t).fun(),util::join(",",args));
}
}
error("unexpected t.type() = %",t.type());
}
str show(Atom a) {
vec<str> args(a.arg_count());
for(size_t i=a.arg_count(); i--;) args[i] = show(a.arg(i));
str sign = a.sign() ? "+" : "-";
str pred_name = a.pred()==Atom::EQ ? "eq" : util::fmt("p%",a.pred());
return util::fmt("%%(%)",sign,pred_name,util::join(",",args));
}
str show(const OrClause &orClause) {
vec<str> atoms;
for(auto a : orClause.atoms) atoms.push_back(show(a));
return util::join(" \\/ ",atoms);
}
str show(const AndClause &andClause) {
vec<str> atoms;
for(auto a : andClause.atoms) atoms.push_back(show(a));
return util::join(" /\\ ",atoms);
}
str show(const NotAndForm &f) {
vec<str> clauses;
for(auto c : f.or_clauses) clauses.push_back(show(c) + "\n");
return util::join("",clauses);
}
str show(const OrForm &f) {
vec<str> clauses;
for(auto c : f.and_clauses) clauses.push_back(show(c) + "\n");
return util::join("",clauses);
}
}
#endif // PRED_FORMAT_H_