Skip to content

Complete typet documentation [DOC-12] #2771

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 3 commits into from
Aug 22, 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
13 changes: 13 additions & 0 deletions src/util/base_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ bool base_type_eqt::base_type_eq_rec(
return true;
}

/// Check types for equality across all levels of hierarchy. For equality
/// in the top level of the hierarchy only use \ref type_eq.
/// Example:
/// - `symbol_typet("a")` and `ns.lookup("a").type` will compare equal,
/// - `struct_typet {symbol_typet("a")}` and `struct_typet {ns.lookup("a")
/// .type}` will also compare equal.
/// \param type1 The first type to compare.
/// \param type2 The second type to compare.
/// \param ns The namespace, needed for resolution of symbols.
bool base_type_eq(
const typet &type1,
const typet &type2,
Expand All @@ -329,6 +338,10 @@ bool base_type_eq(
return base_type_eq.base_type_eq(type1, type2);
}

/// Check expressions for equality across all levels of hierarchy.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I don't understand the meaning of this - perhaps a short example as you've given for the typet overload

/// \param expr1 The first expression to compare.
/// \param expr2 The second expression to compare.
/// \param ns The namespace, needed for resolution of symbols.
bool base_type_eq(
const exprt &expr1,
const exprt &expr2,
Expand Down
14 changes: 13 additions & 1 deletion src/util/std_types.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*******************************************************************\

Module:
Module: Pre-defined types

Author: Daniel Kroening, [email protected]
Maria Svorenova, [email protected]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know, but should the additional Author be Diffblue @peterschrammel?

Copy link
Author

Choose a reason for hiding this comment

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

I followed @peterschrammel recommendation from Slack but happy to change it to whatever makes more sense.


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

/// \file
/// Pre-defined types

#include "std_types.h"

#include "string2int.h"
Expand All @@ -26,6 +30,7 @@ std::size_t floatbv_typet::get_f() const
return unsafe_string2unsigned(id2string(f));
}

/// Return the sequence number of the component with given name.
std::size_t struct_union_typet::component_number(
const irep_idt &component_name) const
{
Expand All @@ -48,6 +53,7 @@ std::size_t struct_union_typet::component_number(
return 0;
}

/// Get the reference to a component with given name.
const struct_union_typet::componentt &struct_union_typet::get_component(
const irep_idt &component_name) const
{
Expand All @@ -73,6 +79,10 @@ typet struct_union_typet::component_type(
return c.type();
}

/// Returns true if the struct is a prefix of \a other, i.e., if this struct
/// has n components then the component types and names of this struct must
/// match the first n components of \a other struct.
/// \param other Struct type to compare with.
bool struct_typet::is_prefix_of(const struct_typet &other) const
{
const componentst &ot_components=other.components();
Expand Down Expand Up @@ -102,12 +112,14 @@ bool struct_typet::is_prefix_of(const struct_typet &other) const
return true; // ok, *this is a prefix of ot
}

/// Returns true if the type is a reference.
bool is_reference(const typet &type)
{
return type.id()==ID_pointer &&
type.get_bool(ID_C_reference);
}

/// Returns if the type is an R value reference.
bool is_rvalue_reference(const typet &type)
{
return type.id()==ID_pointer &&
Expand Down
Loading