-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restored the removal of some useless members generated by the Q_OBJEC…
…T macro. Signed-off-by: Dimitar Dobrev <[email protected]>
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CppSharp.AST; | ||
using CppSharp.Passes; | ||
|
||
namespace QtSharp | ||
{ | ||
public class RemoveQObjectMembersPass : TranslationUnitPass | ||
{ | ||
public override bool VisitClassDecl(Class @class) | ||
{ | ||
if (AlreadyVisited(@class) || @class.Name == "QObject") | ||
{ | ||
return false; | ||
} | ||
|
||
IEnumerable<MacroExpansion> expansions = @class.PreprocessedEntities.OfType<MacroExpansion>(); | ||
|
||
bool isQObject = expansions.Any(e => e.Text == "Q_OBJECT"); | ||
if (isQObject) | ||
{ | ||
RemoveQObjectMembers(@class); | ||
} | ||
return true; | ||
} | ||
|
||
private static void RemoveQObjectMembers(Class @class) | ||
{ | ||
// Every Qt object "inherits" a lot of members via the Q_OBJECT macro. | ||
// See the define of Q_OBJECT in qobjectdefs.h for a list of the members. | ||
// We cannot use the Qt defines for disabling the expansion of these | ||
// because it would mess up with the object layout size. | ||
|
||
RemoveMethodOverloads(@class, "tr"); | ||
RemoveMethodOverloads(@class, "trUtf8"); | ||
RemoveMethodOverloads(@class, "qt_static_metacall"); | ||
RemoveVariables(@class, "staticMetaObject"); | ||
} | ||
|
||
private static void RemoveMethodOverloads(Class @class, string originalName) | ||
{ | ||
var overloads = @class.FindMethodByOriginalName(originalName).ToList(); | ||
foreach (var method in overloads) | ||
@class.Methods.Remove(method); | ||
} | ||
|
||
private static void RemoveVariables(Class @class, string originalName) | ||
{ | ||
var variables = @class.FindVariableByOriginalName(originalName).ToList(); | ||
foreach (var variable in variables) | ||
variable.ExplicitlyIgnore(); | ||
} | ||
} | ||
} |