cprover
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 
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();
31 
33  base_name, qualified?cpp_scopet::QUALIFIED:cpp_scopet::RECURSIVE, id_set);
34 
35  bool using_directive=cpp_using.get_namespace();
36 
37  if(id_set.empty())
38  {
39  error().source_location=cpp_using.name().source_location();
40  error() << "using "
41  << (using_directive?"namespace":"identifier")
42  << " `"
43  << base_name << "' not found" << eom;
44  throw 0;
45  }
46 
47  // go back to where we used to be
48  save_scope.restore();
49 
50  for(cpp_scopest::id_sett::iterator
51  it=id_set.begin();
52  it!=id_set.end();
53  it++)
54  {
55  if(using_directive)
56  {
57  if((*it)->id_class==cpp_idt::id_classt::NAMESPACE)
59  static_cast<cpp_scopet &>(**it));
60  else
61  {
62  // we should likely complain about this
63  }
64  }
65  else // declaration
66  {
67  // we copy all 'normal' identifiers into the current scope
68  if((*it)->id_class!=cpp_idt::id_classt::TEMPLATE_PARAMETER &&
69  (*it)->id_class!=cpp_idt::id_classt::NAMESPACE)
71  }
72  }
73 }
std::set< cpp_idt * > id_sett
Definition: cpp_scopes.h:31
void lookup(const irep_idt &base_name, lookup_kindt kind, id_sett &id_set)
Definition: cpp_scope.cpp:29
static mstreamt & eom(mstreamt &m)
Definition: message.h:193
bool is_qualified() const
Definition: cpp_name.h:108
void convert(cpp_linkage_spect &)
const source_locationt & source_location() const
Definition: cpp_name.h:72
source_locationt source_location
Definition: message.h:175
C++ Language Type Checking.
bool get_namespace() const
Definition: cpp_using.h:34
cpp_scopet & current_scope()
Definition: cpp_scopes.h:33
cpp_namet & name()
Definition: cpp_using.h:24
mstreamt & error()
Definition: message.h:223
cpp_idt & insert(const irep_idt &_base_name)
Definition: cpp_scope.h:48
void add_using_scope(cpp_scopet &other)
Definition: cpp_scope.h:110
cpp_scopet & resolve_scope(const cpp_namet &cpp_name, irep_idt &base_name, cpp_template_args_non_tct &template_args)
cpp_scopest cpp_scopes