Skip to content

Commit 74dc99f

Browse files
author
Daniel Kroening
committed
mathematical functions should be typed as such
The string modeling introduces mathematical functions to deal with the length of strings. They should be typed as such, as opposed to using the range type.
1 parent 46cccb6 commit 74dc99f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

jbmc/src/java_bytecode/java_utils.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/fresh_symbol.h>
1414
#include <util/invariant.h>
1515
#include <util/mathematical_expr.h>
16+
#include <util/mathematical_types.h>
1617
#include <util/message.h>
1718
#include <util/prefix.h>
1819
#include <util/std_types.h>
@@ -252,13 +253,14 @@ void java_add_components_to_class(
252253
/// \return newly created symbol
253254
static auxiliary_symbolt declare_function(
254255
const irep_idt &function_name,
255-
const typet &type,
256+
const mathematical_function_typet &type,
256257
symbol_table_baset &symbol_table)
257258
{
258259
auxiliary_symbolt func_symbol;
259260
func_symbol.base_name=function_name;
260261
func_symbol.pretty_name=function_name;
261262
func_symbol.is_static_lifetime=false;
263+
func_symbol.is_state_var = false;
262264
func_symbol.mode=ID_java;
263265
func_symbol.name=function_name;
264266
func_symbol.type=type;
@@ -267,24 +269,32 @@ static auxiliary_symbolt declare_function(
267269
return func_symbol;
268270
}
269271

270-
/// Create a function application expression.
272+
/// Create a (mathematical) function application expression.
273+
/// The application has the type of the codomain (range) of the function.
271274
/// \param function_name: the name of the function
272-
/// \param arguments: a list of arguments
273-
/// \param type: return type of the function
275+
/// \param arguments: a list of arguments (an element of the domain)
276+
/// \param range: return type (codomain) of the function
274277
/// \param symbol_table: a symbol table
275278
/// \return a function application expression representing:
276279
/// `function_name(arguments)`
277280
exprt make_function_application(
278281
const irep_idt &function_name,
279282
const exprt::operandst &arguments,
280-
const typet &type,
283+
const typet &range,
281284
symbol_table_baset &symbol_table)
282285
{
286+
std::vector<typet> argument_types;
287+
for(const auto &arg : arguments)
288+
argument_types.push_back(arg.type());
289+
283290
// Declaring the function
284-
const auto symbol = declare_function(function_name, type, symbol_table);
291+
const auto symbol = declare_function(
292+
function_name,
293+
mathematical_function_typet(std::move(argument_types), range),
294+
symbol_table);
285295

286296
// Function application
287-
return function_application_exprt(symbol.symbol_expr(), arguments, type);
297+
return function_application_exprt(symbol.symbol_expr(), arguments, range);
288298
}
289299

290300
/// Strip java:: prefix from given identifier

jbmc/src/java_bytecode/java_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ size_t find_closing_delimiter(
9090
exprt make_function_application(
9191
const irep_idt &function_name,
9292
const exprt::operandst &arguments,
93-
const typet &type,
93+
const typet &range,
9494
symbol_table_baset &symbol_table);
9595

9696
irep_idt strip_java_namespace_prefix(const irep_idt &to_strip);

0 commit comments

Comments
 (0)