73c8bf4436
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
29 lines
743 B
C++
29 lines
743 B
C++
/*
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Author: Leonardo de Moura
|
|
*/
|
|
#include <utility>
|
|
#include "util/exception.h"
|
|
#include "kernel/context.h"
|
|
|
|
namespace lean {
|
|
std::pair<name, expr> const & lookup(context const & c, unsigned i) {
|
|
auto const * it = &c;
|
|
while (*it) {
|
|
if (i == 0)
|
|
return head(*it);
|
|
--i;
|
|
it = &tail(*it);
|
|
}
|
|
throw exception("unknown free variable");
|
|
}
|
|
optional<std::pair<name, expr>> find(context const & c, unsigned i) {
|
|
try {
|
|
return optional<std::pair<name, expr>>(lookup(c, i));
|
|
} catch (exception &) {
|
|
return optional<std::pair<name, expr>>();
|
|
}
|
|
}
|
|
}
|