Changeset View
Changeset View
Standalone View
Standalone View
duchain/expressionvisitor.cpp
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 71 | void ExpressionVisitor::visitClassOrInterfaceTypeName(ClassOrInterfaceTypeNameAst* node) { | |||
---|---|---|---|---|---|
86 | 86 | | |||
87 | AbstractType::Ptr type = openTypeFromName(id, true); | 87 | AbstractType::Ptr type = openTypeFromName(id, true); | ||
88 | if (StructureType::Ptr classType = StructureType::Ptr::dynamicCast(type)) { | 88 | if (StructureType::Ptr classType = StructureType::Ptr::dynamicCast(type)) { | ||
89 | DUChainReadLocker lock(DUChain::lock()); | 89 | DUChainReadLocker lock(DUChain::lock()); | ||
90 | useDecl = classType->declaration(topContext()); | 90 | useDecl = classType->declaration(topContext()); | ||
91 | if (useDecl) | 91 | if (useDecl) | ||
92 | useNode = node; | 92 | useNode = node; | ||
93 | else | 93 | else | ||
94 | kDebug() << classType->toString() << "unable to return its declaration."; | 94 | qDebug() << classType->toString() << "unable to return its declaration."; | ||
95 | } else { | 95 | } else { | ||
96 | kDebug() << id.toString() << "cannot be found as a class or interface type name."; | 96 | qDebug() << id.toString() << "cannot be found as a class or interface type name."; | ||
97 | } | 97 | } | ||
98 | 98 | | |||
99 | if (useNode) | 99 | if (useNode) | ||
100 | usingDeclaration(useNode, useDecl); | 100 | usingDeclaration(useNode, useDecl); | ||
101 | } | 101 | } | ||
102 | 102 | | |||
103 | AbstractType::Ptr ExpressionVisitor::openTypeFromName(QualifiedIdentifier id, bool needClass) | 103 | AbstractType::Ptr ExpressionVisitor::openTypeFromName(QualifiedIdentifier id, bool needClass) | ||
104 | { | 104 | { | ||
Show All 12 Lines | 109 | if(!delay) { | |||
117 | if(!delay) { | 117 | if(!delay) { | ||
118 | foreach( Declaration* decl, dec ) { | 118 | foreach( Declaration* decl, dec ) { | ||
119 | // gcc 4.0.1 doesn't eath this // if( needClass && !decl->abstractType().cast<StructureType>() ) | 119 | // gcc 4.0.1 doesn't eath this // if( needClass && !decl->abstractType().cast<StructureType>() ) | ||
120 | if( needClass && !decl->abstractType().cast(static_cast<StructureType *>(0)) ) | 120 | if( needClass && !decl->abstractType().cast(static_cast<StructureType *>(0)) ) | ||
121 | continue; | 121 | continue; | ||
122 | 122 | | |||
123 | if (decl->abstractType() ) { | 123 | if (decl->abstractType() ) { | ||
124 | ///@todo only functions may have multiple declarations here | 124 | ///@todo only functions may have multiple declarations here | ||
125 | //ifDebug( if( dec.count() > 1 ) kDebug() << id.toString() << "was found" << dec.count() << "times" ) | 125 | //ifDebug( if( dec.count() > 1 ) qDebug() << id.toString() << "was found" << dec.count() << "times" ) | ||
126 | //kDebug() << "found for" << id.toString() << ":" << decl->toString() << "type:" << decl->abstractType()->toString() << "context:" << decl->context(); | 126 | //qDebug() << "found for" << id.toString() << ":" << decl->toString() << "type:" << decl->abstractType()->toString() << "context:" << decl->context(); | ||
127 | openedType = decl->abstractType(); | 127 | openedType = decl->abstractType(); | ||
128 | setLastType(decl->abstractType()); | 128 | setLastType(decl->abstractType()); | ||
129 | break; | 129 | break; | ||
130 | } | 130 | } | ||
131 | } | 131 | } | ||
132 | } | 132 | } | ||
133 | 133 | | |||
134 | if(!openedType) | 134 | if(!openedType) | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 185 | { | |||
189 | if (lastInstance().declaration) { | 189 | if (lastInstance().declaration) { | ||
190 | if (node->methodName) { | 190 | if (node->methodName) { | ||
191 | QualifiedIdentifier id (editor()->parseSession()->symbol(node->methodName->ident)); | 191 | QualifiedIdentifier id (editor()->parseSession()->symbol(node->methodName->ident)); | ||
192 | DUContextPointer searchContext; | 192 | DUContextPointer searchContext; | ||
193 | { | 193 | { | ||
194 | DUChainReadLocker lock(DUChain::lock()); | 194 | DUChainReadLocker lock(DUChain::lock()); | ||
195 | StructureType::Ptr classType = lastInstance().declaration->type<StructureType>(); | 195 | StructureType::Ptr classType = lastInstance().declaration->type<StructureType>(); | ||
196 | if (!classType) { | 196 | if (!classType) { | ||
197 | kDebug() << "Type of last instance " << lastInstance().declaration->toString() << "was not a structure."; | 197 | qDebug() << "Type of last instance " << lastInstance().declaration->toString() << "was not a structure."; | ||
198 | return; | 198 | return; | ||
199 | } | 199 | } | ||
200 | searchContext = classType->internalContext(topContext()); | 200 | searchContext = classType->internalContext(topContext()); | ||
201 | if (!searchContext) { | 201 | if (!searchContext) { | ||
202 | kDebug() << "could not find internal context for the structure type of the class to be searched"; | 202 | qDebug() << "could not find internal context for the structure type of the class to be searched"; | ||
203 | return; | 203 | return; | ||
204 | } | 204 | } | ||
205 | kDebug() << "Looking for function" << id << "in" << searchContext->scopeIdentifier(true); | 205 | qDebug() << "Looking for function" << id << "in" << searchContext->scopeIdentifier(true); | ||
206 | } | 206 | } | ||
207 | 207 | | |||
208 | QList<OverloadResolver::Parameter> parameters; | 208 | QList<OverloadResolver::Parameter> parameters; | ||
209 | 209 | | |||
210 | if (node->arguments && node->arguments->expressionSequence) | 210 | if (node->arguments && node->arguments->expressionSequence) | ||
211 | { | 211 | { | ||
212 | const KDevPG::ListNode<ExpressionAst*> *__it = node->arguments->expressionSequence->front(), *__end = __it; | 212 | const KDevPG::ListNode<ExpressionAst*> *__it = node->arguments->expressionSequence->front(), *__end = __it; | ||
213 | do | 213 | do | ||
214 | { | 214 | { | ||
215 | visitNode(__it->element); | 215 | visitNode(__it->element); | ||
216 | // TODO determine l-value-ness if required | 216 | // TODO determine l-value-ness if required | ||
217 | if (lastType()) { | 217 | if (lastType()) { | ||
218 | kDebug() << "Parameter" << lastType()->toString(); | 218 | qDebug() << "Parameter" << lastType()->toString(); | ||
219 | parameters.append(OverloadResolver::Parameter(lastType(), false)); | 219 | parameters.append(OverloadResolver::Parameter(lastType(), false)); | ||
220 | } | 220 | } | ||
221 | 221 | | |||
222 | __it = __it->next; | 222 | __it = __it->next; | ||
223 | } | 223 | } | ||
224 | while (__it != __end); | 224 | while (__it != __end); | ||
225 | } | 225 | } | ||
226 | 226 | | |||
227 | 227 | | |||
228 | DUChainReadLocker lock(DUChain::lock()); | 228 | DUChainReadLocker lock(DUChain::lock()); | ||
229 | OverloadResolver resolver(searchContext); | 229 | OverloadResolver resolver(searchContext); | ||
230 | //kDebug() << "Parameter count:" << parameters.count(); | 230 | //qDebug() << "Parameter count:" << parameters.count(); | ||
231 | useDecl = resolver.resolve(OverloadResolver::ParameterList(parameters), id); | 231 | useDecl = resolver.resolve(OverloadResolver::ParameterList(parameters), id); | ||
232 | if (useDecl) | 232 | if (useDecl) | ||
233 | useNode = node->methodName; | 233 | useNode = node->methodName; | ||
234 | 234 | | |||
235 | kDebug() << "result" << (useDecl ? useDecl->toString() : "null declaration") << useNode; | 235 | qDebug() << "result" << (useDecl ? useDecl->toString() : "null declaration") << useNode; | ||
236 | } | 236 | } | ||
237 | 237 | | |||
238 | if (useNode) | 238 | if (useNode) | ||
239 | usingDeclaration(useNode, useDecl); | 239 | usingDeclaration(useNode, useDecl); | ||
240 | 240 | | |||
241 | } else { | 241 | } else { | ||
242 | kDebug() << "No declaration for the last instance on which to invoke a method"; | 242 | qDebug() << "No declaration for the last instance on which to invoke a method"; | ||
243 | } | 243 | } | ||
244 | } | 244 | } | ||
245 | 245 | | |||
246 | void ExpressionVisitor::visitNewExpression(NewExpressionAst* node) | 246 | void ExpressionVisitor::visitNewExpression(NewExpressionAst* node) | ||
247 | { | 247 | { | ||
248 | ExpressionVisitorBase::visitNewExpression(node); | 248 | ExpressionVisitorBase::visitNewExpression(node); | ||
249 | 249 | | |||
250 | if (lastType()) | 250 | if (lastType()) | ||
Show All 27 Lines | 275 | if (node->simpleNameAccess && node->simpleNameAccess->name) { | |||
278 | DUChainReadLocker lock(DUChain::lock()); | 278 | DUChainReadLocker lock(DUChain::lock()); | ||
279 | CursorInRevision start = editor()->findRange(node, node).start; | 279 | CursorInRevision start = editor()->findRange(node, node).start; | ||
280 | QList<Declaration*> decls = currentContext()->findDeclarations(id, start); | 280 | QList<Declaration*> decls = currentContext()->findDeclarations(id, start); | ||
281 | if (!decls.isEmpty()) { | 281 | if (!decls.isEmpty()) { | ||
282 | setLastInstance(decls.first()); | 282 | setLastInstance(decls.first()); | ||
283 | useDecl = decls.first(); | 283 | useDecl = decls.first(); | ||
284 | useNode = node->simpleNameAccess; | 284 | useNode = node->simpleNameAccess; | ||
285 | } | 285 | } | ||
286 | //kDebug() << currentContext()->localScopeIdentifier().toString() << id << start << decls.count() << useDecl << useNode; | 286 | //qDebug() << currentContext()->localScopeIdentifier().toString() << id << start << decls.count() << useDecl << useNode; | ||
287 | } | 287 | } | ||
288 | 288 | | |||
289 | if (node->superAccess) { | 289 | if (node->superAccess) { | ||
290 | DUChainReadLocker lock(DUChain::lock()); | 290 | DUChainReadLocker lock(DUChain::lock()); | ||
291 | if (ClassDeclaration* decl = dynamic_cast<ClassDeclaration*>(lastInstance().declaration.data())) { | 291 | if (ClassDeclaration* decl = dynamic_cast<ClassDeclaration*>(lastInstance().declaration.data())) { | ||
292 | if (decl->baseClassesSize() >= 1) { | 292 | if (decl->baseClassesSize() >= 1) { | ||
293 | if (StructureType::Ptr baseClass = decl->baseClasses()->baseClass.type<StructureType>()) { | 293 | if (StructureType::Ptr baseClass = decl->baseClasses()->baseClass.type<StructureType>()) { | ||
294 | setLastType(decl->baseClasses()->baseClass.abstractType()); | 294 | setLastType(decl->baseClasses()->baseClass.abstractType()); | ||
Show All 31 Lines | 324 | foreach (Declaration* decl, declContext->findDeclarations(id)) { | |||
326 | if (decl->abstractType() && !FunctionType::Ptr::dynamicCast(decl->abstractType())) { | 326 | if (decl->abstractType() && !FunctionType::Ptr::dynamicCast(decl->abstractType())) { | ||
327 | setLastInstance(decl); | 327 | setLastInstance(decl); | ||
328 | useNode = node->simpleNameAccess; | 328 | useNode = node->simpleNameAccess; | ||
329 | useDecl = decl; | 329 | useDecl = decl; | ||
330 | break; | 330 | break; | ||
331 | } | 331 | } | ||
332 | } | 332 | } | ||
333 | } else { | 333 | } else { | ||
334 | kWarning() << "Internal context for declaration" << lastInstance().declaration->toString() << "was null."; | 334 | qWarning() << "Internal context for declaration" << lastInstance().declaration->toString() << "was null."; | ||
335 | } | 335 | } | ||
336 | } else { | 336 | } else { | ||
337 | kWarning() << "No last instance for primary selector at" << editor()->findRange(node->simpleNameAccess->name, node->simpleNameAccess->name); | 337 | qWarning() << "No last instance for primary selector at" << editor()->findRange(node->simpleNameAccess->name, node->simpleNameAccess->name); | ||
338 | } | 338 | } | ||
339 | } | 339 | } | ||
340 | } | 340 | } | ||
341 | 341 | | |||
342 | if (node->thisAccess) { | 342 | if (node->thisAccess) { | ||
343 | if (lastInstance().isInstance) { | 343 | if (lastInstance().isInstance) { | ||
344 | // Nothing to do - already the correct instance and type? | 344 | // Nothing to do - already the correct instance and type? | ||
345 | } else { | 345 | } else { | ||
Show All 23 Lines |