diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 1717a6c60e..ebc53b331e 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -4,6 +4,6 @@ add_library(util trace.cpp debug.cpp name.cpp name_set.cpp realpath.cpp script_state.cpp script_exception.cpp rb_map.cpp lua.cpp luaref.cpp lua_named_param.cpp stackinfo.cpp lean_path.cpp serializer.cpp lbool.cpp thread_script_state.cpp bitap_fuzzy_search.cpp - init_module.cpp thread.cpp memory_pool.cpp utf8.cpp) + init_module.cpp thread.cpp memory_pool.cpp utf8.cpp name_map.cpp) target_link_libraries(util ${LEAN_LIBS}) diff --git a/src/util/name_map.cpp b/src/util/name_map.cpp new file mode 100644 index 0000000000..2f56b194a1 --- /dev/null +++ b/src/util/name_map.cpp @@ -0,0 +1,17 @@ +/* +Copyright (c) 2014 Microsoft Corporation. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. + +Author: Leonardo de Moura +*/ +#include "util/name_map.h" + +namespace lean { +name const & rename_map::find(name const & k) const { + name const * it = &k; + while (name const * new_it = name_map::find(*it)) { + it = new_it; + } + return *it; +} +} diff --git a/src/util/name_map.h b/src/util/name_map.h index d0f95667d9..0562ada612 100644 --- a/src/util/name_map.h +++ b/src/util/name_map.h @@ -9,4 +9,12 @@ Author: Leonardo de Moura #include "util/name.h" namespace lean { template using name_map = rb_map; + +class rename_map : public name_map { +public: + // Similar to name_map::find, but it "follows" the sequence of renames. + // Example, if map contains "A->B" and "B->C", then find(A) returns C. + // Moreover, if k is not in the map, the result is \c k + name const & find(name const & k) const; +}; }