Skip to content

Commit dd040e5

Browse files
author
Daniel Kroening
committed
Added function_typet.
This is a type for a mathematical function, which is not to be confused with code_typet, which is a function in an imperative program. Use with function_application_exprt. It's envisaged to use this for various side-effect-free builtins.
1 parent bcd88a0 commit dd040e5

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/util/irep_ids.def

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ IREP_ID_ONE(property)
2727
IREP_ID_ONE(property_class)
2828
IREP_ID_ONE(property_id)
2929
IREP_ID_ONE(function)
30+
IREP_ID_ONE(mathematical_function)
3031
IREP_ID_ONE(code)
3132
IREP_ID_ONE(typecast)
3233
IREP_ID_ONE(static_cast)

src/util/std_types.h

+70-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
109
#ifndef CPROVER_UTIL_STD_TYPES_H
1110
#define CPROVER_UTIL_STD_TYPES_H
1211

@@ -1671,4 +1670,74 @@ inline complex_typet &to_complex_type(typet &type)
16711670
return static_cast<complex_typet &>(type);
16721671
}
16731672

1673+
/*! \brief A type for mathematical functions (do not
1674+
confuse with functions/methods in code)
1675+
*/
1676+
class mathematical_function_typet:public typet
1677+
{
1678+
public:
1679+
mathematical_function_typet():typet(ID_mathematical_function)
1680+
{
1681+
subtypes().resize(2);
1682+
}
1683+
1684+
// the domain of the function is composed of zero, one, or
1685+
// many variables
1686+
class variablet:public irept
1687+
{
1688+
public:
1689+
// the identifier is optional
1690+
irep_idt get_identifier() const
1691+
{
1692+
return get(ID_identifier);
1693+
}
1694+
1695+
void set_identifier(const irep_idt &identifier)
1696+
{
1697+
return set(ID_identifier, identifier);
1698+
}
1699+
1700+
typet &type()
1701+
{
1702+
return static_cast<typet &>(add(ID_type));
1703+
}
1704+
1705+
const typet &type() const
1706+
{
1707+
return static_cast<const typet &>(find(ID_type));
1708+
}
1709+
};
1710+
1711+
using domaint=std::vector<variablet>;
1712+
1713+
domaint &domain()
1714+
{
1715+
return (domaint &)subtypes()[0].subtypes();
1716+
}
1717+
1718+
const domaint &domain() const
1719+
{
1720+
return (const domaint &)subtypes()[0].subtypes();
1721+
}
1722+
1723+
variablet &add_variable()
1724+
{
1725+
auto &d=domain();
1726+
d.push_back(variablet());
1727+
return d.back();
1728+
}
1729+
1730+
// The codomain is the set of values that the
1731+
// function maps to (the "target")
1732+
typet &codomain()
1733+
{
1734+
return subtypes()[1];
1735+
}
1736+
1737+
const typet &codomain() const
1738+
{
1739+
return subtypes()[1];
1740+
}
1741+
};
1742+
16741743
#endif // CPROVER_UTIL_STD_TYPES_H

0 commit comments

Comments
 (0)