cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp_typecheck_namespace.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 <
util/source_location.h
>
13
#include <
util/symbol_table_base.h
>
14
15
#include "
cpp_typecheck.h
"
16
17
void
cpp_typecheckt::convert
(
cpp_namespace_spect
&namespace_spec)
18
{
19
// save the scope
20
cpp_save_scopet
saved_scope(
cpp_scopes
);
21
22
const
irep_idt
&name=namespace_spec.
get_namespace
();
23
24
if
(name.
empty
())
25
{
26
// "unique namespace"
27
error
().
source_location
=namespace_spec.
source_location
();
28
error
() <<
"unique namespace not supported yet"
<<
eom
;
29
throw
0;
30
}
31
32
irep_idt
final_name(name);
33
34
std::string identifier=
35
cpp_scopes
.current_scope().prefix+
id2string
(final_name);
36
37
symbol_table_baset::symbolst::const_iterator it =
38
symbol_table
.symbols.find(identifier);
39
40
if
(it!=
symbol_table
.symbols.end())
41
{
42
if
(namespace_spec.
alias
().
is_not_nil
())
43
{
44
error
().
source_location
=namespace_spec.
source_location
();
45
error
() <<
"namespace alias '"
<< final_name <<
"' previously declared\n"
46
<<
"location of previous declaration: "
<< it->second.location
47
<<
eom
;
48
throw
0;
49
}
50
51
if
(it->second.type.id()!=ID_namespace)
52
{
53
error
().
source_location
=namespace_spec.
source_location
();
54
error
() <<
"namespace '"
<< final_name <<
"' previously declared\n"
55
<<
"location of previous declaration: "
<< it->second.location
56
<<
eom
;
57
throw
0;
58
}
59
60
// enter that scope
61
cpp_scopes
.set_scope(it->first);
62
}
63
else
64
{
65
symbolt
symbol{identifier,
typet
(ID_namespace), ID_cpp};
66
symbol.
base_name
=final_name;
67
symbol.
location
=namespace_spec.
source_location
();
68
symbol.
module
=
module
;
69
70
if
(!
symbol_table
.insert(std::move(symbol)).second)
71
{
72
error
().
source_location
=symbol.
location
;
73
error
() <<
"cpp_typecheckt::convert_namespace: symbol_table.move() failed"
74
<<
eom
;
75
throw
0;
76
}
77
78
cpp_scopes
.new_namespace(final_name);
79
}
80
81
if
(namespace_spec.
alias
().
is_not_nil
())
82
{
83
cpp_typecheck_resolvet
resolver(*
this
);
84
cpp_scopet
&s=resolver.
resolve_namespace
(namespace_spec.
alias
());
85
cpp_scopes
.current_scope().add_using_scope(s);
86
}
87
else
88
{
89
// do the declarations
90
for
(
auto
&item : namespace_spec.
items
())
91
convert
(item);
92
}
93
}
c_typecheck_baset::symbol_table
symbol_table_baset & symbol_table
Definition
c_typecheck_base.h:71
cpp_namespace_spect
Definition
cpp_namespace_spec.h:20
cpp_namespace_spect::items
const itemst & items() const
Definition
cpp_namespace_spec.h:29
cpp_namespace_spect::get_namespace
const irep_idt & get_namespace() const
Definition
cpp_namespace_spec.h:39
cpp_namespace_spect::alias
cpp_namet & alias()
Definition
cpp_namespace_spec.h:49
cpp_save_scopet
Definition
cpp_scopes.h:128
cpp_scopet
Definition
cpp_scope.h:21
cpp_typecheck_resolvet::resolve_namespace
cpp_scopet & resolve_namespace(const cpp_namet &cpp_name)
Definition
cpp_typecheck_resolve.cpp:1241
cpp_typecheckt::convert
void convert(cpp_linkage_spect &)
Definition
cpp_typecheck_linkage_spec.cpp:14
cpp_typecheckt::cpp_scopes
cpp_scopest cpp_scopes
Definition
cpp_typecheck.h:92
cpp_typecheckt::cpp_typecheck_resolvet
friend class cpp_typecheck_resolvet
Definition
cpp_typecheck.h:68
dstringt::empty
bool empty() const
Definition
dstring.h:89
exprt::source_location
const source_locationt & source_location() const
Definition
expr.h:236
irept::is_not_nil
bool is_not_nil() const
Definition
irep.h:372
messaget::mstreamt::source_location
source_locationt source_location
Definition
message.h:239
messaget::error
mstreamt & error() const
Definition
message.h:391
messaget::eom
static eomt eom
Definition
message.h:289
symbolt
Symbol table entry.
Definition
symbol.h:28
symbolt::base_name
irep_idt base_name
Base (non-scoped) name.
Definition
symbol.h:46
symbolt::module
irep_idt module
Name of module the symbol belongs to.
Definition
symbol.h:43
symbolt::location
source_locationt location
Source code location of definition of symbol.
Definition
symbol.h:37
typet
The type of an expression, extends irept.
Definition
type.h:29
cpp_typecheck.h
C++ Language Type Checking.
id2string
const std::string & id2string(const irep_idt &d)
Definition
irep.h:44
source_location.h
symbol_table_base.h
Author: Diffblue Ltd.
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
cpp
cpp_typecheck_namespace.cpp
Generated by
1.17.0