ILSpy Plugin corrections/enhancements

This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
User avatar
robert
Posts: 4552
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ILSpy Plugin corrections/enhancements

Post by robert »

Fabrice,
Thanks for the updates.
The ILSpy 7 version has a small problem.
See the decompiled code for an operator in the __Usual Type

Code: Select all

/// <summary>This operator is used in code generated by the compiler when needed.</summary>
[DebuggerStepThrough];
PUBLIC STATIC OPERATOR IMPLICIT(u AS __Usual ) AS Logic
	IF (u:IsNull) .OR. (!u:_initialized)
		RETURN false
	ENDIF
	RETURN u:_usualType SWITCH__UsualType.Logic => u:_logicValue, 
	__UsualType.Long => u:_intValue != 0, 
	__UsualType.Int64 => u:_i64Value != 0, 
	__UsualType.Currency => u:_currencyValue != 0, 
	__UsualType.Decimal => u:_decimalValue != 0m, 
	_ => THROW __Usual.ConversionError(8u, TYPEOF(Logic), u), 
END OPERATOR
This code disassembles to a SWITCH expression, which we do not support (yet) in X#.
If I disable the C# 8 Switch Expression support then it is decompiled into the correct code:

Code: Select all

/// <summary>This operator is used in code generated by the compiler when needed.</summary>
[DebuggerStepThrough];
PUBLIC STATIC OPERATOR IMPLICIT(u AS __Usual ) AS Logic
	IF (u:IsNull) .OR. (!u:_initialized)
		RETURN false
	ENDIF
	SWITCH u:_usualType
	CASE __UsualType.Logic
		RETURN u:_logicValue
	CASE __UsualType.Long
		RETURN u:_intValue != 0
	CASE __UsualType.Int64
		RETURN u:_i64Value != 0
	CASE __UsualType.Currency
		RETURN u:_currencyValue != 0
	CASE __UsualType.Decimal
		RETURN u:_decimalValue != 0m
	OTHERWISE
		THROW __Usual.ConversionError(8u, TYPEOF(Logic), u)
	END SWITCH

END OPERATOR

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

Fabrice, thank you for updating the plugin, I installed the version 6 from Apr 21st
Franz
User avatar
Fabrice
Posts: 463
Joined: Thu Oct 08, 2015 7:47 am
Location: France

ILSpy Plugin corrections/enhancements

Post by Fabrice »

Hi Robert,
thanks for your feedback.
I've just published a new Release that correct this one, and another one related to BinaryOperator, can you give it a try ?
Thanks,
Fab
XSharp Development Team
fabrice(at)xsharp.eu
User avatar
robert
Posts: 4552
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ILSpy Plugin corrections/enhancements

Post by robert »

Fab,
This seems to do it.
I figured it was indeed as easy as disabling the feature.
There may be more features in the C# 8, 9 and 10 area that we are not supporting yet, such as ranges, records, file scoped namespace declarations.

We DO support nint/nunit and init accessors.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

Hi Fabrice,
when I use ILSpy to look at a C# COM DLL which I need for my VO apps, I find this code translated with the X# Plugin:

Code: Select all

LOCAL array2 AS char[]
array2 := "4711".ToCharArray()
_ := array2[0]
Same construct with C# output:

Code: Select all

char[] array2 = "4711".ToCharArray();
_ = array2[0];
What could this "_ := array2[0]" mean? If you are interested I can send you this DLL.
User avatar
Fabrice
Posts: 463
Joined: Thu Oct 08, 2015 7:47 am
Location: France

ILSpy Plugin corrections/enhancements

Post by Fabrice »

Hi Franz,

I would guess that these are Compiler-generated temp vars.
Yes, can you please send me the DLL; I'm curious to see where this append.

Fab
XSharp Development Team
fabrice(at)xsharp.eu
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

Hi Fabrice,
attached the DLL, pls search for getFormat2PIN and you will find the code.
Franz
Test.zip
(73.4 KiB) Downloaded 103 times
User avatar
robert
Posts: 4552
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ILSpy Plugin corrections/enhancements

Post by robert »

Franz,
The _ variable in C# is a so called 'discard'. It is a way of assigning a value to a temporary variable. You can also use this discard for out parameters that you are not interested in.
The compiler will not warn that you are assigning to a discard and not using it.

And X# also supports the discard with the same name (the single underscore character).
I guess that the original code of the assembly assigns the return value of the call to a local and has a assertion check in Debug mode to see if the variable is what is expected.
The assertion is removed in release mode but the assignment is still there.
ILSpy detects that the variable is assigned but not used and uses the discard variable name for it.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

"You can also use this discard for out parameters that you are not interested in"
To avoid warning xs0219 - var never used?

Other question:
I got following C# code from ILSpy:

Code: Select all

public static string ToPIN(this string pin)
	{
		string text = string.Empty;
		for (int i = 0; i < pin.Length; i++)
		{
			text = text + "3" + pin[i];
		}
		return text;
		}
The X# Plugin translates like this:

Code: Select all

public static method ToPIN(pin AS STRING) AS STRING
	LOCAL text AS STRING
	LOCAL i AS LONG

	text := string.Empty
	i := 0	
	WHILE i < pin:Length
//		text := text + "3" + pin[i]		// error XS9078
		text := text + "3" + pin.Substring(i,1)	// OK
		i++
	ENDDO
	RETURN text
C# treats the string as array and can do the loop with

Code: Select all

pin[i]
X# brings error XS9078, I have to correct it to pin.Substring(i,1).
Is X# Plugin wrong or is this a X# compiler problem?
User avatar
robert
Posts: 4552
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ILSpy Plugin corrections/enhancements

Post by robert »

Franz,
Usually the C# compiler is much stricter than the X# compiler, but in this case it is not.
The C# code is adding a character to a string.Behind the scenes it translates

Code: Select all

pin[i] 
to

Code: Select all

pin[i].ToString().
X# is stricter here and does not allow you to add a char to a string

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply