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_type_symbols (symbol_table);
33
35
return false ;
34
36
}
35
37
catch (const std::string &str)
@@ -39,6 +41,51 @@ bool json_symtab_languaget::typecheck(
39
41
}
40
42
}
41
43
44
+ void json_symtab_languaget::follow_type_symbols (
45
+ irept &irep,
46
+ const namespacet &ns)
47
+ {
48
+ ns.follow_type_symbol (irep);
49
+
50
+ for (irept &sub : irep.get_sub ())
51
+ {
52
+ follow_type_symbols (sub, ns);
53
+ }
54
+
55
+ for (auto &entry : irep.get_named_sub ())
56
+ {
57
+ irept &sub = entry.second ;
58
+
59
+ follow_type_symbols (sub, ns);
60
+ }
61
+ }
62
+
63
+ void json_symtab_languaget::follow_type_symbols (symbol_tablet &symbol_table)
64
+ {
65
+ const namespacet ns (symbol_table);
66
+
67
+ std::vector<irep_idt> type_symbol_names;
68
+
69
+ for (auto &entry : symbol_table)
70
+ {
71
+ symbolt &symbol = symbol_table.get_writeable_ref (entry.first );
72
+
73
+ if (symbol.is_type )
74
+ {
75
+ type_symbol_names.push_back (symbol.name );
76
+ }
77
+
78
+ // Modify entries in place
79
+ follow_type_symbols (symbol.type , ns);
80
+ follow_type_symbols (symbol.value , ns);
81
+ }
82
+
83
+ for (const irep_idt &id : type_symbol_names)
84
+ {
85
+ symbol_table.remove (id);
86
+ }
87
+ }
88
+
42
89
void json_symtab_languaget::show_parse (std::ostream &out)
43
90
{
44
91
parsed_json_file.output (out);
0 commit comments