blob: 491ec8df859c562e37c57b1246e46d382b79eb21 (
plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// file : xsde/cxx/parser/validating/inheritance-map.cxx
// author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#include <xsde/cxx/config.hxx>
#include <string.h> // strcmp
#ifndef XSDE_EXCEPTIONS
# include <assert.h> // assert
# include <stdlib.h> // exit
#endif
#include <xsde/cxx/parser/validating/inheritance-map.hxx>
#include <xsde/cxx/parser/validating/inheritance-map-load.hxx>
namespace xsde
{
namespace cxx
{
namespace parser
{
namespace validating
{
inheritance_map* inheritance_map_init::map = 0;
size_t inheritance_map_init::count = 0;
bool inheritance_map::
check (const char* derived, const char* base) const
{
if (strcmp (derived, base) == 0)
return true;
const void* p = find (derived);
if (p)
{
const char* b = *static_cast<const char* const*> (p);
return strcmp (base, b) == 0 ? true : check (b, base);
}
return false;
}
// inheritance_map_init
//
inheritance_map_init::
inheritance_map_init ()
{
if (count == 0)
{
map = new inheritance_map (XSDE_PARSER_IMAP_BUCKETS);
#ifndef XSDE_EXCEPTIONS
if (map == 0 || map->_error () != inheritance_map::error_none)
{
// This is static initialization so there is nothing we can do.
// The best thing is to fail fast. abort() would have probably
// been the better choice here but it is not available on some
// platforms (notably, WinCE).
//
assert (false);
exit (1);
}
#endif
}
++count;
}
inheritance_map_init::
~inheritance_map_init ()
{
if (--count == 0)
delete map;
}
// inheritance_map_entry
//
inheritance_map_entry::
inheritance_map_entry (const char* derived, const char* base)
{
inheritance_map& m = inheritance_map_instance ();
m.insert (derived, base);
#ifndef XSDE_EXCEPTIONS
if (m._error () != inheritance_map::error_none)
{
// This is static initialization so there is nothing we can do.
// The best thing is to fail fast. abort() would have probably
// been the better choice here but it is not available on some
// platforms (notably, WinCE).
//
assert (false);
exit (1);
}
#endif
}
//
//
size_t
parser_imap_elements ()
{
return inheritance_map_instance ().size ();
}
}
}
}
}
|