Skip to content

Commit 1108e72

Browse files
committed
Added an option for skipping private declarations.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 7817b52 commit 1108e72

File tree

12 files changed

+132
-28
lines changed

12 files changed

+132
-28
lines changed

Diff for: src/CppParser/Bindings/CLI/CppParser.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,16 @@ void CppSharp::Parser::CppParserOptions::UnityBuild::set(bool value)
490490
((::CppSharp::CppParser::CppParserOptions*)NativePtr)->unityBuild = value;
491491
}
492492

493+
bool CppSharp::Parser::CppParserOptions::SkipPrivateDeclarations::get()
494+
{
495+
return ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipPrivateDeclarations;
496+
}
497+
498+
void CppSharp::Parser::CppParserOptions::SkipPrivateDeclarations::set(bool value)
499+
{
500+
((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipPrivateDeclarations = value;
501+
}
502+
493503
unsigned int CppSharp::Parser::CppParserOptions::ArgumentsCount::get()
494504
{
495505
auto __ret = ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->getArgumentsCount();

Diff for: src/CppParser/Bindings/CLI/CppParser.h

+6
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ namespace CppSharp
193193
void set(bool);
194194
}
195195

196+
property bool SkipPrivateDeclarations
197+
{
198+
bool get();
199+
void set(bool);
200+
}
201+
196202
property unsigned int ArgumentsCount
197203
{
198204
unsigned int get();

Diff for: src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs

+16
Original file line numberDiff line numberDiff line change
@@ -18041,6 +18041,9 @@ public partial struct __Internal
1804118041
[FieldOffset(148)]
1804218042
internal byte unityBuild;
1804318043

18044+
[FieldOffset(149)]
18045+
internal byte skipPrivateDeclarations;
18046+
1804418047
[SuppressUnmanagedCodeSecurity]
1804518048
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
1804618049
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@@ -18578,6 +18581,19 @@ public bool UnityBuild
1857818581
}
1857918582
}
1858018583

18584+
public bool SkipPrivateDeclarations
18585+
{
18586+
get
18587+
{
18588+
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0;
18589+
}
18590+
18591+
set
18592+
{
18593+
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0);
18594+
}
18595+
}
18596+
1858118597
public uint ArgumentsCount
1858218598
{
1858318599
get

Diff for: src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

+16
Original file line numberDiff line numberDiff line change
@@ -18041,6 +18041,9 @@ public partial struct __Internal
1804118041
[FieldOffset(184)]
1804218042
internal byte unityBuild;
1804318043

18044+
[FieldOffset(185)]
18045+
internal byte skipPrivateDeclarations;
18046+
1804418047
[SuppressUnmanagedCodeSecurity]
1804518048
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
1804618049
EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QAE@XZ")]
@@ -18578,6 +18581,19 @@ public bool UnityBuild
1857818581
}
1857918582
}
1858018583

18584+
public bool SkipPrivateDeclarations
18585+
{
18586+
get
18587+
{
18588+
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0;
18589+
}
18590+
18591+
set
18592+
{
18593+
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0);
18594+
}
18595+
}
18596+
1858118597
public uint ArgumentsCount
1858218598
{
1858318599
get

Diff for: src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

+16
Original file line numberDiff line numberDiff line change
@@ -18040,6 +18040,9 @@ public partial struct __Internal
1804018040
[FieldOffset(288)]
1804118041
internal byte unityBuild;
1804218042

18043+
[FieldOffset(289)]
18044+
internal byte skipPrivateDeclarations;
18045+
1804318046
[SuppressUnmanagedCodeSecurity]
1804418047
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
1804518048
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@@ -18577,6 +18580,19 @@ public bool UnityBuild
1857718580
}
1857818581
}
1857918582

18583+
public bool SkipPrivateDeclarations
18584+
{
18585+
get
18586+
{
18587+
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0;
18588+
}
18589+
18590+
set
18591+
{
18592+
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0);
18593+
}
18594+
}
18595+
1858018596
public uint ArgumentsCount
1858118597
{
1858218598
get

Diff for: src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

+16
Original file line numberDiff line numberDiff line change
@@ -18040,6 +18040,9 @@ public partial struct __Internal
1804018040
[FieldOffset(312)]
1804118041
internal byte unityBuild;
1804218042

18043+
[FieldOffset(313)]
18044+
internal byte skipPrivateDeclarations;
18045+
1804318046
[SuppressUnmanagedCodeSecurity]
1804418047
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
1804518048
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@@ -18577,6 +18580,19 @@ public bool UnityBuild
1857718580
}
1857818581
}
1857918582

18583+
public bool SkipPrivateDeclarations
18584+
{
18585+
get
18586+
{
18587+
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0;
18588+
}
18589+
18590+
set
18591+
{
18592+
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0);
18593+
}
18594+
}
18595+
1858018596
public uint ArgumentsCount
1858118597
{
1858218598
get

Diff for: src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

+16
Original file line numberDiff line numberDiff line change
@@ -18040,6 +18040,9 @@ public partial struct __Internal
1804018040
[FieldOffset(240)]
1804118041
internal byte unityBuild;
1804218042

18043+
[FieldOffset(241)]
18044+
internal byte skipPrivateDeclarations;
18045+
1804318046
[SuppressUnmanagedCodeSecurity]
1804418047
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
1804518048
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@@ -18577,6 +18580,19 @@ public bool UnityBuild
1857718580
}
1857818581
}
1857918582

