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

refactor: Use string_view in instructions and diagnostics #226

Merged

Conversation

slavek-kucera
Copy link
Contributor

No description provided.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 349 Code Smells

75.5% 75.5% Coverage
0.0% 0.0% Duplication

@slavek-kucera slavek-kucera marked this pull request as ready for review February 8, 2022 14:55
@@ -1123,7 +1125,9 @@ bool cattr::check(const std::vector<const asm_operand*>& to_check,
else if (auto complex_op = get_complex_operand(operand); complex_op)
{
// operand is complex
const static std::vector<std::string> complex_operands = { "RMODE", "ALIGN", "FILL", "PART", "PRIORITY" };
const static std::vector<std::string_view> complex_operands = {
"RMODE", "ALIGN", "FILL", "PART", "PRIORITY"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider having e.g. each operand on a separate line to maintain the same look and feel as on lines 1102 - 1112

Suggested change
"RMODE", "ALIGN", "FILL", "PART", "PRIORITY"
"RMODE",
"ALIGN",
"FILL",
"PART",
"PRIORITY"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is really handled by clang-format. While it can be forced to the string-per-line format by attaching , to the last argument, I actually prefer these lists to be as short as possible.

std::vector<label_types> allowed_types;
std::string_view name_of_instruction;
int min_operands = 0;
int max_operands = 0; // maximum number of operands, if not specified, value is -1
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that the comment is no longer accurate

{
std::string name;
bool operandless;
inline_string<6> m_name;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really get why exactly 6 chars are needed here. Consider adding a comment about where this number comes from and also consider creating a separate constant for this instead of using magic numbers.

Nevertheless, keep in mind that I don't know the context yet and the numbers might be completely clear to someone with more experience.

The same comment applies also to line 371 and 376.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These constants are the smallest ones that can be currently used. The various instructions are now instantiated in constexpr so if the value is too small, the compilation will simply fail.


reladdr_transform_mask reladdr_mask;
// Generates a bitmask for an arbitrary mnemonit indicating which operands
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: mnemonit -> mnemonic

const diagnostic_collector& add_diagnostic) const
{
const static std::vector<std::string> other_pair_options = {
const static std::vector<std::string_view> other_pair_options = {
"NOPUSH", "NORECORD", "NOPU", "NORC", "PUSH", "RECORD", "PU", "RC"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider having e.g. each operand on a separate line to maintain the same look and feel as on lines 90 - 109

const std::string,
const diagnostic_collector& add_diagnostic) const
{
const static std::vector<std::string> typecheck_operands = {
const static std::vector<std::string_view> typecheck_operands = {
"MAGNITUDE", "REGISTER", "MAG", "REG", "NOMAGNITUDE", "NOREGISTER", "NOMAG", "NOREG"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider having e.g. each operand on a separate line to maintain the same look and feel as on lines 90 - 109

template<typename T>
std::enable_if_t<!std::is_convertible_v<T&&, std::string_view>, size_t> len(T&&) const
{
return 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comment why 8 is returned

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 205 Code Smells

75.5% 75.5% Coverage
0.0% 0.0% Duplication

@slavek-kucera slavek-kucera merged commit 0652b66 into eclipse-che4z:development Feb 15, 2022
@slavek-kucera slavek-kucera deleted the refactor_instructions branch February 15, 2022 07:27
@github-actions
Copy link

🎉 This PR is included in version 1.1.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@zimlu02 zimlu02 added this to the 1.1.0 milestone Mar 24, 2022
@github-actions
Copy link

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants