-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathcpp_scopes.cpp
83 lines (69 loc) · 2.04 KB
/
cpp_scopes.cpp
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
/*******************************************************************\
Module: C++ Language Type Checking
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// C++ Language Type Checking
#include "cpp_scopes.h"
#include <util/symbol.h>
#include <ostream>
cpp_scopet &cpp_scopest::new_block_scope()
{
unsigned prefix=++current_scope().compound_counter;
return new_scope(std::to_string(prefix), cpp_idt::id_classt::BLOCK_SCOPE);
}
cpp_idt &cpp_scopest::put_into_scope(
const symbolt &symbol,
cpp_scopet &scope,
bool is_friend)
{
PRECONDITION(!symbol.name.empty());
PRECONDITION(!symbol.base_name.empty());
// functions are also scopes
if(symbol.type.id()==ID_code)
{
cpp_scopest::id_mapt::iterator id_it = id_map.find(symbol.name);
if(id_it == id_map.end())
{
irep_idt block_base_name(std::string("$block:")+symbol.base_name.c_str());
cpp_idt &id = scope.insert(block_base_name);
id.id_class=cpp_idt::id_classt::BLOCK_SCOPE;
id.identifier=symbol.name;
id.is_scope=true;
id.prefix = id2string(scope.prefix) + id2string(symbol.base_name) + "::";
id_map[symbol.name]=&id;
}
}
// should go away, and be replaced by the 'tag only declaration' rule
if(is_friend)
{
cpp_save_scopet saved_scope(*this);
go_to(scope);
cpp_idt &id=current_scope().insert(symbol.base_name);
id.identifier=symbol.name;
id.id_class = cpp_idt::id_classt::SYMBOL;
if(id_map.find(symbol.name)==id_map.end())
id_map[symbol.name]=&id;
return id;
}
else
{
cpp_idt &id=scope.insert(symbol.base_name);
id.identifier=symbol.name;
id.id_class = cpp_idt::id_classt::SYMBOL;
if(id_map.find(symbol.name)==id_map.end())
id_map[symbol.name]=&id;
return id;
}
}
void cpp_scopest::print_current(std::ostream &out) const
{
const cpp_scopet *scope=current_scope_ptr;
do
{
scope->print_fields(out);
out << '\n';
scope=&scope->get_parent();
}
while(!scope->is_root_scope());
}