18583+
public bool SkipPrivateDeclarations
18584+
{
18585+
get
18586+
{
18587+
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0;
18588+
}
18589+
18590+
set
18591+
{
18592+
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0);
18593+
}
18594+
}
18595+
1858018596
public uint ArgumentsCount
1858118597
{
1858218598
get

Diff for: src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs

+16
Original file line numberDiff line numberDiff line change
@@ -18041,6 +18041,9 @@ public partial struct __Internal
1804118041
[FieldOffset(312)]
1804218042
internal byte unityBuild;
1804318043

18044+
[FieldOffset(313)]
18045+
internal byte skipPrivateDeclarations;
18046+
1804418047
[SuppressUnmanagedCodeSecurity]
1804518048
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
1804618049
EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QEAA@XZ")]
@@ -18578,6 +18581,19 @@ public bool UnityBuild
1857818581
}
1857918582
}
1858018583

18584+
public bool SkipPrivateDeclarations
18585+
{
18586+
get
18587+
{
18588+
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0;
18589+
}
18590+
18591+
set
18592+
{
18593+
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0);
18594+
}
18595+
}
18596+
1858118597
public uint ArgumentsCount
1858218598
{
1858318599
get

Diff for: src/CppParser/CppParser.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CppParserOptions::CppParserOptions()
1919
, microsoftMode(false)
2020
, verbose(false)
2121
, unityBuild(false)
22+
, skipPrivateDeclarations(true)
2223
{
2324
}
2425

Diff for: src/CppParser/CppParser.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct CS_API CppParserOptions
4545
bool microsoftMode;
4646
bool verbose;
4747
bool unityBuild;
48+
bool skipPrivateDeclarations;
4849
};
4950

5051
enum class ParserDiagnosticLevel

Diff for: src/CppParser/Parser.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,8 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD,
153153

154154
// Dump fields.
155155
uint64_t FieldNo = 0;
156-
for (RecordDecl::field_iterator I = RD->field_begin(),
157-
E = RD->field_end(); I != E; ++I, ++FieldNo) {
158-
auto Field = *I;
159-
uint64_t LocalFieldOffsetInBits = Layout.getFieldOffset(FieldNo);
156+
for (const clang::FieldDecl* Field : RD->fields()) {
157+
uint64_t LocalFieldOffsetInBits = Layout.getFieldOffset(FieldNo++);
160158
CharUnits FieldOffset =
161159
Offset + c->getASTContext().toCharUnitsFromBits(LocalFieldOffsetInBits);
162160

@@ -966,7 +964,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
966964
{
967965
auto MD = cast<CXXMethodDecl>(D);
968966
if (IsSupported(MD))
969-
WalkMethodCXX(MD);
967+
WalkDeclaration(MD);
970968
break;
971969
}
972970
}
@@ -975,19 +973,14 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
975973
return;
976974
}
977975

976+
if (opts->skipPrivateDeclarations &&
977+
Record->getAccess() == clang::AccessSpecifier::AS_private)
978+
return;
979+
978980
for (auto D : Record->decls())
979981
{
980982
switch (D->getKind())
981983
{
982-
case Decl::CXXConstructor:
983-
case Decl::CXXDestructor:
984-
case Decl::CXXConversion:
985-
case Decl::CXXMethod:
986-
{
987-
auto MD = cast<CXXMethodDecl>(D);
988-
WalkMethodCXX(MD);
989-
break;
990-
}
991984
case Decl::AccessSpec:
992985
{
993986
AccessSpecDecl* AS = cast<AccessSpecDecl>(D);
@@ -1514,6 +1507,10 @@ TypeAliasTemplate* Parser::WalkTypeAliasTemplate(
15141507

15151508
FunctionTemplate* Parser::WalkFunctionTemplate(const clang::FunctionTemplateDecl* TD)
15161509
{
1510+
if (opts->skipPrivateDeclarations &&
1511+
TD->getAccess() == clang::AccessSpecifier::AS_private)
1512+
return nullptr;
1513+
15171514
using namespace clang;
15181515

15191516
auto NS = GetNamespace(TD);
@@ -1729,6 +1726,11 @@ static CXXOperatorKind GetOperatorKindFromDecl(clang::DeclarationName Name)
17291726

17301727
Method* Parser::WalkMethodCXX(const clang::CXXMethodDecl* MD)
17311728
{
1729+
if (opts->skipPrivateDeclarations &&
1730+
MD->getAccess() == clang::AccessSpecifier::AS_private &&
1731+
!MD->isVirtual())
1732+
return nullptr;
1733+
17321734
using namespace clang;
17331735

17341736
// We could be in a redeclaration, so process the primary context.
@@ -3930,6 +3932,8 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D)
39303932
{
39313933
auto MD = cast<CXXMethodDecl>(D);
39323934
Decl = WalkMethodCXX(MD);
3935+
if (Decl == nullptr)
3936+
return Decl;
39333937

39343938
auto NS = GetNamespace(MD);
39353939
Decl->_namespace = NS;

Diff for: src/Generator.Tests/Passes/TestPasses.cs

-14
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,6 @@ public void TestUniqueNamesAcrossTranslationUnits()
147147
Assert.AreNotEqual(unnamedEnum1.Name, unnamedEnum2.Name);
148148
}
149149

150-
[Test]
151-
public void TestStructInheritance()
152-
{
153-
154-
}
155-
156-
[Test]
157-
public void TestIgnoringMethod()
158-
{
159-
AstContext.IgnoreClassMethodWithName("Foo", "toIgnore");
160-
Assert.IsFalse(AstContext.FindClass("Foo").First().Methods.Find(
161-
m => m.Name == "toIgnore").IsGenerated);
162-
}
163-
164150
[Test]
165151
public void TestSetPropertyAsReadOnly()
166152
{

0 commit comments

Comments
 (0)