Skip to content
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

X# preprocessor incorrectly replaces UDC (dialect XBase++) #1250

Closed
DenGhostYY opened this issue Apr 28, 2023 · 11 comments
Closed

X# preprocessor incorrectly replaces UDC (dialect XBase++) #1250

DenGhostYY opened this issue Apr 28, 2023 · 11 comments
Assignees
Projects
Milestone

Comments

@DenGhostYY
Copy link

Describe the bug
X# preprocessor incorrectly replaces UDC (dialect XBase++)

Example 1. To Reproduce .prg

/** 
 * enum EnumType {CONST1("desc1"), CONST2("desc2")}
 *      =>
 * class EnumType from Enum
 * exported:
 *      class var CONST1 readonly
 *      class var CONST2 readonly
 *      inline class method initClass()
 *          local i := 0
 *          ::CONST1 := EnumType():new(++i, "CONST1", desc1)
 *          ::CONST2 := EnumType():new(++i, "CONST2", desc2)
 *          ::setValues({::CONST1, ::CONST2})
 *      return
 * endclass
 */
#xtranslate enum <EnumType> { <var1>[(<desc1,...>)] [,<varN>[(<descN,...>)]] };
    =>;
class <EnumType> from Enum;;
exported:;;
    class var <var1> readonly;
    [;class var <varN> readonly];;
    inline class method initClass();;
        local i := 0;;
        ::<var1> := <EnumType>():new(++i, <"var1">[, <desc1>]);
        [;::<varN> := <EnumType>():new(++i, <"varN">, <descN>, nil)];; // [, <descN>] - error XBT0513; без NIL - warning XBT0124
        ::setValues({::<var1>[,::<varN>]});;
    return;;
endclass

#xtranslate enum <EnumType> { <var1>[(<desc1,...>)]  };
    =>;
class <EnumType> from Enum;;
exported:;;
    class var <var1> readonly;;
    inline class method initClass();;
        ::<var1> := <EnumType>():new(1, <"var1">[, <desc1>]);;
        ::setValues({::<var1>});;
    return;;
endclass

enum Quality {GOOD("Well"), BETTER("Stronger"), BEST("Great")}

Expected behavior (xBase++ .ppo)
Output

class Quality from Enum;exported:;class var GOOD readonly;class var  BETTER readonly;class var  BEST readonly;inline class method initClass();local i := 0;::GOOD := Quality():new(++i, "GOOD",  "Well");:: BETTER :=  Quality():new(++i, "BETTER",  "Stronger", nil);:: BEST :=  Quality():new(++i, "BEST",  "Great", nil);::setValues({::GOOD,:: BETTER,:: BEST});return;endclass

Actual behavior (X# .ppo)

class Quality from Enum; exported:; class var GOOD("Well") readonly ;class var BETTER("Stronger") readonly;class var BEST("Great") readonly ; inline class method initClass(); local i := 0; ::GOOD("Well") := Quality ():new(++i, "GOOD("Well")"  ) ;::BETTER("Stronger") := Quality ():new(++i, "BETTER("Stronger")" ,  , nil);::BEST("Great") := Quality ():new(++i, "BEST("Great")" ,  , nil) ; ::setValues({::GOOD("Well") ,::BETTER("Stronger"),::BEST("Great") }); return; endclass

If I write an enumeration in this way,

enum Quality {;
    GOOD("Well"), BETTER("Stronger"), BEST("Great");
}

then the X# preprocessor does not recognize it.

Additional context
X# Compiler version 2.14.0.4 (release)
-dialect:xBase++ -xpp1 -lb -memvar -vo1 -vo3 -vo5 -vo10 -vo15 -vo16

@RobertvanderHulst
Copy link
Member

This example depends on an Enum class. Can you include the code for that class too?
Or are you trying to do this with the .Net enum class?

@DenGhostYY
Copy link
Author

DenGhostYY commented May 2, 2023

enum.zip
Unfortunately, our Alaska Xbase++ enum managed to acquire additional features

@RobertvanderHulst
Copy link
Member

Which incoding are these source files in?

@DenGhostYY
Copy link
Author

DOS 866

@RobertvanderHulst
Copy link
Member

RobertvanderHulst commented May 8, 2023

The problem in this case seems to be in the handling of
enum { [(<desc1,...>)] [,[(<descN,...>)]] };

when matching the token we encounter the '(' token and we do not match that with the '(' inside the optional description part. I'll see if I can fix that.
If I remove the descriptions, then it compiles.
Btw: we do not support readonly class variables (.Net does not support that). Would it be an idea to compile these into auto properties with only a getter

@RobertvanderHulst
Copy link
Member

In the base class Enum I see a problem that you have instance variables with the same name as methods.
That is not allowed in .Net,

@RobertvanderHulst RobertvanderHulst self-assigned this May 9, 2023
@RobertvanderHulst RobertvanderHulst added this to To do in Build 2.17 via automation May 9, 2023
@RobertvanderHulst RobertvanderHulst added this to the 2.17 milestone May 9, 2023
@RobertvanderHulst RobertvanderHulst moved this from To do to In progress in Build 2.17 May 9, 2023
@DenGhostYY
Copy link
Author

DenGhostYY commented May 10, 2023

I agree about the same names for variables and class methods. But not about readonly class variables. Example in C#:

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Example.Values);
            //Example.Values = "def"; // Compiler Error CS0198
            Console.WriteLine(Example.Values);
            Console.ReadKey();
        }

        class Example
        {
            public static readonly string Values = "abc";
        }
    }
}

@RobertvanderHulst
Copy link
Member

RobertvanderHulst commented May 11, 2023

We have added support for readonly in the 2.16 compiler
Variables have to be initialized inline or in the (Class) constructor

@RobertvanderHulst RobertvanderHulst moved this from In progress to Needs testing in Build 2.17 May 11, 2023
@cpyrgas
Copy link

cpyrgas commented Jun 11, 2023

I'm not entirely sure of the correct behavior after the fix (compiler currently gives an error on the original code "error XS0644: 'Quality' cannot derive from special class 'System.Enum'"), so I will let @DenGhostYY confirm this one.

@RobertvanderHulst
Copy link
Member

Chris,

I'm not entirely sure of the correct behavior after the fix (compiler currently gives an error on the original code "error XS0644: 'Quality' cannot derive from special class 'System.Enum'"), so I will let @DenGhostYY confirm this one.
The Enum type is a class that Leonid's company created themselves.

@cpyrgas
Copy link

cpyrgas commented Jun 12, 2023

OK, it's confirmed fixed then!

@cpyrgas cpyrgas closed this as completed Jun 12, 2023
@cpyrgas cpyrgas moved this from Needs testing to Done in Build 2.17 Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

3 participants