-
Notifications
You must be signed in to change notification settings - Fork 273
Add code_typet::get_this #1689
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
Add code_typet::get_this #1689
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -817,9 +817,17 @@ class code_typet:public typet | |
} | ||
|
||
bool has_this() const | ||
{ | ||
return get_this() != nullptr; | ||
} | ||
|
||
const parametert *get_this() const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't return a pointer. I'd suggest to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'd want a reference, so it would have to be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it have to be a reference? Can't you just return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure? Just seemed wasteful to copy it when that's probably unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is on a hot path? Copying an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This particular battle was last fought here: #1462. IIRC the actual conversation was had with Daniel in person, and that PR adds the result to the coding standard doc. Every time someone has to return some "not found / undefined" value there is a tussle between If you continue to object I'll just do whatever you say to get this over with, but I'd like to decide once and for all rather than repeat this conversation every time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Admittedly, I completely missed #1462, and in particular its addition to the coding standard (and of course the offline discussion). I have thus removed my block. Here are my thoughts on the matter:
Now I'm not sure whether this actually adds clarity? Anyway it's just my thoughts, no claim of this being consensus. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: 2, this is definitely an expected failure case (e.g. the function is a free, non-member function) |
||
{ | ||
const parameterst &p=parameters(); | ||
return !p.empty() && p.front().get_this(); | ||
if(!p.empty() && p.front().get_this()) | ||
return &p.front(); | ||
else | ||
return nullptr; | ||
} | ||
|
||
bool is_KnR() const | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a const reference (given we discussed the cost of copy in this PR...).