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

[BUG] enum class xyz: bool not correctly parsed #388

Closed
razajafri opened this issue Mar 30, 2020 · 4 comments
Closed

[BUG] enum class xyz: bool not correctly parsed #388

razajafri opened this issue Mar 30, 2020 · 4 comments
Labels

Comments

@razajafri
Copy link

Javacpp is not translating the cpp boolean enums correctly. Here is the enum defined in cpp

enum class null_order : bool {
  AFTER,  ///< NULL values ordered *after* all other values
  BEFORE  ///< NULL values ordered *before* all other values
};

without info.enumerate() it gets translated to

public static final boolean
  /** NULL values ordered *after* all other values */
  AFTER = 0,
  /** NULL values ordered *before* all other values */
  BEFORE = 1;

with enumerate() the following is the output.

@Namespace("cudf") public enum null_order {
  /** NULL values ordered *after* all other values */
  AFTER(0),
  /** NULL values ordered *before* all other values */
  BEFORE(1);

    public final boolean value;
    private null_order(boolean v) { this.value = v; }
    private null_order(null_order e) { this.value = e.value; }
    public null_order intern() { for (null_order e : values()) if (e.value == value) return e; return this; }
    @Override public String toString() { return intern().name(); }
}

In both cases it is trying to assign an int value to a boolean. How can we get this to correctly generate the code?

@saudet
Copy link
Member

saudet commented Mar 30, 2020

Thanks for the report! I've fixed this in commit 01c7278. Now, without Info.enumerate, it outputs this:

/** enum class null_order */
public static final boolean
  /** NULL values ordered *after* all other values */
  AFTER = 0 != 0,
  /** NULL values ordered *before* all other values */
  BEFORE = 1 != 0;

And with Info.enumerate:

public enum null_order {
  /** NULL values ordered *after* all other values */
  AFTER(0 != 0),
  /** NULL values ordered *before* all other values */
  BEFORE(1 != 0);

    public final boolean value;
    private null_order(boolean v) { this.value = v; }
    private null_order(null_order e) { this.value = e.value; }
    public null_order intern() { for (null_order e : values()) if (e.value == value) return e; return this; }
    @Override public String toString() { return intern().name(); }
}

@cansik I've also added additional casts for byte and short types, so the enums you've been having problems with now get mapped like this:

/** enum Layout */
public static final byte
ANY = (byte)0,  // "any" layout

// I/O data layouts
NCHW = (byte)1
...

@razajafri
Copy link
Author

I updated my javacpp project and did an mvn install... The preset is still failing I get this now...

error: ‘JavaCPP_booleanValueFID’ was not declared in this scope
         env->SetBooleanField(rarg, JavaCPP_booleanValueFID, (jboolean)rval);

The static field isn't defined anywhere, maybe you forgot to check-in something?

@saudet
Copy link
Member

saudet commented Mar 31, 2020

Ah, no, that's something else. I've added support for that in the latest commit. Please try it again!

@saudet
Copy link
Member

saudet commented Apr 15, 2020

All fixed in just released version 1.5.3. Thanks for reporting!

@saudet saudet closed this as completed Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants