feat(library/class): add auxiliary methods

This commit is contained in:
Leonardo de Moura 2015-10-30 16:46:01 -07:00
parent c361fc1f6f
commit 4c573380b2
2 changed files with 17 additions and 0 deletions

View file

@ -346,6 +346,19 @@ bool is_instance(environment const & env, name const & i) {
return s.is_instance(i); return s.is_instance(i);
} }
name_predicate mk_class_pred(environment const & env) {
class_state const & s = class_ext::get_state(env);
class_state::class_instances cs = s.m_instances;
return [=](name const & n) { return cs.contains(n); }; // NOLINT
}
name_predicate mk_instance_pred(environment const & env) {
class_state const & s = class_ext::get_state(env);
class_state::instance_priorities insts = s.m_priorities;
name_set der_insts = s.m_derived_trans_instance_set;
return [=](name const & n) { return insts.contains(n) || der_insts.contains(n); }; // NOLINT
}
bool is_derived_trans_instance(environment const & env, name const & i) { bool is_derived_trans_instance(environment const & env, name const & i) {
class_state const & s = class_ext::get_state(env); class_state const & s = class_ext::get_state(env);
return s.is_derived_trans_instance(i); return s.is_derived_trans_instance(i);

View file

@ -23,6 +23,10 @@ environment add_trans_instance(environment const & env, name const & n, unsigned
bool is_class(environment const & env, name const & c); bool is_class(environment const & env, name const & c);
/** \brief Return true iff \c i was declared with \c add_instance. */ /** \brief Return true iff \c i was declared with \c add_instance. */
bool is_instance(environment const & env, name const & i); bool is_instance(environment const & env, name const & i);
/** \brief Return the set of active classes (as a predicate) for the given environment */
name_predicate mk_class_pred(environment const & env);
/** \brief Return the set of active instances (as a predicate) for the given environment */
name_predicate mk_instance_pred(environment const & env);
/** \brief Return true iff \c i is a derived transitive instance. */ /** \brief Return true iff \c i is a derived transitive instance. */
bool is_derived_trans_instance(environment const & env, name const & i); bool is_derived_trans_instance(environment const & env, name const & i);
/** \brief Return the instances of the given class. */ /** \brief Return the instances of the given class. */