|
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 #include "Semantic.h" |
|
62 #include "TranslationUnit.h" |
|
63 #include "Control.h" |
|
64 #include "Scope.h" |
|
65 #include "Symbols.h" |
|
66 #include "Token.h" |
|
67 #include "CheckSpecifier.h" |
|
68 #include "CheckDeclaration.h" |
|
69 #include "CheckDeclarator.h" |
|
70 #include "CheckStatement.h" |
|
71 #include "CheckExpression.h" |
|
72 #include "CheckName.h" |
|
73 |
|
74 using namespace CPlusPlus; |
|
75 |
|
76 class Semantic::Data |
|
77 { |
|
78 public: |
|
79 Data(Semantic *semantic, TranslationUnit *translationUnit) |
|
80 : semantic(semantic), |
|
81 translationUnit(translationUnit), |
|
82 control(translationUnit->control()), |
|
83 skipFunctionBodies(false), |
|
84 visibility(Symbol::Public), |
|
85 ojbcVisibility(Symbol::Protected), |
|
86 methodKey(Function::NormalMethod), |
|
87 checkSpecifier(0), |
|
88 checkDeclaration(0), |
|
89 checkDeclarator(0), |
|
90 checkExpression(0), |
|
91 checkStatement(0), |
|
92 checkName(0) |
|
93 { } |
|
94 |
|
95 ~Data() |
|
96 { |
|
97 delete checkSpecifier; |
|
98 delete checkDeclaration; |
|
99 delete checkDeclarator; |
|
100 delete checkExpression; |
|
101 delete checkStatement; |
|
102 delete checkName; |
|
103 } |
|
104 |
|
105 Semantic *semantic; |
|
106 TranslationUnit *translationUnit; |
|
107 Control *control; |
|
108 bool skipFunctionBodies; |
|
109 int visibility; |
|
110 int ojbcVisibility; |
|
111 int methodKey; |
|
112 CheckSpecifier *checkSpecifier; |
|
113 CheckDeclaration *checkDeclaration; |
|
114 CheckDeclarator *checkDeclarator; |
|
115 CheckExpression *checkExpression; |
|
116 CheckStatement *checkStatement; |
|
117 CheckName *checkName; |
|
118 }; |
|
119 |
|
120 Semantic::Semantic(TranslationUnit *translationUnit) |
|
121 { |
|
122 d = new Data(this, translationUnit); |
|
123 d->checkSpecifier = new CheckSpecifier(this); |
|
124 d->checkDeclaration = new CheckDeclaration(this); |
|
125 d->checkDeclarator = new CheckDeclarator(this); |
|
126 d->checkExpression = new CheckExpression(this); |
|
127 d->checkStatement = new CheckStatement(this); |
|
128 d->checkName = new CheckName(this); |
|
129 } |
|
130 |
|
131 Semantic::~Semantic() |
|
132 { delete d; } |
|
133 |
|
134 TranslationUnit *Semantic::translationUnit() const |
|
135 { return d->translationUnit; } |
|
136 |
|
137 Control *Semantic::control() const |
|
138 { return d->control; } |
|
139 |
|
140 FullySpecifiedType Semantic::check(SpecifierListAST *specifier, Scope *scope) |
|
141 { return d->checkSpecifier->check(specifier, scope); } |
|
142 |
|
143 void Semantic::check(DeclarationAST *declaration, Scope *scope, TemplateParameters *templateParameters) |
|
144 { d->checkDeclaration->check(declaration, scope, templateParameters); } |
|
145 |
|
146 FullySpecifiedType Semantic::check(DeclaratorAST *declarator, const FullySpecifiedType &type, |
|
147 Scope *scope, const Name **name) |
|
148 { return d->checkDeclarator->check(declarator, type, scope, name); } |
|
149 |
|
150 FullySpecifiedType Semantic::check(PtrOperatorListAST *ptrOperators, const FullySpecifiedType &type, |
|
151 Scope *scope) |
|
152 { return d->checkDeclarator->check(ptrOperators, type, scope); } |
|
153 |
|
154 FullySpecifiedType Semantic::check(ObjCMethodPrototypeAST *methodPrototype, Scope *scope) |
|
155 { return d->checkDeclarator->check(methodPrototype, scope); } |
|
156 |
|
157 FullySpecifiedType Semantic::check(ObjCTypeNameAST *typeName, Scope *scope) |
|
158 { return d->checkSpecifier->check(typeName, scope); } |
|
159 |
|
160 void Semantic::check(ObjCMessageArgumentDeclarationAST *arg, Scope *scope) |
|
161 { return d->checkName->check(arg, scope); } |
|
162 |
|
163 FullySpecifiedType Semantic::check(ExpressionAST *expression, Scope *scope) |
|
164 { return d->checkExpression->check(expression, scope); } |
|
165 |
|
166 void Semantic::check(StatementAST *statement, Scope *scope) |
|
167 { d->checkStatement->check(statement, scope); } |
|
168 |
|
169 const Name *Semantic::check(NameAST *name, Scope *scope) |
|
170 { return d->checkName->check(name, scope); } |
|
171 |
|
172 const Name *Semantic::check(NestedNameSpecifierListAST *name, Scope *scope) |
|
173 { return d->checkName->check(name, scope); } |
|
174 |
|
175 const Name *Semantic::check(ObjCSelectorAST *args, Scope *scope) |
|
176 { return d->checkName->check(args, scope); } |
|
177 |
|
178 bool Semantic::skipFunctionBodies() const |
|
179 { return d->skipFunctionBodies; } |
|
180 |
|
181 void Semantic::setSkipFunctionBodies(bool skipFunctionBodies) |
|
182 { d->skipFunctionBodies = skipFunctionBodies; } |
|
183 |
|
184 int Semantic::currentVisibility() const |
|
185 { return d->visibility; } |
|
186 |
|
187 int Semantic::switchVisibility(int visibility) |
|
188 { |
|
189 int previousVisibility = d->visibility; |
|
190 d->visibility = visibility; |
|
191 return previousVisibility; |
|
192 } |
|
193 |
|
194 int Semantic::currentObjCVisibility() const |
|
195 { return d->ojbcVisibility; } |
|
196 |
|
197 int Semantic::switchObjCVisibility(int visibility) |
|
198 { |
|
199 int previousOjbCVisibility = d->ojbcVisibility; |
|
200 d->ojbcVisibility = visibility; |
|
201 return previousOjbCVisibility; |
|
202 } |
|
203 |
|
204 int Semantic::currentMethodKey() const |
|
205 { return d->methodKey; } |
|
206 |
|
207 int Semantic::switchMethodKey(int methodKey) |
|
208 { |
|
209 int previousMethodKey = d->methodKey; |
|
210 d->methodKey = methodKey; |
|
211 return previousMethodKey; |
|
212 } |
|
213 |
|
214 int Semantic::visibilityForAccessSpecifier(int tokenKind) const |
|
215 { |
|
216 switch (tokenKind) { |
|
217 case T_PUBLIC: |
|
218 return Symbol::Public; |
|
219 case T_PROTECTED: |
|
220 return Symbol::Protected; |
|
221 case T_PRIVATE: |
|
222 return Symbol::Private; |
|
223 case T_Q_SIGNALS: |
|
224 return Symbol::Protected; |
|
225 default: |
|
226 return Symbol::Public; |
|
227 } |
|
228 } |
|
229 |
|
230 int Semantic::visibilityForObjCAccessSpecifier(int tokenKind) const |
|
231 { |
|
232 switch (tokenKind) { |
|
233 case T_AT_PUBLIC: |
|
234 return Symbol::Public; |
|
235 case T_AT_PROTECTED: |
|
236 return Symbol::Protected; |
|
237 case T_AT_PRIVATE: |
|
238 return Symbol::Private; |
|
239 case T_AT_PACKAGE: |
|
240 return Symbol::Package; |
|
241 default: |
|
242 return Symbol::Protected; |
|
243 } |
|
244 } |
|
245 |
|
246 bool Semantic::isObjCClassMethod(int tokenKind) const |
|
247 { |
|
248 switch (tokenKind) { |
|
249 case T_PLUS: |
|
250 return true; |
|
251 case T_MINUS: |
|
252 default: |
|
253 return false; |
|
254 } |
|
255 } |
|
256 |
|
257 int Semantic::visibilityForClassKey(int tokenKind) const |
|
258 { |
|
259 switch (tokenKind) { |
|
260 case T_CLASS: |
|
261 return Symbol::Private; |
|
262 case T_STRUCT: |
|
263 case T_UNION: |
|
264 return Symbol::Public; |
|
265 default: |
|
266 return Symbol::Public; |
|
267 } |
|
268 } |
|
269 |
|
270 |