cprover
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 "cpp_scope.h"
17 
19  is_member(false),
20  is_method(false),
21  is_static_member(false),
22  is_scope(false),
23  is_constructor(false),
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(cpp_id_mapt::const_iterator it=sub.begin();
38  it!=sub.end();
39  it++)
40  it->second.print(out, indent+2);
41 
42  out << '\n';
43  }
44 }
45 
46 void cpp_idt::print_fields(std::ostream &out, unsigned indent) const
47 {
48  for(unsigned i=0; i<indent; i++) out << ' ';
49  out << "**identifier=" << identifier << '\n';
50 
51  for(unsigned i=0; i<indent; i++) out << ' ';
52  out << " prefix=" << prefix << '\n';
53 
54  for(unsigned i=0; i<indent; i++) out << ' ';
55  out << " suffix=" << suffix << '\n';
56 
57  for(unsigned i=0; i<indent; i++) out << ' ';
58  out << " base_name=" << base_name << '\n';
59 
60  for(unsigned i=0; i<indent; i++) out << ' ';
61  out << " method=" << is_method << '\n';
62 
63  for(unsigned i=0; i<indent; i++) out << ' ';
64  out << " class_identifier=" << class_identifier << '\n';
65 
66  for(scope_listt::const_iterator
67  it=secondary_scopes.begin();
68  it!=secondary_scopes.end();
69  it++)
70  {
71  for(unsigned i=0; i<indent; i++) out << ' ';
72  out << " secondary_scope=" << (*it)->identifier << '\n';
73  }
74 
75  for(scope_listt::const_iterator
76  it=using_scopes.begin();
77  it!=using_scopes.end();
78  it++)
79  {
80  for(unsigned i=0; i<indent; i++) out << ' ';
81  out << " using_scope=" << (*it)->identifier << '\n';
82  }
83 
84  for(unsigned i=0; i<indent; i++) out << ' ';
85  out << " flags:";
86  if(is_constructor)
87  out << " constructor";
88  if(is_scope)
89  out << " scope";
90  if(is_member)
91  out << " member";
93  out << " static_member";
94  out << '\n';
95 
96  for(unsigned i=0; i<indent; i++) out << ' ';
97  out << " id_class=" << id_class << '\n';
98 }
99 
100 std::ostream &operator<<(std::ostream &out, const cpp_idt &cpp_id)
101 {
102  cpp_id.print(out, 0);
103  return out;
104 }
105 
106 std::ostream &operator<<(std::ostream &out, const cpp_idt::id_classt &id_class)
107 {
108  switch(id_class)
109  {
110  case cpp_idt::id_classt::UNKNOWN: return out<<"UNKNOWN";
111  case cpp_idt::id_classt::SYMBOL: return out<<"SYMBOL";
112  case cpp_idt::id_classt::TYPEDEF: return out<<"TYPEDEF";
113  case cpp_idt::id_classt::CLASS: return out<<"CLASS";
114  case cpp_idt::id_classt::TEMPLATE: return out<<"TEMPLATE";
115  case cpp_idt::id_classt::TEMPLATE_PARAMETER:return out<<"TEMPLATE_PARAMETER";
116  case cpp_idt::id_classt::ROOT_SCOPE: return out<<"ROOT_SCOPE";
117  case cpp_idt::id_classt::BLOCK_SCOPE: return out<<"BLOCK_SCOPE";
118  case cpp_idt::id_classt::TEMPLATE_SCOPE: return out<<"TEMPLATE_SCOPE";
119  case cpp_idt::id_classt::NAMESPACE: return out<<"NAMESPACE";
120  default: return out << "(OTHER)";
121  }
122 }
const irept & get_nil_irep()
Definition: irep.cpp:56
cpp_id_mapt sub
Definition: cpp_id.h:105
static bool is_constructor(const irep_idt &method_name)
bool is_member
Definition: cpp_id.h:48
void print(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:31
void print_fields(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:46
bool is_constructor
Definition: cpp_id.h:48
std::ostream & operator<<(std::ostream &out, const cpp_idt &cpp_id)
Definition: cpp_id.cpp:100
bool is_static_member
Definition: cpp_id.h:48
C++ Language Type Checking.
std::string suffix
Definition: cpp_id.h:80
std::string prefix
Definition: cpp_id.h:80
bool is_scope
Definition: cpp_id.h:48
irep_idt base_name
Definition: cpp_id.h:73
irep_idt identifier
Definition: cpp_id.h:73
id_classt id_class
Definition: cpp_id.h:51
scope_listt using_scopes
Definition: cpp_id.h:109
irep_idt class_identifier
Definition: cpp_id.h:76
C++ Language Type Checking.
Base class for all expressions.
Definition: expr.h:42
cpp_idt()
Definition: cpp_id.cpp:18
bool is_method
Definition: cpp_id.h:48
id_classt
Definition: cpp_id.h:33
scope_listt secondary_scopes
Definition: cpp_id.h:109
Definition: cpp_id.h:28