jeremiah-c-leary / vhdl-style-guide

Style guide enforcement for VHDL
GNU General Public License v3.0
192 stars 39 forks source link

Generic map case rules apply only to component insantiations, and not other instances where generic maps can be used #1319

Open JHertz5 opened 6 days ago

JHertz5 commented 6 days ago

Environment v3.27.0

Describe the bug Generic maps can be used in package instantiations, subprogram instantiations, blocks and component instantiations. However, most generic map rules only apply to component instantiations.

To Reproduce Steps to reproduce the behavior:

  1. Create a file tes.vhd with the following contents
    
    PACKAGE MY_PKG_G IS NEW MY_PKG
    GENERIC MAP (G_TEST => C_TEST);

ARCHITECTURE RTL OF TEST IS

FUNCTION MY_FUNC IS NEW MY_FUNC GENERIC MAP (G_TEST => C_TEST);

BEGIN

CMP_G_TEST : COMPONENT TEST GENERIC MAP (G_TEST => C_TEST);

MY_BLOCK : BLOCK IS

GENERIC (G_TEST : BOOLEAN); GENERIC MAP (G_TEST => C_TEST);

BEGIN

END BLOCK MY_BLOCK;

END ARCHITECTURE RTL;

2. Run `vsg -f test.vhd --fix`
3. Observe the following output
```vhdl
PACKAGE MY_PKG_G IS NEW MY_PKG
GENERIC MAP (
G_TEST => C_TEST
);

architecture rtl of test is

function MY_FUNC IS NEW MY_FUNC
GENERIC MAP (
G_TEST => C_TEST
);

begin

  cmp_g_test : component test
    generic map (
      g_test => C_TEST
    );

  my_block : block is

    generic (
      g_test : BOOLEAN
    );
GENERIC MAP (
G_TEST => C_TEST
);

  begin

  end block my_block;

end architecture rtl;

Note that the component instantiation is now nicely formatted, while the others are not.

Expected behavior I expect the generic map rules to act on all of these instances.

JHertz5 commented 4 days ago

Analysis of generic map rules

I've done some testing and the results are actually better than I'd expected. It turns out that all generic map rules other than 001 and 002 do already work on all instances of generic maps.

generic map rule component package subprogram block
001 y n n n
002 y n n n
003 y y y y
004 y y y y
005 y y y y
006 y y y y
007 y y y y
008 y y y y
100 y y y y
600 y y y y
601 y y y y

I've also discovered that the alignment rule that I'd been looking for to work on generic maps was actually instantiation_001, so I'll need an alignment rule for each of the constructs within which generic maps appear. I will create a separate issue (#1333) for this.

JHertz5 commented 4 days ago

I've created a PR #1332 to resolve this issue.