fix(frontends/lean/token_table): static initialization problem

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-06-11 10:56:04 -07:00
parent 3dc26666b9
commit 8fcc25d55a

View file

@ -40,11 +40,8 @@ static char const * g_pi_unicode = "\u03A0";
static char const * g_forall_unicode = "\u2200";
static char const * g_arrow_unicode = "\u2192";
// Auxiliary class for creating the initial token set
class init_token_table_fn {
public:
token_table m_token_table;
init_token_table_fn() {
token_table init_token_table() {
token_table t;
char const * builtin[] = {"fun", "Pi", "let", "in", "have", "show", "by", "from", "(", ")", "{", "}",
".{", "Type", "...", ",", ".", ":", "calc", ":=", "--", "(*", "(--", "->",
"proof", "qed", "private", nullptr};
@ -64,32 +61,40 @@ public:
auto it = builtin;
while (*it) {
m_token_table = add_token(m_token_table, *it);
t = add_token(t, *it);
it++;
}
it = commands;
while (*it) {
m_token_table = add_command_token(m_token_table, *it);
t = add_command_token(t, *it);
++it;
}
auto it2 = aliases;
while (it2->first) {
m_token_table = add_token(m_token_table, it2->first, it2->second);
t = add_token(t, it2->first, it2->second);
it2++;
}
it2 = cmd_aliases;
while (it2->first) {
m_token_table = add_command_token(m_token_table, it2->first, it2->second);
t = add_command_token(t, it2->first, it2->second);
++it2;
}
return t;
}
};
static init_token_table_fn g_init;
token_table mk_default_token_table() {
static optional<token_table> r;
if (!r)
r = init_token_table();
return *r;
}
static token_table g_init(mk_default_token_table());
token_table mk_token_table() { return token_table(); }
token_table mk_default_token_table() { return g_init.m_token_table; }
DECL_UDATA(token_table)
static int mk_token_table(lua_State * L) { return push_token_table(L, mk_token_table()); }