forked from qt-creator/qt-creator
C++: Document::functionAt provides line information
Needed for the debugger. Change-Id: I6465f6dc53017df212e403ea8a9a1c7977ac1671 Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -493,8 +493,12 @@ void Document::setGlobalNamespace(Namespace *globalNamespace)
|
|||||||
*
|
*
|
||||||
* \param line the line number, starting with line 1
|
* \param line the line number, starting with line 1
|
||||||
* \param column the column number, starting with column 1
|
* \param column the column number, starting with column 1
|
||||||
|
* \param lineOpeningDeclaratorParenthesis optional output parameter, the line of the opening
|
||||||
|
parenthesis of the declarator starting with 1
|
||||||
|
* \param lineClosingBrace optional output parameter, the line of the closing brace starting with 1
|
||||||
*/
|
*/
|
||||||
QString Document::functionAt(int line, int column) const
|
QString Document::functionAt(int line, int column, int *lineOpeningDeclaratorParenthesis,
|
||||||
|
int *lineClosingBrace) const
|
||||||
{
|
{
|
||||||
if (line < 1 || column < 1)
|
if (line < 1 || column < 1)
|
||||||
return QString();
|
return QString();
|
||||||
@@ -517,7 +521,19 @@ QString Document::functionAt(int line, int column) const
|
|||||||
if (!scope)
|
if (!scope)
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
// We found the function scope, extract its name.
|
// We found the function scope
|
||||||
|
if (lineOpeningDeclaratorParenthesis) {
|
||||||
|
unsigned line;
|
||||||
|
translationUnit()->getPosition(scope->startOffset(), &line);
|
||||||
|
*lineOpeningDeclaratorParenthesis = static_cast<int>(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lineClosingBrace) {
|
||||||
|
unsigned line;
|
||||||
|
translationUnit()->getPosition(scope->endOffset(), &line);
|
||||||
|
*lineClosingBrace = static_cast<int>(line);
|
||||||
|
}
|
||||||
|
|
||||||
const QList<const Name *> fullyQualifiedName = LookupContext::fullyQualifiedName(scope);
|
const QList<const Name *> fullyQualifiedName = LookupContext::fullyQualifiedName(scope);
|
||||||
return Overview().prettyName(fullyQualifiedName);
|
return Overview().prettyName(fullyQualifiedName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ public:
|
|||||||
QList<Macro> definedMacros() const
|
QList<Macro> definedMacros() const
|
||||||
{ return _definedMacros; }
|
{ return _definedMacros; }
|
||||||
|
|
||||||
QString functionAt(int line, int column) const;
|
QString functionAt(int line, int column, int *lineOpeningDeclaratorParenthesis = 0,
|
||||||
|
int *lineClosingBrace = 0) const;
|
||||||
Symbol *lastVisibleSymbolAt(unsigned line, unsigned column = 0) const;
|
Symbol *lastVisibleSymbolAt(unsigned line, unsigned column = 0) const;
|
||||||
Scope *scopeAt(unsigned line, unsigned column = 0);
|
Scope *scopeAt(unsigned line, unsigned column = 0);
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ void tst_Lookup::document_functionAt_data()
|
|||||||
QTest::addColumn<int>("line");
|
QTest::addColumn<int>("line");
|
||||||
QTest::addColumn<int>("column");
|
QTest::addColumn<int>("column");
|
||||||
QTest::addColumn<QString>("expectedFunction");
|
QTest::addColumn<QString>("expectedFunction");
|
||||||
|
QTest::addColumn<int>("expectedOpeningDeclaratorParenthesisLine");
|
||||||
|
QTest::addColumn<int>("expectedClosingBraceLine");
|
||||||
|
|
||||||
QByteArray source = "\n"
|
QByteArray source = "\n"
|
||||||
"void Foo::Bar() {\n" // line 1
|
"void Foo::Bar() {\n" // line 1
|
||||||
@@ -172,12 +174,12 @@ void tst_Lookup::document_functionAt_data()
|
|||||||
" }\n" // line 5
|
" }\n" // line 5
|
||||||
"}\n";
|
"}\n";
|
||||||
QString expectedFunction = QString::fromLatin1("Foo::Bar");
|
QString expectedFunction = QString::fromLatin1("Foo::Bar");
|
||||||
QTest::newRow("nonInline1") << source << 1 << 2 << QString();
|
QTest::newRow("nonInline1") << source << 1 << 2 << QString() << -1 << -1;
|
||||||
QTest::newRow("nonInline2") << source << 1 << 11 << expectedFunction;
|
QTest::newRow("nonInline2") << source << 1 << 11 << expectedFunction << 1 << 6;
|
||||||
QTest::newRow("nonInline3") << source << 2 << 2 << expectedFunction;
|
QTest::newRow("nonInline3") << source << 2 << 2 << expectedFunction << 1 << 6;
|
||||||
QTest::newRow("nonInline4") << source << 3 << 10 << expectedFunction;
|
QTest::newRow("nonInline4") << source << 3 << 10 << expectedFunction << 1 << 6;
|
||||||
QTest::newRow("nonInline5") << source << 4 << 3 << expectedFunction;
|
QTest::newRow("nonInline5") << source << 4 << 3 << expectedFunction << 1 << 6;
|
||||||
QTest::newRow("nonInline6") << source << 6 << 1 << expectedFunction;
|
QTest::newRow("nonInline6") << source << 6 << 1 << expectedFunction << 1 << 6;
|
||||||
|
|
||||||
source = "\n"
|
source = "\n"
|
||||||
"namespace N {\n" // line 1
|
"namespace N {\n" // line 1
|
||||||
@@ -188,9 +190,16 @@ void tst_Lookup::document_functionAt_data()
|
|||||||
"};\n"
|
"};\n"
|
||||||
"}\n"; // line 7
|
"}\n"; // line 7
|
||||||
expectedFunction = QString::fromLatin1("N::C::f");
|
expectedFunction = QString::fromLatin1("N::C::f");
|
||||||
QTest::newRow("inline1") << source << 1 << 2 << QString();
|
QTest::newRow("inline1") << source << 1 << 2 << QString() << -1 << -1;
|
||||||
QTest::newRow("inline2") << source << 2 << 10 << QString();
|
QTest::newRow("inline2") << source << 2 << 10 << QString() << -1 << -1;
|
||||||
QTest::newRow("inline2") << source << 3 << 10 << expectedFunction;
|
QTest::newRow("inline2") << source << 3 << 10 << expectedFunction << 3 << 5;
|
||||||
|
|
||||||
|
source = "\n"
|
||||||
|
"void f(Helper helper = [](){})\n" // line 1
|
||||||
|
"{\n"
|
||||||
|
"}\n"; // line 3
|
||||||
|
expectedFunction = QString::fromLatin1("f");
|
||||||
|
QTest::newRow("inlineWithLambdaArg1") << source << 2 << 1 << expectedFunction << 1 << 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Lookup::document_functionAt()
|
void tst_Lookup::document_functionAt()
|
||||||
@@ -199,14 +208,23 @@ void tst_Lookup::document_functionAt()
|
|||||||
QFETCH(int, line);
|
QFETCH(int, line);
|
||||||
QFETCH(int, column);
|
QFETCH(int, column);
|
||||||
QFETCH(QString, expectedFunction);
|
QFETCH(QString, expectedFunction);
|
||||||
|
QFETCH(int, expectedOpeningDeclaratorParenthesisLine);
|
||||||
|
QFETCH(int, expectedClosingBraceLine);
|
||||||
|
|
||||||
Document::Ptr doc = Document::create("document_functionAt");
|
Document::Ptr doc = Document::create("document_functionAt");
|
||||||
doc->setUtf8Source(source);
|
doc->setUtf8Source(source);
|
||||||
doc->parse();
|
doc->parse();
|
||||||
doc->check();
|
doc->check();
|
||||||
|
|
||||||
QVERIFY(doc->diagnosticMessages().isEmpty());
|
QVERIFY(doc->diagnosticMessages().isEmpty());
|
||||||
QCOMPARE(doc->functionAt(line, column), expectedFunction);
|
|
||||||
|
int actualOpeningDeclaratorParenthesisLine = -1;
|
||||||
|
int actualClosingBraceLine = -1;
|
||||||
|
const QString actualFunction = doc->functionAt(line, column,
|
||||||
|
&actualOpeningDeclaratorParenthesisLine,
|
||||||
|
&actualClosingBraceLine);
|
||||||
|
QCOMPARE(actualFunction, expectedFunction);
|
||||||
|
QCOMPARE(actualOpeningDeclaratorParenthesisLine, expectedOpeningDeclaratorParenthesisLine);
|
||||||
|
QCOMPARE(actualClosingBraceLine, expectedClosingBraceLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Lookup::simple_class_1()
|
void tst_Lookup::simple_class_1()
|
||||||
|
|||||||
Reference in New Issue
Block a user