6
6
7
7
\*******************************************************************/
8
8
9
+ #include < iomanip>
10
+
9
11
#include < util/std_expr.h>
10
12
#include < util/prefix.h>
11
13
@@ -91,11 +93,23 @@ void java_bytecode_typecheckt::typecheck_expr_java_new_array(
91
93
typecheck_type (type);
92
94
}
93
95
94
- static void escape_non_alnum (std::string &toescape)
96
+ static std::string escape_non_alnum (const std::string &toescape)
95
97
{
98
+ std::ostringstream escaped;
96
99
for (auto &ch : toescape)
97
- if (!isalnum (ch))
98
- ch=' _' ;
100
+ {
101
+ if (ch==' _' )
102
+ escaped << " __" ;
103
+ else if (isalnum (ch))
104
+ escaped << ch;
105
+ else
106
+ escaped << ' _'
107
+ << std::hex
108
+ << std::setfill (' 0' )
109
+ << std::setw (2 )
110
+ << (unsigned int )ch;
111
+ }
112
+ return escaped.str ();
99
113
}
100
114
101
115
/* ******************************************************************\
@@ -115,29 +129,20 @@ void java_bytecode_typecheckt::typecheck_expr_java_string_literal(exprt &expr)
115
129
const irep_idt value=expr.get (ID_value);
116
130
const symbol_typet string_type (" java::java.lang.String" );
117
131
118
- auto findit=string_literal_to_symbol_name.find (value);
119
- if (findit!=string_literal_to_symbol_name.end ())
132
+ std::string escaped_symbol_name=
133
+ " java::java.lang.String.Literal." ;
134
+ escaped_symbol_name+=escape_non_alnum (id2string (value));
135
+
136
+ auto findit=symbol_table.symbols .find (escaped_symbol_name);
137
+ if (findit!=symbol_table.symbols .end ())
120
138
{
121
- expr=symbol_exprt ( findit->second , pointer_typet (string_type) );
139
+ expr=findit->second . symbol_expr ( );
122
140
return ;
123
141
}
124
142
125
143
// Create a new symbol:
126
- std::ostringstream identifier_str;
127
- std::string escaped=id2string (value);
128
- escape_non_alnum (escaped);
129
- identifier_str << " java::java.lang.String.Literal." << escaped;
130
- // Avoid naming clashes by virtue of escaping:
131
- // NOTE this increments the count stored in the map.
132
- size_t unique_num=++(escaped_string_literal_count[identifier_str.str ()]);
133
- if (unique_num!=1 )
134
- identifier_str << unique_num;
135
-
136
- irep_idt identifier_id=identifier_str.str ();
137
- string_literal_to_symbol_name.insert (std::make_pair (value, identifier_id));
138
-
139
144
symbolt new_symbol;
140
- new_symbol.name =identifier_id ;
145
+ new_symbol.name =escaped_symbol_name ;
141
146
new_symbol.type =pointer_typet (string_type);
142
147
new_symbol.base_name =" Literal" ;
143
148
new_symbol.pretty_name =value;
0 commit comments