Welcome, Guest
Username: Password: Remember me
This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
  • Page:
  • 1

TOPIC:

ILSpy Plugin corrections/enhancements 19 Apr 2022 12:18 #22213

  • Fabrice
  • Fabrice's Avatar
  • Topic Author


  • Posts: 368
  • Hi,
    I open a new discussion here that is related to my ILSpy plugin.
    If you find an issue in the generated code, please reply here with a sample.

    Thanks,
    Fab

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 08:43 #22225

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • Hi Fabrice,
    if I translate the following C# Code with your plugin
    public class Program
    {
    	static void Main()
    	{
    		System.Console.WriteLine("Hello XIDE from c#!");
    	}
    }
    it says (ignore the "e" we already talked about)
    PUBLIC CLASS Program
    	PRIVATE STATIC METHOD Main() AS VOID
    		Console.WriteLine("e""Hello XIDE from c#!")
    END CLASS
    When I compile the X# Code I get the error "error XS1558: 'Functions' does not have a suitable static 'Start' function". Do I always need a start function in X# or why is this start Class/Method not accepted?

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 08:57 #22228

    • robert
    • robert's Avatar


  • Posts: 3599
  • Franz,
    X# has chosen to use the Start function instead of the Main method as entry point.
    If you change the code to
    public class Program
    	private static method Start() as void
    		Console.WriteLine("e""Hello XIDE from c#!")
    end class
    then you can tell the compiler to use the Program class for the entry point.
    In Visual Studio this can be done on the Application page of the Project properties:


    This sets the compiler option -main: www.xsharp.eu/help/opt-main.html

    Robert
    XSharp Development Team
    The Netherlands
    Attachments:

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 09:02 #22229

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • C#
    foreach (var readerName in readerNames) {
       ...
    }
    Translation
    LOCAL @@array AS STRING[]
    @@array := readerNames
    FOREACH AS STRING IN @@array 
    NEXT
    a little bit complicated and readerName missing in FOREACH, why not directly using array readerNames instead of @@array?

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 09:17 #22230

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • Hi Robert,
    thank you for info, I changed the code and putted the switch "-main:Program" to Properties/Compiler/Additional Switches in XIDE and it compiled without error.

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 10:34 #22232

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • C#
    using System;
    public class Program
    {
       static void Main()
       {
          int[] arr = {1,2,3};
          foreach (var val in arr) {
             int i = 1;
             if (i == 1) {
                Console.WriteLine("if");
             } else {
                Console.WriteLine("else");
                Console.WriteLine("else");
             }
          }
       }
    }
    Translation to X#
    using System
    public class Program
    	private static method Main() as void
    		local arr as Long[]
    		local @@array as Long[]
    		local i as Long
    		//
    		arr := <Long>;
    			{1,;
    			2,;
    			3;
    			}
    		@@array := arr
    		foreach as Long in @@array 
    			i := 1
    			if i == 1
    				Console.WriteLine("e""if")
    				continueendif
    			Console.WriteLine("e""else")
    			Console.WriteLine("e""else")
    		next
    end class
    Else is lost, what means "continueendif"?
    If I do if ... else outside of foreach it translates ok.
    You also see the @@array translation of the former noted posting.

    Please Log in or Create an account to join the conversation.

    Last edit: by lagraf.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 11:11 #22235

    • Fabrice
    • Fabrice's Avatar
    • Topic Author


  • Posts: 368
  • LOCAL @@array AS STRING[]
    @@array := readerNames
    FOREACH AS STRING IN @@array 
    NEXT
    This is an exemple of the difference between the code you write, and the compiler generated code.
    I could try to handle it, catching all FOREACH and rebuilding/guessing what was the original code.

    Please Log in or Create an account to join the conversation.

    Last edit: by Fabrice.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 11:16 #22236

    • Fabrice
    • Fabrice's Avatar
    • Topic Author


  • Posts: 368
  • lagraf wrote: Else is lost, what means "continueendif"?

    The "continueendif" is a Plugin error, we are missing a newline between continue and endif; and continue is a C# keyword that translate to a LOOP in X#, that will jump back to the nearest FOR/FOREACH/WHILE/... so there, no need for the ELSE clause as in the IF we are jumping back on top.

    Please Log in or Create an account to join the conversation.

    Last edit: by Fabrice.

    ILSpy Plugin corrections/enhancements 20 Apr 2022 12:04 #22239

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • Fabrice,
    1) FOREACH
    LOCAL @@array AS STRING[]
    @@array := readerNames
    FOREACH AS STRING IN @@array 
    NEXT
    The @@array is waste but not the problem, foreach has lost readerName where each @@array entry is shown, something like
    FOREACH readerName AS STRING IN @@array 
    2) CONTINUEENDIF
    if ... else ... endif is not the same like if ... loop ... endif when statements behind the endif, so I testet this and it translates right!
    foreach as Long in @@array 
    	i := 1
    	if i == 1
    		 Console.WriteLine("e""if")
            else
                     Console.WriteLine("e""else")
                     Console.WriteLine("e""else")
            endif
            Console.WriteLine("ever")
    next
    @@array := arr
    foreach as Long in @@array 
    	i := 1
    	if i == 1
    		Console.WriteLine("e""if")
    	else
    		Console.WriteLine("e""else")
    		Console.WriteLine("e""else")
    	endif
    	Console.WriteLine("e""ever")
    next

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 21 Apr 2022 11:15 #22250

    • Fabrice
    • Fabrice's Avatar
    • Topic Author


  • Posts: 368
  • Hi Franz,

    I have updated the ILSpy plugin :
    The LOOP keyword is now generated instead of "continue"
    The variable declaration in FOREACH has been corrected
    Same for the "e"scaped String.

    Go to the github page : github.com/X-Sharp/ILSpy-Plugin
    On the right, you can get the latest ILSpy plugin, dated today 2022/04/21
    I have also included a version for the latest V7.2.1 version of ILSpy.

    Regards,
    Fab

    Please Log in or Create an account to join the conversation.

    Last edit: by Fabrice.

    ILSpy Plugin corrections/enhancements 21 Apr 2022 12:27 #22252

    • robert
    • robert's Avatar


  • Posts: 3599
  • Fabrice,
    Thanks for the updates.
    The ILSpy 7 version has a small problem.
    See the decompiled code for an operator in the __Usual Type
    /// <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:
    /// <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

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 21 Apr 2022 13:20 #22253

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • Fabrice, thank you for updating the plugin, I installed the version 6 from Apr 21st
    Franz

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 21 Apr 2022 14:59 #22254

    • Fabrice
    • Fabrice's Avatar
    • Topic Author


  • Posts: 368
  • 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

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 21 Apr 2022 15:49 #22255

    • robert
    • robert's Avatar


  • Posts: 3599
  • 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

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 24 Apr 2022 13:47 #22297

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • 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:
    LOCAL array2 AS char[]
    array2 := "4711".ToCharArray()
    _ := array2[0]
    Same construct with C# output:
    char[] array2 = "4711".ToCharArray();
    _ = array2[0];
    What could this "_ := array2[0]" mean? If you are interested I can send you this DLL.

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 24 Apr 2022 22:32 #22299

    • Fabrice
    • Fabrice's Avatar
    • Topic Author


  • Posts: 368
  • 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

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 25 Apr 2022 09:30 #22301

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • Hi Fabrice,
    attached the DLL, pls search for getFormat2PIN and you will find the code.
    Franz

    File Attachment:

    File Name: Test.zip
    File Size:73 KB
    Attachments:

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 25 Apr 2022 19:46 #22305

    • robert
    • robert's Avatar


  • Posts: 3599
  • 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

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 27 Apr 2022 16:32 #22311

    • lagraf
    • lagraf's Avatar


  • Posts: 338
  • "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:
    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:
    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
    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?

    Please Log in or Create an account to join the conversation.

    ILSpy Plugin corrections/enhancements 27 Apr 2022 22:28 #22312

    • robert
    • robert's Avatar


  • Posts: 3599
  • 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
    pin[i] 
    to
    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

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.
    • Page:
    • 1