Skip to content

Conversation

@thomasspriggs
Copy link
Contributor

@thomasspriggs thomasspriggs commented Oct 3, 2019

This PR renames the components of class_method_descriptor_exprt, in order to make their purpose clearer. The constructor of this class and its getters are documented and validation is added.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/ N/A (No user visible behaviour.)
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed). N/A (None claimed)
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

The class as stored in an `class_method_descriptor_exprt` is actually a
unique identifier of the class in the symbol table. Therefore it makes
sense to refer to it as a `class_id` rather than just as a name.
Because it is preferable to use the interface provided.
This is specifically the name of the method only. Not any other part of
the expression.
The component to which a `class_method_descriptor_exprt` is referring to
is specifically a particular overload of a method. The particular
overload is distinguished based on a mangling process. Therefore
`mangled_method_name` more accurately describes that this component is
the the mangled name of a method, as opposed to any other kind of class
component such as a field.
This makes it possible to find the code for constructing the identifier
for a `class_method_descriptor_exprt` by looking at
`class_method_descriptor_exprt` only. Where as previously it would have
been neccessary to search for all places where the contructor was used.
To complete the documentation of each of the getters.
In order to ensure we an invalid expression is never constructed or cast
to.
As the expresion is now checked on construction and casting, we no
longer need check for its validity in the places where it is used.
To complete the complete the documentation of the constructor.
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: 89d2d73).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/130227916

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Couple of questions but lgtm. But the 💡 seems to be like a really strong improvement

const irep_idt method_name = get_virtual_method_target(
instantiated_classes, call_basename, call_class, symbol_table);
CHECK_RETURN(!method_name.empty());
const irep_idt &method_name = virtual_function.mangled_method_name();
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ keep one rename per commit in future

Copy link
Contributor

Choose a reason for hiding this comment

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

method_name and method_id is confusing as to what is the difference between them. Perhaps method_name and resolved_method_symbol_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be an improvement if I renamed the method_name variable to mangled_method_name?

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

One suggestion

const irep_idt method_name = get_virtual_method_target(
instantiated_classes, call_basename, call_class, symbol_table);
CHECK_RETURN(!method_name.empty());
const irep_idt &method_name = virtual_function.mangled_method_name();
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be easier if we used method_base_name and mangled_method_base_name, making it clear that neither includes the package/class qualifiers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me, base_name means "not mangled". So mangled_method_base_name would read as a contradiction.

}
};

inline void validate_expr(const class class_method_descriptor_exprt &value)

Choose a reason for hiding this comment

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

I’m not sure what the class keyword is doing here. Seems redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't redundant. It is an inline forward declaration of the class_method_descriptor_exprt class. The forward declaration of this validate_expr function needs to be before the definition of the class_method_descriptor_exprt class because it is used from inside the classes constructor. The class also needs to be forward declared in order for the function forward declaration to be valid. So the two forward declarations break a cyclic dependency problem and can't be removed without either re-introducing the problem, or defining the constructor out of line instead of in-line. I could remove the keyword class from this line of code and put class class_method_descriptor_exprt; on the proceeding line, but this was a little more succinct.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW coding guidelines say forward declarations should be put at the top of the file with the includes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I'll try and remember for next time.

@thomasspriggs thomasspriggs merged commit 5e95689 into diffblue:develop Dec 3, 2019
@thomasspriggs thomasspriggs deleted the tas/virtual-function-expr branch December 3, 2019 13:31
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.

5 participants