-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VbToCs: integer divide, narrowing/widening #43
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,14 @@ static bool IgnoreInContext(SyntaxToken m, TokenContext context) | |
} | ||
} | ||
|
||
|
||
static bool IsConversionOperator(SyntaxToken token) | ||
{ | ||
bool isConvOp= token.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.ExplicitKeyword, Microsoft.CodeAnalysis.CSharp.SyntaxKind.ImplicitKeyword) | ||
||token.IsKind(VBasic.SyntaxKind.NarrowingKeyword, VBasic.SyntaxKind.WideningKeyword); | ||
return isConvOp; | ||
} | ||
|
||
static bool IsVisibility(SyntaxToken token, TokenContext context) | ||
{ | ||
return token.IsKind(VBasic.SyntaxKind.PublicKeyword, VBasic.SyntaxKind.FriendKeyword, VBasic.SyntaxKind.ProtectedKeyword, VBasic.SyntaxKind.PrivateKeyword) | ||
|
@@ -333,6 +341,7 @@ static SyntaxKind ConvertToken(VBasic.SyntaxKind t, TokenContext context = Token | |
case VBasic.SyntaxKind.MultiplyExpression: | ||
return SyntaxKind.MultiplyExpression; | ||
case VBasic.SyntaxKind.DivideExpression: | ||
case VBasic.SyntaxKind.IntegerDivideExpression: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't worry about integer divide - that's already fixed in master |
||
return SyntaxKind.DivideExpression; | ||
case VBasic.SyntaxKind.ModuloExpression: | ||
return SyntaxKind.ModuloExpression; | ||
|
@@ -401,6 +410,11 @@ static SyntaxKind ConvertToken(VBasic.SyntaxKind t, TokenContext context = Token | |
return SyntaxKind.DoubleKeyword; | ||
case VBasic.SyntaxKind.CStrKeyword: | ||
return SyntaxKind.StringKeyword; | ||
// Converts | ||
case VBasic.SyntaxKind.NarrowingKeyword: | ||
return SyntaxKind.ExplicitKeyword; | ||
case VBasic.SyntaxKind.WideningKeyword: | ||
return SyntaxKind.ImplicitKeyword; | ||
// | ||
case VBasic.SyntaxKind.AssemblyKeyword: | ||
return SyntaxKind.AssemblyKeyword; | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -633,5 +633,62 @@ public string TestMethod() | |||
} | ||||
}"); | ||||
} | ||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Fact] | ||||
public void IntegerDivideExpression() | ||||
{ | ||||
TestConversionVisualBasicToCSharp(@"Class TestClass | ||||
Sub TestMethod(ByRef i As Integer) | ||||
Dim k as Integer | ||||
k = i \ 1000000 | ||||
End Sub | ||||
End Class" | ||||
, @"class TestClass | ||||
{ | ||||
public void TestMethod(ref int i) | ||||
{ | ||||
int k; | ||||
k = i / 1000000; | ||||
} | ||||
}"); | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep this is the right sort of test for integer division - now already covered in master by
|
||||
|
||||
|
||||
|
||||
|
||||
[Fact] | ||||
public void NarrowingWideningExpression() | ||||
{ | ||||
//TestConversionVisualBasicToCSharp => Failing! because of cr/lf after "operator MyInt" in expected CS below: | ||||
TestConversionVisualBasicToCSharpWithoutComments(@"Public Class MyInt | ||||
Public Shared Narrowing Operator CType(i As Integer) As MyInt | ||||
Return New MyInt() | ||||
End Operator | ||||
Public Shared Widening Operator CType(myInt As MyInt) As Integer | ||||
Return 1 | ||||
End Operator | ||||
End Class" | ||||
, @"public class MyInt | ||||
{ | ||||
public static explicit operator MyInt | ||||
(int i) | ||||
{ | ||||
return new MyInt(); | ||||
} | ||||
public static implicit operator int | ||||
(MyInt myInt) | ||||
{ | ||||
return 1; | ||||
} | ||||
}"); | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep you're on the right track here too! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here there's an issue I didn't knew how to fix: the parameters list is send to the next line instead of staying on the same line as the operator declaration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I'm happy with that fix for the test failure. Good job figuring it out - I've added this as a separate issue to try to make it clearer for others (#45). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test probably belongs in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do...if you can wait...I'm on the steep slope of the learning curve ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BaronBodissey No worries then - I'll tidy things up and get it merged now |
||||
|
||||
|
||||
|
||||
|
||||
} | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you're on the right track here