Changeset View
Changeset View
Standalone View
Standalone View
duchain/helper.cpp
Context not available. | |||||
28 | #include <language/duchain/duchain.h> | 28 | #include <language/duchain/duchain.h> | ||
---|---|---|---|---|---|
29 | #include <language/duchain/stringhelpers.h> | 29 | #include <language/duchain/stringhelpers.h> | ||
30 | #include <language/duchain/parsingenvironment.h> | 30 | #include <language/duchain/parsingenvironment.h> | ||
31 | #include <language/duchain/types/unsuretype.h> | ||||
32 | #include <language/duchain/types/integraltype.h> | ||||
31 | #include <interfaces/icore.h> | 33 | #include <interfaces/icore.h> | ||
32 | #include <interfaces/iprojectcontroller.h> | 34 | #include <interfaces/iprojectcontroller.h> | ||
33 | #include <interfaces/iuicontroller.h> | 35 | #include <interfaces/iuicontroller.h> | ||
Context not available. | |||||
42 | #include "declarations/classdeclaration.h" | 44 | #include "declarations/classdeclaration.h" | ||
43 | #include "declarations/classmethoddeclaration.h" | 45 | #include "declarations/classmethoddeclaration.h" | ||
44 | #include "declarations/functiondeclaration.h" | 46 | #include "declarations/functiondeclaration.h" | ||
47 | #include "types/indexedcontainer.h" | ||||
48 | #include "types/integraltypeextended.h" | ||||
49 | #include "expressionparser.h" | ||||
50 | #include "expressionvisitor.h" | ||||
45 | 51 | | |||
46 | #include "duchaindebug.h" | 52 | #include "duchaindebug.h" | ||
47 | 53 | | |||
Context not available. | |||||
418 | } | 424 | } | ||
419 | } | 425 | } | ||
420 | 426 | | |||
427 | AbstractType::Ptr parameterTypehint(const ParameterTypeAst* parameterType, EditorIntegrator *editor, DUContext* currentContext) | ||||
428 | { | ||||
429 | Q_ASSERT(parameterType); | ||||
430 | AbstractType::Ptr type; | ||||
431 | | ||||
432 | if (parameterType->objectType) { | ||||
433 | //don't use openTypeFromName as it uses cursor for findDeclarations | ||||
434 | DeclarationPointer decl = findDeclarationImportHelper(currentContext, | ||||
435 | identifierForNamespace(parameterType->objectType, editor), ClassDeclarationType); | ||||
436 | if (decl) { | ||||
437 | type = decl->abstractType(); | ||||
438 | } | ||||
439 | } else if (parameterType->arrayType != -1) { | ||||
440 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeArray)); | ||||
441 | } else if (parameterType->boolType != -1) { | ||||
442 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeBoolean)); | ||||
443 | } else if (parameterType->floatType != -1) { | ||||
444 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeFloat)); | ||||
445 | } else if (parameterType->intType != -1) { | ||||
446 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeInt)); | ||||
447 | } else if (parameterType->stringType != -1) { | ||||
448 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeString)); | ||||
449 | } | ||||
450 | | ||||
451 | if (type && parameterType->isNullable != -1) { | ||||
452 | AbstractType::Ptr nullType = AbstractType::Ptr(new IntegralType(IntegralType::TypeNull)); | ||||
453 | if (type.cast<UnsureType>()) { | ||||
454 | UnsureType::Ptr unsure = type.cast<UnsureType>(); | ||||
455 | unsure->addType(nullType->indexed()); | ||||
456 | } else { | ||||
457 | UnsureType::Ptr unsure(new UnsureType()); | ||||
458 | unsure->addType(type->indexed()); | ||||
459 | unsure->addType(nullType->indexed()); | ||||
460 | | ||||
461 | type = AbstractType::Ptr(unsure); | ||||
462 | } | ||||
463 | } | ||||
464 | | ||||
465 | return type; | ||||
466 | } | ||||
467 | | ||||
468 | AbstractType::Ptr parameterType(const ParameterAst* node, AbstractType::Ptr phpDocTypehint, EditorIntegrator* editor, DUContext* currentContext) | ||||
469 | { | ||||
470 | AbstractType::Ptr type; | ||||
471 | if (node->parameterType) { | ||||
472 | type = parameterTypehint(node->parameterType, editor, currentContext); | ||||
473 | } else if (node->defaultValue) { | ||||
474 | ExpressionVisitor v(editor); | ||||
475 | node->defaultValue->ducontext = currentContext; | ||||
476 | v.visitNode(node->defaultValue); | ||||
477 | type = v.result().type(); | ||||
478 | } | ||||
479 | if (!type) { | ||||
480 | if (phpDocTypehint) { | ||||
481 | type = phpDocTypehint; | ||||
482 | } else { | ||||
483 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeMixed)); | ||||
484 | } | ||||
485 | } | ||||
486 | | ||||
487 | if ( node->isRef != -1 ) { | ||||
488 | ReferenceType::Ptr p( new ReferenceType() ); | ||||
489 | p->setBaseType( type ); | ||||
490 | | ||||
491 | type = p.cast<AbstractType>(); | ||||
492 | } | ||||
493 | | ||||
494 | if (node->isVariadic != -1) { | ||||
495 | IndexedContainer *container = new IndexedContainer(); | ||||
496 | const IndexedString *containerType = new IndexedString("array"); | ||||
497 | container->addEntry(type); | ||||
498 | container->setPrettyName(*containerType); | ||||
499 | type = AbstractType::Ptr(container); | ||||
500 | } | ||||
501 | | ||||
502 | Q_ASSERT(type); | ||||
503 | return type; | ||||
504 | } | ||||
505 | | ||||
421 | } | 506 | } | ||
Context not available. |