Skip to content

Parse bridge flag [TG-4115] #2527

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

Closed
wants to merge 2 commits into from
Closed

Conversation

thk123
Copy link
Contributor

@thk123 thk123 commented Jul 5, 2018

Based on #2526

tidy up removed to separate PR

First some tidy up - there are four different tables in the java bytecode spec that have different values but were all using the same macros in the parser. This is confusing (and led to some nonsense lines, reading ACC_PROTECTED on a class for example, which isn't legal. Instead pulled each table into an enum, linking to the docs. To allow bitwise & and name scoping, namespaces were required.

Then the actual work - parse the ACC_BRIDGE which is a flag for methods that the compiler generates to deal with type erasure.

I didn't add a method to code_typet as this is very Java specific. Is it worth introducing a java_code_typet for java method types?

@thk123
Copy link
Contributor Author

thk123 commented Jul 5, 2018

TG PR: diffblue/test-gen#2034

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 10ac97e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/78217964

#ifdef _MSC_VER
#define UNUSED
#else
#define UNUSED __attribute__((unused))
#endif

/// Represents the bit flag from class access and property flags
/// https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1-200-E.1
namespace class_access_flagst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using enum class should remove this weird namespace.

Copy link
Contributor Author

@thk123 thk123 Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately using enum class means it cannot be implicitly converted to int (to be used in the logical and later). I could replace the word namespace with class, but that feels weirder. @thomasspriggs suggested writing a method called read_flag, but as they would all be unique types I'd either have to write one per type, or template it and lose type safety (not too bad, but I prefer this option) - let me know what you'd prefer me to do.

Copy link
Contributor

@thomasspriggs thomasspriggs Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about doing away with the defines / enums and using this approach instead?

  struct flagst {
    bool is_public : 1;
    bool is_private : 1;
    bool is_protected : 1;
    bool is_static : 1;
    bool is_final : 1;
    void : 4;
    bool is_interface : 1;
    bool is_abstract : 1;
    void : 1;
    bool is_synthetic : 1;
    bool is_annotation : 1;
    bool is_enum : 1;
    void : 1;
  } flags = *reinterpret_cast<flagst*>(&access_flags);

  parsed_class.is_abstract = flags.is_abstract;
  parsed_class.is_enum = flags.is_enum; 
  parsed_class.is_final = flags.is_final; 
  parsed_class.is_interface = flags.is_interface;
  parsed_class.is_synthetic = flags.is_synthetic;
  parsed_class.is_annotation = flags.is_annotation;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterschrammel I really like Tom's suggestion above, if you'd like it I'll go ahead and change it for that with some unit tests to check we get each method correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterschrammel Going to pull this refactor out into a different PR to unblock this - but could you express an opinion on whether you like Toms suggested approach (I think I'd probably put the struct directly into parse_treet::classt to avoid the is_abstract=is_abstract duplication.

thk123 added 2 commits July 11, 2018 18:10
This is used for compiler generated methods to deal with type erasure.
@thk123 thk123 force-pushed the parse-bridge-flag branch from 10ac97e to ac9bc2d Compare July 11, 2018 17:10
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: ac9bc2d).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/78728751
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

Copy link
Contributor

@thomasspriggs thomasspriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@peterschrammel
Copy link
Member

@thomasspriggs, needs a rebase.

@peterschrammel
Copy link
Member

Replaced by #2582.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants