mirror of https://github.com/mono/CppSharp.git
3 changed files with 103 additions and 0 deletions
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
using System; |
||||
|
||||
namespace CppSharp.AST |
||||
{ |
||||
public abstract class Expression |
||||
{ |
||||
public string DebugText; |
||||
|
||||
public abstract TV Visit<TV>(IExpressionVisitor<TV> visitor); |
||||
} |
||||
|
||||
public class BuiltinTypeExpression : Expression |
||||
{ |
||||
public long Value { get; set; } |
||||
|
||||
public BuiltinType Type { get; set; } |
||||
|
||||
public bool IsHexadecimal |
||||
{ |
||||
get |
||||
{ |
||||
if (DebugText == null) |
||||
{ |
||||
return false; |
||||
} |
||||
return DebugText.Contains("0x") || DebugText.Contains("0X"); |
||||
} |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
var printAsHex = IsHexadecimal && Type.IsUnsigned; |
||||
var format = printAsHex ? "x" : string.Empty; |
||||
var value = Type.IsUnsigned ? Value.ToString(format) : |
||||
((long)Value).ToString(format); |
||||
return printAsHex ? "0x" + value : value; |
||||
} |
||||
|
||||
public override T Visit<T>(IExpressionVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitBuiltinExpression(this); |
||||
} |
||||
} |
||||
|
||||
public interface IExpressionVisitor<out T> |
||||
{ |
||||
T VisitBuiltinExpression(BuiltinTypeExpression builtinType); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
using CppSharp.AST; |
||||
using CppSharp.Types; |
||||
|
||||
namespace CppSharp.Generators.CSharp |
||||
{ |
||||
public class CSharpExpressionPrinterResult |
||||
{ |
||||
public string Value; |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return Value; |
||||
} |
||||
} |
||||
|
||||
public static class CSharpExpressionPrinterExtensions |
||||
{ |
||||
public static CSharpExpressionPrinterResult CSharpValue(this Expression value, |
||||
CSharpExpressionPrinter printer) |
||||
{ |
||||
return value.Visit(printer); |
||||
} |
||||
|
||||
} |
||||
public class CSharpExpressionPrinter : IExpressionPrinter<CSharpExpressionPrinterResult>, |
||||
IExpressionVisitor<CSharpExpressionPrinterResult> |
||||
{ |
||||
public CSharpExpressionPrinterResult VisitBuiltinExpression(BuiltinTypeExpression builtinType) |
||||
{ |
||||
return new CSharpExpressionPrinterResult() |
||||
{ |
||||
Value = builtinType.ToString(), |
||||
}; |
||||
} |
||||
|
||||
public string ToString(Type type) |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
using CppSharp.AST; |
||||
|
||||
namespace CppSharp.Types |
||||
{ |
||||
public interface IExpressionPrinter |
||||
{ |
||||
string ToString(Type type); |
||||
} |
||||
|
||||
public interface IExpressionPrinter<out T> : IExpressionPrinter, IExpressionVisitor<T> |
||||
{ |
||||
} |
||||
} |
Loading…
Reference in new issue