Skip to content

Improvement to c_enum_typet interface #7764

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

Merged

Conversation

esteffin
Copy link
Contributor

This PR improves the c_enum_typet interface to avoid having to directly access its sub components to add members.
To achieve this it:

  • adds a new members() function returning a non-const reference
  • adds a new constructor that has 2 parameters: the underlying type and a std::vector of members to populate the enumeration with.

The PR also refactor the code where the c_enum_typet values are populated in c_typecheck_type to use the new members function.

@codecov
Copy link

codecov bot commented Jun 13, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (5d80835) 78.57% compared to head (2498769) 78.57%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #7764   +/-   ##
========================================
  Coverage    78.57%   78.57%           
========================================
  Files         1693     1693           
  Lines       193306   193309    +3     
========================================
+ Hits        151890   151893    +3     
  Misses       41416    41416           
Impacted Files Coverage Δ
src/ansi-c/c_typecheck_type.cpp 77.00% <100.00%> (-0.03%) ⬇️
src/util/c_types.h 100.00% <100.00%> (ø)
...smt2_incremental/construct_value_expr_from_smt.cpp 100.00% <100.00%> (ø)
...olvers/smt2_incremental/encoding/enum_encoding.cpp 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@esteffin esteffin requested review from a team and thomasspriggs June 14, 2023 15:52
@esteffin esteffin force-pushed the esteffin/improve-c-enum-constructor branch from 705f150 to a247ba0 Compare June 14, 2023 23:00
@esteffin esteffin force-pushed the esteffin/improve-c-enum-constructor branch from a247ba0 to 7a5c6c4 Compare June 15, 2023 09:37
Enrico Steffinlongo added 2 commits June 15, 2023 10:42
Interface for c_enum_typet has limited support for management of enum
members.
This commit adds:
- a function for exposing the member vector as a non-const reference,
- a constructor that takes the underlying type and a list of members and
  sets the constructed type accordingly.
@esteffin esteffin force-pushed the esteffin/improve-c-enum-constructor branch from 7a5c6c4 to 2498769 Compare June 15, 2023 09:42
@@ -36,7 +36,8 @@ static type_symbolt make_c_enum_type_symbol(std::size_t underlying_size)
const signedbv_typet underlying_type{underlying_size};
c_enum_typet enum_type{underlying_type};

auto &members = enum_type.add(ID_body).get_sub();
auto &members = enum_type.members();
members.reserve(20);
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ I might have stored 20 in a constant instead of duplicating the same magic number in 2 places.
⛏️ Also reserve is used for performance reasons. So maybe it is better to omit it in a unit test context in order to aid readability.

@thomasspriggs thomasspriggs merged commit ce831a0 into diffblue:develop Jun 15, 2023
@esteffin esteffin deleted the esteffin/improve-c-enum-constructor branch June 15, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants