[PATCH 2/4] fixup the usebuilder, the codegenerator, and the duchain test
Floris Ruijter
flo.ruijt at hotmail.com
Sat Feb 5 04:23:56 UTC 2011
---
languages/cpp/cppduchain/tests/test_duchain.cpp | 64 +++++++++++++++++++++++
languages/cpp/cppduchain/tests/test_duchain.h | 1 +
languages/cpp/cppduchain/usebuilder.cpp | 2 +-
languages/cpp/parser/codegenerator.cpp | 3 +-
4 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/languages/cpp/cppduchain/tests/test_duchain.cpp b/languages/cpp/cppduchain/tests/test_duchain.cpp
index e9789a0..87308e6 100644
--- a/languages/cpp/cppduchain/tests/test_duchain.cpp
+++ b/languages/cpp/cppduchain/tests/test_duchain.cpp
@@ -5846,5 +5846,69 @@ void TestDUChain::testCommentAfterFunctionCall()
QVERIFY(top->childContexts().last()->localDeclarations().isEmpty());
QCOMPARE(m_view->uses().size(), 1);
}
+void TestDUChain::testPointerToMember()
+{
+ // 1 2 3
+ // 123456789012345678901234567890
+ LockedTopDUContext top = parse( "struct AA {"
+ "\n int j;"
+ "\n};"
+ "\nstruct BB{"
+ "\n int AA::* pj;"
+ "\n};"
+ "\nvoid f(int AA::* par){"
+ "\n BB b;"
+ "\n int AA::* BB::* ppj=&BB::pj;"
+ "\n b.*ppj=par;"
+ "\n}",DumpAll
+ );
+ QVERIFY(top);
+ DUChainReadLocker lock;
+ QVERIFY(top->problems().isEmpty());
+ QCOMPARE(top->childContexts().size(),4);
+ QCOMPARE(top->localDeclarations().size(),3);
+
+ QCOMPARE(top->localDeclarations().at(0)->uses().begin()->size(),3);
+ QCOMPARE(top->localDeclarations().at(1)->uses().begin()->size(),3);
+
+ QCOMPARE(top->localDeclarations().at(0)->uses().begin()->at(0),RangeInRevision(4,6,4,8));
+ QCOMPARE(top->localDeclarations().at(0)->uses().begin()->at(1),RangeInRevision(6,11,6,13));
+ QCOMPARE(top->localDeclarations().at(0)->uses().begin()->at(2),RangeInRevision(8,6,8,8));
+
+ QCOMPARE(top->localDeclarations().at(1)->uses().begin()->at(0),RangeInRevision(7,2,7,4));
+ QCOMPARE(top->localDeclarations().at(1)->uses().begin()->at(1),RangeInRevision(8,12,8,14));
+ QCOMPARE(top->localDeclarations().at(1)->uses().begin()->at(2),RangeInRevision(8,23,8,25));
+
+ {
+ DUContext* ctx = top->childContexts().at(1);
+ Declaration* dec = ctx->localDeclarations().first();
+ PtrToMemberType::Ptr type = dec->abstractType().cast<PtrToMemberType>();
+ QVERIFY(type);
+ StructureType::Ptr structType = type->ClassType().cast<StructureType>();
+ QVERIFY(structType);
+ QCOMPARE(structType->qualifiedIdentifier().toString(), QString("AA"));
+ }
+ {
+ DUContext* ctx = top->childContexts().at(3);
+ Declaration* dec = ctx->localDeclarations().at(1);
+ PtrToMemberType::Ptr type = dec->abstractType().cast<PtrToMemberType>();
+
+ {
+ QVERIFY(type);
+ StructureType::Ptr structType = type->ClassType().cast<StructureType>();
+ QVERIFY(structType);
+ QCOMPARE(structType->qualifiedIdentifier().toString(), QString("BB"));
+ }
+
+ PtrToMemberType::Ptr ptype = type->baseType().cast<PtrToMemberType>();
+ {
+ QVERIFY(ptype);
+ StructureType::Ptr structType = ptype->ClassType().cast<StructureType>();
+ QVERIFY(structType);
+ QCOMPARE(structType->qualifiedIdentifier().toString(), QString("AA"));
+ }
+ }
+
+}
#include "test_duchain.moc"
diff --git a/languages/cpp/cppduchain/tests/test_duchain.h b/languages/cpp/cppduchain/tests/test_duchain.h
index 4cd7d05..23efbb0 100644
--- a/languages/cpp/cppduchain/tests/test_duchain.h
+++ b/languages/cpp/cppduchain/tests/test_duchain.h
@@ -190,6 +190,7 @@ private slots:
void testAutoTypes();
void testCommentAfterFunctionCall();
+ void testPointerToMember();
private:
void assertNoMemberFunctionModifiers(KDevelop::ClassFunctionDeclaration* memberFun);
diff --git a/languages/cpp/cppduchain/usebuilder.cpp b/languages/cpp/cppduchain/usebuilder.cpp
index 68b08fb..dc5bb2f 100644
--- a/languages/cpp/cppduchain/usebuilder.cpp
+++ b/languages/cpp/cppduchain/usebuilder.cpp
@@ -233,7 +233,7 @@ void UseBuilder::visitSimpleDeclaration(SimpleDeclarationAST* node)
}
it = it->next;
} while (it != end);
- }else{
+ } else {
DefaultVisitor::visitSimpleDeclaration(node);
}
}
diff --git a/languages/cpp/parser/codegenerator.cpp b/languages/cpp/parser/codegenerator.cpp
index fcdb04c..3cb23dc 100644
--- a/languages/cpp/parser/codegenerator.cpp
+++ b/languages/cpp/parser/codegenerator.cpp
@@ -612,8 +612,7 @@ void CodeGenerator::visitPtrOperator(PtrOperatorAST* node)
void CodeGenerator::visitPtrToMember(PtrToMemberAST* node)
{
- // TODO fix AST
- Q_UNUSED(node);
+ visit(node->class_type);
printToken(Token_scope);
m_output << "*";
}
--
1.7.2.3
--=-YJ6GuBAZyr1K7+YjIxxv
Content-Disposition: attachment; filename="0003-rename-ClassType-to-classType.patch"
Content-Type: text/x-patch; name="0003-rename-ClassType-to-classType.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit
More information about the KDevelop-devel
mailing list