diff --git a/src/CppParser/Bindings/CLI/CppParser.cpp b/src/CppParser/Bindings/CLI/CppParser.cpp index fb1145d76c..8be6b6fef7 100644 --- a/src/CppParser/Bindings/CLI/CppParser.cpp +++ b/src/CppParser/Bindings/CLI/CppParser.cpp @@ -490,6 +490,16 @@ void CppSharp::Parser::CppParserOptions::UnityBuild::set(bool value) ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->unityBuild = value; } +bool CppSharp::Parser::CppParserOptions::SkipPrivateDeclarations::get() +{ + return ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipPrivateDeclarations; +} + +void CppSharp::Parser::CppParserOptions::SkipPrivateDeclarations::set(bool value) +{ + ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipPrivateDeclarations = value; +} + unsigned int CppSharp::Parser::CppParserOptions::ArgumentsCount::get() { auto __ret = ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->getArgumentsCount(); diff --git a/src/CppParser/Bindings/CLI/CppParser.h b/src/CppParser/Bindings/CLI/CppParser.h index 96b8bee886..831deadcaf 100644 --- a/src/CppParser/Bindings/CLI/CppParser.h +++ b/src/CppParser/Bindings/CLI/CppParser.h @@ -193,6 +193,12 @@ namespace CppSharp void set(bool); } + property bool SkipPrivateDeclarations + { + bool get(); + void set(bool); + } + property unsigned int ArgumentsCount { unsigned int get(); diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs index 18870ea944..c27f61dca2 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -18041,6 +18041,9 @@ public partial struct __Internal [FieldOffset(148)] internal byte unityBuild; + [FieldOffset(149)] + internal byte skipPrivateDeclarations; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] @@ -18578,6 +18581,19 @@ public bool UnityBuild } } + public bool SkipPrivateDeclarations + { + get + { + return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0; + } + + set + { + ((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0); + } + } + public uint ArgumentsCount { get diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs index 5dde710257..7ef6585208 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs @@ -18041,6 +18041,9 @@ public partial struct __Internal [FieldOffset(184)] internal byte unityBuild; + [FieldOffset(185)] + internal byte skipPrivateDeclarations; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QAE@XZ")] @@ -18578,6 +18581,19 @@ public bool UnityBuild } } + public bool SkipPrivateDeclarations + { + get + { + return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0; + } + + set + { + ((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0); + } + } + public uint ArgumentsCount { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs index 252ddac1d1..363fe87ba9 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -18040,6 +18040,9 @@ public partial struct __Internal [FieldOffset(288)] internal byte unityBuild; + [FieldOffset(289)] + internal byte skipPrivateDeclarations; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] @@ -18577,6 +18580,19 @@ public bool UnityBuild } } + public bool SkipPrivateDeclarations + { + get + { + return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0; + } + + set + { + ((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0); + } + } + public uint ArgumentsCount { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs index 2e6323b2af..f007df4722 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs @@ -18040,6 +18040,9 @@ public partial struct __Internal [FieldOffset(312)] internal byte unityBuild; + [FieldOffset(313)] + internal byte skipPrivateDeclarations; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] @@ -18577,6 +18580,19 @@ public bool UnityBuild } } + public bool SkipPrivateDeclarations + { + get + { + return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0; + } + + set + { + ((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0); + } + } + public uint ArgumentsCount { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs index 9405c1c5da..9b32ab2d76 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs @@ -18040,6 +18040,9 @@ public partial struct __Internal [FieldOffset(240)] internal byte unityBuild; + [FieldOffset(241)] + internal byte skipPrivateDeclarations; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] @@ -18577,6 +18580,19 @@ public bool UnityBuild } } + public bool SkipPrivateDeclarations + { + get + { + return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0; + } + + set + { + ((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0); + } + } + public uint ArgumentsCount { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs index d518c76fee..d0141ba3a3 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs @@ -18041,6 +18041,9 @@ public partial struct __Internal [FieldOffset(312)] internal byte unityBuild; + [FieldOffset(313)] + internal byte skipPrivateDeclarations; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QEAA@XZ")] @@ -18578,6 +18581,19 @@ public bool UnityBuild } } + public bool SkipPrivateDeclarations + { + get + { + return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipPrivateDeclarations != 0; + } + + set + { + ((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipPrivateDeclarations = (byte) (value ? 1 : 0); + } + } + public uint ArgumentsCount { get diff --git a/src/CppParser/CppParser.cpp b/src/CppParser/CppParser.cpp index 8a11d20843..51020944ff 100644 --- a/src/CppParser/CppParser.cpp +++ b/src/CppParser/CppParser.cpp @@ -19,6 +19,7 @@ CppParserOptions::CppParserOptions() , microsoftMode(false) , verbose(false) , unityBuild(false) + , skipPrivateDeclarations(true) { } diff --git a/src/CppParser/CppParser.h b/src/CppParser/CppParser.h index f0a19b8d02..b0f6c404b1 100644 --- a/src/CppParser/CppParser.h +++ b/src/CppParser/CppParser.h @@ -45,6 +45,7 @@ struct CS_API CppParserOptions bool microsoftMode; bool verbose; bool unityBuild; + bool skipPrivateDeclarations; }; enum class ParserDiagnosticLevel diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 333b6715df..919e0e0a1f 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -153,10 +153,8 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD, // Dump fields. uint64_t FieldNo = 0; - for (RecordDecl::field_iterator I = RD->field_begin(), - E = RD->field_end(); I != E; ++I, ++FieldNo) { - auto Field = *I; - uint64_t LocalFieldOffsetInBits = Layout.getFieldOffset(FieldNo); + for (const clang::FieldDecl* Field : RD->fields()) { + uint64_t LocalFieldOffsetInBits = Layout.getFieldOffset(FieldNo++); CharUnits FieldOffset = Offset + c->getASTContext().toCharUnitsFromBits(LocalFieldOffsetInBits); @@ -966,7 +964,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC) { auto MD = cast(D); if (IsSupported(MD)) - WalkMethodCXX(MD); + WalkDeclaration(MD); break; } } @@ -975,19 +973,14 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC) return; } + if (opts->skipPrivateDeclarations && + Record->getAccess() == clang::AccessSpecifier::AS_private) + return; + for (auto D : Record->decls()) { switch (D->getKind()) { - case Decl::CXXConstructor: - case Decl::CXXDestructor: - case Decl::CXXConversion: - case Decl::CXXMethod: - { - auto MD = cast(D); - WalkMethodCXX(MD); - break; - } case Decl::AccessSpec: { AccessSpecDecl* AS = cast(D); @@ -1514,6 +1507,10 @@ TypeAliasTemplate* Parser::WalkTypeAliasTemplate( FunctionTemplate* Parser::WalkFunctionTemplate(const clang::FunctionTemplateDecl* TD) { + if (opts->skipPrivateDeclarations && + TD->getAccess() == clang::AccessSpecifier::AS_private) + return nullptr; + using namespace clang; auto NS = GetNamespace(TD); @@ -1729,6 +1726,11 @@ static CXXOperatorKind GetOperatorKindFromDecl(clang::DeclarationName Name) Method* Parser::WalkMethodCXX(const clang::CXXMethodDecl* MD) { + if (opts->skipPrivateDeclarations && + MD->getAccess() == clang::AccessSpecifier::AS_private && + !MD->isVirtual()) + return nullptr; + using namespace clang; // We could be in a redeclaration, so process the primary context. @@ -3930,6 +3932,8 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D) { auto MD = cast(D); Decl = WalkMethodCXX(MD); + if (Decl == nullptr) + return Decl; auto NS = GetNamespace(MD); Decl->_namespace = NS; diff --git a/src/Generator.Tests/Passes/TestPasses.cs b/src/Generator.Tests/Passes/TestPasses.cs index a193f5c56c..a9a582db93 100644 --- a/src/Generator.Tests/Passes/TestPasses.cs +++ b/src/Generator.Tests/Passes/TestPasses.cs @@ -147,20 +147,6 @@ public void TestUniqueNamesAcrossTranslationUnits() Assert.AreNotEqual(unnamedEnum1.Name, unnamedEnum2.Name); } - [Test] - public void TestStructInheritance() - { - - } - - [Test] - public void TestIgnoringMethod() - { - AstContext.IgnoreClassMethodWithName("Foo", "toIgnore"); - Assert.IsFalse(AstContext.FindClass("Foo").First().Methods.Find( - m => m.Name == "toIgnore").IsGenerated); - } - [Test] public void TestSetPropertyAsReadOnly() {