CBMC
cpp_declaration.h
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 #ifndef CPROVER_CPP_CPP_DECLARATION_H
13 #define CPROVER_CPP_CPP_DECLARATION_H
14 
15 #include "cpp_declarator.h"
16 #include "cpp_storage_spec.h"
17 #include "cpp_member_spec.h"
18 #include "cpp_template_type.h"
19 #include "cpp_template_args.h"
20 
21 class cpp_declarationt:public exprt
22 {
23 public:
24  typedef std::vector<cpp_declaratort> declaratorst;
25 
26  cpp_declarationt():exprt(ID_cpp_declaration)
27  {
28  }
29 
30  bool is_empty() const
31  {
32  return type().is_nil() && !has_operands();
33  }
34 
35  bool is_constructor() const
36  {
37  return type().id()==ID_constructor;
38  }
39 
40  bool is_static_assert() const
41  {
42  return get_bool(ID_is_static_assert);
43  }
44 
45  bool is_destructor() const
46  {
47  return type().id()==ID_destructor;
48  }
49 
50  bool is_template() const
51  {
52  return get_bool(ID_is_template);
53  }
54 
55  bool is_class_template() const
56  {
57  return is_template() &&
58  type().id()==ID_struct &&
59  declarators().empty();
60  }
61 
62  const declaratorst &declarators() const
63  {
64  return (const declaratorst &)operands();
65  }
66 
68  {
69  return (declaratorst &)operands();
70  }
71 
73  {
74  return static_cast<const cpp_storage_spect &>(
75  find(ID_storage_spec));
76  }
77 
79  {
80  return static_cast<cpp_storage_spect &>(
81  add(ID_storage_spec));
82  }
83 
85  {
86  return static_cast<const cpp_member_spect &>(
87  find(ID_member_spec));
88  }
89 
91  {
92  return static_cast<cpp_member_spect &>(
93  add(ID_member_spec));
94  }
95 
97  {
98  return static_cast<template_typet &>(add(ID_template_type));
99  }
100 
102  {
103  return static_cast<const template_typet &>(find(ID_template_type));
104  }
105 
107  {
108  return static_cast<cpp_template_args_non_tct &>(
109  add(ID_partial_specialization_args));
110  }
111 
113  {
114  return static_cast<const cpp_template_args_non_tct &>(
115  find(ID_partial_specialization_args));
116  }
117 
119  {
120  set(ID_specialization_of, id);
121  }
122 
124  {
125  return get(ID_specialization_of);
126  }
127 
129  {
130  set(ID_is_typedef, true);
131  }
132 
133  bool is_typedef() const
134  {
135  return get_bool(ID_is_typedef);
136  }
137 
138  void output(std::ostream &out) const;
139 
140  // for assigning a tag for struct/union in the type based on
141  // the name of the first declarator
143  void name_anon_struct_union(typet &dest);
144 };
145 
147 {
148  PRECONDITION(irep.id() == ID_cpp_declaration);
149  return static_cast<cpp_declarationt &>(irep);
150 }
151 
152 inline const cpp_declarationt &to_cpp_declaration(const irept &irep)
153 {
154  PRECONDITION(irep.id() == ID_cpp_declaration);
155  return static_cast<const cpp_declarationt &>(irep);
156 }
157 
158 #endif // CPROVER_CPP_CPP_DECLARATION_H
bool is_destructor() const
cpp_member_spect & member_spec()
bool is_static_assert() const
void output(std::ostream &out) const
cpp_storage_spect & storage_spec()
const declaratorst & declarators() const
void set_specialization_of(const irep_idt &id)
irep_idt get_specialization_of() const
bool is_template() const
declaratorst & declarators()
const cpp_storage_spect & storage_spec() const
const cpp_member_spect & member_spec() const
bool is_constructor() const
bool is_class_template() const
bool is_empty() const
const template_typet & template_type() const
std::vector< cpp_declaratort > declaratorst
const cpp_template_args_non_tct & partial_specialization_args() const
template_typet & template_type()
cpp_template_args_non_tct & partial_specialization_args()
bool is_typedef() const
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
Base class for all expressions.
Definition: expr.h:56
bool has_operands() const
Return true if there is at least one operand.
Definition: expr.h:91
typet & type()
Return the type of the expression.
Definition: expr.h:84
operandst & operands()
Definition: expr.h:94
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:360
bool get_bool(const irep_idt &name) const
Definition: irep.cpp:57
const irept & find(const irep_idt &name) const
Definition: irep.cpp:93
const irep_idt & get(const irep_idt &name) const
Definition: irep.cpp:44
void set(const irep_idt &name, const irep_idt &value)
Definition: irep.h:408
const irep_idt & id() const
Definition: irep.h:384
irept & add(const irep_idt &name)
Definition: irep.cpp:103
bool is_nil() const
Definition: irep.h:364
The type of an expression, extends irept.
Definition: type.h:29
cpp_declarationt & to_cpp_declaration(irept &irep)
C++ Language Type Checking.
C++ Language Type Checking.
#define PRECONDITION(CONDITION)
Definition: invariant.h:463