Use consistent naming for functional objects

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-07-24 00:45:38 -07:00
parent 4ae0c4c445
commit 4b61639f4d
7 changed files with 29 additions and 32 deletions

View file

@ -22,8 +22,7 @@ expr abstract(unsigned n, expr const * s, expr const & e) {
return e;
};
replace_proc<decltype(f)> proc(f);
return proc(e);
return replace_fn<decltype(f)>(f)(e);
}
expr abstract_p(unsigned n, expr const * s, expr const & e) {
lean_assert(std::all_of(s, s+n, closed));
@ -38,7 +37,6 @@ expr abstract_p(unsigned n, expr const * s, expr const & e) {
return e;
};
replace_proc<decltype(f)> proc(f);
return proc(e);
return replace_fn<decltype(f)>(f)(e);
}
}

View file

@ -118,9 +118,9 @@ void expr_cell::dealloc() {
}
class eq_functor {
class eq_fn {
expr_cell_pair_set m_eq_visited;
public:
bool apply(expr const & a, expr const & b) {
if (eqp(a, b)) return true;
if (a.hash() != b.hash()) return false;
@ -164,11 +164,14 @@ public:
lean_unreachable();
return false;
}
public:
bool operator()(expr const & a, expr const & b) {
return apply(a, b);
}
};
bool operator==(expr const & a, expr const & b) {
eq_functor f;
return f.apply(a, b);
return eq_fn()(a, b);
}
// Low-level pretty printer

View file

@ -34,8 +34,6 @@ The main API is divided in the following sections
======================================= */
enum class expr_kind { Var, Constant, App, Lambda, Pi, Prop, Type, Numeral };
class max_sharing_functor;
/**
\brief Base class used to represent expressions.
@ -46,19 +44,19 @@ class max_sharing_functor;
class expr_cell {
protected:
unsigned m_kind:16;
unsigned m_max_shared:1; // flag (used by max_sharing_functor) indicating if the cell has maximally shared subexpressions
unsigned m_closed:1; // flag (used by has_free_var_functor): 1 means it is definitely close, 0 means don't know
unsigned m_max_shared:1; // flag (used by max_sharing_fn) indicating if the cell has maximally shared subexpressions
unsigned m_closed:1; // flag (used by has_free_var_fn): 1 means it is definitely close, 0 means don't know
unsigned m_hash;
MK_LEAN_RC(); // Declare m_rc counter
void dealloc();
bool max_shared() const { return m_max_shared == 1; }
void set_max_shared() { m_max_shared = 1; }
friend class max_sharing_functor;
friend class max_sharing_fn;
bool is_closed() const { return m_closed == 1; }
void set_closed() { m_closed = 1; }
friend class has_free_var_functor;
friend class has_free_var_fn;
public:
expr_cell(expr_kind k, unsigned h);
expr_kind kind() const { return static_cast<expr_kind>(m_kind); }
@ -334,7 +332,7 @@ typedef std::pair<expr_cell*, unsigned> expr_cell_offset;
// =======================================
// =======================================
// Auxiliary functors
// Auxiliary functionals
struct expr_hash { unsigned operator()(expr const & e) const { return e.hash(); } };
struct expr_eqp { bool operator()(expr const & e1, expr const & e2) const { return eqp(e1, e2); } };
struct expr_cell_hash { unsigned operator()(expr_cell * e) const { return e->hash(); } };

View file

@ -10,9 +10,9 @@ Author: Leonardo de Moura
namespace lean {
class has_free_var_functor {
class has_free_var_fn {
expr_cell_offset_set m_visited;
public:
bool apply(expr const & e, unsigned offset) {
// handle easy cases
switch (e.kind()) {
@ -54,11 +54,12 @@ public:
return result;
}
public:
bool operator()(expr const & e) { return apply(e, 0); }
};
bool has_free_vars(expr const & e) {
has_free_var_functor f;
return f.apply(e, 0);
return has_free_var_fn()(e);
}
}

View file

@ -25,7 +25,6 @@ expr instantiate(unsigned n, expr const * s, expr const & e) {
return e;
};
replace_proc<decltype(f)> proc(f);
return proc(e);
return replace_fn<decltype(f)>(f)(e);
}
}

View file

@ -10,7 +10,7 @@ Author: Leonardo de Moura
namespace lean {
class max_sharing_functor {
class max_sharing_fn {
struct expr_struct_eq { unsigned operator()(expr const & e1, expr const & e2) const { return e1 == e2; }};
typedef typename std::unordered_set<expr, expr_hash, expr_struct_eq> expr_cache;
@ -21,8 +21,6 @@ class max_sharing_functor {
m_cache.insert(a);
}
public:
expr apply(expr const & a) {
auto r = m_cache.find(a);
if (r != m_cache.end()) {
@ -75,16 +73,16 @@ public:
lean_unreachable();
return a;
}
public:
expr operator()(expr const & a) { return apply(a); }
};
expr max_sharing(expr const & a) {
if (a.raw()->max_shared()) {
if (a.raw()->max_shared())
return a;
}
else {
max_sharing_functor f;
return f.apply(a);
}
else
return max_sharing_fn()(a);
}
} // namespace lean

View file

@ -20,7 +20,7 @@ namespace lean {
bindings operators that enclosing s.
*/
template<typename F>
class replace_proc {
class replace_fn {
expr_cell_offset_map<expr> m_cache;
F m_f;
@ -75,7 +75,7 @@ class replace_proc {
}
public:
replace_proc(F const & f):
replace_fn(F const & f):
m_f(f) {
}