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())
62  }
63 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
cpp_declarationt::storage_spec
const cpp_storage_spect & storage_spec() const
Definition: cpp_declaration.h:72
typet::subtype
const typet & subtype() const
Definition: type.h:50
cpp_declarationt::declaratorst
std::vector< cpp_declaratort > declaratorst
Definition: cpp_declaration.h:24
typet
The type of an expression, extends irept.
Definition: type.h:28
irept::pretty
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:495
irept::find
const irept & find(const irep_idt &name) const
Definition: irep.cpp:106
cpp_declaration.h
to_type_with_subtypes
const type_with_subtypest & to_type_with_subtypes(const typet &type)
Definition: type.h:237
cpp_declarationt::name_anon_struct_union
void name_anon_struct_union()
Definition: cpp_declaration.h:142
cpp_declarationt::declarators
const declaratorst & declarators() const
Definition: cpp_declaration.h:62
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:84
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:47
irept::set
void set(const irep_idt &name, const irep_idt &value)
Definition: irep.h:420
irept::is_nil
bool is_nil() const
Definition: irep.h:376
irept::id
const irep_idt & id() const
Definition: irep.h:396
cpp_declarationt::is_template
bool is_template() const
Definition: cpp_declaration.h:50
cpp_declarationt::output
void output(std::ostream &out) const
Definition: cpp_declaration.cpp:16
cpp_namet
Definition: cpp_name.h:16
cpp_declarationt::template_type
template_typet & template_type()
Definition: cpp_declaration.h:96