Browse Source

Fixed forum-9858: problem with sizeof operator converting from C# to VB.NET

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4569 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
e051b6560f
  1. 42
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  2. 42
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBNetConverterTest.cs

42
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -814,7 +814,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -814,7 +814,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
VisitReturnTypeAttributes(parameterDeclarationExpression.Attributes, data);
VisitReturnTypeAttributes(parameterDeclarationExpression.Attributes, data);
TrackedVisit(parameterDeclarationExpression.TypeReference, data);
return null;
}
@ -983,7 +983,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -983,7 +983,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
VisitReturnTypeAttributes(indexerDeclaration.Attributes, data);
VisitReturnTypeAttributes(indexerDeclaration.Attributes, data);
TrackedVisit(indexerDeclaration.TypeReference, data);
PrintInterfaceImplementations(indexerDeclaration.InterfaceImplementations);
@ -1410,6 +1410,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1410,6 +1410,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitYieldStatement(YieldStatement yieldStatement, object data)
{
UnsupportedNode(yieldStatement);
outputFormatter.PrintText("yield ");
TrackedVisit(yieldStatement.Statement, data);
return null;
}
@ -2420,7 +2422,38 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2420,7 +2422,38 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data)
{
if (!sizeOfExpression.TypeReference.IsArrayType) {
if (sizeOfExpression.TypeReference.PointerNestingLevel != 0) {
outputFormatter.PrintText("IntPtr.Size");
return null;
} else {
switch (sizeOfExpression.TypeReference.Type) {
case "System.Byte":
case "System.SByte":
outputFormatter.PrintText("1");
return null;
case "System.Char":
case "System.Int16":
case "System.UInt16":
outputFormatter.PrintText("2");
return null;
case "System.Single":
case "System.Int32":
case "System.UInt32":
outputFormatter.PrintText("4");
return null;
case "System.Double":
case "System.Int64":
case "System.UInt64":
outputFormatter.PrintText("8");
return null;
}
}
}
UnsupportedNode(sizeOfExpression);
outputFormatter.PrintText("sizeof(");
TrackedVisit(sizeOfExpression.TypeReference, data);
outputFormatter.PrintText(")");
return null;
}
@ -2481,6 +2514,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2481,6 +2514,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data)
{
UnsupportedNode(pointerReferenceExpression);
TrackedVisit(pointerReferenceExpression.TargetObject, data);
outputFormatter.PrintText(".");
outputFormatter.PrintIdentifier(pointerReferenceExpression.MemberName);
PrintTypeArguments(pointerReferenceExpression.TypeArguments);
return null;
}
@ -2565,6 +2602,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2565,6 +2602,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data)
{
UnsupportedNode(stackAllocExpression);
outputFormatter.PrintText("stackalloc");
return null;
}

42
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBNetConverterTest.cs

@ -419,9 +419,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -419,9 +419,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void StaticClass()
{
TestProgram("public static class Test {}", @"Public NotInheritable Class Test" + Environment.NewLine +
" Private Sub New()" + Environment.NewLine +
" End Sub" + Environment.NewLine +
"End Class" + Environment.NewLine);
" Private Sub New()" + Environment.NewLine +
" End Sub" + Environment.NewLine +
"End Class" + Environment.NewLine);
}
[Test]
@ -500,17 +500,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -500,17 +500,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram(@"public class Convert { void Run(string s) { char c; if ((c = s[0]) == '\n') { c = ' '; } } }",
@"Public Class Convert" + Environment.NewLine +
" Private Sub Run(ByVal s As String)" + Environment.NewLine +
" Dim c As Char" + Environment.NewLine +
" If (InlineAssignHelper(c, s(0))) = ControlChars.Lf Then" + Environment.NewLine +
" c = \" \"C" + Environment.NewLine +
" End If" + Environment.NewLine +
" End Sub" + Environment.NewLine +
" Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T" + Environment.NewLine +
" target = value" + Environment.NewLine +
" Return value" + Environment.NewLine +
" End Function" + Environment.NewLine +
"End Class" + Environment.NewLine);
" Private Sub Run(ByVal s As String)" + Environment.NewLine +
" Dim c As Char" + Environment.NewLine +
" If (InlineAssignHelper(c, s(0))) = ControlChars.Lf Then" + Environment.NewLine +
" c = \" \"C" + Environment.NewLine +
" End If" + Environment.NewLine +
" End Sub" + Environment.NewLine +
" Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T" + Environment.NewLine +
" target = value" + Environment.NewLine +
" Return value" + Environment.NewLine +
" End Function" + Environment.NewLine +
"End Class" + Environment.NewLine);
}
[Test]
@ -538,5 +538,19 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -538,5 +538,19 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestStatement(@"string Test = ""\t\a"";",
@"Dim Test As String = vbTab & ChrW(7)");
}
[Test]
public void SizeOfInt32()
{
TestStatement(@"byte[] ret = new byte[IntPtr.Size * sizeof(int)];",
@"Dim ret As Byte() = New Byte(IntPtr.Size * 4 - 1) {}");
}
[Test]
public void SizeOfInt32Pointer()
{
TestStatement(@"int i = sizeof(int*);",
@"Dim i As Integer = IntPtr.Size");
}
}
}

Loading…
Cancel
Save