Mercurial > projects > qtd
annotate generator/parser/rpp/pp-environment.h @ 52:09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
author | eldar |
---|---|
date | Mon, 18 May 2009 15:23:28 +0000 |
parents | e78566595089 |
children |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
52
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
3 ** Copyright (C) 1992-2009 Nokia. All rights reserved. |
1 | 4 ** Copyright 2005 Roberto Raggi <roberto@kdevelop.org> |
5 ** | |
6 ** This file is part of Qt Jambi. | |
7 ** | |
52
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
8 ** Commercial Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
9 Licensees holding valid Qt Commercial licenses may use this file in |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
10 accordance with the Qt Commercial License Agreement provided with the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
11 Software or, alternatively, in accordance with the terms contained in |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
12 a written agreement between you and Nokia. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
13 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
14 GNU Lesser General Public License Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
15 Alternatively, this file may be used under the terms of the GNU Lesser |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
16 General Public License version 2.1 as published by the Free Software |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
17 Foundation and appearing in the file LICENSE.LGPL included in the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
18 packaging of this file. Please review the following information to |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
19 ensure the GNU Lesser General Public License version 2.1 requirements |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
20 will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
21 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
22 In addition, as a special exception, Nokia gives you certain |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
23 additional rights. These rights are described in the Nokia Qt LGPL |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
24 Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
25 package. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
26 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
27 GNU General Public License Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
28 Alternatively, this file may be used under the terms of the GNU |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
29 General Public License version 3.0 as published by the Free Software |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
30 Foundation and appearing in the file LICENSE.GPL included in the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
31 packaging of this file. Please review the following information to |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
32 ensure the GNU General Public License version 3.0 requirements will be |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
33 met: http://www.gnu.org/copyleft/gpl.html. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
34 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
35 If you are unsure which license is appropriate for your use, please |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
36 contact the sales department at qt-sales@nokia.com. |
1 | 37 |
38 ** | |
39 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
40 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
41 ** | |
42 ****************************************************************************/ | |
43 | |
44 #ifndef PP_ENVIRONMENT_H | |
45 #define PP_ENVIRONMENT_H | |
46 | |
47 #include <vector> | |
48 #include <cstring> | |
49 | |
50 namespace rpp { | |
51 | |
52 class pp_environment | |
53 { | |
54 public: | |
55 typedef std::vector<pp_macro*>::const_iterator const_iterator; | |
56 | |
57 public: | |
58 pp_environment (): | |
59 current_line (0), | |
60 _M_hash_size (4093) | |
61 { | |
62 _M_base = (pp_macro **) memset (new pp_macro* [_M_hash_size], 0, _M_hash_size * sizeof (pp_macro*)); | |
63 } | |
64 | |
65 ~pp_environment () | |
66 { | |
67 for (std::size_t i = 0; i < _M_macros.size (); ++i) | |
68 delete _M_macros [i]; | |
69 | |
70 delete [] _M_base; | |
71 } | |
72 | |
73 const_iterator first_macro () const { return _M_macros.begin (); } | |
74 const_iterator last_macro () const { return _M_macros.end (); } | |
75 | |
76 inline void bind (pp_fast_string const *__name, pp_macro const &__macro) | |
77 { | |
78 std::size_t h = hash_code (*__name) % _M_hash_size; | |
79 pp_macro *m = new pp_macro (__macro); | |
80 m->name = __name; | |
81 m->next = _M_base [h]; | |
82 m->hash_code = h; | |
83 _M_base [h] = m; | |
84 | |
85 _M_macros.push_back (m); | |
86 | |
87 if (_M_macros.size() == _M_hash_size) | |
88 rehash(); | |
89 } | |
90 | |
91 inline void unbind (pp_fast_string const *__name) | |
92 { | |
93 if (pp_macro *m = resolve (__name)) | |
94 m->hidden = true; | |
95 } | |
96 | |
97 inline void unbind (char const *__s, std::size_t __size) | |
98 { | |
99 pp_fast_string __tmp (__s, __size); | |
100 unbind (&__tmp); | |
101 } | |
102 | |
103 inline pp_macro *resolve (pp_fast_string const *__name) const | |
104 { | |
105 std::size_t h = hash_code (*__name) % _M_hash_size; | |
106 pp_macro *it = _M_base [h]; | |
107 | |
108 while (it && it->name && it->hash_code == h && (*it->name != *__name || it->hidden)) | |
109 it = it->next; | |
110 | |
111 return it; | |
112 } | |
113 | |
114 inline pp_macro *resolve (char const *__data, std::size_t __size) const | |
115 { | |
116 pp_fast_string const __tmp (__data, __size); | |
117 return resolve (&__tmp); | |
118 } | |
119 | |
120 std::string current_file; | |
121 int current_line; | |
122 | |
123 private: | |
124 inline std::size_t hash_code (pp_fast_string const &s) const | |
125 { | |
126 std::size_t hash_value = 0; | |
127 | |
128 for (std::size_t i = 0; i < s.size (); ++i) | |
129 hash_value = (hash_value << 5) - hash_value + s.at (i); | |
130 | |
131 return hash_value; | |
132 } | |
133 | |
134 void rehash() | |
135 { | |
136 delete[] _M_base; | |
137 | |
138 _M_hash_size <<= 1; | |
139 | |
140 _M_base = (pp_macro **) memset (new pp_macro* [_M_hash_size], 0, _M_hash_size * sizeof(pp_macro*)); | |
141 for (std::size_t index = 0; index < _M_macros.size (); ++index) | |
142 { | |
143 pp_macro *elt = _M_macros [index]; | |
144 std::size_t h = hash_code (*elt->name) % _M_hash_size; | |
145 elt->next = _M_base [h]; | |
146 elt->hash_code = h; | |
147 _M_base [h] = elt; | |
148 } | |
149 } | |
150 | |
151 private: | |
152 std::vector<pp_macro*> _M_macros; | |
153 pp_macro **_M_base; | |
154 std::size_t _M_hash_size; | |
155 }; | |
156 | |
157 } // namespace rpp | |
158 | |
159 #endif // PP_ENVIRONMENT_H | |
160 | |
161 // kate: space-indent on; indent-width 2; replace-tabs on; |