Skip to content

Commit a6d0a38

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 bc145fd commit a6d0a38

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-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

+67-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,71 @@ inline complex_typet &to_complex_type(typet &type)
16711670
return static_cast<complex_typet &>(type);
16721671
}
16731672

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

0 commit comments

Comments
 (0)