File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
sources/ClangSharp.PInvokeGenerator
tests/ClangSharp.PInvokeGenerator.UnitTests Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,22 @@ private void VisitBinaryOperator(BinaryOperator binaryOperator)
41
41
outputBuilder . Write ( ' ' ) ;
42
42
outputBuilder . Write ( binaryOperator . OpcodeStr ) ;
43
43
outputBuilder . Write ( ' ' ) ;
44
- Visit ( binaryOperator . RHS ) ;
44
+
45
+ if ( binaryOperator . IsShiftOp || binaryOperator . IsShiftAssignOp )
46
+ {
47
+ // RHS of shift operation in C# must be an int
48
+ outputBuilder . Write ( "(int)" ) ;
49
+ outputBuilder . Write ( '(' ) ;
50
+
51
+ Visit ( binaryOperator . RHS ) ;
52
+
53
+ outputBuilder . Write ( ')' ) ;
54
+ }
55
+ else
56
+ {
57
+ Visit ( binaryOperator . RHS ) ;
58
+ }
59
+
45
60
StopCSharpCode ( ) ;
46
61
}
47
62
Original file line number Diff line number Diff line change @@ -283,14 +283,18 @@ public static partial class Methods
283
283
[ Test ]
284
284
public Task UnsignedIntBitshiftTest ( )
285
285
{
286
- var inputContents = @"#define BITSHIFT 1 << 1U" ;
286
+ var inputContents = @"#define LEFT 1 << 1U
287
+ #define RIGHT 1 >> 1U" ;
287
288
288
289
var expectedOutputContents = @"namespace ClangSharp.Test
289
290
{
290
291
public static partial class Methods
291
292
{
292
- [NativeTypeName(""#define BITSHIFT 1 << 1U"")]
293
- public const int BITSHIFT = 1 << (int)(1U);
293
+ [NativeTypeName(""#define LEFT 1 << 1U"")]
294
+ public const int LEFT = 1 << (int)(1U);
295
+
296
+ [NativeTypeName(""#define RIGHT 1 >> 1U"")]
297
+ public const int RIGHT = 1 >> (int)(1U);
294
298
}
295
299
}
296
300
" ;
You can’t perform that action at this time.
0 commit comments