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

Unexpected alignment within function #571

Closed
imd1 opened this issue Apr 30, 2021 · 11 comments
Closed

Unexpected alignment within function #571

imd1 opened this issue Apr 30, 2021 · 11 comments
Assignees
Labels

Comments

@imd1
Copy link
Contributor

imd1 commented Apr 30, 2021

Environment
VSG latest master, Centos 7.6

Describe the bug
After VSG has reported success, the following code snippet has non-optimal vertical alignment

Screenshots

  function slv_to_hex_str2 (s : std_logic_vector) return string is
    variable slv4 : std_logic_vector( 3 downto 0);
    variable data : std_logic_vector(s'left downto 0);
    variable str  : string(s'length / 4 downto 1);
  begin
    data          := s;
    for i in ((s'length / 4) - 1) downto 0 loop
      slv4       := data((((i + 1) * 4) - 1) downto (i * 4));
      str( i + 1 ) := INT_TO_HEX(TO_INTEGER(unsigned(slv4)));
    end loop;
    return str;
  end function;

@imd1 imd1 added the bug label Apr 30, 2021
@jeremiah-c-leary
Copy link
Owner

Hey @imd1 ,

Are you referring to the alignment of the variable assignment operator :=?

@imd1
Copy link
Contributor Author

imd1 commented May 5, 2021

Hey @imd1 ,

Are you referring to the alignment of the variable assignment operator :=?

I would have expected this based on default VSG behavior seen so far:

  function slv_to_hex_str2 (s : std_logic_vector) return string is
    variable slv4 : std_logic_vector( 3 downto 0);
    variable data : std_logic_vector(s'left downto 0);
    variable str  : string(s'length / 4 downto 1);
  begin
    data := s;
    for i in ((s'length / 4) - 1) downto 0 loop
      slv4         := data((((i + 1) * 4) - 1) downto (i * 4));
      str( i + 1 ) := INT_TO_HEX(TO_INTEGER(unsigned(slv4)));
    end loop;
    return str;
  end function;

@imd1
Copy link
Contributor Author

imd1 commented Jun 21, 2021

@jeremiah-c-leary : can you give me some tips how to fix this?

jeremiah-c-leary added a commit that referenced this issue Oct 7, 2021
Adding the ability to also align variable assignments.

  1)  Updated documentation
  2)  Updated test
  3)  Updated rule to align <= and :=
@jeremiah-c-leary
Copy link
Owner

Hey @imd1,

I added the alignment of := and <= to the rule subprogram_body_400. Previously it was only aligning the <=. Plus I just recently added this rule.

I think we need to add a parameter to stop aligning if a loop is encountered. Take this for a spin and let me know if you agree.

I pushed this to the issue-571 branch.

--Jeremy

@jeremiah-c-leary jeremiah-c-leary self-assigned this Oct 7, 2021
@jeremiah-c-leary jeremiah-c-leary added this to To do in Release 3.3.0 via automation Oct 7, 2021
@jeremiah-c-leary jeremiah-c-leary moved this from To do to User Validation in Release 3.3.0 Oct 7, 2021
@imd1
Copy link
Contributor Author

imd1 commented Oct 7, 2021

think we need to add a parameter to stop aligning if a loop is encountered.

I would assume this new rule (and other similar new rules) would use the control statements like loop_statements_ends_group
(https://vhdl-style-guide.readthedocs.io/en/latest/configuring.html#rule-specific-keyword-alignment-configuration) - have you not used the relevant underlying rule where these control statements are defined?

@imd1
Copy link
Contributor Author

imd1 commented Oct 7, 2021

think we need to add a parameter to stop aligning if a loop is encountered.

I would assume this new rule (and other similar new rules) would use the control statements like loop_statements_ends_group (https://vhdl-style-guide.readthedocs.io/en/latest/configuring.html#rule-specific-keyword-alignment-configuration) - have you not used the relevant underlying rule where these control statements are defined?

I've just noticed that subprogram_body_400 is an existing rule and should be picking these control statements up already

@imd1
Copy link
Contributor Author

imd1 commented Oct 7, 2021

Take this for a spin and let me know if you agree.

I've visually reviewed your changes, and they look good to me.

Feels like this issue is similar to #562 - I assume the solution is similar

@jeremiah-c-leary
Copy link
Owner

I've just noticed that subprogram_body_400 is an existing rule and should be picking these control statements up already

let me research a little.

@jeremiah-c-leary
Copy link
Owner

Well...it is there...but is set to false:

{
  "rule": {
    "subprogram_body_400": {
      "indentSize": 2,
      "phase": 5,
      "disable": false,
      "fixable": true,
      "severity": "Error",
      "compact_alignment": true,
      "blank_line_ends_group": true,
      "comment_line_ends_group": true,
      "if_control_statements_ends_group": true,
      "case_control_statements_ends_group": true,
      "loop_control_statements_ends_group": false
    }
  }
}

I will set it to true.

jeremiah-c-leary added a commit that referenced this issue Oct 8, 2021
Setting loop_control_statements_ends_group to true for default behavior.
@jeremiah-c-leary
Copy link
Owner

Just pushed changing loop_control_statements_ends_group to true.

If the results are good I will merge it to master.

--Jeremy

@imd1
Copy link
Contributor Author

imd1 commented Oct 8, 2021

I'm happy for you to merge

Release 3.3.0 automation moved this from User Validation to Done Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

No branches or pull requests

2 participants