feat(library/init/meta): add simple tactics for testing where a declaration was defined

This commit is contained in:
Leonardo de Moura 2017-02-11 10:57:06 -08:00
parent 2d31007625
commit 2f5159e7eb
3 changed files with 16 additions and 1 deletions

View file

@ -23,6 +23,10 @@ def is_some {α : Type u} : option α → bool
| (some _) := tt
| none := ff
def is_none {α : Type u} : option α → bool
| (some _) := ff
| none := tt
end option
instance (α : Type u) : inhabited (option α) :=

View file

@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.declaration init.meta.exceptional
import init.meta.declaration init.meta.exceptional init.data.option.basic
meta constant environment : Type
@ -93,6 +93,11 @@ match (refl_for env (const_name (get_app_fn e))) with
else none
| none := none
end
/-- Return true if 'n' has been declared in the current file -/
meta def in_current_file (env : environment) (n : name) : bool :=
(env^.decl_olean n)^.is_none && env^.contains n
end environment
meta instance : has_to_string environment :=

View file

@ -931,6 +931,12 @@ do m ← mk_meta_var type,
set_goals gs,
return (a, m)
/-- Return tt iff 'd' is a declaration in one of the current open namespaces -/
meta def in_open_namespaces (d : name) : tactic bool :=
do ns ← open_namespaces,
env ← get_env,
return $ ns^.any (λ n, n^.is_prefix_of d) && env^.contains d
end tactic
open tactic