Skip to content

use a tuple for function arguments #4321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/util/irep_ids.def
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ IREP_ID_ONE(typeid)
IREP_ID_TWO(C_quoted, #quoted)
IREP_ID_ONE(to_member)
IREP_ID_ONE(pointer_to_member)
IREP_ID_ONE(tuple)

// Projects depending on this code base that wish to extend the list of
// available ids should provide a file local_irep_ids.def in their source tree
Expand Down
2 changes: 1 addition & 1 deletion src/util/mathematical_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function_application_exprt::function_application_exprt(
: binary_exprt(
_function,
ID_function_application,
multi_ary_exprt(irep_idt(), std::move(_arguments), typet()),
tuple_exprt(std::move(_arguments)),
to_mathematical_function_type(_function.type()).codomain())
{
const auto &domain = to_mathematical_function_type(_function.type()).domain();
Expand Down
16 changes: 14 additions & 2 deletions src/util/mathematical_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ inline void validate_expr(const factorial_power_exprt &value)
validate_operands(value, 2, "Factorial power must have two operands");
}

class tuple_exprt : public multi_ary_exprt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth moving this to std_expr.h and use it in those places where we currently do use ID_arguments?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I would suggest putting all the .*_exprt classes in a new module (separate from util) and have one class per header file, but that's a much bigger change.

Copy link
Collaborator

@tautschnig tautschnig Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, but this is a very intrusive change -- a lot of code in util already depends on std_expr.h:

$ git grep 'include.*std_expr.h' src/util/ | wc -l
43

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the arguments/parameters of a C/C++ function are a very different thing from the arguments/parameters of a mathematical function. In particular, there is no tuple building going on in C/C++ or Java.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Member Author

@kroening kroening Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romainbrenguier getting slightly off-topic, we could separate the 'irep/expression' related things from the 'non irep utilities', say making a directory named "irep". There could be dummy headers for a transition period.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that sounds good

{
public:
explicit tuple_exprt(exprt::operandst operands)
: multi_ary_exprt(ID_tuple, std::move(operands), typet())
{
}
};

/// \brief Application of (mathematical) function
class function_application_exprt : public binary_exprt
{
Expand All @@ -197,9 +206,12 @@ class function_application_exprt : public binary_exprt
const symbol_exprt &_function,
const argumentst &_arguments,
const typet &_type)
: binary_exprt(_function, ID_function_application, exprt(), _type)
: binary_exprt(
_function,
ID_function_application,
tuple_exprt(_arguments),
_type)
{
arguments() = _arguments;
}

function_application_exprt(
Expand Down