Skip to content

Commit f798fef

Browse files
authored
Merge pull request #1178 from smowton/smowton/feature/string_literal_util
Add a utility for spotting string literal identifiers
2 parents 7f1d9f8 + 5cb4c9a commit f798fef

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/java_bytecode/java_bytecode_typecheck_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]
2121
#include "java_bytecode_typecheck.h"
2222
#include "java_pointer_casts.h"
2323
#include "java_types.h"
24+
#include "java_utils.h"
2425

2526
void java_bytecode_typecheckt::typecheck_expr(exprt &expr)
2627
{
@@ -101,8 +102,7 @@ void java_bytecode_typecheckt::typecheck_expr_java_string_literal(exprt &expr)
101102
const irep_idt value=expr.get(ID_value);
102103
const symbol_typet string_type("java::java.lang.String");
103104

104-
std::string escaped_symbol_name=
105-
"java::java.lang.String.Literal.";
105+
std::string escaped_symbol_name=JAVA_STRING_LITERAL_PREFIX ".";
106106
escaped_symbol_name+=escape_non_alnum(id2string(value));
107107

108108
auto findit=symbol_table.symbols.find(escaped_symbol_name);

src/java_bytecode/java_entry_point.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Author: Daniel Kroening, [email protected]
3131
#include "java_entry_point.h"
3232
#include "java_object_factory.h"
3333
#include "java_types.h"
34+
#include "java_utils.h"
3435

3536
#define INITIALIZE CPROVER_PREFIX "initialize"
3637

@@ -71,7 +72,7 @@ static bool should_init_symbol(const symbolt &sym)
7172
sym.mode==ID_java)
7273
return true;
7374

74-
return has_prefix(id2string(sym.name), "java::java.lang.String.Literal");
75+
return is_java_string_literal_id(sym.name);
7576
}
7677

7778
void java_static_lifetime_init(
@@ -102,14 +103,13 @@ void java_static_lifetime_init(
102103
bool allow_null=!assume_init_pointers_not_null;
103104
if(allow_null)
104105
{
105-
std::string namestr=id2string(sym.symbol_expr().get_identifier());
106+
irep_idt nameid=sym.symbol_expr().get_identifier();
107+
std::string namestr=id2string(nameid);
106108
const std::string suffix="@class_model";
107109
// Static '.class' fields are always non-null.
108110
if(has_suffix(namestr, suffix))
109111
allow_null=false;
110-
if(allow_null && has_prefix(
111-
namestr,
112-
"java::java.lang.String.Literal"))
112+
if(allow_null && is_java_string_literal_id(nameid))
113113
allow_null=false;
114114
}
115115
auto newsym=object_factory(

src/java_bytecode/java_utils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,8 @@ void merge_source_location_rec(
107107
for(exprt &op : expr.operands())
108108
merge_source_location_rec(op, source_location);
109109
}
110+
111+
bool is_java_string_literal_id(const irep_idt &id)
112+
{
113+
return has_prefix(id2string(id), JAVA_STRING_LITERAL_PREFIX);
114+
}

src/java_bytecode/java_utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
99

1010
#include <util/type.h>
1111
#include <util/symbol_table.h>
12+
#include <util/message.h>
1213

1314
#include "java_bytecode_parse_tree.h"
1415

@@ -45,4 +46,10 @@ void merge_source_location_rec(
4546
exprt &expr,
4647
const source_locationt &source_location);
4748

49+
#define JAVA_STRING_LITERAL_PREFIX "java::java.lang.String.Literal"
50+
51+
/// \param id: any string
52+
/// \return Returns true if 'id' identifies a string literal symbol
53+
bool is_java_string_literal_id(const irep_idt &id);
54+
4855
#endif // CPROVER_JAVA_BYTECODE_JAVA_UTILS_H

0 commit comments

Comments
 (0)