Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/json-symtab-language/json_symtab_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Author: Chris Smowton, [email protected]
#include "json_symtab_language.h"
#include <json/json_parser.h>
#include <util/json_symbol_table.h>
#include <util/namespace.h>

bool json_symtab_languaget::parse(
std::istream &instream,
Expand All @@ -30,6 +31,7 @@ bool json_symtab_languaget::typecheck(
try
{
symbol_table_from_json(parsed_json_file, symbol_table);
follow_type_symbols(symbol_table);
return false;
}
catch(const std::string &str)
Expand All @@ -39,6 +41,51 @@ bool json_symtab_languaget::typecheck(
}
}

void json_symtab_languaget::follow_type_symbols(
irept &irep,
const namespacet &ns)
{
ns.follow_type_symbol(irep);

for(irept &sub : irep.get_sub())
{
follow_type_symbols(sub, ns);
}

for(auto &entry : irep.get_named_sub())
{
irept &sub = entry.second;

follow_type_symbols(sub, ns);
}
}

void json_symtab_languaget::follow_type_symbols(symbol_tablet &symbol_table)
{
const namespacet ns(symbol_table);

std::vector<irep_idt> type_symbol_names;

for(auto &entry : symbol_table)
{
symbolt &symbol = symbol_table.get_writeable_ref(entry.first);

if(symbol.is_type)
{
type_symbol_names.push_back(symbol.name);
}

// Modify entries in place
follow_type_symbols(symbol.type, ns);
follow_type_symbols(symbol.value, ns);
}

for(const irep_idt &id : type_symbol_names)
{
symbol_table.remove(id);
}
}

void json_symtab_languaget::show_parse(std::ostream &out)
{
parsed_json_file.output(out);
Expand Down
3 changes: 3 additions & 0 deletions src/json-symtab-language/json_symtab_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class json_symtab_languaget:public languaget
}

protected:
void follow_type_symbols(symbol_tablet &symbol_table);
void follow_type_symbols(irept &irep, const namespacet &ns);

jsont parsed_json_file;
};

Expand Down
1 change: 1 addition & 0 deletions src/util/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SRC = arith_tools.cpp \
json_expr.cpp \
json_irep.cpp \
json_stream.cpp \
json_symbol.cpp \
json_symbol_table.cpp \
lispexpr.cpp \
lispirep.cpp \
Expand Down
17 changes: 17 additions & 0 deletions src/util/namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ void namespace_baset::follow_symbol(irept &irep) const
}
}

void namespace_baset::follow_type_symbol(irept &irep) const
{
while(irep.id() == ID_symbol)
{
const symbolt &symbol = lookup(irep);

if(symbol.is_type && !symbol.type.is_nil())
{
irep = symbol.type;
}
else
{
break;
}
}
}

const typet &namespace_baset::follow(const typet &src) const
{
if(src.id()!=ID_symbol)
Expand Down
1 change: 1 addition & 0 deletions src/util/namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class namespace_baset
virtual ~namespace_baset();

void follow_symbol(irept &irep) const;
void follow_type_symbol(irept &irep) const;
void follow_macros(exprt &expr) const;
const typet &follow(const typet &src) const;

Expand Down
2 changes: 1 addition & 1 deletion src/util/symbol_table_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class symbol_table_baset
return &**this;
}

symbolt &get_writeable_symbol(const irep_idt &identifier)
symbolt &get_writeable_symbol()
{
if(on_get_writeable)
on_get_writeable((*this)->first);
Expand Down