Skip to content

Added function_typet #1761

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
Feb 11, 2018
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 @@ -27,6 +27,7 @@ IREP_ID_ONE(property)
IREP_ID_ONE(property_class)
IREP_ID_ONE(property_id)
IREP_ID_ONE(function)
IREP_ID_ONE(mathematical_function)
IREP_ID_ONE(code)
IREP_ID_ONE(typecast)
IREP_ID_ONE(static_cast)
Expand Down
71 changes: 70 additions & 1 deletion src/util/std_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Author: Daniel Kroening, [email protected]

\*******************************************************************/


#ifndef CPROVER_UTIL_STD_TYPES_H
#define CPROVER_UTIL_STD_TYPES_H

Expand Down Expand Up @@ -1671,4 +1670,74 @@ inline complex_typet &to_complex_type(typet &type)
return static_cast<complex_typet &>(type);
}

/*! \brief A type for mathematical functions (do not
confuse with functions/methods in code)
*/
class mathematical_function_typet:public typet
{
public:
mathematical_function_typet():typet(ID_mathematical_function)
{
subtypes().resize(2);
}

// the domain of the function is composed of zero, one, or
// many variables
class variablet:public irept
{
public:
// the identifier is optional
irep_idt get_identifier() const
{
return get(ID_identifier);
}

void set_identifier(const irep_idt &identifier)
{
return set(ID_identifier, identifier);
}

typet &type()
{
return static_cast<typet &>(add(ID_type));
}

const typet &type() const
{
return static_cast<const typet &>(find(ID_type));
}
};

using domaint=std::vector<variablet>;

domaint &domain()
{
return (domaint &)subtypes()[0].subtypes();
Copy link
Collaborator

Choose a reason for hiding this comment

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

static_cast

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't work, the types are incomparable.

}

const domaint &domain() const
{
return (const domaint &)subtypes()[0].subtypes();
Copy link
Collaborator

Choose a reason for hiding this comment

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

static_cast

Copy link
Member Author

Choose a reason for hiding this comment

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

Same here.

}

variablet &add_variable()
{
auto &d=domain();
d.push_back(variablet());
return d.back();
}

// The codomain is the set of values that the
// function maps to (the "target")
typet &codomain()
{
return subtypes()[1];
}

const typet &codomain() const
{
return subtypes()[1];
}
};

#endif // CPROVER_UTIL_STD_TYPES_H