| 1 |
// file : cutl/compiler/context.cxx |
| 2 |
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC |
| 3 |
// license : MIT; see accompanying LICENSE file |
| 4 |
|
| 5 |
#include <cutl/compiler/context.hxx> |
| 6 |
|
| 7 |
using namespace std; |
| 8 |
|
| 9 |
namespace cutl |
| 10 |
{ |
| 11 |
namespace compiler |
| 12 |
{ |
| 13 |
void context:: |
| 14 |
set (string const& key, container::any const& value) |
| 15 |
{ |
| 16 |
using container::any; |
| 17 |
|
| 18 |
std::pair<map::iterator, bool> r ( |
| 19 |
map_.insert (map::value_type (key, value))); |
| 20 |
|
| 21 |
any& x (r.first->second); |
| 22 |
|
| 23 |
if (!r.second) |
| 24 |
{ |
| 25 |
if (value.type_info () != x.type_info ()) |
| 26 |
throw typing (); |
| 27 |
|
| 28 |
x = value; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
void context:: |
| 33 |
remove (string const& key) |
| 34 |
{ |
| 35 |
map::iterator i (map_.find (key)); |
| 36 |
|
| 37 |
if (i == map_.end ()) |
| 38 |
throw no_entry (); |
| 39 |
|
| 40 |
map_.erase (i); |
| 41 |
} |
| 42 |
|
| 43 |
type_info const& context:: |
| 44 |
type_info (string const& key) const |
| 45 |
{ |
| 46 |
map::const_iterator i (map_.find (key)); |
| 47 |
|
| 48 |
if (i == map_.end ()) |
| 49 |
throw no_entry (); |
| 50 |
|
| 51 |
return i->second.type_info (); |
| 52 |
} |
| 53 |
} |
| 54 |
} |