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 }
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:503
cpp_idt::class_identifier
irep_idt class_identifier
Definition: cpp_id.h:75
ai_verifier_statust::UNKNOWN
@ UNKNOWN
cpp_idt::id_classt::CLASS
@ CLASS
cpp_idt::id_classt::UNKNOWN
@ UNKNOWN
cpp_idt::id_classt::TEMPLATE
@ TEMPLATE
cpp_idt::identifier
irep_idt identifier
Definition: cpp_id.h:72
invariant.h
exprt
Base class for all expressions.
Definition: expr.h:55
cpp_idt::suffix
std::string suffix
Definition: cpp_id.h:79
cpp_idt::id_classt::BLOCK_SCOPE
@ BLOCK_SCOPE
cpp_idt::sub
cpp_id_mapt sub
Definition: cpp_id.h:104
cpp_idt
Definition: cpp_id.h:22
cpp_idt::id_classt
id_classt
Definition: cpp_id.h:27
cpp_idt::is_scope
bool is_scope
Definition: cpp_id.h:43
cpp_idt::is_method
bool is_method
Definition: cpp_id.h:42
cpp_idt::id_classt::SYMBOL
@ SYMBOL
cpp_idt::secondary_scopes
scope_listt secondary_scopes
Definition: cpp_id.h:108
cpp_idt::id_classt::TEMPLATE_PARAMETER
@ TEMPLATE_PARAMETER
cpp_idt::is_constructor
bool is_constructor
Definition: cpp_id.h:43
cpp_idt::id_classt::ROOT_SCOPE
@ ROOT_SCOPE
cpp_idt::is_member
bool is_member
Definition: cpp_id.h:42
cpp_idt::id_classt::TEMPLATE_SCOPE
@ TEMPLATE_SCOPE
cpp_idt::using_scopes
scope_listt using_scopes
Definition: cpp_id.h:108
operator<<
std::ostream & operator<<(std::ostream &out, const cpp_idt &cpp_id)
Definition: cpp_id.cpp:92
cpp_idt::print_fields
void print_fields(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:44
cpp_idt::id_classt::TYPEDEF
@ TYPEDEF
cpp_idt::is_static_member
bool is_static_member
Definition: cpp_id.h:42
cpp_idt::id_class
id_classt id_class
Definition: cpp_id.h:45
cpp_idt::cpp_idt
cpp_idt()
Definition: cpp_id.cpp:18
cpp_idt::prefix
std::string prefix
Definition: cpp_id.h:79
get_nil_irep
const irept & get_nil_irep()
Definition: irep.cpp:20
is_constructor
static bool is_constructor(const irep_idt &method_name)
Definition: java_bytecode_convert_method.cpp:121
cpp_idt::print
void print(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:31
cpp_idt::base_name
irep_idt base_name
Definition: cpp_id.h:72
cpp_idt::id_classt::ENUM
@ ENUM
cpp_idt::id_classt::NAMESPACE
@ NAMESPACE
cpp_id.h