mirror of https://github.com/mono/CppSharp.git
13 changed files with 881 additions and 0 deletions
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>8.0.30703</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{6BEB8FA2-97AA-40B7-AB92-42F6EDDC4490}</ProjectGuid> |
||||
<OutputType>Library</OutputType> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
<RootNamespace>Bridge</RootNamespace> |
||||
<AssemblyName>Bridge</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<FileAlignment>512</FileAlignment> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>..\..\bin\</OutputPath> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core" /> |
||||
<Reference Include="System.Xml.Linq" /> |
||||
<Reference Include="System.Data.DataSetExtensions" /> |
||||
<Reference Include="Microsoft.CSharp" /> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="Class.cs" /> |
||||
<Compile Include="Comment.cs" /> |
||||
<Compile Include="Declaration.cs" /> |
||||
<Compile Include="Enumeration.cs" /> |
||||
<Compile Include="Field.cs" /> |
||||
<Compile Include="Function.cs" /> |
||||
<Compile Include="Library.cs" /> |
||||
<Compile Include="Method.cs" /> |
||||
<Compile Include="Namespace.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="Property.cs" /> |
||||
<Compile Include="Type.cs" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
Other similar extension points exist, see Microsoft.Common.targets. |
||||
<Target Name="BeforeBuild"> |
||||
</Target> |
||||
<Target Name="AfterBuild"> |
||||
</Target> |
||||
--> |
||||
</Project> |
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
// A C++ access specifier.
|
||||
public enum AccessSpecifier |
||||
{ |
||||
Private, |
||||
Protected, |
||||
Public |
||||
} |
||||
|
||||
// Represents a base class of a C++ class.
|
||||
public class BaseClassSpecifier |
||||
{ |
||||
BaseClassSpecifier(Class @class, AccessSpecifier access, |
||||
bool isVirtual = false) |
||||
{ |
||||
Class = @class; |
||||
Access = access; |
||||
IsVirtual = isVirtual; |
||||
} |
||||
|
||||
public Class Class { get; set; } |
||||
public AccessSpecifier Access { get; set; } |
||||
public bool IsVirtual { get; set; } |
||||
} |
||||
|
||||
// Represents a C++ virtual function table.
|
||||
public class VFTable |
||||
{ |
||||
|
||||
} |
||||
|
||||
// Represents a C++ virtual base table.
|
||||
public class VBTable |
||||
{ |
||||
|
||||
} |
||||
|
||||
// Represents ABI-specific layout details for a class.
|
||||
public class ClassLayout |
||||
{ |
||||
public CppAbi ABI { get; set; } |
||||
public bool HasOwnVFTable { get; set; } |
||||
public VFTable VirtualFunctions { get; set; } |
||||
public VBTable VirtualBases { get; set; } |
||||
} |
||||
|
||||
// Represents a C++ record declaration.
|
||||
public class Class : Declaration |
||||
{ |
||||
|
||||
public Class() |
||||
{ |
||||
Bases = new List<BaseClassSpecifier>(); |
||||
Fields = new List<Field>(); |
||||
Properties = new List<Property>(); |
||||
Methods = new List<Method>(); |
||||
NestedClasses = new List<Class>(); |
||||
NestedEnums = new List<Enumeration>(); |
||||
IsAbstract = false; |
||||
} |
||||
|
||||
public List<BaseClassSpecifier> Bases; |
||||
public List<Class> NestedClasses; |
||||
public List<Enumeration> NestedEnums; |
||||
public List<Field> Fields; |
||||
public List<Property> Properties; |
||||
public List<Method> Methods; |
||||
|
||||
public bool HasBase |
||||
{ |
||||
get { return Bases.Count > 0; } |
||||
} |
||||
|
||||
// True if the record is a POD (Plain Old Data) type.
|
||||
public bool IsPOD; |
||||
|
||||
// ABI-specific class layout.
|
||||
public List<ClassLayout> Layouts { get; set; } |
||||
|
||||
// True if class only provides pure virtual methods.
|
||||
public bool IsAbstract { get; set; } |
||||
|
||||
public string TemplateName { get; set; } |
||||
public string TemplateClassName { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a C++ comment.
|
||||
/// </summary>
|
||||
public class Comment |
||||
{ |
||||
|
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a C++ declaration.
|
||||
/// </summary>
|
||||
public class Declaration |
||||
{ |
||||
public Declaration() |
||||
{ |
||||
} |
||||
|
||||
public Declaration(string name) |
||||
{ |
||||
Name = name; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return Name; |
||||
} |
||||
|
||||
// Name of the type.
|
||||
public string Name; |
||||
|
||||
// Doxygen-style brief comment.
|
||||
public string BriefComment; |
||||
|
||||
// Namespace the type is declared in.
|
||||
public Namespace Namespace; |
||||
|
||||
// Wether the type should be ignored.
|
||||
public bool Ignore; |
||||
|
||||
// Contains a debug text of the type declaration.
|
||||
public string DebugText; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents a C preprocessor macro definition.
|
||||
/// </summary>
|
||||
public class MacroDefine : Declaration |
||||
{ |
||||
public MacroDefine() |
||||
{ |
||||
} |
||||
|
||||
// Contains the macro definition text.
|
||||
public string Expression; |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a C/C++ enumeration.
|
||||
/// </summary>
|
||||
public class Enumeration : Declaration |
||||
{ |
||||
[Flags] |
||||
public enum EnumModifiers |
||||
{ |
||||
Anonymous, |
||||
Scoped, |
||||
Flags |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents a C/C++ enumeration item.
|
||||
/// </summary>
|
||||
public class Item |
||||
{ |
||||
public string Name; |
||||
public long Value; |
||||
public string Expression; |
||||
public string Comment; |
||||
public bool ExplicitValue = true; |
||||
} |
||||
|
||||
public Enumeration() |
||||
{ |
||||
Items = new List<Item>(); |
||||
ItemsByName = new Dictionary<string, Item>(); |
||||
Type = new BuiltinType(PrimitiveType.Int32); |
||||
} |
||||
|
||||
public Enumeration AddItem(Item item) |
||||
{ |
||||
Items.Add(item); |
||||
ItemsByName[item.Name] = item; |
||||
return this; |
||||
} |
||||
|
||||
public Enumeration SetFlags() |
||||
{ |
||||
Modifiers |= EnumModifiers.Flags; |
||||
return this; |
||||
} |
||||
|
||||
public BuiltinType Type { get; set; } |
||||
public EnumModifiers Modifiers { get; set; } |
||||
|
||||
public List<Item> Items; |
||||
public Dictionary<string, Item> ItemsByName; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
using System; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a field in a C/C++ record declaration.
|
||||
/// </summary>
|
||||
public class Field : Declaration |
||||
{ |
||||
public Field() |
||||
{ |
||||
} |
||||
|
||||
public Field(string name, Type type, AccessSpecifier access) |
||||
{ |
||||
Name = name; |
||||
Type = type; |
||||
Access = access; |
||||
} |
||||
|
||||
public Type Type { get; set; } |
||||
public AccessSpecifier Access { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
public enum CallingConvention |
||||
{ |
||||
Default, |
||||
C, |
||||
StdCall, |
||||
ThisCall, |
||||
FastCall |
||||
} |
||||
|
||||
public enum ParameterUsage |
||||
{ |
||||
Unknown, |
||||
In, |
||||
Out, |
||||
InOut |
||||
} |
||||
|
||||
public class Parameter : Declaration |
||||
{ |
||||
public Parameter() |
||||
{ |
||||
Usage = ParameterUsage.Unknown; |
||||
HasDefaultValue = false; |
||||
} |
||||
|
||||
public Type Type { get; set; } |
||||
public ParameterUsage Usage { get; set; } |
||||
public bool HasDefaultValue { get; set; } |
||||
} |
||||
|
||||
public class Function : Declaration |
||||
{ |
||||
public Function() |
||||
{ |
||||
Parameters = new List<Parameter>(); |
||||
CallingConvention = CallingConvention.Default; |
||||
IsVariadic = false; |
||||
IsInline = false; |
||||
} |
||||
|
||||
public Type ReturnType { get; set; } |
||||
public List<Parameter> Parameters { get; set; } |
||||
public CallingConvention CallingConvention { get; set; } |
||||
public bool IsVariadic { get; set; } |
||||
public bool IsInline { get; set; } |
||||
|
||||
// The C# name
|
||||
public string FormattedName { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
public enum CppAbi |
||||
{ |
||||
Itanium, |
||||
Microsoft, |
||||
ARM |
||||
} |
||||
|
||||
public enum InlineMethods |
||||
{ |
||||
Present, |
||||
Unavailable |
||||
} |
||||
|
||||
[DebuggerDisplay("File = {FileName}, Ignored = {Ignore}")] |
||||
public class Module |
||||
{ |
||||
public Module(string File) |
||||
{ |
||||
Global = new Namespace(); |
||||
Macros = new List<MacroDefine>(); |
||||
Namespaces = new List<Namespace>(); |
||||
FilePath = File; |
||||
Ignore = false; |
||||
} |
||||
|
||||
public bool Ignore; |
||||
public string FilePath; |
||||
|
||||
public string FileName |
||||
{ |
||||
get { return Path.GetFileName(FilePath); } |
||||
} |
||||
|
||||
public List<MacroDefine> Macros; |
||||
|
||||
public Namespace Global; |
||||
public List<Namespace> Namespaces; |
||||
|
||||
public bool HasDeclarations |
||||
{ |
||||
get |
||||
{ |
||||
return Global.HasDeclarations |
||||
|| Namespaces.Exists(n => n.HasDeclarations); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class Library |
||||
{ |
||||
public Library(string name) |
||||
{ |
||||
Name = name; |
||||
Modules = new List<Module>(); |
||||
} |
||||
|
||||
public Module FindOrCreateModule(string File) |
||||
{ |
||||
var module = Modules.Find(m => m.FilePath.Equals(File)); |
||||
|
||||
if (module == null) |
||||
{ |
||||
module = new Module(File); |
||||
Modules.Add(module); |
||||
} |
||||
|
||||
return module; |
||||
} |
||||
|
||||
public Enumeration FindEnum(string Name) |
||||
{ |
||||
foreach (var module in Modules) |
||||
{ |
||||
var type = module.Global.FindEnum(Name); |
||||
if (type != null) return type; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public Class FindClass(string Name) |
||||
{ |
||||
foreach (var module in Modules) |
||||
{ |
||||
var type = module.Global.FindClass(Name); |
||||
if (type != null) return type; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public string Name { get; set; } |
||||
public List<Module> Modules { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a C++ method.
|
||||
/// </summary>
|
||||
public class Method : Function |
||||
{ |
||||
|
||||
public Method() |
||||
{ |
||||
} |
||||
|
||||
public AccessSpecifier Access { get; set; } |
||||
|
||||
public bool IsVirtual { get; set; } |
||||
public bool IsStatic { get; set; } |
||||
public bool IsConst { get; set; } |
||||
public bool IsArtificial { get; set; } |
||||
public bool IsConstructor { get; set; } |
||||
public bool IsDestructor { get; set; } |
||||
public bool IsCopyCtor { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a C++ namespace.
|
||||
/// </summary>
|
||||
public class Namespace |
||||
{ |
||||
public Namespace() |
||||
: this(null, String.Empty) |
||||
{ |
||||
} |
||||
|
||||
public Namespace(Namespace parent, string name, bool isAnonymous = false) |
||||
{ |
||||
Name = name; |
||||
Parent = parent; |
||||
IsAnonymous = isAnonymous; |
||||
|
||||
Enums = new List<Enumeration>(); |
||||
Functions = new List<Function>(); |
||||
Classes = new List<Class>(); |
||||
} |
||||
|
||||
public Enumeration FindEnum(string Name) |
||||
{ |
||||
return FindEnumWithName(Name); |
||||
} |
||||
|
||||
public Function FindFunction(string Name) |
||||
{ |
||||
return Functions.Find(e => e.Name.Equals(Name)); |
||||
} |
||||
|
||||
public Class FindClass(string Name) |
||||
{ |
||||
return Classes.Find(e => e.Name.Equals(Name)); |
||||
} |
||||
|
||||
public T FindType<T>(string Name) where T : Declaration |
||||
{ |
||||
var type = FindEnumWithName(Name) |
||||
?? FindFunction(Name) ?? (Declaration)FindClass(Name); |
||||
|
||||
return type as T; |
||||
} |
||||
|
||||
public Enumeration FindEnumWithName(string Name) |
||||
{ |
||||
return Enums.Find(e => e.Name.Equals(Name)); |
||||
} |
||||
|
||||
public Enumeration FindEnumWithItem(string Name) |
||||
{ |
||||
return Enums.Find(e => e.ItemsByName.ContainsKey(Name)); |
||||
} |
||||
|
||||
public bool HasDeclarations |
||||
{ |
||||
get |
||||
{ |
||||
Predicate<Declaration> pred = (t => !t.Ignore); |
||||
return Enums.Exists(pred) || HasFunctions || Classes.Exists(pred); |
||||
} |
||||
} |
||||
|
||||
public bool HasFunctions |
||||
{ |
||||
get |
||||
{ |
||||
Predicate<Declaration> pred = (t => !t.Ignore); |
||||
return Functions.Exists(pred); |
||||
} |
||||
} |
||||
|
||||
public string Name { get; set; } |
||||
public Namespace Parent { get; set; } |
||||
public bool IsAnonymous { get; set; } |
||||
|
||||
public List<Enumeration> Enums; |
||||
public List<Function> Functions; |
||||
public List<Class> Classes; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Bridge")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("Microsoft")] |
||||
[assembly: AssemblyProduct("Bridge")] |
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("5b0589ff-83fd-4b9b-bcff-14fde1263358")] |
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")] |
||||
[assembly: AssemblyFileVersion("1.0.0.0")] |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a C++ property.
|
||||
/// </summary>
|
||||
public class Property |
||||
{ |
||||
|
||||
public Property(string name, Declaration type) |
||||
{ |
||||
Name = name; |
||||
Type = type; |
||||
} |
||||
|
||||
public string Name |
||||
{ |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public Declaration Type |
||||
{ |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public Method GetMethod |
||||
{ |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public Method SetMethod |
||||
{ |
||||
get; |
||||
set; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,232 @@
@@ -0,0 +1,232 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
namespace Cxxi |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a C++ type reference.
|
||||
/// </summary>
|
||||
public abstract class Type |
||||
{ |
||||
public Type() |
||||
{ |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return ToCSharp(); |
||||
} |
||||
|
||||
// Converts the type to a C# type.
|
||||
public abstract string ToCSharp(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents a C++ tag type reference.
|
||||
/// </summary>
|
||||
public class TagType : Type |
||||
{ |
||||
public TagType() |
||||
{ |
||||
} |
||||
|
||||
public Declaration Declaration; |
||||
|
||||
public override string ToCSharp() |
||||
{ |
||||
if (Declaration == null) |
||||
return string.Empty; |
||||
return Declaration.Name; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents an C/C++ array type.
|
||||
/// </summary>
|
||||
public class ArrayType : Type |
||||
{ |
||||
public enum ArraySize |
||||
{ |
||||
Constant, |
||||
Variable |
||||
} |
||||
|
||||
public ArrayType() |
||||
{ |
||||
} |
||||
|
||||
// Type of the array elements.
|
||||
public Type Type; |
||||
|
||||
// Size type of array.
|
||||
public ArraySize SizeType; |
||||
|
||||
// In case of a constant size array.
|
||||
public long Size; |
||||
|
||||
public override string ToCSharp() |
||||
{ |
||||
return string.Format("{0}[{1}]", Type, Size); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents an C/C++ function type.
|
||||
/// </summary>
|
||||
public class FunctionType : Type |
||||
{ |
||||
// Return type of the function.
|
||||
public Type ReturnType; |
||||
|
||||
public override string ToCSharp() |
||||
{ |
||||
return string.Format("Func<{0}>", ReturnType); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents a C++ pointer/reference type.
|
||||
/// </summary>
|
||||
public class PointerType : Type |
||||
{ |
||||
public PointerType() |
||||
{ |
||||
|
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the modifiers on a C++ type reference.
|
||||
/// </summary>
|
||||
public enum TypeModifier |
||||
{ |
||||
Value, |
||||
Pointer, |
||||
// L-value references
|
||||
LVReference, |
||||
// R-value references
|
||||
RVReference |
||||
} |
||||
|
||||
static string ConvertModifierToString(TypeModifier modifier) |
||||
{ |
||||
switch (modifier) |
||||
{ |
||||
case TypeModifier.Value: return string.Empty; |
||||
case TypeModifier.Pointer: |
||||
case TypeModifier.LVReference: |
||||
case TypeModifier.RVReference: return "*"; |
||||
} |
||||
|
||||
return string.Empty; |
||||
} |
||||
|
||||
public Type Pointee; |
||||
|
||||
public TypeModifier Modifier; |
||||
|
||||
public override string ToCSharp() |
||||
{ |
||||
if (Pointee is FunctionType) |
||||
return Pointee.ToCSharp(); |
||||
|
||||
return string.Format("{0}{1}", |
||||
Pointee, ConvertModifierToString(Modifier)); |
||||
} |
||||
} |
||||
|
||||
#region Primitives
|
||||
|
||||
/// <summary>
|
||||
/// Represents the C++ built-in types.
|
||||
/// </summary>
|
||||
public enum PrimitiveType |
||||
{ |
||||
Null, |
||||
Void, |
||||
Bool, |
||||
WideChar, |
||||
Int8, |
||||
UInt8, |
||||
Int16, |
||||
UInt16, |
||||
Int32, |
||||
UInt32, |
||||
Int64, |
||||
UInt64, |
||||
Float, |
||||
Double |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents an instance of a C++ built-in type.
|
||||
/// </summary>
|
||||
public class BuiltinType : Type |
||||
{ |
||||
public BuiltinType() |
||||
{ |
||||
} |
||||
|
||||
public BuiltinType(PrimitiveType type) |
||||
{ |
||||
Type = type; |
||||
} |
||||
|
||||
// Primitive type of built-in type.
|
||||
public PrimitiveType Type; |
||||
|
||||
public override string ToCSharp() |
||||
{ |
||||
return Type.ConvertToTypeName(); |
||||
} |
||||
} |
||||
|
||||
public static class PrimitiveTypeExtensions |
||||
{ |
||||
public static System.Type ConvertToType(this PrimitiveType Primitive) |
||||
{ |
||||
switch (Primitive) |
||||
{ |
||||
case PrimitiveType.Bool: return typeof(bool); |
||||
case PrimitiveType.Void: return typeof(void); |
||||
case PrimitiveType.WideChar: return typeof(char); |
||||
case PrimitiveType.Int8: return typeof(sbyte); |
||||
case PrimitiveType.UInt8: return typeof(byte); |
||||
case PrimitiveType.Int16: return typeof(short); |
||||
case PrimitiveType.UInt16: return typeof(ushort); |
||||
case PrimitiveType.Int32: return typeof(int); |
||||
case PrimitiveType.UInt32: return typeof(uint); |
||||
case PrimitiveType.Int64: return typeof(long); |
||||
case PrimitiveType.UInt64: return typeof(ulong); |
||||
case PrimitiveType.Float: return typeof(float); |
||||
case PrimitiveType.Double: return typeof(double); |
||||
} |
||||
|
||||
return typeof(int); |
||||
} |
||||
|
||||
public static string ConvertToTypeName(this PrimitiveType Primitive) |
||||
{ |
||||
switch (Primitive) |
||||
{ |
||||
case PrimitiveType.Bool: return "bool"; |
||||
case PrimitiveType.Void: return "void"; |
||||
case PrimitiveType.WideChar: return "char"; |
||||
case PrimitiveType.Int8: return "sbyte"; |
||||
case PrimitiveType.UInt8: return "byte"; |
||||
case PrimitiveType.Int16: return "short"; |
||||
case PrimitiveType.UInt16: return "ushort"; |
||||
case PrimitiveType.Int32: return "int"; |
||||
case PrimitiveType.UInt32: return "uint"; |
||||
case PrimitiveType.Int64: return "long"; |
||||
case PrimitiveType.UInt64: return "ulong"; |
||||
case PrimitiveType.Float: return "float"; |
||||
case PrimitiveType.Double: return "double"; |
||||
} |
||||
|
||||
return String.Empty; |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
} |
Loading…
Reference in new issue