Browse Source

Added support for getting the array element size to the AST.

pull/547/head
triton 10 years ago
parent
commit
2593f4727f
  1. 3
      src/AST/Type.cs
  2. 3
      src/Core/Parser/ASTConverter.cs
  3. 1
      src/CppParser/AST.h
  4. 10
      src/CppParser/Bindings/CLI/AST.cpp
  5. 6
      src/CppParser/Bindings/CLI/AST.h
  6. 24
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs
  7. 24
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs
  8. 24
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs
  9. 24
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs
  10. 5
      src/CppParser/Parser.cpp

3
src/AST/Type.cs

@ -166,6 +166,9 @@ namespace CppSharp.AST
// In case of a constant size array. // In case of a constant size array.
public long Size; public long Size;
// Size of the element type of the array.
public long ElementSize;
public ArrayType() public ArrayType()
{ {
} }

3
src/Core/Parser/ASTConverter.cs

@ -419,7 +419,8 @@ namespace CppSharp
{ {
Size = type.Size, Size = type.Size,
SizeType = VisitArraySizeType(type.SizeType), SizeType = VisitArraySizeType(type.SizeType),
QualifiedType = VisitQualified(type.QualifiedType) QualifiedType = VisitQualified(type.QualifiedType),
ElementSize = type.ElementSize
}; };
VisitType(type, _type); VisitType(type, _type);
return _type; return _type;

1
src/CppParser/AST.h

@ -84,6 +84,7 @@ public:
CppSharp::CppParser::AST::QualifiedType QualifiedType; CppSharp::CppParser::AST::QualifiedType QualifiedType;
ArraySize SizeType; ArraySize SizeType;
long Size; long Size;
long ElementSize;
}; };
class Parameter; class Parameter;

10
src/CppParser/Bindings/CLI/AST.cpp

@ -327,6 +327,16 @@ void CppSharp::Parser::AST::ArrayType::Size::set(long value)
((::CppSharp::CppParser::AST::ArrayType*)NativePtr)->Size = value; ((::CppSharp::CppParser::AST::ArrayType*)NativePtr)->Size = value;
} }
long CppSharp::Parser::AST::ArrayType::ElementSize::get()
{
return ((::CppSharp::CppParser::AST::ArrayType*)NativePtr)->ElementSize;
}
void CppSharp::Parser::AST::ArrayType::ElementSize::set(long value)
{
((::CppSharp::CppParser::AST::ArrayType*)NativePtr)->ElementSize = value;
}
CppSharp::Parser::AST::FunctionType::FunctionType(::CppSharp::CppParser::AST::FunctionType* native) CppSharp::Parser::AST::FunctionType::FunctionType(::CppSharp::CppParser::AST::FunctionType* native)
: CppSharp::Parser::AST::Type((::CppSharp::CppParser::AST::Type*)native) : CppSharp::Parser::AST::Type((::CppSharp::CppParser::AST::Type*)native)
{ {

6
src/CppParser/Bindings/CLI/AST.h

@ -508,6 +508,12 @@ namespace CppSharp
long get(); long get();
void set(long); void set(long);
} }
property long ElementSize
{
long get();
void set(long);
}
}; };
public ref class FunctionType : CppSharp::Parser::AST::Type public ref class FunctionType : CppSharp::Parser::AST::Type

24
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs

@ -740,7 +740,7 @@ namespace CppSharp
public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 24)] [StructLayout(LayoutKind.Explicit, Size = 28)]
public new partial struct Internal public new partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
@ -758,6 +758,9 @@ namespace CppSharp
[FieldOffset(20)] [FieldOffset(20)]
public int Size; public int Size;
[FieldOffset(24)]
public int ElementSize;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST9ArrayTypeC2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST9ArrayTypeC2Ev")]
@ -791,7 +794,7 @@ namespace CppSharp
private static ArrayType.Internal* __CopyValue(ArrayType.Internal native) private static ArrayType.Internal* __CopyValue(ArrayType.Internal native)
{ {
var ret = Marshal.AllocHGlobal(24); var ret = Marshal.AllocHGlobal(28);
CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native)); CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native));
return (ArrayType.Internal*) ret; return (ArrayType.Internal*) ret;
} }
@ -811,7 +814,7 @@ namespace CppSharp
public ArrayType() public ArrayType()
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(24); __Instance = Marshal.AllocHGlobal(28);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0(__Instance); Internal.ctor_0(__Instance);
@ -820,7 +823,7 @@ namespace CppSharp
public ArrayType(CppSharp.Parser.AST.ArrayType _0) public ArrayType(CppSharp.Parser.AST.ArrayType _0)
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(24); __Instance = Marshal.AllocHGlobal(28);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance; var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance;
@ -884,6 +887,19 @@ namespace CppSharp
((Internal*) __Instance)->Size = value; ((Internal*) __Instance)->Size = value;
} }
} }
public int ElementSize
{
get
{
return ((Internal*) __Instance)->ElementSize;
}
set
{
((Internal*) __Instance)->ElementSize = value;
}
}
} }
public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable

24
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs

