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

possibility to check if a value belongs to an enumeration #518

Open
DarkDimius opened this issue Feb 22, 2017 · 3 comments
Open

possibility to check if a value belongs to an enumeration #518

DarkDimius opened this issue Feb 22, 2017 · 3 comments
Assignees

Comments

@DarkDimius
Copy link

DarkDimius commented Feb 22, 2017

something like:

seg:
  - id: tag
    type: u1
  - id: etc
    if: enum_known.contains(tag)
enums:
  enum_known:
    1: utf8
@GreyCat GreyCat self-assigned this Feb 22, 2017
@GreyCat
Copy link
Member

GreyCat commented Feb 22, 2017

Thanks for the suggestion!

The main problem here is that enums are not members, so it's impossible to call methods on them as is. Generally, object attributes (i.e. sequence attributes, instances, etc), types and enums are 3 different things and general abc syntax invokes only object attributes. We've kind of solve this problem with typecasting, so we need to invent some syntax to access enums as well.

There is currently only syntax element that concerns enums, and that is enum_name::enum_member, which resolves into EnumByName(...) AST expression, this, in turn, is translated into getting enum by name expression.

Any ideas?

@DarkDimius
Copy link
Author

Given that there seems to be a plan to implement instanceOf checks, maybe this can be factored into those?

I.E, while tag.is<u1> will be checking type of data, tag.is<enum_known> will be checking if tag value belongs to range of values of enum_known.

@GreyCat
Copy link
Member

GreyCat commented Feb 22, 2017

I'm not really sure about instanceOf style checks now. The problem is that not all languages have some sort of RTTI. .NET CLR and JVM have them (albeit, as you know, JVM widely employs type erasure). C++ requires quite a few changes to enable RTTI, make classes properly virtual and enable stuff like typeid. C, if we'll ever support it, has absolutely no RTTI.

I like your proposal on checking syntax :)

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

No branches or pull requests

2 participants