-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathlanguage_util.cpp
113 lines (85 loc) · 2.46 KB
/
language_util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************\
Module:
Author: Daniel Kroening, [email protected]
\*******************************************************************/
#include "language_util.h"
#include <util/invariant.h>
#include <util/message.h>
#include <util/namespace.h>
#include <util/std_expr.h>
#include <util/symbol_table.h>
#include "language.h"
#include "mode.h"
#include <memory>
std::string from_expr_using_mode(
const namespacet &ns,
const irep_idt &mode,
const exprt &expr)
{
std::unique_ptr<languaget> language = (mode == ID_unknown)
? get_default_language()
: get_language_from_mode(mode);
INVARIANT(
language, "could not retrieve language for mode '" + id2string(mode) + "'");
std::string result;
language->from_expr(expr, result, ns);
return result;
}
std::string from_expr(
const namespacet &ns,
const irep_idt &identifier,
const exprt &expr)
{
std::unique_ptr<languaget> p(get_language_from_identifier(ns, identifier));
std::string result;
p->from_expr(expr, result, ns);
return result;
}
std::string from_type(
const namespacet &ns,
const irep_idt &identifier,
const typet &type)
{
std::unique_ptr<languaget> p(get_language_from_identifier(ns, identifier));
std::string result;
p->from_type(type, result, ns);
return result;
}
std::string type_to_name(
const namespacet &ns,
const irep_idt &identifier,
const typet &type)
{
std::unique_ptr<languaget> p(get_language_from_identifier(ns, identifier));
std::string result;
p->type_to_name(type, result, ns);
return result;
}
std::string from_expr(const exprt &expr)
{
symbol_tablet symbol_table;
return from_expr(namespacet(symbol_table), irep_idt(), expr);
}
std::string from_type(const typet &type)
{
symbol_tablet symbol_table;
return from_type(namespacet(symbol_table), irep_idt(), type);
}
exprt to_expr(
const namespacet &ns,
const irep_idt &identifier,
const std::string &src)
{
std::unique_ptr<languaget> p(get_language_from_identifier(ns, identifier));
const symbolt &symbol=ns.lookup(identifier);
exprt expr;
null_message_handlert null_message_handler;
if(p->to_expr(src, id2string(symbol.module), expr, ns, null_message_handler))
return nil_exprt();
return expr;
}
std::string type_to_name(const typet &type)
{
symbol_tablet symbol_table;
return type_to_name(namespacet(symbol_table), irep_idt(), type);
}