mirror of https://github.com/mono/CppSharp.git
16 changed files with 696 additions and 271 deletions
@ -1,6 +1,90 @@ |
|||||||
namespace CppSharp.AST |
namespace CppSharp |
||||||
{ |
{ |
||||||
|
/// <summary>
|
||||||
|
/// Encodes a location in the source.
|
||||||
|
/// The SourceManager can decode this to get at the full include stack,
|
||||||
|
/// line and column information.
|
||||||
|
/// </summary>
|
||||||
public struct SourceLocation |
public struct SourceLocation |
||||||
{ |
{ |
||||||
|
private const uint MacroIDBit = 1U << 31; |
||||||
|
|
||||||
|
public SourceLocation(uint id) |
||||||
|
{ |
||||||
|
ID = id; |
||||||
|
} |
||||||
|
|
||||||
|
public readonly uint ID; |
||||||
|
|
||||||
|
public bool IsFileID |
||||||
|
{ |
||||||
|
get { return (ID & MacroIDBit) == 0; } |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsMacroID |
||||||
|
{ |
||||||
|
get { return (ID & MacroIDBit) != 0; } |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if this is a valid SourceLocation object.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsValid |
||||||
|
{ |
||||||
|
get { return ID != 0; } |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if this is an invalid SourceLocation object.
|
||||||
|
/// Invalid SourceLocations are often used when events have no corresponding
|
||||||
|
/// location in the source (e.g. a diagnostic is required for a command line
|
||||||
|
/// option).
|
||||||
|
/// </summary>
|
||||||
|
public bool IsInvalid |
||||||
|
{ |
||||||
|
get { return ID == 0; } |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Offset into the source manager's global input view.
|
||||||
|
/// </summary>
|
||||||
|
public uint Offset |
||||||
|
{ |
||||||
|
get { return ID & ~MacroIDBit; } |
||||||
|
} |
||||||
|
|
||||||
|
public static bool operator ==(SourceLocation a, SourceLocation b) |
||||||
|
{ |
||||||
|
return a.ID == b.ID; |
||||||
|
} |
||||||
|
|
||||||
|
public static bool operator !=(SourceLocation a, SourceLocation b) |
||||||
|
{ |
||||||
|
return !(a == b); |
||||||
|
} |
||||||
|
|
||||||
|
public bool Equals(SourceLocation other) |
||||||
|
{ |
||||||
|
return ID == other.ID; |
||||||
|
} |
||||||
|
|
||||||
|
public override bool Equals(object obj) |
||||||
|
{ |
||||||
|
if (ReferenceEquals(null, obj)) return false; |
||||||
|
return obj is SourceLocation && Equals((SourceLocation)obj); |
||||||
|
} |
||||||
|
|
||||||
|
public override int GetHashCode() |
||||||
|
{ |
||||||
|
return (int)ID; |
||||||
|
} |
||||||
|
|
||||||
|
public override string ToString() |
||||||
|
{ |
||||||
|
if (IsInvalid) |
||||||
|
return "<invalid>"; |
||||||
|
|
||||||
|
return IsMacroID ? "Macro ID: " + ID : "File ID: " + Offset; |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,32 @@ |
|||||||
|
#include "Sources.h" |
||||||
|
|
||||||
|
using namespace System; |
||||||
|
using namespace System::Runtime::InteropServices; |
||||||
|
|
||||||
|
CppSharp::Parser::SourceLocation::SourceLocation(::CppSharp::CppParser::SourceLocation* native) |
||||||
|
{ |
||||||
|
__ID = native->ID; |
||||||
|
} |
||||||
|
|
||||||
|
CppSharp::Parser::SourceLocation::SourceLocation(System::IntPtr native) |
||||||
|
{ |
||||||
|
auto __native = (::CppSharp::CppParser::SourceLocation*)native.ToPointer(); |
||||||
|
__ID = __native->ID; |
||||||
|
} |
||||||
|
|
||||||
|
CppSharp::Parser::SourceLocation::SourceLocation(unsigned int ID) |
||||||
|
{ |
||||||
|
::CppSharp::CppParser::SourceLocation _native(ID); |
||||||
|
this->ID = _native.ID; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned int CppSharp::Parser::SourceLocation::ID::get() |
||||||
|
{ |
||||||
|
return __ID; |
||||||
|
} |
||||||
|
|
||||||
|
void CppSharp::Parser::SourceLocation::ID::set(unsigned int value) |
||||||
|
{ |
||||||
|
__ID = value; |
||||||
|
} |
||||||
|
|
@ -0,0 +1,37 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "CppSharp.h" |
||||||
|
#include <Sources.h> |
||||||
|
|
||||||
|
namespace CppSharp |
||||||
|
{ |
||||||
|
namespace Parser |
||||||
|
{ |
||||||
|
value struct SourceLocation; |
||||||
|
value struct SourceManager; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
namespace CppSharp |
||||||
|
{ |
||||||
|
namespace Parser |
||||||
|
{ |
||||||
|
public value struct SourceLocation |
||||||
|
{ |
||||||
|
public: |
||||||
|
|
||||||
|
SourceLocation(::CppSharp::CppParser::SourceLocation* native); |
||||||
|
SourceLocation(System::IntPtr native); |
||||||
|
SourceLocation(unsigned int ID); |
||||||
|
|
||||||
|
property unsigned int ID |
||||||
|
{ |
||||||
|
unsigned int get(); |
||||||
|
void set(unsigned int); |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
unsigned int __ID; |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,123 @@ |
|||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// This is autogenerated code by CppSharp.
|
||||||
|
// Do not edit this file or all your changes will be lost after re-generation.
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
using System; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
using System.Security; |
||||||
|
|
||||||
|
namespace CppSharp |
||||||
|
{ |
||||||
|
namespace Parser |
||||||
|
{ |
||||||
|
public unsafe partial struct SourceLocation |
||||||
|
{ |
||||||
|
[StructLayout(LayoutKind.Explicit, Size = 4)] |
||||||
|
public struct Internal |
||||||
|
{ |
||||||
|
[FieldOffset(0)] |
||||||
|
public uint ID; |
||||||
|
|
||||||
|
[SuppressUnmanagedCodeSecurity] |
||||||
|
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, |
||||||
|
EntryPoint="??0SourceLocation@CppParser@CppSharp@@QAE@XZ")] |
||||||
|
internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance); |
||||||
|
|
||||||
|
[SuppressUnmanagedCodeSecurity] |
||||||
|
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, |
||||||
|
EntryPoint="??0SourceLocation@CppParser@CppSharp@@QAE@I@Z")] |
||||||
|
internal static extern global::System.IntPtr ctor_1(global::System.IntPtr instance, uint ID); |
||||||
|
|
||||||
|
[SuppressUnmanagedCodeSecurity] |
||||||
|
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, |
||||||
|
EntryPoint="??0SourceLocation@CppParser@CppSharp@@QAE@ABU012@@Z")] |
||||||
|
internal static extern global::System.IntPtr cctor_2(global::System.IntPtr instance, global::System.IntPtr _0); |
||||||
|
} |
||||||
|
|
||||||
|
internal SourceLocation(SourceLocation.Internal* native) |
||||||
|
: this(new global::System.IntPtr(native)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
internal SourceLocation(SourceLocation.Internal native) |
||||||
|
: this(&native) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public SourceLocation(global::System.IntPtr native, bool isInternalImpl = false) : this() |
||||||
|
{ |
||||||
|
var __ptr = (Internal*)native.ToPointer(); |
||||||
|
ID = __ptr->ID; |
||||||
|
} |
||||||
|
|
||||||
|
internal Internal ToInternal() |
||||||
|
{ |
||||||
|
var __native = new CppSharp.Parser.SourceLocation.Internal(); |
||||||
|
var __ptr = &__native; |
||||||
|
__native.ID = ID; |
||||||
|
return __native; |
||||||
|
} |
||||||
|
|
||||||
|
internal void FromInternal(Internal* native) |
||||||
|
{ |
||||||
|
var __ptr = native; |
||||||
|
ID = __ptr->ID; |
||||||
|
} |
||||||
|
|
||||||
|
public SourceLocation(uint ID) |
||||||
|
: this() |
||||||
|
{ |
||||||
|
var __fixedInstance = ToInternal(); |
||||||
|
Internal.ctor_1(new global::System.IntPtr(&__fixedInstance), ID); |
||||||
|
FromInternal(&__fixedInstance); |
||||||
|
} |
||||||
|
|
||||||
|
public uint ID |
||||||
|
{ |
||||||
|
get; |
||||||
|
|
||||||
|
set |
||||||
|
; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public unsafe partial struct SourceManager |
||||||
|
{ |
||||||
|
[StructLayout(LayoutKind.Explicit, Size = 1)] |
||||||
|
public struct Internal |
||||||
|
{ |
||||||
|
[SuppressUnmanagedCodeSecurity] |
||||||
|
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, |
||||||
|
EntryPoint="??0SourceManager@CppParser@CppSharp@@QAE@ABU012@@Z")] |
||||||
|
internal static extern global::System.IntPtr cctor_1(global::System.IntPtr instance, global::System.IntPtr _0); |
||||||
|
} |
||||||
|
|
||||||
|
internal SourceManager(SourceManager.Internal* native) |
||||||
|
: this(new global::System.IntPtr(native)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
internal SourceManager(SourceManager.Internal native) |
||||||
|
: this(&native) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public SourceManager(global::System.IntPtr native, bool isInternalImpl = false) : this() |
||||||
|
{ |
||||||
|
var __ptr = (Internal*)native.ToPointer(); |
||||||
|
} |
||||||
|
|
||||||
|
internal Internal ToInternal() |
||||||
|
{ |
||||||
|
var __native = new CppSharp.Parser.SourceManager.Internal(); |
||||||
|
var __ptr = &__native; |
||||||
|
return __native; |
||||||
|
} |
||||||
|
|
||||||
|
internal void FromInternal(Internal* native) |
||||||
|
{ |
||||||
|
var __ptr = native; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
#include "Sources.h" |
||||||
|
|
||||||
|
namespace CppSharp { namespace CppParser { |
||||||
|
|
||||||
|
SourceLocation::SourceLocation() |
||||||
|
: ID(0) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
SourceLocation::SourceLocation(unsigned ID) |
||||||
|
: ID(ID) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
} } |
@ -0,0 +1,21 @@ |
|||||||
|
/************************************************************************
|
||||||
|
* |
||||||
|
* CppSharp |
||||||
|
* Licensed under the simplified BSD license. All rights reserved. |
||||||
|
* |
||||||
|
************************************************************************/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "Helpers.h" |
||||||
|
|
||||||
|
namespace CppSharp { namespace CppParser { |
||||||
|
|
||||||
|
struct CS_API CS_VALUE_TYPE SourceLocation |
||||||
|
{ |
||||||
|
SourceLocation(); |
||||||
|
SourceLocation(unsigned ID); |
||||||
|
unsigned ID; |
||||||
|
}; |
||||||
|
|
||||||
|
} } |
Loading…
Reference in new issue