cprover
cpp_declarator.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: C++ Language Type Checking
4 
5 Author: Daniel Kroening, kroening@cs.cmu.edu
6 
7 \*******************************************************************/
8 
11 
12 #include "cpp_declarator.h"
13 
14 #include <ansi-c/merged_type.h>
15 
16 #include <ostream>
17 #include <cassert>
18 
19 void cpp_declaratort::output(std::ostream &out) const
20 {
21  out << " name: " << name().pretty() << '\n';
22  out << " type: " << type().pretty() << '\n';
23  out << " value: " << value().pretty() << '\n';
24  out << " init_args: " << init_args().pretty() << '\n';
25  out << " method_qualifier: " << method_qualifier().pretty() << '\n';
26 }
27 
28 typet cpp_declaratort::merge_type(const typet &declaration_type) const
29 {
30  typet dest_type=type();
31 
32  if(declaration_type.id()=="cpp-cast-operator")
33  return dest_type;
34 
35  typet *p=&dest_type;
36 
37  // walk down subtype until we hit nil
38  while(true)
39  {
40  typet &t=*p;
41  if(t.is_nil())
42  {
43  t=declaration_type;
44  break;
45  }
46  else if(t.id()==ID_merged_type)
47  {
48  // the chain continues with the last one
49  auto &merged_type = to_merged_type(t);
50  p = &merged_type.last_type();
51  }
52  else
53  {
54  assert(!t.id().empty());
55  p=&t.subtype();
56  }
57  }
58 
59  return dest_type;
60 }
typet::subtype
const typet & subtype() const
Definition: type.h:47
typet
The type of an expression, extends irept.
Definition: type.h:29
irept::pretty
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:488
merged_type.h
cpp_declaratort::name
cpp_namet & name()
Definition: cpp_declarator.h:36
cpp_declaratort::output
void output(std::ostream &out) const
Definition: cpp_declarator.cpp:19
to_merged_type
const merged_typet & to_merged_type(const typet &type)
conversion to merged_typet
Definition: merged_type.h:29
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:81
irept::is_nil
bool is_nil() const
Definition: irep.h:398
irept::id
const irep_idt & id() const
Definition: irep.h:418
dstringt::empty
bool empty() const
Definition: dstring.h:88
cpp_declarator.h
C++ Language Type Checking.
cpp_declaratort::init_args
exprt & init_args()
Definition: cpp_declarator.h:59
cpp_declaratort::method_qualifier
irept & method_qualifier()
Definition: cpp_declarator.h:68
cpp_declaratort::value
exprt & value()
Definition: cpp_declarator.h:42
cpp_declaratort::merge_type
typet merge_type(const typet &declaration_type) const
Definition: cpp_declarator.cpp:28