Skip to content

Commit 637b17b

Browse files
committed
Move magic "compiled" string behind an API in symbolt
Magic strings yield a risk of inconsistency, and fail to provide documentation.
1 parent f5d5715 commit 637b17b

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/goto-cc/compile.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -724,15 +724,13 @@ void compilet::convert_symbols(goto_functionst &dest)
724724
symbol_table.symbols.find(*it);
725725
assert(s_it!=symbol_table.symbols.end());
726726

727-
if(s_it->second.type.id()==ID_code &&
728-
!s_it->second.is_macro &&
729-
!s_it->second.is_type &&
730-
s_it->second.value.id()!="compiled" &&
731-
s_it->second.value.is_not_nil())
727+
if(
728+
s_it->second.is_function() && !s_it->second.is_compiled() &&
729+
s_it->second.value.is_not_nil())
732730
{
733731
debug() << "Compiling " << s_it->first << eom;
734732
converter.convert_function(s_it->first, dest.function_map[s_it->first]);
735-
symbol_table.get_writeable_ref(*it).value=exprt("compiled");
733+
symbol_table.get_writeable_ref(*it).set_compiled();
736734
}
737735
}
738736
}

src/goto-programs/goto_convert_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void goto_convert_functionst::convert_function(
152152
f.type=to_code_type(symbol.type);
153153

154154
if(symbol.value.is_nil() ||
155-
symbol.value.id()=="compiled") /* goto_inline may have removed the body */
155+
symbol.is_compiled()) /* goto_inline may have removed the body */
156156
return;
157157

158158
if(symbol.value.id()!=ID_code)

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ IREP_ID_ONE(w_ok)
699699
IREP_ID_ONE(super_class)
700700
IREP_ID_ONE(exceptions_thrown_list)
701701
IREP_ID_TWO(C_java_method_type, #java_method_type)
702+
IREP_ID_ONE(compiled)
702703

703704
// Projects depending on this code base that wish to extend the list of
704705
// available ids should provide a file local_irep_ids.def in their source tree

src/util/symbol.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <iosfwd>
2121

2222
#include "expr.h"
23+
#include "invariant.h"
2324

2425
/*! \brief Symbol table entry.
2526
\ingroup gr_symbol_table
@@ -107,6 +108,21 @@ class symbolt
107108
{
108109
return !is_type && !is_macro && type.id()==ID_code;
109110
}
111+
112+
/// Returns true iff the the symbol's value has been compiled to a goto
113+
/// program.
114+
bool is_compiled() const
115+
{
116+
return type.id() == ID_code && value == exprt(ID_compiled);
117+
}
118+
119+
/// Set the symbol's value to "compiled"; to be used once the code-typed value
120+
/// has been converted to a goto program.
121+
void set_compiled()
122+
{
123+
PRECONDITION(type.id() == ID_code);
124+
value = exprt(ID_compiled);
125+
}
110126
};
111127

112128
std::ostream &operator<<(std::ostream &out, const symbolt &symbol);

0 commit comments

Comments
 (0)