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
Fabrice
Posts: 463
Joined: Thu Oct 08, 2015 7:47 am
Location: France

ILSpy Plugin corrections/enhancements

Post by Fabrice »

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
XSharp Development Team
fabrice(at)xsharp.eu
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

Hi Fabrice,
if I translate the following C# Code with your plugin

Code: Select all

public class Program
{
	static void Main()
	{
		System.Console.WriteLine("Hello XIDE from c#!");
	}
}
it says (ignore the "e" we already talked about)

Code: Select all

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?
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ILSpy Plugin corrections/enhancements

Post by robert »

Franz,
X# has chosen to use the Start function instead of the Main method as entry point.
If you change the code to

Code: Select all

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:
props.png
props.png (4.73 KiB) Viewed 970 times
This sets the compiler option -main: https://www.xsharp.eu/help/opt-main.html

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

ILSpy Plugin corrections/enhancements

Post by lagraf »

C#

Code: Select all

foreach (var readerName in readerNames) {
   ...
}
Translation

Code: Select all

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?
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

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.
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

C#

Code: Select all

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#

Code: Select all

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.
User avatar
Fabrice
Posts: 463
Joined: Thu Oct 08, 2015 7:47 am
Location: France

ILSpy Plugin corrections/enhancements

Post by Fabrice »

Code: Select all

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.
XSharp Development Team
fabrice(at)xsharp.eu
User avatar
Fabrice
Posts: 463
Joined: Thu Oct 08, 2015 7:47 am
Location: France

ILSpy Plugin corrections/enhancements

Post by Fabrice »

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.
XSharp Development Team
fabrice(at)xsharp.eu
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

ILSpy Plugin corrections/enhancements

Post by lagraf »

Fabrice,
1) FOREACH

Code: Select all

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

Code: Select all

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!

Code: Select all

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

Code: Select all

@@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
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 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 : https://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
XSharp Development Team
fabrice(at)xsharp.eu
Post Reply