Changeset View
Changeset View
Standalone View
Standalone View
duchain/expressionvisitor.cpp
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Line(s) | 178 | if ( node->variablePropertiesSequence && | |||
---|---|---|---|---|---|
185 | m_isAssignmentExpressionEqual = false; | 185 | m_isAssignmentExpressionEqual = false; | ||
186 | DefaultVisitor::visitVariable(node); | 186 | DefaultVisitor::visitVariable(node); | ||
187 | m_isAssignmentExpressionEqual = isAssignmentExpressionEqual; | 187 | m_isAssignmentExpressionEqual = isAssignmentExpressionEqual; | ||
188 | } else { | 188 | } else { | ||
189 | DefaultVisitor::visitVariable(node); | 189 | DefaultVisitor::visitVariable(node); | ||
190 | } | 190 | } | ||
191 | } | 191 | } | ||
192 | 192 | | |||
193 | void ExpressionVisitor::visitVarExpression(VarExpressionAst *node) | ||||
194 | { | ||||
195 | DefaultVisitor::visitVarExpression(node); | ||||
196 | if (node->isGenerator != -1) { | ||||
197 | DeclarationPointer generatorDecl = findDeclarationImport(ClassDeclarationType, QualifiedIdentifier("generator")); | ||||
198 | | ||||
199 | if (generatorDecl) { | ||||
200 | m_result.setType(AbstractType::Ptr(new IntegralType(IntegralType::TypeMixed))); | ||||
201 | if (hasCurrentClosureReturnType()) { | ||||
202 | FunctionType::Ptr closureType = currentClosureReturnType().cast<FunctionType>(); | ||||
203 | closureType->setReturnType(generatorDecl->abstractType()); | ||||
204 | } | ||||
205 | } | ||||
206 | } | ||||
207 | } | ||||
208 | | ||||
193 | void ExpressionVisitor::visitVarExpressionNewObject(VarExpressionNewObjectAst *node) | 209 | void ExpressionVisitor::visitVarExpressionNewObject(VarExpressionNewObjectAst *node) | ||
194 | { | 210 | { | ||
195 | DefaultVisitor::visitVarExpressionNewObject(node); | 211 | DefaultVisitor::visitVarExpressionNewObject(node); | ||
196 | if (node->className->staticIdentifier != -1) { | 212 | if (node->className->staticIdentifier != -1) { | ||
197 | static const QualifiedIdentifier id(QStringLiteral("static")); | 213 | static const QualifiedIdentifier id(QStringLiteral("static")); | ||
198 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, id); | 214 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, id); | ||
199 | usingDeclaration(node->className, dec); | 215 | usingDeclaration(node->className, dec); | ||
200 | m_result.setDeclaration(dec); | 216 | m_result.setDeclaration(dec); | ||
Show All 10 Lines | |||||
211 | { | 227 | { | ||
212 | DefaultVisitor::visitVarExpressionArray(node); | 228 | DefaultVisitor::visitVarExpressionArray(node); | ||
213 | m_result.setType(AbstractType::Ptr(new IntegralType(IntegralType::TypeArray))); | 229 | m_result.setType(AbstractType::Ptr(new IntegralType(IntegralType::TypeArray))); | ||
214 | } | 230 | } | ||
215 | 231 | | |||
216 | void ExpressionVisitor::visitClosure(ClosureAst* node) | 232 | void ExpressionVisitor::visitClosure(ClosureAst* node) | ||
217 | { | 233 | { | ||
218 | auto* closureType = new FunctionType; | 234 | auto* closureType = new FunctionType; | ||
219 | m_result.setType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | 235 | closureType->setReturnType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | ||
236 | openClosureReturnType(AbstractType::Ptr(closureType)); | ||||
220 | if (node->functionBody) { | 237 | if (node->functionBody) { | ||
221 | visitInnerStatementList(node->functionBody); | 238 | visitInnerStatementList(node->functionBody); | ||
222 | } | 239 | } | ||
223 | if (node->returnType && node->returnType->typehint && isClassTypehint(node->returnType->typehint, m_editor)) { | 240 | if (node->returnType && node->returnType->typehint && isClassTypehint(node->returnType->typehint, m_editor)) { | ||
224 | NamespacedIdentifierAst* objectType = node->returnType->typehint->genericType; | 241 | NamespacedIdentifierAst* objectType = node->returnType->typehint->genericType; | ||
225 | QualifiedIdentifier id = identifierForNamespace(objectType, m_editor); | 242 | QualifiedIdentifier id = identifierForNamespace(objectType, m_editor); | ||
226 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, id); | 243 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, id); | ||
227 | 244 | | |||
228 | usingDeclaration(objectType->namespaceNameSequence->back()->element, dec); | 245 | usingDeclaration(objectType->namespaceNameSequence->back()->element, dec); | ||
229 | buildNamespaceUses(objectType, id); | 246 | buildNamespaceUses(objectType, id); | ||
230 | } | 247 | } | ||
231 | 248 | | |||
232 | //First try return typehint or phpdoc return typehint | 249 | //Override found type with return typehint or phpdoc return typehint | ||
233 | AbstractType::Ptr type = returnType(node->returnType, {}, m_editor, m_currentContext); | 250 | AbstractType::Ptr type = returnType(node->returnType, {}, m_editor, m_currentContext); | ||
234 | if (!type) { | 251 | | ||
235 | //If failed, use the inferred type from return statements | 252 | if (type) { | ||
236 | type = m_result.type(); | | |||
237 | } | | |||
238 | closureType->setReturnType(type); | 253 | closureType->setReturnType(type); | ||
254 | } | ||||
239 | 255 | | |||
240 | if (node->parameters->parametersSequence) { | 256 | if (node->parameters->parametersSequence) { | ||
241 | const KDevPG::ListNode< ParameterAst* >* it = node->parameters->parametersSequence->front(); | 257 | const KDevPG::ListNode< ParameterAst* >* it = node->parameters->parametersSequence->front(); | ||
242 | forever { | 258 | forever { | ||
243 | AbstractType::Ptr type = parameterType(it->element, {}, m_editor, m_currentContext); | 259 | AbstractType::Ptr type = parameterType(it->element, {}, m_editor, m_currentContext); | ||
244 | closureType->addArgument(type); | 260 | closureType->addArgument(type); | ||
245 | 261 | | |||
246 | if (it->element->parameterType && it->element->parameterType->typehint | 262 | if (it->element->parameterType && it->element->parameterType->typehint | ||
Show All 32 Lines | 294 | if ( it->hasNext() ) { | |||
279 | it = it->next; | 295 | it = it->next; | ||
280 | } else { | 296 | } else { | ||
281 | break; | 297 | break; | ||
282 | } | 298 | } | ||
283 | } | 299 | } | ||
284 | } | 300 | } | ||
285 | 301 | | |||
286 | m_result.setType(AbstractType::Ptr(closureType)); | 302 | m_result.setType(AbstractType::Ptr(closureType)); | ||
303 | closeClosureReturnType(); | ||||
287 | } | 304 | } | ||
288 | 305 | | |||
289 | void ExpressionVisitor::visitFunctionCallParameterList( FunctionCallParameterListAst* node ) | 306 | void ExpressionVisitor::visitFunctionCallParameterList( FunctionCallParameterListAst* node ) | ||
290 | { | 307 | { | ||
291 | QList<DeclarationPointer> decs = m_result.allDeclarations(); | 308 | QList<DeclarationPointer> decs = m_result.allDeclarations(); | ||
292 | AbstractType::Ptr type = m_result.type(); | 309 | AbstractType::Ptr type = m_result.type(); | ||
293 | 310 | | |||
294 | DefaultVisitor::visitFunctionCallParameterList( node ); | 311 | DefaultVisitor::visitFunctionCallParameterList( node ); | ||
▲ Show 20 Lines • Show All 448 Lines • ▼ Show 20 Line(s) | 759 | if (node->instanceofType && node->instanceofType->identifier) { | |||
743 | const QualifiedIdentifier id = identifierForNamespace(node->instanceofType->identifier, m_editor); | 760 | const QualifiedIdentifier id = identifierForNamespace(node->instanceofType->identifier, m_editor); | ||
744 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, id); | 761 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, id); | ||
745 | usingDeclaration(node->instanceofType->identifier->namespaceNameSequence->back()->element, dec); | 762 | usingDeclaration(node->instanceofType->identifier->namespaceNameSequence->back()->element, dec); | ||
746 | buildNamespaceUses(node->instanceofType->identifier, id); | 763 | buildNamespaceUses(node->instanceofType->identifier, id); | ||
747 | m_result.setDeclaration(dec); | 764 | m_result.setDeclaration(dec); | ||
748 | } | 765 | } | ||
749 | } | 766 | } | ||
750 | 767 | | |||
768 | void ExpressionVisitor::visitStatement(StatementAst *node) | ||||
769 | { | ||||
770 | DefaultVisitor::visitStatement(node); | ||||
771 | | ||||
772 | if (node->returnExpr) { | ||||
773 | FunctionType::Ptr closureType = currentClosureReturnType().cast<FunctionType>(); | ||||
774 | | ||||
775 | if (closureType) { | ||||
776 | closureType->setReturnType(m_result.type()); | ||||
777 | } | ||||
778 | } | ||||
779 | } | ||||
780 | | ||||
751 | QString ExpressionVisitor::stringForNode(AstNode* id) | 781 | QString ExpressionVisitor::stringForNode(AstNode* id) | ||
752 | { | 782 | { | ||
753 | if (!id) | 783 | if (!id) | ||
754 | return QString(); | 784 | return QString(); | ||
755 | 785 | | |||
756 | return m_editor->parseSession()->symbol(id); | 786 | return m_editor->parseSession()->symbol(id); | ||
757 | } | 787 | } | ||
758 | 788 | | |||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |