CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cpp_typecheck_namespace.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: C++ Language Type Checking
4
5Author: Daniel Kroening, kroening@cs.cmu.edu
6
7\*******************************************************************/
8
11
14
15#include "cpp_typecheck.h"
16
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=
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
79 }
80
81 if(namespace_spec.alias().is_not_nil())
82 {
84 cpp_scopet &s=resolver.resolve_namespace(namespace_spec.alias());
86 }
87 else
88 {
89 // do the declarations
90 for(auto &item : namespace_spec.items())
92 }
93}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
symbol_table_baset & symbol_table
std::string prefix
Definition cpp_id.h:79
cpp_scopet & new_namespace(const irep_idt &new_scope_name)
Definition cpp_scopes.h:49
cpp_scopet & set_scope(const irep_idt &identifier)
Definition cpp_scopes.h:87
cpp_scopet & current_scope()
Definition cpp_scopes.h:32
void add_using_scope(cpp_scopet &other)
Definition cpp_scope.h:109
void convert(cpp_linkage_spect &)
cpp_scopest cpp_scopes
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
bool empty() const
Definition dstring.h:89
source_locationt source_location
Definition message.h:239
mstreamt & error() const
Definition message.h:391
static eomt eom
Definition message.h:289
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
Symbol table entry.
Definition symbol.h:28
The type of an expression, extends irept.
Definition type.h:29
C++ Language Type Checking.
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
Author: Diffblue Ltd.