CBMC
cpp_id.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_id.h"
13 
14 #include <ostream>
15 
16 #include <util/invariant.h>
17 
19  is_member(false),
20  is_method(false),
21  is_static_member(false),
22  is_scope(false),
23  is_constructor(false),
24  id_class(id_classt::UNKNOWN),
25  this_expr(static_cast<const exprt &>(get_nil_irep())),
26  compound_counter(0),
27  parent(nullptr)
28 {
29 }
30 
31 void cpp_idt::print(std::ostream &out, unsigned indent) const
32 {
33  print_fields(out, indent);
34 
35  if(!sub.empty())
36  {
37  for(const auto &s : sub)
38  s.second.print(out, indent + 2);
39 
40  out << '\n';
41  }
42 }
43 
44 void cpp_idt::print_fields(std::ostream &out, unsigned indent) const
45 {
46  out << std::string(indent, ' ');
47  out << "**identifier=" << identifier << '\n';
48 
49  out << std::string(indent, ' ');
50  out << " prefix=" << prefix << '\n';
51 
52  out << std::string(indent, ' ');
53  out << " suffix=" << suffix << '\n';
54 
55  out << std::string(indent, ' ');
56  out << " base_name=" << base_name << '\n';
57 
58  out << std::string(indent, ' ');
59  out << " method=" << is_method << '\n';
60 
61  out << std::string(indent, ' ');
62  out << " class_identifier=" << class_identifier << '\n';
63 
64  for(const auto &s : secondary_scopes)
65  {
66  out << std::string(indent, ' ');
67  out << " secondary_scope=" << s->identifier << '\n';
68  }
69 
70  for(const auto &s : using_scopes)
71  {
72  out << std::string(indent, ' ');
73  out << " using_scope=" << s->identifier << '\n';
74  }
75 
76  out << std::string(indent, ' ');
77  out << " flags:";
78  if(is_constructor)
79  out << " constructor";
80  if(is_scope)
81  out << " scope";
82  if(is_member)
83  out << " member";
85  out << " static_member";
86  out << '\n';
87 
88  out << std::string(indent, ' ');
89  out << " id_class=" << id_class << '\n';
90 }
91 
92 std::ostream &operator<<(std::ostream &out, const cpp_idt &cpp_id)
93 {
94  cpp_id.print(out, 0);
95  return out;
96 }
97 
98 std::ostream &operator<<(std::ostream &out, const cpp_idt::id_classt &id_class)
99 {
100  // clang-format off
101  switch(id_class)
102  {
103  case cpp_idt::id_classt::UNKNOWN: return out<<"UNKNOWN";
104  case cpp_idt::id_classt::SYMBOL: return out<<"SYMBOL";
105  case cpp_idt::id_classt::TYPEDEF: return out<<"TYPEDEF";
106  case cpp_idt::id_classt::CLASS: return out<<"CLASS";
107  case cpp_idt::id_classt::TEMPLATE: return out<<"TEMPLATE";
108  case cpp_idt::id_classt::TEMPLATE_PARAMETER:return out<<"TEMPLATE_PARAMETER";
109  case cpp_idt::id_classt::ROOT_SCOPE: return out<<"ROOT_SCOPE";
110  case cpp_idt::id_classt::BLOCK_SCOPE: return out<<"BLOCK_SCOPE";
111  case cpp_idt::id_classt::TEMPLATE_SCOPE: return out<<"TEMPLATE_SCOPE";
112  case cpp_idt::id_classt::NAMESPACE: return out<<"NAMESPACE";
113  case cpp_idt::id_classt::ENUM: return out<<"ENUM";
114  }
115  // clang-format on
116 
117  UNREACHABLE;
118 }
Definition: cpp_id.h:23
irep_idt identifier
Definition: cpp_id.h:72
bool is_member
Definition: cpp_id.h:42
scope_listt using_scopes
Definition: cpp_id.h:108
std::string prefix
Definition: cpp_id.h:79
bool is_scope
Definition: cpp_id.h:43
id_classt
Definition: cpp_id.h:28
cpp_id_mapt sub
Definition: cpp_id.h:104
id_classt id_class
Definition: cpp_id.h:45
void print(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:31
bool is_constructor
Definition: cpp_id.h:43
bool is_method
Definition: cpp_id.h:42
cpp_idt()
Definition: cpp_id.cpp:18
bool is_static_member
Definition: cpp_id.h:42
void print_fields(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:44
scope_listt secondary_scopes
Definition: cpp_id.h:108
irep_idt class_identifier
Definition: cpp_id.h:75
irep_idt base_name
Definition: cpp_id.h:72
std::string suffix
Definition: cpp_id.h:79
Base class for all expressions.
Definition: expr.h:56
std::ostream & operator<<(std::ostream &out, const cpp_idt &cpp_id)
Definition: cpp_id.cpp:92
C++ Language Type Checking.
const irept & get_nil_irep()
Definition: irep.cpp:19
static bool is_constructor(const irep_idt &method_name)
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525