Commit f7950baf authored by Francis Herne's avatar Francis Herne
Browse files

Ensure that CodeAst nodes always start at (0, 0).

Previously the start was that of the first child node.

From CPython 3.8.2, the range of an attribute access `(expr).blah`
 includes the leading parenthesis, and thus starts before `expr`.

The range of kdev-python's Attribute node represents only the range of
 `blah`, and is calculated in an awkward way.

When an attribute access of a parenthesized expression appeared at the
 start of a file, the start of the attribute range from CPython was
 before that of the CodeAst node (based on the start of `expr`)
 resulting in an incorrect range being calculated.

This case is very unusual in real code, but fixes the tests. ;-)
parent 9cceeef5
......@@ -70,6 +70,11 @@ void RangeFixVisitor::visitNode(Ast* node) {
}
};
void RangeFixVisitor::visitCode(CodeAst* node) {
node->startLine = node->startCol = 0;
AstDefaultVisitor::visitCode(node);
}
void RangeFixVisitor::visitFunctionDefinition(FunctionDefinitionAst* node) {
cutDefinitionPreamble(node->name, node->async ? "asyncdef" : "def");
AstDefaultVisitor::visitFunctionDefinition(node);
......
......@@ -37,6 +37,7 @@ class KDEVPYTHONPARSER_NO_EXPORT RangeFixVisitor : public AstDefaultVisitor {
public:
RangeFixVisitor(const QString& contents) : lines(contents.split('\n')) {};
void visitNode(Ast* node) override;
void visitCode(Python::CodeAst* node) override;
void visitFunctionDefinition(FunctionDefinitionAst* node) override;
void visitClassDefinition(ClassDefinitionAst* node) override;
void visitAttribute(AttributeAst* node) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment