|
|
|
@ -5,33 +5,22 @@ using Type = CppSharp.AST.Type;
@@ -5,33 +5,22 @@ using Type = CppSharp.AST.Type;
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
public static string CSharpValue(this Expression value, CSharpExpressionPrinter printer) |
|
|
|
|
{ |
|
|
|
|
return value.Visit(printer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class CSharpExpressionPrinter : IExpressionPrinter<CSharpExpressionPrinterResult> |
|
|
|
|
public class CSharpExpressionPrinter : IExpressionPrinter<string> |
|
|
|
|
{ |
|
|
|
|
public CSharpExpressionPrinter(CSharpTypePrinter typePrinter) |
|
|
|
|
{ |
|
|
|
|
this.typePrinter = typePrinter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public CSharpExpressionPrinterResult VisitExpression(Expression expr) |
|
|
|
|
public string VisitExpression(Expression expr) |
|
|
|
|
{ |
|
|
|
|
switch (expr.Class) |
|
|
|
|
{ |
|
|
|
@ -40,32 +29,26 @@ namespace CppSharp.Generators.CSharp
@@ -40,32 +29,26 @@ namespace CppSharp.Generators.CSharp
|
|
|
|
|
switch (callExpr.Declaration.GenerationKind) |
|
|
|
|
{ |
|
|
|
|
case GenerationKind.Generate: |
|
|
|
|
return new CSharpExpressionPrinterResult |
|
|
|
|
{ |
|
|
|
|
Value = string.Format("{0}.{1}({2})", |
|
|
|
|
typePrinter.VisitDeclaration(callExpr.Declaration.Namespace), |
|
|
|
|
callExpr.Declaration.Name, |
|
|
|
|
string.Join(", ", callExpr.Arguments.Select(VisitExpression))) |
|
|
|
|
}; |
|
|
|
|
return string.Format("{0}.{1}({2})", |
|
|
|
|
typePrinter.VisitDeclaration(callExpr.Declaration.Namespace), |
|
|
|
|
callExpr.Declaration.Name, |
|
|
|
|
string.Join(", ", callExpr.Arguments.Select(VisitExpression))); |
|
|
|
|
case GenerationKind.Internal: |
|
|
|
|
// a non-ctor can only be internal if it's been converted to a property
|
|
|
|
|
var property = ((Class) callExpr.Declaration.Namespace).Properties.First( |
|
|
|
|
p => p.GetMethod == callExpr.Declaration); |
|
|
|
|
return new CSharpExpressionPrinterResult |
|
|
|
|
{ |
|
|
|
|
Value = string.Format("{0}.{1}", |
|
|
|
|
typePrinter.VisitDeclaration(callExpr.Declaration.Namespace), |
|
|
|
|
property.Name) |
|
|
|
|
}; |
|
|
|
|
return string.Format("{0}.{1}", |
|
|
|
|
typePrinter.VisitDeclaration(callExpr.Declaration.Namespace), |
|
|
|
|
property.Name); |
|
|
|
|
default: |
|
|
|
|
return new CSharpExpressionPrinterResult { Value = expr.String }; |
|
|
|
|
return expr.String; |
|
|
|
|
} |
|
|
|
|
case StatementClass.DeclarationReference: |
|
|
|
|
if (expr.Declaration is Variable) |
|
|
|
|
return new CSharpExpressionPrinterResult { Value = expr.Declaration.Name }; |
|
|
|
|
if (expr.Declaration is Variable || expr.Declaration is Enumeration.Item) |
|
|
|
|
return expr.Declaration.Visit(typePrinter).Type; |
|
|
|
|
goto default; |
|
|
|
|
default: |
|
|
|
|
return new CSharpExpressionPrinterResult { Value = expr.String }; |
|
|
|
|
return expr.String; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|