11
11
#include " json_symtab_language.h"
12
12
#include < json/json_parser.h>
13
13
#include < util/json_symbol_table.h>
14
+ #include < util/namespace.h>
14
15
15
16
bool json_symtab_languaget::parse (
16
17
std::istream &instream,
@@ -30,6 +31,7 @@ bool json_symtab_languaget::typecheck(
30
31
try
31
32
{
32
33
symbol_table_from_json (parsed_json_file, symbol_table);
34
+ follow_symbol_types (symbol_table);
33
35
return false ;
34
36
}
35
37
catch (const std::string &str)
@@ -39,6 +41,65 @@ bool json_symtab_languaget::typecheck(
39
41
}
40
42
}
41
43
44
+ void json_symtab_languaget::follow_symbol_types (
45
+ irept &irep,
46
+ const namespacet &ns)
47
+ {
48
+ if (irep.id () == ID_symbol)
49
+ {
50
+ const symbolt &symbol = ns.lookup (irep);
51
+
52
+ if (symbol.is_type )
53
+ {
54
+ ns.follow_symbol (irep);
55
+ }
56
+ }
57
+
58
+ for (irept &sub : irep.get_sub ())
59
+ {
60
+ follow_symbol_types (sub, ns);
61
+ }
62
+
63
+ for (auto &entry : irep.get_named_sub ())
64
+ {
65
+ irept &sub = entry.second ;
66
+
67
+ follow_symbol_types (sub, ns);
68
+ }
69
+ }
70
+
71
+ void json_symtab_languaget::follow_symbol_types (symbol_tablet &symbol_table)
72
+ {
73
+ const namespacet ns (symbol_table);
74
+
75
+ typedef symbol_tablet::symbolst symbolst;
76
+ symbolst &symbols = symbol_table.symbols ;
77
+
78
+ for (auto &entry : symbols)
79
+ {
80
+ symbolt &symbol = entry.second ;
81
+
82
+ // Modify entries in place
83
+ follow_symbol_types (symbol.type , ns);
84
+ follow_symbol_types (symbol.value , ns);
85
+ }
86
+
87
+ // Remove type entries from the symbol table
88
+ for (symbolst::iterator it = symbols.begin (); it != symbols.end ();)
89
+ {
90
+ const symbolt &symbol = it->second ;
91
+
92
+ if (symbol.is_type )
93
+ {
94
+ it = symbols.erase (it);
95
+ }
96
+ else
97
+ {
98
+ it++;
99
+ }
100
+ }
101
+ }
102
+
42
103
void json_symtab_languaget::show_parse (std::ostream &out)
43
104
{
44
105
parsed_json_file.output (out);
0 commit comments