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

Enums #62

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Enums #62

wants to merge 9 commits into from

Conversation

zygzagZ
Copy link
Contributor

@zygzagZ zygzagZ commented May 5, 2021

I do not consider this part of code perfect, yet this is what I came up with to manage elf types more easily.

I think constants should be accessed with Class::CONSTANT, eg. Visibility::NONE, yet these enums currently work only with
Visibility.NONE. I did not fix it, I was short on time. I also don't see clear solution.

What I wanted from these enums:

  • fiddle with easily in byebug, cast to string: puts symbol.st_vis to print None instead of ... 42 or whatever.
  • use in expressions just as constants before: symbol.st_vis + 2 to be 44 (or whatever) instead of "None2", currently may require casting with .to_i
  • allow assigning with symbol symbol.st_vis = :none, dunno if works

Part of #52

lib/elftools/enums.rb Show resolved Hide resolved
attr_reader :values
end

def initialize(attrs = 0)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm confused about the name - shouldn't "attrs" be "value"?

Copy link
Owner

Choose a reason for hiding this comment

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

add description about the parameter, seems it can be an integer or a symbol

lib/elftools/enums.rb Outdated Show resolved Hide resolved
lib/elftools/enums.rb Outdated Show resolved Hide resolved
lib/elftools/enums.rb Outdated Show resolved Hide resolved
class Relocation32 < Enum
exclusive true
enum_attr :none, 0
enum_attr :"32", 1
Copy link
Owner

Choose a reason for hiding this comment

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

I don't like these integer names but.. sigh

lib/elftools/sections/relocation_section.rb Outdated Show resolved Hide resolved
lib/elftools/sections/relocation_section.rb Outdated Show resolved Hide resolved
lib/elftools/sections/relocation_section.rb Show resolved Hide resolved
lib/elftools/sections/sym_tab_section.rb Show resolved Hide resolved
Allow usages:
```
Bind::LOCAL
Bind.LOCAL
Bind[:local]
```
Allow comparisons:
```
b == 0
b == 'local'
b == :local
b == Bind::LOCAL
```
end

class << self
attr_reader :values
Copy link
Owner

Choose a reason for hiding this comment

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

add document of its type

class << self
attr_reader :values

def val(value)
Copy link
Owner

Choose a reason for hiding this comment

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

add document

def val(value)
key = if value.is_a? self.class
value.to_i
elsif values.keys.include?(value)
Copy link
Owner

Choose a reason for hiding this comment

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

keys.include? can be replaced with "key?"


def inspect
v = self.class.values[@value]
v ? "#{self.class.name}.#{v.upcase}" : @value
Copy link
Owner

Choose a reason for hiding this comment

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

unsure whether it matters - shouldn't "@value" be "@value.inspect"?

@david942j
Copy link
Owner

Any update here :) ?

@david942j
Copy link
Owner

yes?

@zygzagZ
Copy link
Contributor Author

zygzagZ commented Jul 24, 2021 via email

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.

None yet

2 participants