Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/typebuilder.cpp
Show First 20 Lines • Show All 293 Lines • ▼ Show 20 Line(s) | |||||
294 | void TypeBuilder::visitClassStatement(ClassStatementAst *node) | 294 | void TypeBuilder::visitClassStatement(ClassStatementAst *node) | ||
295 | { | 295 | { | ||
296 | if (node->methodName) { | 296 | if (node->methodName) { | ||
297 | //method declaration | 297 | //method declaration | ||
298 | m_currentFunctionParams = parseDocCommentParams(node); | 298 | m_currentFunctionParams = parseDocCommentParams(node); | ||
299 | 299 | | |||
300 | FunctionType::Ptr functionType = FunctionType::Ptr(new FunctionType()); | 300 | FunctionType::Ptr functionType = FunctionType::Ptr(new FunctionType()); | ||
301 | openType(functionType); | 301 | openType(functionType); | ||
302 | openContextType(functionType); | ||||
302 | 303 | | |||
303 | AbstractType::Ptr phpdocReturnType = parseDocComment(node, QStringLiteral("return")); | 304 | AbstractType::Ptr phpdocReturnType = parseDocComment(node, QStringLiteral("return")); | ||
304 | functionType->setReturnType(returnType(node->returnType, phpdocReturnType, editor(), currentContext())); | 305 | functionType->setReturnType(returnType(node->returnType, phpdocReturnType, editor(), currentContext())); | ||
305 | m_gotReturnTypeFromDocComment = functionType->returnType(); | 306 | m_gotReturnTypeFromDocComment = functionType->returnType(); | ||
306 | updateCurrentType(); | 307 | updateCurrentType(); | ||
307 | 308 | | |||
308 | TypeBuilderBase::visitClassStatement(node); | 309 | TypeBuilderBase::visitClassStatement(node); | ||
309 | if (currentType<FunctionType>() && !currentType<FunctionType>()->returnType()) { | 310 | if (currentType<FunctionType>() && !currentType<FunctionType>()->returnType()) { | ||
310 | currentType<FunctionType>()->setReturnType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | 311 | currentType<FunctionType>()->setReturnType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | ||
311 | } | 312 | } | ||
313 | closeContextType(); | ||||
312 | closeType(); | 314 | closeType(); | ||
313 | } else { | 315 | } else { | ||
314 | //member-variable | 316 | //member-variable | ||
315 | parseDocComment(node, QStringLiteral("var")); | 317 | parseDocComment(node, QStringLiteral("var")); | ||
316 | TypeBuilderBase::visitClassStatement(node); | 318 | TypeBuilderBase::visitClassStatement(node); | ||
317 | if (m_gotTypeFromDocComment) { | 319 | if (m_gotTypeFromDocComment) { | ||
318 | clearLastType(); | 320 | clearLastType(); | ||
319 | m_gotTypeFromDocComment = false; | 321 | m_gotTypeFromDocComment = false; | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | |||||
386 | { | 388 | { | ||
387 | m_currentFunctionParams = parseDocCommentParams(node); | 389 | m_currentFunctionParams = parseDocCommentParams(node); | ||
388 | // the predeclarationbuilder should have already built the type | 390 | // the predeclarationbuilder should have already built the type | ||
389 | // and the declarationbuilder should have set it to open | 391 | // and the declarationbuilder should have set it to open | ||
390 | Q_ASSERT(hasCurrentType()); | 392 | Q_ASSERT(hasCurrentType()); | ||
391 | FunctionType::Ptr type = currentType<FunctionType>(); | 393 | FunctionType::Ptr type = currentType<FunctionType>(); | ||
392 | Q_ASSERT(type); | 394 | Q_ASSERT(type); | ||
393 | 395 | | |||
396 | openContextType(type); | ||||
397 | | ||||
394 | AbstractType::Ptr phpdocReturnType = parseDocComment(node, QStringLiteral("return")); | 398 | AbstractType::Ptr phpdocReturnType = parseDocComment(node, QStringLiteral("return")); | ||
395 | type->setReturnType(returnType(node->returnType, phpdocReturnType, editor(), currentContext())); | 399 | type->setReturnType(returnType(node->returnType, phpdocReturnType, editor(), currentContext())); | ||
396 | m_gotReturnTypeFromDocComment = type->returnType(); | 400 | m_gotReturnTypeFromDocComment = type->returnType(); | ||
397 | 401 | | |||
398 | updateCurrentType(); | 402 | updateCurrentType(); | ||
399 | 403 | | |||
400 | TypeBuilderBase::visitFunctionDeclarationStatement(node); | 404 | TypeBuilderBase::visitFunctionDeclarationStatement(node); | ||
401 | 405 | | |||
402 | if (!type->returnType()) { | 406 | if (!type->returnType()) { | ||
403 | type->setReturnType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | 407 | type->setReturnType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | ||
404 | } | 408 | } | ||
409 | | ||||
410 | closeContextType(); | ||||
405 | } | 411 | } | ||
406 | 412 | | |||
407 | void TypeBuilder::visitClosure(ClosureAst* node) | 413 | void TypeBuilder::visitClosure(ClosureAst* node) | ||
408 | { | 414 | { | ||
409 | m_currentFunctionParams = parseDocCommentParams(node); | 415 | m_currentFunctionParams = parseDocCommentParams(node); | ||
410 | FunctionType::Ptr type = FunctionType::Ptr(new FunctionType()); | 416 | FunctionType::Ptr type = FunctionType::Ptr(new FunctionType()); | ||
411 | openType(type); | 417 | openType(type); | ||
418 | openContextType(type); | ||||
412 | 419 | | |||
413 | AbstractType::Ptr phpdocReturnType = parseDocComment(node, QStringLiteral("return")); | 420 | AbstractType::Ptr phpdocReturnType = parseDocComment(node, QStringLiteral("return")); | ||
414 | type->setReturnType(returnType(node->returnType, phpdocReturnType, editor(), currentContext())); | 421 | type->setReturnType(returnType(node->returnType, phpdocReturnType, editor(), currentContext())); | ||
415 | m_gotReturnTypeFromDocComment = type->returnType(); | 422 | m_gotReturnTypeFromDocComment = type->returnType(); | ||
416 | 423 | | |||
417 | updateCurrentType(); | 424 | updateCurrentType(); | ||
418 | 425 | | |||
419 | TypeBuilderBase::visitClosure(node); | 426 | TypeBuilderBase::visitClosure(node); | ||
420 | 427 | | |||
421 | if (!type->returnType()) { | 428 | if (!type->returnType()) { | ||
422 | type->setReturnType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | 429 | type->setReturnType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | ||
423 | } | 430 | } | ||
431 | closeContextType(); | ||||
424 | closeType(); | 432 | closeType(); | ||
425 | } | 433 | } | ||
426 | 434 | | |||
427 | void TypeBuilder::visitAssignmentExpression(AssignmentExpressionAst* node) | 435 | void TypeBuilder::visitAssignmentExpression(AssignmentExpressionAst* node) | ||
428 | { | 436 | { | ||
429 | // performance: only try to find type when we are actually in an assignment expr | 437 | // performance: only try to find type when we are actually in an assignment expr | ||
430 | if (node->assignmentExpression || node->assignmentExpressionEqual) { | 438 | if (node->assignmentExpression || node->assignmentExpressionEqual) { | ||
431 | openAbstractType(getTypeForNode(node)); | 439 | openAbstractType(getTypeForNode(node)); | ||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | 570 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, | |||
563 | identifierForNamespace(node->catchClass, m_editor)); | 571 | identifierForNamespace(node->catchClass, m_editor)); | ||
564 | if (dec && dec->abstractType()) { | 572 | if (dec && dec->abstractType()) { | ||
565 | openAbstractType(dec->abstractType()); | 573 | openAbstractType(dec->abstractType()); | ||
566 | closeType(); | 574 | closeType(); | ||
567 | } | 575 | } | ||
568 | 576 | | |||
569 | } | 577 | } | ||
570 | 578 | | |||
579 | void TypeBuilder::visitVarExpression(Php::VarExpressionAst *node) | ||||
580 | { | ||||
581 | if (hasCurrentContextType() && node->isGenerator != -1 && !m_gotReturnTypeFromDocComment) { | ||||
582 | FunctionType::Ptr ft = FunctionType::Ptr::dynamicCast(currentContextType()); | ||||
583 | DeclarationPointer generatorDecl = findDeclarationImport(ClassDeclarationType, QualifiedIdentifier("generator")); | ||||
584 | | ||||
585 | if (ft && generatorDecl) { | ||||
586 | AbstractType::Ptr generatorType = generatorDecl->abstractType(); | ||||
587 | | ||||
588 | if (generatorType) { | ||||
589 | ft->setReturnType(generatorType); | ||||
590 | } | ||||
591 | } | ||||
592 | | ||||
593 | updateCurrentType(); | ||||
594 | } | ||||
595 | | ||||
596 | TypeBuilderBase::visitVarExpression(node); | ||||
597 | } | ||||
598 | | ||||
571 | void TypeBuilder::updateCurrentType() | 599 | void TypeBuilder::updateCurrentType() | ||
572 | { | 600 | { | ||
573 | // do nothing | 601 | // do nothing | ||
574 | } | 602 | } | ||
575 | 603 | | |||
576 | } | 604 | } | ||
577 | 605 | |