Changeset View
Changeset View
Standalone View
Standalone View
duchain/overloadresolver.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "overloadresolver.h" | 20 | #include "overloadresolver.h" | ||
21 | #include <language/duchain/ducontext.h> | 21 | #include <language/duchain/ducontext.h> | ||
22 | #include <language/duchain/declaration.h> | 22 | #include <language/duchain/declaration.h> | ||
23 | #include <language/duchain/indexedstring.h> | 23 | #include <serialization/indexedstring.h> | ||
24 | #include <language/duchain/classfunctiondeclaration.h> | 24 | #include <language/duchain/classfunctiondeclaration.h> | ||
25 | #include <language/duchain/types/alltypes.h> | 25 | #include <language/duchain/types/alltypes.h> | ||
26 | #include <QtAlgorithms> | 26 | #include <QtAlgorithms> | ||
27 | 27 | | |||
28 | #include "typeconversion.h" | 28 | #include "typeconversion.h" | ||
29 | #include "typeutils.h" | 29 | #include "typeutils.h" | ||
30 | #include "viablefunctions.h" | 30 | #include "viablefunctions.h" | ||
31 | 31 | | |||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Line(s) | 207 | { | |||
212 | KDevelop::DUContext* templateContext = tempDecl->templateParameterContext(); | 212 | KDevelop::DUContext* templateContext = tempDecl->templateParameterContext(); | ||
213 | if(!templateContext) { | 213 | if(!templateContext) { | ||
214 | //May be just within a template, but without own template parameters | 214 | //May be just within a template, but without own template parameters | ||
215 | return declaration; | 215 | return declaration; | ||
216 | } | 216 | } | ||
217 | 217 | | |||
218 | FunctionType::Ptr functionType = declaration->type<FunctionType>(); | 218 | FunctionType::Ptr functionType = declaration->type<FunctionType>(); | ||
219 | if(!functionType) { | 219 | if(!functionType) { | ||
220 | kDebug(9007) << "Template function has no function type"; | 220 | qDebug(9007) << "Template function has no function type"; | ||
221 | return declaration; | 221 | return declaration; | ||
222 | } | 222 | } | ||
223 | 223 | | |||
224 | const IndexedType* arguments( functionType->indexedArguments() ); | 224 | const IndexedType* arguments( functionType->indexedArguments() ); | ||
225 | if(params.parameters.count() > functionType->indexedArgumentsSize()) | 225 | if(params.parameters.count() > functionType->indexedArgumentsSize()) | ||
226 | return declaration; | 226 | return declaration; | ||
227 | 227 | | |||
228 | //templateContext contains the template-parameters that we need to find instantiations for | 228 | //templateContext contains the template-parameters that we need to find instantiations for | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
285 | uint OverloadResolver::matchParameterTypes(const AbstractType::Ptr& argumentType, const AbstractType::Ptr& parameterType, QMap<IndexedString, AbstractType::Ptr>& instantiatedTypes, bool keepValue) const | 285 | uint OverloadResolver::matchParameterTypes(const AbstractType::Ptr& argumentType, const AbstractType::Ptr& parameterType, QMap<IndexedString, AbstractType::Ptr>& instantiatedTypes, bool keepValue) const | ||
286 | { | 286 | { | ||
287 | 287 | | |||
288 | if(!argumentType && !parameterType) | 288 | if(!argumentType && !parameterType) | ||
289 | return 1; | 289 | return 1; | ||
290 | if(!argumentType || !parameterType) | 290 | if(!argumentType || !parameterType) | ||
291 | return 0; | 291 | return 0; | ||
292 | 292 | | |||
293 | ifDebugOverloadResolution( kDebug() << "matching" << argumentType->toString() << "to" << parameterType->toString(); ) | 293 | ifDebugOverloadResolution( qDebug() << "matching" << argumentType->toString() << "to" << parameterType->toString(); ) | ||
294 | 294 | | |||
295 | if(instantiatedTypes.isEmpty()) | 295 | if(instantiatedTypes.isEmpty()) | ||
296 | return 1; | 296 | return 1; | ||
297 | 297 | | |||
298 | DelayedType::Ptr delayed = parameterType.cast<DelayedType>(); | 298 | DelayedType::Ptr delayed = parameterType.cast<DelayedType>(); | ||
299 | if(delayed) | 299 | if(delayed) | ||
300 | return incrementIfSuccessful( matchParameterTypes( argumentType, delayed->identifier(), instantiatedTypes , keepValue) ); | 300 | return incrementIfSuccessful( matchParameterTypes( argumentType, delayed->identifier(), instantiatedTypes , keepValue) ); | ||
301 | 301 | | |||
Show All 20 Lines | 321 | /*if(CppTemplateParameterType::Ptr templateParam = parameterType.cast<CppTemplateParameterType>()) { | |||
322 | ///@todo Allow template-parameters with even more template-parameters declared | 322 | ///@todo Allow template-parameters with even more template-parameters declared | ||
323 | //Directly assign argumentType to the template parameter | 323 | //Directly assign argumentType to the template parameter | ||
324 | Declaration* decl = templateParam->declaration(m_topContext.data()); | 324 | Declaration* decl = templateParam->declaration(m_topContext.data()); | ||
325 | if(decl) { | 325 | if(decl) { | ||
326 | IndexedString id = decl->identifier().identifier(); | 326 | IndexedString id = decl->identifier().identifier(); | ||
327 | if(instantiatedTypes[id].isNull()) { | 327 | if(instantiatedTypes[id].isNull()) { | ||
328 | instantiatedTypes[id] = argumentType; | 328 | instantiatedTypes[id] = argumentType; | ||
329 | return 1; | 329 | return 1; | ||
330 | }else if(instantiatedTypes[id]->equals(argumentType.unsafeData())) { | 330 | }else if(instantiatedTypes[id]->equals(argumentType.data())) { | ||
331 | return 1; | 331 | return 1; | ||
332 | }else{ | 332 | }else{ | ||
333 | //Mismatch, another type was already assigned | 333 | //Mismatch, another type was already assigned | ||
334 | return 0; | 334 | return 0; | ||
335 | } | 335 | } | ||
336 | } | 336 | } | ||
337 | }*/ | 337 | }*/ | ||
338 | 338 | | |||
339 | ///Match assigned template-parameters, for example when matching QList<int> to QList<T>, assign int to T. | 339 | ///Match assigned template-parameters, for example when matching QList<int> to QList<T>, assign int to T. | ||
340 | const IdentifiedType* identifiedArgument = dynamic_cast<const IdentifiedType*>(argumentType.unsafeData()); | 340 | const IdentifiedType* identifiedArgument = dynamic_cast<const IdentifiedType*>(argumentType.data()); | ||
341 | const IdentifiedType* identifiedParameter = dynamic_cast<const IdentifiedType*>(parameterType.unsafeData()); | 341 | const IdentifiedType* identifiedParameter = dynamic_cast<const IdentifiedType*>(parameterType.data()); | ||
342 | 342 | | |||
343 | if( identifiedArgument && identifiedParameter ) | 343 | if( identifiedArgument && identifiedParameter ) | ||
344 | { | 344 | { | ||
345 | //TemplateDeclaration* argumentTemplateDeclaration = dynamic_cast<TemplateDeclaration*>(identifiedArgument->declaration(m_topContext.data())); | 345 | //TemplateDeclaration* argumentTemplateDeclaration = dynamic_cast<TemplateDeclaration*>(identifiedArgument->declaration(m_topContext.data())); | ||
346 | //TemplateDeclaration* parameterTemplateDeclaration = dynamic_cast<TemplateDeclaration*>(identifiedParameter->declaration(m_topContext.data())); | 346 | //TemplateDeclaration* parameterTemplateDeclaration = dynamic_cast<TemplateDeclaration*>(identifiedParameter->declaration(m_topContext.data())); | ||
347 | //if(!argumentTemplateDeclaration || !parameterTemplateDeclaration) | 347 | //if(!argumentTemplateDeclaration || !parameterTemplateDeclaration) | ||
348 | return 1; | 348 | return 1; | ||
349 | 349 | | |||
Show All 19 Lines | |||||
369 | } | 369 | } | ||
370 | 370 | | |||
371 | return 1; | 371 | return 1; | ||
372 | } | 372 | } | ||
373 | 373 | | |||
374 | AbstractType::Ptr getContainerType(AbstractType::Ptr type, int depth, TopDUContext* topContext) { | 374 | AbstractType::Ptr getContainerType(AbstractType::Ptr type, int depth, TopDUContext* topContext) { | ||
375 | for(int a = 0; a < depth; a++) { | 375 | for(int a = 0; a < depth; a++) { | ||
376 | AbstractType::Ptr real = TypeUtils::realType(type, topContext); | 376 | AbstractType::Ptr real = TypeUtils::realType(type, topContext); | ||
377 | IdentifiedType* idType = dynamic_cast<IdentifiedType*>(real.unsafeData()); | 377 | IdentifiedType* idType = dynamic_cast<IdentifiedType*>(real.data()); | ||
378 | if(!idType) | 378 | if(!idType) | ||
379 | return AbstractType::Ptr(); | 379 | return AbstractType::Ptr(); | ||
380 | 380 | | |||
381 | Declaration* decl = idType->declaration(topContext); | 381 | Declaration* decl = idType->declaration(topContext); | ||
382 | Declaration* containerDecl = decl->context()->owner(); | 382 | Declaration* containerDecl = decl->context()->owner(); | ||
383 | 383 | | |||
384 | if(containerDecl) | 384 | if(containerDecl) | ||
385 | type = containerDecl->abstractType(); | 385 | type = containerDecl->abstractType(); | ||
386 | else | 386 | else | ||
387 | return AbstractType::Ptr(); | 387 | return AbstractType::Ptr(); | ||
388 | } | 388 | } | ||
389 | return type; | 389 | return type; | ||
390 | } | 390 | } | ||
391 | 391 | | |||
392 | uint OverloadResolver::matchParameterTypes(AbstractType::Ptr argumentType, const IndexedTypeIdentifier& parameterType, QMap<IndexedString, AbstractType::Ptr>& instantiatedTypes, bool keepValue) const | 392 | uint OverloadResolver::matchParameterTypes(AbstractType::Ptr argumentType, const IndexedTypeIdentifier& parameterType, QMap<IndexedString, AbstractType::Ptr>& instantiatedTypes, bool keepValue) const | ||
393 | { | 393 | { | ||
394 | ifDebugOverloadResolution( kDebug() << "1 matching" << argumentType->toString() << "to" << parameterType.toString() << parameterType.pointerDepth(); ) | 394 | ifDebugOverloadResolution( qDebug() << "1 matching" << argumentType->toString() << "to" << parameterType.toString() << parameterType.pointerDepth(); ) | ||
395 | if(!argumentType) | 395 | if(!argumentType) | ||
396 | return 1; | 396 | return 1; | ||
397 | if(instantiatedTypes.isEmpty()) | 397 | if(instantiatedTypes.isEmpty()) | ||
398 | return 1; | 398 | return 1; | ||
399 | 399 | | |||
400 | QualifiedIdentifier parameterQid(parameterType.identifier().identifier()); | 400 | QualifiedIdentifier parameterQid(parameterType.identifier().identifier()); | ||
401 | 401 | | |||
402 | if(parameterQid.isEmpty()) | 402 | if(parameterQid.isEmpty()) | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |