29
29
#include <language/duchain/stringhelpers.h>
30
30
#include <language/duchain/aliasdeclaration.h>
31
31
#include <language/duchain/types/integraltype.h>
32
#include <language/duchain/types/unsuretype.h>
33
34
#include <interfaces/icore.h>
34
35
#include <interfaces/ilanguagecontroller.h>
516
517
void DeclarationBuilder::visitParameter(ParameterAst *node)
519
AbstractFunctionDeclaration* funDec = dynamic_cast<AbstractFunctionDeclaration*>(currentDeclaration());
518
521
if (node->defaultValue) {
519
AbstractFunctionDeclaration* funDec = dynamic_cast<AbstractFunctionDeclaration*>(currentDeclaration());
521
funDec->addDefaultParameter(IndexedString(editor()->parseSession()->symbol(node->defaultValue)));
522
QString symbol = editor()->parseSession()->symbol(node->defaultValue);
523
funDec->addDefaultParameter(IndexedString(symbol));
524
if ( node->parameterType && symbol.compare(QLatin1String("null"), Qt::CaseInsensitive) != 0 ) {
525
reportError(i18n("Default value for parameters with a class type hint can only be NULL."), node->defaultValue);
527
} else if ( !node->defaultValue && funDec->defaultParametersSize() ) {
528
reportError(i18n("Following parameters must have a default value assigned."), node);
531
// create variable declaration for argument
525
532
DUChainWriteLocker lock(DUChain::lock());
526
533
SimpleRange newRange = editorFindRange(node->variable, node->variable);
527
openDefinition<Declaration>(identifierForNode(node->variable), newRange);
534
openDefinition<VariableDeclaration>(identifierForNode(node->variable), newRange);
528
535
currentDeclaration()->setKind(Declaration::Instance);
653
660
DUChainWriteLocker lock(DUChain::lock());
654
661
// check if this variable is already declared
656
QList< Declaration* > decs = parentCtx->findLocalDeclarations(identifier.first(), startPos(node));
663
QList< Declaration* > decs = parentCtx->findDeclarations(identifier.first(), startPos(node));
657
664
if ( !decs.isEmpty() ) {
658
665
QList< Declaration* >::const_iterator it = decs.constEnd() - 1;
660
667
// we expect that the list of declarations has the newest declaration at back
661
668
if ( dynamic_cast<VariableDeclaration*>( *it ) ) {
662
if ( (*it)->abstractType()->indexed() == type->indexed() ) {
670
if ( (*it)->abstractType() && !(*it)->abstractType()->equals(type.unsafeData()) ) {
671
// if it's currently mixed and we now get something more definite, use that instead
672
if ( ReferenceType::Ptr rType = ReferenceType::Ptr::dynamicCast((*it)->abstractType()) ) {
673
if ( IntegralType::Ptr integral = IntegralType::Ptr::dynamicCast(rType->baseType()) ) {
674
if ( integral->dataType() == IntegralType::TypeMixed ) {
675
// referenced mixed to referenced @p type
676
ReferenceType::Ptr newType(new ReferenceType());
677
newType->setBaseType(type);
678
(*it)->setType(newType);
683
if ( IntegralType::Ptr integral = IntegralType::Ptr::dynamicCast((*it)->abstractType()) ) {
684
if ( integral->dataType() == IntegralType::TypeMixed ) {
686
(*it)->setType(type);
690
// else make it unsure
691
UnsureType::Ptr unsure = UnsureType::Ptr::dynamicCast((*it)->abstractType());
692
// maybe it's referenced?
693
ReferenceType::Ptr rType = ReferenceType::Ptr::dynamicCast((*it)->abstractType());
694
if ( !unsure && rType ) {
695
unsure = UnsureType::Ptr::dynamicCast(rType->baseType());
698
unsure = UnsureType::Ptr(new UnsureType());
700
unsure->addType(rType->baseType()->indexed());
702
unsure->addType((*it)->indexedType());
705
unsure->addType(type->indexed());
707
rType->setBaseType(AbstractType::Ptr(unsure.unsafeData()));
708
(*it)->setType(rType);
710
(*it)->setType(unsure);
668
715
if ( it == decs.constBegin() ) {
1049
1096
// when we are recompiling, it's important to mark decs as encountered
1050
1097
// and update their comments
1051
1098
if ( recompiling() && !wasEncountered(dec) ) {
1052
kDebug() << "old:" << dec->comment();
1053
1099
dec->setComment(comment());
1054
1100
setEncountered(dec);
1055
kDebug() << "new:" << dec->comment();