Browse Source

Fixed regression when parsing multiple non-member friend declarations.

pull/413/head
triton 10 years ago
parent
commit
43531f0b38
  1. 10
      src/CppParser/Parser.cpp
  2. 10
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 1
      tests/CSharpTemp/CSharpTemp.cs
  4. 24
      tests/CSharpTemp/CSharpTemp.h

10
src/CppParser/Parser.cpp

@ -2408,7 +2408,11 @@ Friend* Parser::WalkFriend(clang::FriendDecl *FD)
auto NS = GetNamespace(FD); auto NS = GetNamespace(FD);
assert(NS && "Expected a valid namespace"); 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)) if (auto F = NS->FindFriend(USR))
return F; return F;
@ -2416,8 +2420,8 @@ Friend* Parser::WalkFriend(clang::FriendDecl *FD)
HandleDeclaration(FD, F); HandleDeclaration(FD, F);
F->_Namespace = NS; F->_Namespace = NS;
if (auto D = FD->getFriendDecl()) if (FriendDecl)
F->Declaration = WalkDeclarationDef(D); F->Declaration = WalkDeclarationDef(FriendDecl);
//auto TL = FD->getFriendType()->getTypeLoc(); //auto TL = FD->getFriendType()->getTypeLoc();
//F->QualifiedType = GetQualifiedType(VD->getType(), WalkType(FD->getFriendType(), &TL)); //F->QualifiedType = GetQualifiedType(VD->getType(), WalkType(FD->getFriendType(), &TL));

10
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -206,4 +206,14 @@ public class CSharpTempTests : GeneratorTestFixture
{ {
QMap.Iterator test_iter; QMap.Iterator test_iter;
} }
[Test]
public void TestMultipleNonMemberFriends()
{
var s1 = new QSize();
var s2 = new QSize();
var sum = s1 + s2;
var sub = s1 - s2;
}
} }

1
tests/CSharpTemp/CSharpTemp.cs

@ -88,6 +88,7 @@ namespace CppSharp.Tests
ctx.SetClassAsValueType("TestCopyConstructorVal"); ctx.SetClassAsValueType("TestCopyConstructorVal");
ctx.SetClassAsValueType("QGenericArgument"); ctx.SetClassAsValueType("QGenericArgument");
ctx.SetClassAsValueType("StructWithPrivateFields"); ctx.SetClassAsValueType("StructWithPrivateFields");
ctx.SetClassAsValueType("QSize");
ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor");
} }

24
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; }; template <> struct QIntegerForSize<8> { typedef uint64_t Unsigned; typedef int64_t Signed; };
typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint; typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint; typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::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);
}
Loading…
Cancel
Save