CBMC
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  for(typet &subtype : to_type_with_subtypes(dest).subtypes())
61  name_anon_struct_union(subtype);
62  }
63 }
void output(std::ostream &out) const
const declaratorst & declarators() const
bool is_template() const
const cpp_storage_spect & storage_spec() const
std::vector< cpp_declaratort > declaratorst
template_typet & template_type()
void name_anon_struct_union()
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
typet & type()
Return the type of the expression.
Definition: expr.h:84
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:482
const irept & find(const irep_idt &name) const
Definition: irep.cpp:93
void set(const irep_idt &name, const irep_idt &value)
Definition: irep.h:408
const irep_idt & id() const
Definition: irep.h:384
bool is_nil() const
Definition: irep.h:364
The type of an expression, extends irept.
Definition: type.h:29
C++ Language Type Checking.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:40
const type_with_subtypest & to_type_with_subtypes(const typet &type)
Definition: type.h:252