Changeset View
Changeset View
Standalone View
Standalone View
duchain/declarationbuilder.cpp
Show First 20 Lines • Show All 454 Lines • ▼ Show 20 Line(s) | 430 | foreach ( AliasAst* name, node->names ) { | |||
---|---|---|---|---|---|
455 | } | 455 | } | ||
456 | if ( ! success && problem ) { | 456 | if ( ! success && problem ) { | ||
457 | DUChainWriteLocker lock; | 457 | DUChainWriteLocker lock; | ||
458 | topContext()->addProblem(problem); | 458 | topContext()->addProblem(problem); | ||
459 | } | 459 | } | ||
460 | } | 460 | } | ||
461 | } | 461 | } | ||
462 | 462 | | |||
463 | void spoofNodePosition(Ast* node, const CursorInRevision& pos) { | | |||
464 | // Ridiculous hack, see next comment. | | |||
465 | node->startLine = node->endLine = pos.line; | | |||
466 | node->startCol = node->endCol = pos.column - 1; | | |||
467 | if (node->astType == Ast::TupleAstType) { | | |||
468 | // Recursion to bodge all declarations, e.g. | | |||
469 | // [x + y * z for x, (y, z) in foo] | | |||
470 | foreach(auto elem, static_cast<TupleAst*>(node)->elements) { | | |||
471 | spoofNodePosition(elem, pos); | | |||
472 | } | | |||
473 | } | | |||
474 | } | | |||
475 | | ||||
476 | void DeclarationBuilder::visitComprehension(ComprehensionAst* node) | 463 | void DeclarationBuilder::visitComprehension(ComprehensionAst* node) | ||
477 | { | 464 | { | ||
478 | Python::AstDefaultVisitor::visitComprehension(node); | 465 | Python::AstDefaultVisitor::visitComprehension(node); | ||
479 | // make the declaration zero chars long; it must appear at the beginning of the context, | | |||
480 | // because it is actually used *before* its real declaration: [foo for foo in bar] | | |||
481 | // The DUChain doesn't like this, so for now, the declaration is at the opening bracket, | | |||
482 | // and both other occurrences are uses of that declaration. | | |||
483 | // TODO add a special case to the usebuilder to display the second occurrence as a declaration | | |||
484 | spoofNodePosition(node->target, currentContext()->range().start); | | |||
485 | | ||||
486 | ExpressionVisitor v(currentContext()); | 466 | ExpressionVisitor v(currentContext()); | ||
487 | v.visitNode(node->iterator); | 467 | v.visitNode(node->iterator); | ||
488 | assignToUnknown(node->target, Helper::contentOfIterable(v.lastType(), topContext())); | 468 | assignToUnknown(node->target, Helper::contentOfIterable(v.lastType(), topContext())); | ||
489 | } | 469 | } | ||
490 | 470 | | |||
491 | void DeclarationBuilder::visitImport(ImportAst* node) | 471 | void DeclarationBuilder::visitImport(ImportAst* node) | ||
492 | { | 472 | { | ||
493 | Python::ContextBuilder::visitImport(node); | 473 | Python::ContextBuilder::visitImport(node); | ||
▲ Show 20 Lines • Show All 1407 Lines • Show Last 20 Lines |