summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Funk <kfunk@kde.org>2017-03-07 08:09:42 (GMT)
committerKevin Funk <kfunk@kde.org>2017-03-07 08:16:10 (GMT)
commitc99456ae037d58c96a1ecb5727eff68cd6a7cd2a (patch)
treeee2e09dd372c71de3658bc622ee44285edbd6bf0
parent1f15b3b33a8bcc25dbb2e714b63a50e16d38761c (diff)
Support of Class::{expr}() syntax from Php 5.4
Summary: PHP 5.4 features [[ https://bugs.kde.org/show_bug.cgi?id=305779 | bug305779 ]] Reviewers: kfunk, mwolff, zhigalin, #kdevelop, pprkut Reviewed By: mwolff, zhigalin, #kdevelop, pprkut Subscribers: kdevelop-devel, #kdevelop Tags: #kdevelop Differential Revision: https://phabricator.kde.org/D4902
-rw-r--r--duchain/expressionvisitor.cpp7
-rw-r--r--duchain/tests/duchain.cpp22
-rw-r--r--duchain/tests/duchain.h1
-rw-r--r--parser/php.g1
4 files changed, 31 insertions, 0 deletions
diff --git a/duchain/expressionvisitor.cpp b/duchain/expressionvisitor.cpp
index 1743fa5..91a1636 100644
--- a/duchain/expressionvisitor.cpp
+++ b/duchain/expressionvisitor.cpp
@@ -343,6 +343,13 @@ void ExpressionVisitor::visitFunctionCall(FunctionCallAst* node)
}
} else if (node->varFunctionName) {
//static function call foo::$bar()
+ } else if (node->expr) {
+ //static function call foo::{expr}()
+ const QualifiedIdentifier id = identifierForNamespace(node->stringFunctionNameOrClass, m_editor);
+ DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, id);
+ usingDeclaration(node->stringFunctionNameOrClass->namespaceNameSequence->back()->element, dec);
+ buildNamespaceUses(node->stringFunctionNameOrClass, id);
+ m_result.setDeclaration(dec);
} else {
//global function call foo();
const QualifiedIdentifier id = identifierForNamespace(node->stringFunctionNameOrClass, m_editor);
diff --git a/duchain/tests/duchain.cpp b/duchain/tests/duchain.cpp
index d294f00..ee7a3b7 100644
--- a/duchain/tests/duchain.cpp
+++ b/duchain/tests/duchain.cpp
@@ -2998,3 +2998,25 @@ void TestDUChain::wrongUseOfThisAsArray()
QCOMPARE(top->problems().size(),1);
}
+
+void TestDUChain::staticFunctionClassPhp54()
+{
+ QByteArray method("<?php\n"
+ " class A\n"
+ " {\n"
+ " public static function func() {} \n"
+ " }\n"
+ " A::{'func'}(); \n");
+
+ TopDUContext* top = parse(method);
+ QVERIFY(top);
+ DUChainReleaser releaseTop(top);
+ DUChainWriteLocker lock(DUChain::lock());
+
+ QVERIFY(top->problems().isEmpty());
+ QCOMPARE(top->localDeclarations().count(),1);
+
+ Declaration* dec = top->localDeclarations().at(0);
+ ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(dec);
+ QCOMPARE(classDec->uses().count(),1);
+}
diff --git a/duchain/tests/duchain.h b/duchain/tests/duchain.h
index 194bada..8edc192 100644
--- a/duchain/tests/duchain.h
+++ b/duchain/tests/duchain.h
@@ -151,6 +151,7 @@ private slots:
void testTodoExtractor();
void useThisAsArray();
void wrongUseOfThisAsArray();
+ void staticFunctionClassPhp54();
};
}
diff --git a/parser/php.g b/parser/php.g
index 4975d14..7074302 100644
--- a/parser/php.g
+++ b/parser/php.g
@@ -650,6 +650,7 @@ expression=booleanOrExpression
(
stringFunctionName=identifier LPAREN stringParameterList=functionCallParameterList RPAREN
| varFunctionName=variableWithoutObjects LPAREN stringParameterList=functionCallParameterList RPAREN
+ | LBRACE (expr=expr) RBRACE LPAREN stringParameterList=functionCallParameterList RPAREN
)
)
| varFunctionName=variableWithoutObjects LPAREN varParameterList=functionCallParameterList RPAREN