From 43531f0b3864261b73c94eb1098a2d7c7dc721b5 Mon Sep 17 00:00:00 2001 From: triton Date: Sun, 22 Feb 2015 19:09:07 +0000 Subject: [PATCH] Fixed regression when parsing multiple non-member friend declarations. --- src/CppParser/Parser.cpp | 10 +++++++--- tests/CSharpTemp/CSharpTemp.Tests.cs | 10 ++++++++++ tests/CSharpTemp/CSharpTemp.cs | 1 + tests/CSharpTemp/CSharpTemp.h | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 55b02a1f..4ab53e45 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -2408,7 +2408,11 @@ Friend* Parser::WalkFriend(clang::FriendDecl *FD) auto NS = GetNamespace(FD); assert(NS && "Expected a valid namespace"); - auto USR = GetDeclUSR(FD); + auto FriendDecl = FD->getFriendDecl(); + + // Work around clangIndex's lack of USR handling for friends and pass the + // pointed to friend declaration instead. + auto USR = GetDeclUSR(FriendDecl ? (Decl*)FriendDecl : FD); if (auto F = NS->FindFriend(USR)) return F; @@ -2416,8 +2420,8 @@ Friend* Parser::WalkFriend(clang::FriendDecl *FD) HandleDeclaration(FD, F); F->_Namespace = NS; - if (auto D = FD->getFriendDecl()) - F->Declaration = WalkDeclarationDef(D); + if (FriendDecl) + F->Declaration = WalkDeclarationDef(FriendDecl); //auto TL = FD->getFriendType()->getTypeLoc(); //F->QualifiedType = GetQualifiedType(VD->getType(), WalkType(FD->getFriendType(), &TL)); diff --git a/tests/CSharpTemp/CSharpTemp.Tests.cs b/tests/CSharpTemp/CSharpTemp.Tests.cs index d9a03bd7..227aeab9 100644 --- a/tests/CSharpTemp/CSharpTemp.Tests.cs +++ b/tests/CSharpTemp/CSharpTemp.Tests.cs @@ -206,4 +206,14 @@ public class CSharpTempTests : GeneratorTestFixture { QMap.Iterator test_iter; } + + [Test] + public void TestMultipleNonMemberFriends() + { + var s1 = new QSize(); + var s2 = new QSize(); + + var sum = s1 + s2; + var sub = s1 - s2; + } } \ No newline at end of file diff --git a/tests/CSharpTemp/CSharpTemp.cs b/tests/CSharpTemp/CSharpTemp.cs index 1dba61ac..41a0decb 100644 --- a/tests/CSharpTemp/CSharpTemp.cs +++ b/tests/CSharpTemp/CSharpTemp.cs @@ -88,6 +88,7 @@ namespace CppSharp.Tests ctx.SetClassAsValueType("TestCopyConstructorVal"); ctx.SetClassAsValueType("QGenericArgument"); ctx.SetClassAsValueType("StructWithPrivateFields"); + ctx.SetClassAsValueType("QSize"); ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); } diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index 4f884763..951485d8 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -403,3 +403,27 @@ template <> struct QIntegerForSize<4> { typedef uint32_t Unsigned; typedef int32 template <> struct QIntegerForSize<8> { typedef uint64_t Unsigned; typedef int64_t Signed; }; typedef QIntegerForSize::Signed qregisterint; typedef QIntegerForSize::Unsigned qregisteruint; + +class QSize +{ +public: + QSize(int w, int h); + friend inline const QSize operator+(const QSize &, const QSize &); + friend inline const QSize operator-(const QSize &, const QSize &); + +private: + int wd; + int ht; +}; + +inline QSize::QSize(int w, int h) : wd(w), ht(h) {} + +inline const QSize operator+(const QSize & s1, const QSize & s2) +{ + return QSize(s1.wd + s2.wd, s1.ht + s2.ht); +} + +inline const QSize operator-(const QSize &s1, const QSize &s2) +{ + return QSize(s1.wd - s2.wd, s1.ht - s2.ht); +} \ No newline at end of file