cprover
destructor.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Destructor Calls
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "destructor.h"
13 
14 #include <util/namespace.h>
15 #include <util/std_code.h>
16 
18  const namespacet &ns,
19  const typet &type)
20 {
21  if(type.id() == ID_struct_tag)
22  {
23  return get_destructor(ns, ns.follow_tag(to_struct_tag_type(type)));
24  }
25  else if(type.id()==ID_struct)
26  {
27  const exprt &methods=static_cast<const exprt&>(type.find(ID_methods));
28 
29  forall_operands(it, methods)
30  {
31  if(it->type().id()==ID_code)
32  {
33  const code_typet &code_type=to_code_type(it->type());
34 
35  if(code_type.return_type().id()==ID_destructor &&
36  code_type.parameters().size()==1)
37  {
38  const typet &arg_type=code_type.parameters().front().type();
39 
40  if(arg_type.id()==ID_pointer &&
41  ns.follow(arg_type.subtype())==type)
42  {
43  const symbol_exprt symbol_expr(it->get(ID_name), it->type());
44  return code_function_callt(symbol_expr);
45  }
46  }
47  }
48  }
49  }
50 
51  return static_cast<const code_function_callt &>(get_nil_irep());
52 }
typet::subtype
const typet & subtype() const
Definition: type.h:47
typet
The type of an expression, extends irept.
Definition: type.h:28
irept::find
const irept & find(const irep_namet &name) const
Definition: irep.cpp:106
get_destructor
code_function_callt get_destructor(const namespacet &ns, const typet &type)
Definition: destructor.cpp:17
exprt
Base class for all expressions.
Definition: expr.h:54
namespace_baset::follow_tag
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Definition: namespace.cpp:63
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:80
namespace.h
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:91
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1213
to_code_type
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:744
forall_operands
#define forall_operands(it, expr)
Definition: expr.h:18
code_typet
Base type of functions.
Definition: std_types.h:539
irept::id
const irep_idt & id() const
Definition: irep.h:407
to_struct_tag_type
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition: std_types.h:474
code_typet::parameters
const parameterst & parameters() const
Definition: std_types.h:655
std_code.h
destructor.h
Destructor Calls.
namespace_baset::follow
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
Definition: namespace.cpp:49
code_typet::return_type
const typet & return_type() const
Definition: std_types.h:645
get_nil_irep
const irept & get_nil_irep()
Definition: irep.cpp:20