From 1a293f8965f6d26e3ea4f819903a432e3b1216c2 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 30 Aug 2013 23:23:56 +0300 Subject: [PATCH 1/3] Added copy constructors to some of the AST classes. Signed-off-by: Dimitar Dobrev --- src/AST/ClassLayout.cs | 16 ++++++++++++++++ src/AST/Declaration.cs | 30 ++++++++++++++++++++++++++++-- src/AST/Function.cs | 17 +++++++++++++++++ src/AST/Method.cs | 20 +++++++++++++++++++- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/AST/ClassLayout.cs b/src/AST/ClassLayout.cs index 45609121..3721dda4 100644 --- a/src/AST/ClassLayout.cs +++ b/src/AST/ClassLayout.cs @@ -87,6 +87,22 @@ namespace CppSharp.AST VFTables = new List(); } + public ClassLayout(ClassLayout classLayout) + : this() + { + ABI = classLayout.ABI; + HasOwnVFPtr = classLayout.HasOwnVFPtr; + VBPtrOffset = classLayout.VBPtrOffset; + PrimaryBase = classLayout.PrimaryBase; + HasVirtualBases = classLayout.HasVirtualBases; + Alignment = classLayout.Alignment; + Size = classLayout.Size; + DataSize = classLayout.DataSize; + VFTables.AddRange(classLayout.VFTables); + Layout = new VTableLayout(); + Layout.Components.AddRange(classLayout.Layout.Components); + } + /// /// Does this class provide its own virtual-function table /// pointer, rather than inheriting one from a primary base diff --git a/src/AST/Declaration.cs b/src/AST/Declaration.cs index 38fc0e54..c973f351 100644 --- a/src/AST/Declaration.cs +++ b/src/AST/Declaration.cs @@ -55,7 +55,11 @@ namespace CppSharp.AST } private string name; - public virtual string OriginalName { get; set;} + public virtual string OriginalName + { + get { return originalName; } + set { originalName = value; } + } // Name of the declaration. public virtual string Name @@ -194,6 +198,7 @@ namespace CppSharp.AST // Pointer to the original declaration from Clang. public IntPtr OriginalPtr; + private string originalName; protected Declaration() { @@ -205,7 +210,28 @@ namespace CppSharp.AST protected Declaration(string name) : this() { - Name = name; + this.name = name; + } + + protected Declaration(Declaration declaration) + : this() + { + Namespace = declaration.Namespace; + originalName = declaration.OriginalName; + name = declaration.Name; + Comment = declaration.Comment; + IgnoreFlags = declaration.IgnoreFlags; + Access = declaration.Access; + DebugText = declaration.DebugText; + IsIncomplete = declaration.IsIncomplete; + IsDependent = declaration.IsDependent; + CompleteDeclaration = declaration.CompleteDeclaration; + DefinitionOrder = declaration.DefinitionOrder; + ExcludeFromPasses = new HashSet( + declaration.ExcludeFromPasses); + PreprocessedEntities = new List( + declaration.PreprocessedEntities); + OriginalPtr = declaration.OriginalPtr; } public override string ToString() diff --git a/src/AST/Function.cs b/src/AST/Function.cs index f967472a..6c44348d 100644 --- a/src/AST/Function.cs +++ b/src/AST/Function.cs @@ -76,6 +76,23 @@ namespace CppSharp.AST IsInline = false; } + public Function(Function function) + : base(function) + { + Parameters = new List(); + ReturnType = function.ReturnType; + IsReturnIndirect = function.IsReturnIndirect; + Parameters.AddRange(function.Parameters); + IsVariadic = function.IsVariadic; + IsInline = function.IsInline; + IsPure = function.IsPure; + OperatorKind = function.OperatorKind; + CallingConvention = function.CallingConvention; + SynthKind = function.SynthKind; + OriginalFunction = function.OriginalFunction; + Mangled = function.Mangled; + } + public QualifiedType ReturnType { get; set; } public bool IsReturnIndirect { get; set; } diff --git a/src/AST/Method.cs b/src/AST/Method.cs index d8cfdabe..adc7c4c3 100644 --- a/src/AST/Method.cs +++ b/src/AST/Method.cs @@ -67,13 +67,31 @@ namespace CppSharp.AST /// /// Represents a C++ record method declaration. /// - public class Method : Function, ITypedDecl + public class Method : Function { public Method() { Access = AccessSpecifier.Public; } + public Method(Method method) + : base(method) + { + Access = method.Access; + AccessDecl = method.AccessDecl; + IsVirtual = method.IsVirtual; + IsConst = method.IsConst; + IsImplicit = method.IsImplicit; + IsSynthetized = method.IsSynthetized; + IsOverride = method.IsOverride; + IsProxy = method.IsProxy; + Kind = method.Kind; + IsDefaultConstructor = method.IsDefaultConstructor; + IsCopyConstructor = method.IsCopyConstructor; + IsMoveConstructor = method.IsMoveConstructor; + Conversion = method.Conversion; + } + public AccessSpecifierDecl AccessDecl { get; set; } public bool IsVirtual { get; set; } From e0a3cde7a427a1118b5e29f2fc2e308cc50ef701 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 30 Aug 2013 23:25:04 +0300 Subject: [PATCH 2/3] Generated protected methods and fields. Signed-off-by: Dimitar Dobrev --- src/Generator/AST/Utils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator/AST/Utils.cs b/src/Generator/AST/Utils.cs index a4600c09..40dd92b1 100644 --- a/src/Generator/AST/Utils.cs +++ b/src/Generator/AST/Utils.cs @@ -37,7 +37,7 @@ namespace CppSharp.AST if (method.Kind == CXXMethodKind.Conversion) return true; - if (method.Access != AccessSpecifier.Public) + if (method.Access == AccessSpecifier.Private) return true; return false; @@ -45,7 +45,7 @@ namespace CppSharp.AST public static bool CheckIgnoreField(Field field) { - if (field.Access != AccessSpecifier.Public) + if (field.Access == AccessSpecifier.Private) return true; return field.Ignore; From 0f5e27f939cdc77e461d613a2d5a5ceba8e596a2 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 30 Aug 2013 23:26:56 +0300 Subject: [PATCH 3/3] Fixed a bug that caused the generation of the uncompilable expression "&*IntPtr". Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 6f1bb060..fd976038 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -243,6 +243,7 @@ namespace CppSharp.Generators.CSharp } else { + instance = instance.Trim('*'); Context.SupportBefore.WriteLine( "CppSharp.Runtime.Helpers.memcpy({0}, new IntPtr(&{1}), new UIntPtr({2}));", instanceName, instance, @class.Layout.Size);