-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathcpp_typecheck_namespace.cpp
More file actions
93 lines (75 loc) · 2.42 KB
/
cpp_typecheck_namespace.cpp
File metadata and controls
93 lines (75 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************\
Module: C++ Language Type Checking
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// C++ Language Type Checking
#include <util/source_location.h>
#include <util/symbol_table_base.h>
#include "cpp_typecheck.h"
void cpp_typecheckt::convert(cpp_namespace_spect &namespace_spec)
{
// save the scope
cpp_save_scopet saved_scope(cpp_scopes);
const irep_idt &name=namespace_spec.get_namespace();
if(name.empty())
{
// "unique namespace"
error().source_location=namespace_spec.source_location();
error() << "unique namespace not supported yet" << eom;
throw 0;
}
irep_idt final_name(name);
std::string identifier=
cpp_scopes.current_scope().prefix+id2string(final_name);
symbol_table_baset::symbolst::const_iterator it =
symbol_table.symbols.find(identifier);
if(it!=symbol_table.symbols.end())
{
if(namespace_spec.alias().is_not_nil())
{
error().source_location=namespace_spec.source_location();
error() << "namespace alias '" << final_name << "' previously declared\n"
<< "location of previous declaration: " << it->second.location
<< eom;
throw 0;
}
if(it->second.type.id()!=ID_namespace)
{
error().source_location=namespace_spec.source_location();
error() << "namespace '" << final_name << "' previously declared\n"
<< "location of previous declaration: " << it->second.location
<< eom;
throw 0;
}
// enter that scope
cpp_scopes.set_scope(it->first);
}
else
{
symbolt symbol{identifier, typet(ID_namespace), ID_cpp};
symbol.base_name=final_name;
symbol.location=namespace_spec.source_location();
symbol.module=module;
if(!symbol_table.insert(std::move(symbol)).second)
{
error().source_location=symbol.location;
error() << "cpp_typecheckt::convert_namespace: symbol_table.move() failed"
<< eom;
throw 0;
}
cpp_scopes.new_namespace(final_name);
}
if(namespace_spec.alias().is_not_nil())
{
cpp_typecheck_resolvet resolver(*this);
cpp_scopet &s=resolver.resolve_namespace(namespace_spec.alias());
cpp_scopes.current_scope().add_using_scope(s);
}
else
{
// do the declarations
for(auto &item : namespace_spec.items())
convert(item);
}
}