cprover
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 <cassert>
16 
17 #include "cpp_declarator.h"
18 #include "cpp_storage_spec.h"
19 #include "cpp_member_spec.h"
20 #include "cpp_template_type.h"
21 #include "cpp_template_args.h"
22 
23 class cpp_declarationt:public exprt
24 {
25 public:
26  typedef std::vector<cpp_declaratort> declaratorst;
27 
28  cpp_declarationt():exprt(ID_cpp_declaration)
29  {
30  }
31 
32  bool is_empty() const
33  {
34  return type().is_nil() && !has_operands();
35  }
36 
37  bool is_constructor() const
38  {
39  return type().id()==ID_constructor;
40  }
41 
42  bool is_static_assert() const
43  {
44  return get_bool(ID_is_static_assert);
45  }
46 
47  bool is_destructor() const
48  {
49  return type().id()==ID_destructor;
50  }
51 
52  bool is_template() const
53  {
54  return get_bool(ID_is_template);
55  }
56 
57  bool is_class_template() const
58  {
59  return is_template() &&
60  type().id()==ID_struct &&
61  declarators().empty();
62  }
63 
64  const declaratorst &declarators() const
65  {
66  return (const declaratorst &)operands();
67  }
68 
69  declaratorst &declarators()
70  {
71  return (declaratorst &)operands();
72  }
73 
75  {
76  return static_cast<const cpp_storage_spect &>(
77  find(ID_storage_spec));
78  }
79 
81  {
82  return static_cast<cpp_storage_spect &>(
83  add(ID_storage_spec));
84  }
85 
87  {
88  return static_cast<const cpp_member_spect &>(
89  find(ID_member_spec));
90  }
91 
93  {
94  return static_cast<cpp_member_spect &>(
95  add(ID_member_spec));
96  }
97 
99  {
100  return static_cast<template_typet &>(add(ID_template_type));
101  }
102 
104  {
105  return static_cast<const template_typet &>(find(ID_template_type));
106  }
107 
109  {
110  return static_cast<cpp_template_args_non_tct &>(
111  add("partial_specialization_args"));
112  }
113 
115  {
116  return static_cast<const cpp_template_args_non_tct &>(
117  find("partial_specialization_args"));
118  }
119 
121  {
122  set("specialization_of", id);
123  }
124 
126  {
127  return get("specialization_of");
128  }
129 
131  {
132  set(ID_is_typedef, true);
133  }
134 
135  bool is_typedef() const
136  {
137  return get_bool(ID_is_typedef);
138  }
139 
140  void output(std::ostream &out) const;
141 
142  // for assigning a tag for struct/union in the type based on
143  // the name of the first declarator
145  void name_anon_struct_union(typet &dest);
146 };
147 
149 {
150  assert(irep.id()==ID_cpp_declaration);
151  return static_cast<cpp_declarationt &>(irep);
152 }
153 
154 inline const cpp_declarationt &to_cpp_declaration(const irept &irep)
155 {
156  assert(irep.id()==ID_cpp_declaration);
157  return static_cast<const cpp_declarationt &>(irep);
158 }
159 
160 #endif // CPROVER_CPP_CPP_DECLARATION_H
bool is_typedef() const
The type of an expression.
Definition: type.h:20
bool is_nil() const
Definition: irep.h:103
const cpp_storage_spect & storage_spec() const
bool is_destructor() const
void name_anon_struct_union()
irep_idt get_specialization_of() const
cpp_template_args_non_tct & partial_specialization_args()
typet & type()
Definition: expr.h:60
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:240
C++ Language Type Checking.
const cpp_member_spect & member_spec() const
bool is_class_template() const
const template_typet & template_type() const
const irep_idt & id() const
Definition: irep.h:189
cpp_member_spect & member_spec()
const declaratorst & declarators() const
void set_specialization_of(const irep_idt &id)
Base class for tree-like data structures with sharing.
Definition: irep.h:87
declaratorst & declarators()
bool is_constructor() const
C++ Language Type Checking.
bool has_operands() const
Definition: expr.h:67
bool is_template() const
cpp_declarationt & to_cpp_declaration(irept &irep)
Base class for all expressions.
Definition: expr.h:46
bool is_static_assert() const
irept & add(const irep_namet &name)
Definition: irep.cpp:306
operandst & operands()
Definition: expr.h:70
template_typet & template_type()
std::vector< cpp_declaratort > declaratorst
const irept & find(const irep_namet &name) const
Definition: irep.cpp:285
const cpp_template_args_non_tct & partial_specialization_args() const
void output(std::ostream &out) const
bool is_empty() const
cpp_storage_spect & storage_spec()