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
|
/********************* -*- C++ -*- */
/** expr_manager.h
** This file is part of the CVC4 prototype.
** Copyright (c) 2009 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.
**
**/
#ifndef __CVC4__EXPR_MANAGER_H
#define __CVC4__EXPR_MANAGER_H
#include <vector>
#include <map>
#include "expr/expr.h"
#include "kind.h"
namespace CVC4 {
namespace expr {
class ExprBuilder;
}/* CVC4::expr namespace */
class CVC4_PUBLIC ExprManager {
static __thread ExprManager* s_current;
friend class CVC4::ExprBuilder;
typedef std::map<uint64_t, std::vector<Expr> > hash_t;
hash_t d_hash;
Expr lookup(uint64_t hash, const Expr& e) {
hash_t::iterator i = d_hash.find(hash);
if(i == d_hash.end()) {
// insert
std::vector<Expr> v;
v.push_back(e);
d_hash.insert(std::make_pair(hash, v));
return e;
} else {
for(std::vector<Expr>::iterator j = i->second.begin(); j != i->second.end(); ++j) {
if(e.getKind() != j->getKind())
continue;
if(e.numChildren() != j->numChildren())
continue;
Expr::iterator c1 = e.begin();
Expr::iterator c2 = j->begin();
while(c1 != e.end() && c2 != j->end()) {
if(c1->d_ev != c2->d_ev)
break;
}
if(c1 != e.end() || c2 != j->end())
continue;
return *j;
}
// didn't find it, insert
std::vector<Expr> v;
v.push_back(e);
d_hash.insert(std::make_pair(hash, v));
return e;
}
}
public:
static ExprManager* currentEM() { return s_current; }
// general expression-builders
Expr mkExpr(Kind kind);
Expr mkExpr(Kind kind, Expr child1);
Expr mkExpr(Kind kind, Expr child1, Expr child2);
Expr mkExpr(Kind kind, Expr child1, Expr child2, Expr child3);
Expr mkExpr(Kind kind, Expr child1, Expr child2, Expr child3, Expr child4);
Expr mkExpr(Kind kind, Expr child1, Expr child2, Expr child3, Expr child4, Expr child5);
// N-ary version
Expr mkExpr(Kind kind, std::vector<Expr> children);
// TODO: these use the current EM (but must be renamed)
/*
static Expr mkExpr(Kind kind)
{ currentEM()->mkExpr(kind); }
static Expr mkExpr(Kind kind, Expr child1);
{ currentEM()->mkExpr(kind, child1); }
static Expr mkExpr(Kind kind, Expr child1, Expr child2);
{ currentEM()->mkExpr(kind, child1, child2); }
static Expr mkExpr(Kind kind, Expr child1, Expr child2, Expr child3);
{ currentEM()->mkExpr(kind, child1, child2, child3); }
static Expr mkExpr(Kind kind, Expr child1, Expr child2, Expr child3, Expr child4);
{ currentEM()->mkExpr(kind, child1, child2, child3, child4); }
static Expr mkExpr(Kind kind, Expr child1, Expr child2, Expr child3, Expr child4, Expr child5);
{ currentEM()->mkExpr(kind, child1, child2, child3, child4, child5); }
*/
// do we want a varargs one? perhaps not..
};
}/* CVC4 namespace */
#endif /* __CVC4__EXPR_MANAGER_H */
|