Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/declarationbuilder.cpp
Show First 20 Lines • Show All 745 Lines • ▼ Show 20 Line(s) | 745 | { | |||
---|---|---|---|---|---|
746 | PushValue<ParameterAst*> push(m_functionDeclarationPreviousArgument, 0); | 746 | PushValue<ParameterAst*> push(m_functionDeclarationPreviousArgument, 0); | ||
747 | 747 | | |||
748 | DeclarationBuilderBase::visitParameterList(node); | 748 | DeclarationBuilderBase::visitParameterList(node); | ||
749 | } | 749 | } | ||
750 | 750 | | |||
751 | void DeclarationBuilder::visitParameter(ParameterAst *node) | 751 | void DeclarationBuilder::visitParameter(ParameterAst *node) | ||
752 | { | 752 | { | ||
753 | AbstractFunctionDeclaration* funDec = dynamic_cast<AbstractFunctionDeclaration*>(currentDeclaration()); | 753 | AbstractFunctionDeclaration* funDec = dynamic_cast<AbstractFunctionDeclaration*>(currentDeclaration()); | ||
754 | Q_ASSERT(funDec); | 754 | Q_ASSERT(funDec); | ||
kfunk: This looks a bit like a hack.
And it also introduces a regression for e.g.:
`function x($b, $a… | |||||
755 | 755 | | |||
756 | if (node->defaultValue) { | 756 | if (node->defaultValue) { | ||
757 | QString symbol = m_editor->parseSession()->symbol(node->defaultValue); | 757 | QString symbol = m_editor->parseSession()->symbol(node->defaultValue); | ||
758 | funDec->addDefaultParameter(IndexedString(symbol)); | 758 | funDec->addDefaultParameter(IndexedString(symbol)); | ||
759 | if (node->isVariadic != -1) { | 759 | if (node->isVariadic != -1) { | ||
760 | reportError(i18n("Variadic parameter cannot have a default value"), node->defaultValue); | 760 | reportError(i18n("Variadic parameter cannot have a default value"), node->defaultValue); | ||
761 | } else if ( node->parameterType && node->parameterType->objectType && symbol.compare(QLatin1String("null"), Qt::CaseInsensitive) != 0 ) { | 761 | } else if ( node->parameterType && node->parameterType->objectType && symbol.compare(QLatin1String("null"), Qt::CaseInsensitive) != 0 ) { | ||
762 | reportError(i18n("Default value for parameters with a class type hint can only be NULL."), node->defaultValue); | 762 | reportError(i18n("Default value for parameters with a class type hint can only be NULL."), node->defaultValue); | ||
763 | } | 763 | } | ||
764 | } else if ( !node->defaultValue && funDec->defaultParametersSize() ) { | 764 | } else { | ||
765 | reportError(i18n("Following parameters must have a default value assigned."), node); | 765 | funDec->addDefaultParameter(IndexedString{}); | ||
766 | } | 766 | } | ||
767 | { | 767 | { | ||
768 | // create variable declaration for argument | 768 | // create variable declaration for argument | ||
769 | DUChainWriteLocker lock(DUChain::lock()); | 769 | DUChainWriteLocker lock(DUChain::lock()); | ||
770 | RangeInRevision newRange = editorFindRange(node->variable, node->variable); | 770 | RangeInRevision newRange = editorFindRange(node->variable, node->variable); | ||
771 | VariableDeclaration *dec = openDefinition<VariableDeclaration>(identifierForNode(node->variable), newRange); | 771 | VariableDeclaration *dec = openDefinition<VariableDeclaration>(identifierForNode(node->variable), newRange); | ||
772 | dec->setKind(Declaration::Instance); | 772 | dec->setKind(Declaration::Instance); | ||
773 | dec->setVariadic(node->isVariadic != -1); | 773 | dec->setVariadic(node->isVariadic != -1); | ||
▲ Show 20 Lines • Show All 733 Lines • Show Last 20 Lines |
This looks a bit like a hack.
And it also introduces a regression for e.g.:
function x($b, $a = 1) -> Won't show the default arg anymore.
Maybe this issue should be addresses at the DUChain-level in kdevplatform? You can probably add a addEmptyDefaultParameter() method in FunctionDefinition in kdevplatform.
Then here (pseudo-algo), do two passes over the param list:
(Or some similar approach..., I don't know the exact DUChain API of the top of my head)