|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com> |
|
42 // |
|
43 // Permission is hereby granted, free of charge, to any person obtaining a copy |
|
44 // of this software and associated documentation files (the "Software"), to deal |
|
45 // in the Software without restriction, including without limitation the rights |
|
46 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
47 // copies of the Software, and to permit persons to whom the Software is |
|
48 // furnished to do so, subject to the following conditions: |
|
49 // |
|
50 // The above copyright notice and this permission notice shall be included in |
|
51 // all copies or substantial portions of the Software. |
|
52 // |
|
53 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
54 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
55 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
56 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
57 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
58 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
59 // THE SOFTWARE. |
|
60 |
|
61 #ifndef CPLUSPLUS_SCOPE_H |
|
62 #define CPLUSPLUS_SCOPE_H |
|
63 |
|
64 #include "CPlusPlusForwardDeclarations.h" |
|
65 |
|
66 |
|
67 namespace CPlusPlus { |
|
68 |
|
69 class CPLUSPLUS_EXPORT Scope |
|
70 { |
|
71 Scope(const Scope &other); |
|
72 void operator =(const Scope &other); |
|
73 |
|
74 public: |
|
75 typedef Symbol **iterator; |
|
76 |
|
77 public: |
|
78 /// Constructs an empty Scope. |
|
79 Scope(ScopedSymbol *owner = 0); |
|
80 |
|
81 /// Destroy this scope. |
|
82 ~Scope(); |
|
83 |
|
84 /// Returns this scope's owner Symbol. |
|
85 ScopedSymbol *owner() const; |
|
86 |
|
87 /// Sets this scope's owner Symbol. |
|
88 void setOwner(ScopedSymbol *owner); // ### remove me |
|
89 |
|
90 /// Returns the enclosing scope. |
|
91 Scope *enclosingScope() const; |
|
92 |
|
93 /// Returns the eclosing namespace scope. |
|
94 Scope *enclosingNamespaceScope() const; |
|
95 |
|
96 /// Returns the enclosing class scope. |
|
97 Scope *enclosingClassScope() const; |
|
98 |
|
99 /// Returns the enclosing enum scope. |
|
100 Scope *enclosingEnumScope() const; |
|
101 |
|
102 /// Rerturns the enclosing function scope. |
|
103 Scope *enclosingFunctionScope() const; |
|
104 |
|
105 /// Rerturns the enclosing Block scope. |
|
106 Scope *enclosingBlockScope() const; |
|
107 |
|
108 /// Returns true if this scope's owner is a Namespace Symbol. |
|
109 bool isNamespaceScope() const; |
|
110 |
|
111 /// Returns true if this scope's owner is a Class Symbol. |
|
112 bool isClassScope() const; |
|
113 |
|
114 /// Returns true if this scope's owner is an Enum Symbol. |
|
115 bool isEnumScope() const; |
|
116 |
|
117 /// Returns true if this scope's owner is a Block Symbol. |
|
118 bool isBlockScope() const; |
|
119 |
|
120 /// Returns true if this scope's owner is a Function Symbol. |
|
121 bool isFunctionScope() const; |
|
122 |
|
123 /// Returns true if this scope's owner is a Prototype Symbol. |
|
124 bool isPrototypeScope() const; |
|
125 |
|
126 /// Returns true if this scope's owner is an ObjCClass Symbol. |
|
127 bool isObjCClassScope() const; |
|
128 |
|
129 /// Returns true if this scope's owner is an ObjCMethod symbol. |
|
130 bool isObjCMethodScope() const; |
|
131 |
|
132 /// Adds a Symbol to this Scope. |
|
133 void enterSymbol(Symbol *symbol); |
|
134 |
|
135 /// Returns true if this Scope is empty; otherwise returns false. |
|
136 bool isEmpty() const; |
|
137 |
|
138 /// Returns the number of symbols is in the scope. |
|
139 unsigned symbolCount() const; |
|
140 |
|
141 /// Returns the Symbol at the given position. |
|
142 Symbol *symbolAt(unsigned index) const; |
|
143 |
|
144 /// Returns the first Symbol in the scope. |
|
145 iterator firstSymbol() const; |
|
146 |
|
147 /// Returns the last Symbol in the scope. |
|
148 iterator lastSymbol() const; |
|
149 |
|
150 Symbol *lookat(const Name *name) const; |
|
151 Symbol *lookat(const Identifier *id) const; |
|
152 Symbol *lookat(int operatorId) const; |
|
153 |
|
154 private: |
|
155 /// Returns the hash value for the given Symbol. |
|
156 unsigned hashValue(Symbol *symbol) const; |
|
157 |
|
158 /// Updates the hash table. |
|
159 void rehash(); |
|
160 |
|
161 private: |
|
162 enum { DefaultInitialSize = 11 }; |
|
163 |
|
164 ScopedSymbol *_owner; |
|
165 |
|
166 Symbol **_symbols; |
|
167 int _allocatedSymbols; |
|
168 int _symbolCount; |
|
169 |
|
170 Symbol **_hash; |
|
171 int _hashSize; |
|
172 }; |
|
173 |
|
174 } // end of namespace CPlusPlus |
|
175 |
|
176 |
|
177 #endif // CPLUSPLUS_SCOPE_H |