cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp_typecheck_using.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_typecheck.h
"
13
14
#include <
util/source_location.h
>
15
16
void
cpp_typecheckt::convert
(
cpp_usingt
&cpp_using)
17
{
18
// there are two forms of using clauses:
19
// a) using namespace SCOPE; ("using directive")
20
// b) using SCOPE::id; ("using declaration")
21
22
cpp_typecheck_resolvet
resolver(*
this
);
23
cpp_save_scopet
save_scope(this->
cpp_scopes
);
24
25
irep_idt
base_name;
26
cpp_template_args_non_tct
template_args;
27
resolver.
resolve_scope
(cpp_using.
name
(), base_name, template_args);
28
29
bool
qualified=cpp_using.
name
().
is_qualified
();
30
31
const
auto
id_set =
cpp_scopes
.current_scope().lookup(
32
base_name, qualified ?
cpp_scopet::QUALIFIED
:
cpp_scopet::RECURSIVE
);
33
34
bool
using_directive=cpp_using.
get_namespace
();
35
36
if
(id_set.empty())
37
{
38
error
().
source_location
=cpp_using.
name
().
source_location
();
39
error
() <<
"using "
<< (using_directive ?
"namespace"
:
"identifier"
)
40
<<
" '"
<< base_name <<
"' not found"
<<
eom
;
41
throw
0;
42
}
43
44
// go back to where we used to be
45
save_scope.
restore
();
46
47
for
(cpp_scopest::id_sett::iterator
48
it=id_set.begin();
49
it!=id_set.end();
50
it++)
51
{
52
if
(using_directive)
53
{
54
if
((*it)->id_class==
cpp_idt::id_classt::NAMESPACE
)
55
cpp_scopes
.current_scope().add_using_scope(
56
static_cast<
cpp_scopet
&
>
(**it));
57
else
58
{
59
// we should likely complain about this
60
}
61
}
62
else
// declaration
63
{
64
// we copy all 'normal' identifiers into the current scope
65
if
((*it)->id_class!=
cpp_idt::id_classt::TEMPLATE_PARAMETER
&&
66
(*it)->id_class!=
cpp_idt::id_classt::NAMESPACE
)
67
cpp_scopes
.current_scope().insert(**it);
68
}
69
}
70
}
cpp_idt::id_classt::TEMPLATE_PARAMETER
@ TEMPLATE_PARAMETER
Definition
cpp_id.h:35
cpp_idt::id_classt::NAMESPACE
@ NAMESPACE
Definition
cpp_id.h:36
cpp_namet::is_qualified
bool is_qualified() const
Definition
cpp_name.h:109
cpp_namet::source_location
const source_locationt & source_location() const
Definition
cpp_name.h:73
cpp_save_scopet
Definition
cpp_scopes.h:128
cpp_save_scopet::restore
void restore()
Definition
cpp_scopes.h:141
cpp_scopet
Definition
cpp_scope.h:21
cpp_scopet::QUALIFIED
@ QUALIFIED
Definition
cpp_scope.h:30
cpp_scopet::RECURSIVE
@ RECURSIVE
Definition
cpp_scope.h:30
cpp_template_args_non_tct
Definition
cpp_template_args.h:45
cpp_typecheck_resolvet::resolve_scope
cpp_scopet & resolve_scope(const cpp_namet &cpp_name, irep_idt &base_name, cpp_template_args_non_tct &template_args)
Definition
cpp_typecheck_resolve.cpp:866
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
cpp_usingt
Definition
cpp_using.h:18
cpp_usingt::name
cpp_namet & name()
Definition
cpp_using.h:24
cpp_usingt::get_namespace
bool get_namespace() const
Definition
cpp_using.h:34
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
cpp_typecheck.h
C++ Language Type Checking.
source_location.h
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
cpp
cpp_typecheck_using.cpp
Generated by
1.17.0