Skip to content

Commit 7bc0db7

Browse files
committed
Don't wrap trivial constructors and destructors
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 87b8471 commit 7bc0db7

File tree

10 files changed

+809
-1632
lines changed

10 files changed

+809
-1632
lines changed

src/AST/FunctionExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,17 @@ public static bool CanOverride(this Method @override, Method method)
9292
ParameterTypeComparer.Instance)) ||
9393
(@override.IsDestructor && method.IsDestructor && method.IsVirtual);
9494
}
95+
96+
public static bool NeedsSymbol(this Method method)
97+
{
98+
Class @class = (Class) method.Namespace;
99+
// virtual functions cannot really be inlined and
100+
// we don't need their symbols anyway as we call them through the v-table
101+
return (!method.IsVirtual && !method.IsSynthetized &&
102+
!method.IsDefaultConstructor && !method.IsCopyConstructor && !method.IsDestructor) ||
103+
(method.IsDefaultConstructor && @class.HasNonTrivialDefaultConstructor) ||
104+
(method.IsCopyConstructor && @class.HasNonTrivialCopyConstructor) ||
105+
(method.IsDestructor && !method.IsVirtual && @class.HasNonTrivialDestructor);
106+
}
95107
}
96108
}

src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser-symbols.cpp

Lines changed: 132 additions & 271 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser-symbols.cpp

Lines changed: 132 additions & 271 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser-symbols.cpp

Lines changed: 132 additions & 271 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser-symbols.cpp

Lines changed: 132 additions & 271 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser-symbols.cpp

Lines changed: 132 additions & 271 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser-symbols.cpp

Lines changed: 132 additions & 271 deletions
Large diffs are not rendered by default.

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ private void GatherClassInternalFunctions(Class @class, bool includeCtors,
655655

656656
foreach (var method in @class.Methods)
657657
{
658-
if (!method.IsGenerated || ASTUtils.CheckIgnoreMethod(method))
658+
if (!method.IsGenerated || ASTUtils.CheckIgnoreMethod(method) ||
659+
(!method.NeedsSymbol() && !method.IsOperator))
659660
continue;
660661

661662
if (method.IsConstructor)

src/Generator/Passes/FindSymbolsPass.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ private bool CheckForSymbol(Declaration decl)
8383
var mangledDecl = decl as IMangledDecl;
8484
var method = decl as Method;
8585
if (decl.IsGenerated && mangledDecl != null &&
86-
// virtual functions cannot really be inlined and
87-
// we don't need their symbols anyway as we call them through the v-table
88-
!(method != null && (method.IsVirtual || method.IsSynthetized)) &&
86+
method?.NeedsSymbol() == true &&
8987
!VisitMangledDeclaration(mangledDecl))
9088
{
9189
decl.ExplicitlyIgnore();

src/Generator/Passes/GenerateSymbolsPass.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private bool NeedsSymbol(Function function)
125125
var method = function as Method;
126126
bool isInImplicitSpecialization;
127127
var declarationContext = function.Namespace;
128+
var @class = declarationContext as Class;
128129
do
129130
{
130131
isInImplicitSpecialization =
@@ -138,8 +139,7 @@ declarationContext is ClassTemplateSpecialization specialization &&
138139
!function.IsDependent && !function.IsPure && function.Namespace.IsGenerated &&
139140
(!string.IsNullOrEmpty(function.Body) ||
140141
isInImplicitSpecialization || function.IsImplicit) &&
141-
// we don't need symbols for virtual functions anyway
142-
(method == null || (!method.IsVirtual && !method.IsSynthetized)) &&
142+
(method?.NeedsSymbol() != false) &&
143143
// we cannot handle nested anonymous types
144144
(!(function.Namespace is Class) || !string.IsNullOrEmpty(function.Namespace.OriginalName)) &&
145145
!Context.Symbols.FindLibraryBySymbol(function.Mangled, out _);

0 commit comments

Comments
 (0)