Browse Source

Fixed SD2-1040: External subs declarations not converted correctly from VB to C#

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2200 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts 2.1-Beta3
Daniel Grunwald 19 years ago
parent
commit
137ebabd5a
  1. 1430
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 2
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 5
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  4. 1
      src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs
  5. 5
      src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs
  6. 11
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs
  7. 8
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs
  8. 6
      src/Libraries/NRefactory/Test/Parser/Statements/LocalVariableDeclarationTests.cs

1430
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

2
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -1378,8 +1378,6 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration @@ -1378,8 +1378,6 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
if(type.RankSpecifier != null) {
Error("array rank only allowed one time");
} else {
for (int i = 0; i < dimension.Count; i++)
dimension[i] = Expression.AddInteger(dimension[i], 1);
if (rank == null) {
type.RankSpecifier = new int[] { dimension.Count - 1 };
} else {

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

@ -1159,7 +1159,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1159,7 +1159,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
break;
}
if (declareDeclaration.TypeReference.IsNull) {
bool isVoid = declareDeclaration.TypeReference.IsNull || declareDeclaration.TypeReference.SystemType == "System.Void";
if (isVoid) {
outputFormatter.PrintToken(Tokens.Sub);
} else {
outputFormatter.PrintToken(Tokens.Function);
@ -1185,7 +1186,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1185,7 +1186,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
AppendCommaSeparatedList(declareDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
if (!declareDeclaration.TypeReference.IsNull) {
if (!isVoid) {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();

1
src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs

@ -19,6 +19,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -19,6 +19,7 @@ namespace ICSharpCode.NRefactory.Visitors
{
// The following conversions are implemented:
// Public Event EventName(param As String) -> automatic delegate declaration
// static variables inside methods become fields
public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
{

5
src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs

@ -133,6 +133,11 @@ namespace ICSharpCode.NRefactory.Visitors @@ -133,6 +133,11 @@ namespace ICSharpCode.NRefactory.Visitors
if ((method.Modifier & Modifiers.Visibility) == 0)
method.Modifier |= Modifiers.Public;
method.Modifier |= Modifiers.Extern | Modifiers.Static;
if (method.TypeReference.IsNull) {
method.TypeReference = new TypeReference("System.Void");
}
Attribute att = new Attribute("DllImport", null, null);
att.PositionalArguments.Add(CreateStringLiteral(declareDeclaration.Library));
if (declareDeclaration.Alias.Length > 0) {

11
src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs

@ -230,6 +230,15 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -230,6 +230,15 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"public static extern int MessageBox(IntPtr hwnd, string t, string caption, UInt32 t2);");
}
[Test]
public void PInvokeSub()
{
TestMember("Private Declare Sub Sleep Lib \"kernel32\" (ByVal dwMilliseconds As Long)",
"[DllImport(\"kernel32\", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]\n" +
"private static extern void Sleep(long dwMilliseconds);",
"System.Runtime.InteropServices");
}
[Test]
public void Constructor()
{
@ -604,6 +613,8 @@ static int static_Test2_j = 0;"); @@ -604,6 +613,8 @@ static int static_Test2_j = 0;");
{
TestStatement("Dim i As String() = New String(1) {}",
"string[] i = new string[2];");
TestStatement("Dim i(1) As String",
"string[] i = new string[2];");
TestStatement("Dim i As String() = New String(1) {\"0\", \"1\"}",
"string[] i = new string[2] {\"0\", \"1\"};");
TestStatement("Dim i As String(,) = New String(5, 5) {}",

8
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

@ -264,6 +264,14 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -264,6 +264,14 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"Public Declare Auto Function SendMessage Lib \"user32.dll\" Alias \"SendMessageW\" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr");
}
[Test]
public void PInvokeSub()
{
TestMember("[DllImport(\"kernel32\", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]\n" +
"private static extern void Sleep(long dwMilliseconds);",
"Private Declare Ansi Sub Sleep Lib \"kernel32\" (ByVal dwMilliseconds As Long)");
}
[Test]
public void Constructor()
{

6
src/Libraries/NRefactory/Test/Parser/Statements/LocalVariableDeclarationTests.cs

@ -234,7 +234,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -234,7 +234,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer;
Assert.AreEqual(new int[] { 0 } , ace.CreateType.RankSpecifier);
Assert.AreEqual(1, ace.Arguments.Count);
Assert.AreEqual(11, ((PrimitiveExpression)ace.Arguments[0]).Value);
Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value);
}
[Test]
@ -250,7 +250,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -250,7 +250,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer;
Assert.AreEqual(new int[] { 0 } , ace.CreateType.RankSpecifier);
Assert.AreEqual(1, ace.Arguments.Count);
Assert.AreEqual(11, ((PrimitiveExpression)ace.Arguments[0]).Value);
Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value);
}
[Test]
@ -276,7 +276,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -276,7 +276,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer;
Assert.AreEqual(new int[] {0, 0}, ace.CreateType.RankSpecifier);
Assert.AreEqual(1, ace.Arguments.Count);
Assert.AreEqual(11, ((PrimitiveExpression)ace.Arguments[0]).Value);
Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value);
}
[Test]

Loading…
Cancel
Save