forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request diffblue#2203 from diffblue/typed-lookup
strongly type the lookup() methods in namespacet
- Loading branch information
Showing
15 changed files
with
80 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,11 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <cassert> | ||
|
||
#include "string2int.h" | ||
#include "symbol_table.h" | ||
#include "prefix.h" | ||
#include "std_expr.h" | ||
#include "std_types.h" | ||
#include "string2int.h" | ||
#include "symbol_table.h" | ||
|
||
unsigned get_max( | ||
const std::string &prefix, | ||
|
@@ -44,43 +45,37 @@ namespace_baset::~namespace_baset() | |
{ | ||
} | ||
|
||
void namespace_baset::follow_symbol(irept &irep) const | ||
const symbolt &namespace_baset::lookup(const symbol_exprt &expr) const | ||
{ | ||
while(irep.id()==ID_symbol) | ||
{ | ||
const symbolt &symbol=lookup(irep); | ||
return lookup(expr.get_identifier()); | ||
} | ||
|
||
if(symbol.is_type) | ||
{ | ||
if(symbol.type.is_nil()) | ||
return; | ||
else | ||
irep=symbol.type; | ||
} | ||
else | ||
{ | ||
if(symbol.value.is_nil()) | ||
return; | ||
else | ||
irep=symbol.value; | ||
} | ||
} | ||
const symbolt &namespace_baset::lookup(const symbol_typet &type) const | ||
{ | ||
return lookup(type.get_identifier()); | ||
} | ||
|
||
const symbolt &namespace_baset::lookup(const tag_typet &type) const | ||
{ | ||
return lookup(type.get_identifier()); | ||
} | ||
|
||
const typet &namespace_baset::follow(const typet &src) const | ||
{ | ||
if(src.id()!=ID_symbol) | ||
return src; | ||
|
||
const symbolt *symbol=&lookup(src); | ||
const symbolt *symbol = &lookup(to_symbol_type(src)); | ||
|
||
// let's hope it's not cyclic... | ||
while(true) | ||
{ | ||
assert(symbol->is_type); | ||
if(symbol->type.id()!=ID_symbol) | ||
DATA_INVARIANT(symbol->is_type, "symbol type points to type"); | ||
|
||
if(symbol->type.id() == ID_symbol) | ||
symbol = &lookup(to_symbol_type(symbol->type)); | ||
else | ||
return symbol->type; | ||
symbol=&lookup(symbol->type); | ||
} | ||
} | ||
|
||
|
@@ -112,7 +107,7 @@ void namespace_baset::follow_macros(exprt &expr) const | |
{ | ||
if(expr.id()==ID_symbol) | ||
{ | ||
const symbolt &symbol=lookup(expr); | ||
const symbolt &symbol = lookup(to_symbol_expr(expr)); | ||
|
||
if(symbol.is_macro && !symbol.value.is_nil()) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,9 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "type_eq.h" | ||
|
||
#include <cassert> | ||
|
||
#include "type.h" | ||
#include "symbol.h" | ||
#include "namespace.h" | ||
#include "std_types.h" | ||
#include "symbol.h" | ||
|
||
bool type_eq(const typet &type1, const typet &type2, const namespacet &ns) | ||
{ | ||
|
@@ -24,7 +22,7 @@ bool type_eq(const typet &type1, const typet &type2, const namespacet &ns) | |
|
||
if(type1.id()==ID_symbol) | ||
{ | ||
const symbolt &symbol=ns.lookup(type1); | ||
const symbolt &symbol = ns.lookup(to_symbol_type(type1)); | ||
if(!symbol.is_type) | ||
throw "symbol "+id2string(symbol.name)+" is not a type"; | ||
|
||
|
@@ -33,7 +31,7 @@ bool type_eq(const typet &type1, const typet &type2, const namespacet &ns) | |
|
||
if(type2.id()==ID_symbol) | ||
{ | ||
const symbolt &symbol=ns.lookup(type2); | ||
const symbolt &symbol = ns.lookup(to_symbol_type(type2)); | ||
if(!symbol.is_type) | ||
throw "symbol "+id2string(symbol.name)+" is not a type"; | ||
|
||
|