cprover
cpp_declaration.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_declaration.h"
13 
14 #include <ostream>
15 
16 void cpp_declarationt::output(std::ostream &out) const
17 {
18  out << "is_template: " << is_template() << "\n";
19  out << "storage: " << storage_spec().pretty() << "\n";
20  out << "template_type: " << template_type().pretty() << "\n";
21  out << "type: " << type().pretty() << "\n";
22 
23  out << "Declarators:" << "\n";
24 
25  for(const auto &it : declarators())
26  {
27  it.output(out);
28  out << "\n";
29  }
30 }
31 
33 {
34  // We name any anon struct/unions according to the first
35  // declarator. No need to do anon enums, which get
36  // a name based on the enum elements.
37 
38  if(dest.id()==ID_struct || dest.id()==ID_union)
39  {
40  if(dest.find(ID_tag).is_nil())
41  {
42  // it's anonymous
43 
44  const declaratorst &d=declarators();
45 
46  if(!d.empty() &&
47  d.front().name().is_simple_name())
48  {
49  // Anon struct/unions without declarator are pretty
50  // useless, but still possible.
51 
52  irep_idt base_name="anon-"+id2string(d.front().name().get_base_name());
53  dest.set(ID_tag, cpp_namet(base_name));
54  dest.set(ID_C_is_anonymous, true);
55  }
56  }
57  }
58  else if(dest.id()==ID_merged_type)
59  {
60  Forall_subtypes(it, dest)
62  }
63 }
The type of an expression.
Definition: type.h:22
bool is_nil() const
Definition: irep.h:172
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
const cpp_storage_spect & storage_spec() const
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:641
void name_anon_struct_union()
typet & type()
Definition: expr.h:56
const irep_idt & id() const
Definition: irep.h:259
const declaratorst & declarators() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
C++ Language Type Checking.
bool is_template() const
#define Forall_subtypes(it, type)
Definition: type.h:167
template_typet & template_type()
std::vector< cpp_declaratort > declaratorst
const irept & find(const irep_namet &name) const
Definition: irep.cpp:285
void output(std::ostream &out) const
void set(const irep_namet &name, const irep_idt &value)
Definition: irep.h:286