@ -740,7 +740,7 @@ namespace CppSharp
public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 24)] [StructLayout(LayoutKind.Explicit, Size = 28)]
public new partial struct Internal public new partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
@ -758,6 +758,9 @@ namespace CppSharp
[FieldOffset(20)] [FieldOffset(20)]
public int Size; public int Size;
[FieldOffset(24)]
public int ElementSize;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0ArrayType@AST@CppParser@CppSharp@@QAE@XZ")] EntryPoint="??0ArrayType@AST@CppParser@CppSharp@@QAE@XZ")]
@ -791,7 +794,7 @@ namespace CppSharp
private static ArrayType.Internal* __CopyValue(ArrayType.Internal native) private static ArrayType.Internal* __CopyValue(ArrayType.Internal native)
{ {
var ret = Marshal.AllocHGlobal(24); var ret = Marshal.AllocHGlobal(28);
CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native)); CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native));
return (ArrayType.Internal*) ret; return (ArrayType.Internal*) ret;
} }
@ -811,7 +814,7 @@ namespace CppSharp
public ArrayType() public ArrayType()
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(24); __Instance = Marshal.AllocHGlobal(28);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0(__Instance); Internal.ctor_0(__Instance);
@ -820,7 +823,7 @@ namespace CppSharp
public ArrayType(CppSharp.Parser.AST.ArrayType _0) public ArrayType(CppSharp.Parser.AST.ArrayType _0)
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(24); __Instance = Marshal.AllocHGlobal(28);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance; var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance;
@ -884,6 +887,19 @@ namespace CppSharp
((Internal*) __Instance)->Size = value; ((Internal*) __Instance)->Size = value;
} }
} }
public int ElementSize
{
get
{
return ((Internal*) __Instance)->ElementSize;
}
set
{
((Internal*) __Instance)->ElementSize = value;
}
}
} }
public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable

24
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs

@ -740,7 +740,7 @@ namespace CppSharp
public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 40)] [StructLayout(LayoutKind.Explicit, Size = 48)]
public new partial struct Internal public new partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
@ -758,6 +758,9 @@ namespace CppSharp
[FieldOffset(32)] [FieldOffset(32)]
public long Size; public long Size;
[FieldOffset(40)]
public long ElementSize;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST9ArrayTypeC2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST9ArrayTypeC2Ev")]
@ -791,7 +794,7 @@ namespace CppSharp
private static ArrayType.Internal* __CopyValue(ArrayType.Internal native) private static ArrayType.Internal* __CopyValue(ArrayType.Internal native)
{ {
var ret = Marshal.AllocHGlobal(40); var ret = Marshal.AllocHGlobal(48);
CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native)); CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native));
return (ArrayType.Internal*) ret; return (ArrayType.Internal*) ret;
} }
@ -811,7 +814,7 @@ namespace CppSharp
public ArrayType() public ArrayType()
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(40); __Instance = Marshal.AllocHGlobal(48);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0(__Instance); Internal.ctor_0(__Instance);
@ -820,7 +823,7 @@ namespace CppSharp
public ArrayType(CppSharp.Parser.AST.ArrayType _0) public ArrayType(CppSharp.Parser.AST.ArrayType _0)
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(40); __Instance = Marshal.AllocHGlobal(48);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance; var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance;
@ -884,6 +887,19 @@ namespace CppSharp
((Internal*) __Instance)->Size = value; ((Internal*) __Instance)->Size = value;
} }
} }
public long ElementSize
{
get
{
return ((Internal*) __Instance)->ElementSize;
}
set
{
((Internal*) __Instance)->ElementSize = value;
}
}
} }
public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable

24
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs

@ -740,7 +740,7 @@ namespace CppSharp
public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 40)] [StructLayout(LayoutKind.Explicit, Size = 48)]
public new partial struct Internal public new partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
@ -758,6 +758,9 @@ namespace CppSharp
[FieldOffset(32)] [FieldOffset(32)]
public long Size; public long Size;
[FieldOffset(40)]
public long ElementSize;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST9ArrayTypeC2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST9ArrayTypeC2Ev")]
@ -791,7 +794,7 @@ namespace CppSharp
private static ArrayType.Internal* __CopyValue(ArrayType.Internal native) private static ArrayType.Internal* __CopyValue(ArrayType.Internal native)
{ {
var ret = Marshal.AllocHGlobal(40); var ret = Marshal.AllocHGlobal(48);
CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native)); CppSharp.Parser.AST.ArrayType.Internal.cctor_2(ret, new global::System.IntPtr(&native));
return (ArrayType.Internal*) ret; return (ArrayType.Internal*) ret;
} }
@ -811,7 +814,7 @@ namespace CppSharp
public ArrayType() public ArrayType()
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(40); __Instance = Marshal.AllocHGlobal(48);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0(__Instance); Internal.ctor_0(__Instance);
@ -820,7 +823,7 @@ namespace CppSharp
public ArrayType(CppSharp.Parser.AST.ArrayType _0) public ArrayType(CppSharp.Parser.AST.ArrayType _0)
: this((Internal*) null) : this((Internal*) null)
{ {
__Instance = Marshal.AllocHGlobal(40); __Instance = Marshal.AllocHGlobal(48);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance; var arg0 = ReferenceEquals(_0, null) ? global::System.IntPtr.Zero : _0.__Instance;
@ -884,6 +887,19 @@ namespace CppSharp
((Internal*) __Instance)->Size = value; ((Internal*) __Instance)->Size = value;
} }
} }
public long ElementSize
{
get
{
return ((Internal*) __Instance)->ElementSize;
}
set
{
((Internal*) __Instance)->ElementSize = value;
}
}
} }
public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable

5
src/CppParser/Parser.cpp

@ -1750,10 +1750,11 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc(); if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = new ArrayType(); auto A = new ArrayType();
A->QualifiedType = GetQualifiedType(AT->getElementType(), auto ElemTy = AT->getElementType();
WalkType(AT->getElementType(), &Next)); A->QualifiedType = GetQualifiedType(ElemTy, WalkType(ElemTy, &Next));
A->SizeType = ArrayType::ArraySize::Constant; A->SizeType = ArrayType::ArraySize::Constant;
A->Size = AST->getConstantArrayElementCount(AT); A->Size = AST->getConstantArrayElementCount(AT);
A->ElementSize = (long)AST->getTypeSize(ElemTy);
Ty = A; Ty = A;
break; break;

Loading…
Cancel
Save