-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added marshalling to struct... #525
base: main
Are you sure you want to change the base?
Changes from 1 commit
077e505
766c526
48e40fe
4855cfd
21938df
ed0b28a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Linq; | ||
using CppSharp.AST; | ||
|
||
namespace CppSharp.Passes | ||
{ | ||
public class CheckValueTypeClassesPass : TranslationUnitPass | ||
{ | ||
public CheckValueTypeClassesPass() | ||
{ | ||
} | ||
|
||
public override bool VisitClassDecl(Class @class) | ||
{ | ||
@class.Type = CheckClassIsStructible(@class, Driver) ? ClassType.ValueType : @class.Type; | ||
return base.VisitClassDecl(@class); | ||
} | ||
|
||
private bool CheckClassIsStructible(Class @class, Driver Driver) | ||
{ | ||
if (@class.IsUnion || @class.Namespace.Templates.Any(tmp => tmp.Name.Equals(@class.Name))) | ||
return false; | ||
if (@class.IsInterface || @class.IsStatic || @class.IsAbstract) | ||
return false; | ||
if (@class.Declarations.Any(decl => decl.Access == AccessSpecifier.Protected)) | ||
return false; | ||
if (@class.Methods.Any(m => m.IsVirtual)) | ||
return false; | ||
if (@class.HasBaseClass && @class.BaseClass.IsRefType) | ||
return false; | ||
|
||
var allTrUnits = Driver.ASTContext.TranslationUnits; | ||
if (allTrUnits.Any(trUnit => trUnit.Classes.Any( | ||
cls => cls.Bases.Any(clss => clss.IsClass && clss.Class == @class)))) | ||
return false; | ||
|
||
if (@class.IsPOD || @class.IsValueType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What @tritao had in mind was to use IsPOD instead of IsValueType. So you'd best change it to just: return @class.IsPOD. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
return true; | ||
|
||
return false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ public override void Preprocess(Driver driver, ASTContext ctx) | |
{ | ||
driver.AddTranslationUnitPass(new GetterSetterToPropertyPass()); | ||
driver.AddTranslationUnitPass(new CheckMacroPass()); | ||
driver.AddTranslationUnitPass(new CheckValueTypeClassesPass()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is supposed to be added to Driver, not just to the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will have to see how to do that. WIll try. |
||
ctx.SetClassAsValueType("Bar"); | ||
ctx.SetClassAsValueType("Bar2"); | ||
ctx.IgnoreClassWithName("IgnoredType"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's OK but just so you know, there's a short cut: @class.IsDynamic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh. great! Thanks.