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

[BUG] macros breaking indentation #231

Open
miguel9554 opened this issue Jun 30, 2023 · 18 comments
Open

[BUG] macros breaking indentation #231

miguel9554 opened this issue Jun 30, 2023 · 18 comments

Comments

@miguel9554
Copy link

When using macros inside other syntax elements with their own indenting (module instantiation, fucntions, contraints etc) the indentation is broken, see following example

class my_class;

    int my_var;

    constraint reg_addr_c {
        `ifndef MY_MACRO
            my_var == 2;
        `else
            my_var == 3;
        `endif
    }

        function new();
        endfunction

endclass

The function declaration should be at the level of constraint again, but it is at the level of the macro block.

@vhda
Copy link
Owner

vhda commented Jun 30, 2023

I sometimes feel that certain SystemVerilog features were developed by JavaScript engineers...
I'm pretty sure the problem is related with that semicolon inside the brackets and the expression not ending in a semicolon, but will need sometime to investigate (sorry, real life TM).

@ThunderMikey
Copy link

The same if I do

`uvm_analysis_imp_decl(_w)

  class xxx;
  endclass

@vhda
Copy link
Owner

vhda commented Jun 30, 2023

UVM is also done by JavaScript engineers 😝

@miguel9554
Copy link
Author

Hey, I don't think it has to do with the semicolon inside constraints block, that seems to work OK. Some examples

Removing macro, using constraint block per correct SV syntax works OK

class my_class;

    int my_var;

    constraint reg_addr_c {
        my_var == 2;
    }

    function new();
    endfunction

endclass

You can also try not including the semicolon, or including it after the brace (even though it doesn't compile, just to test the vim plugin) and indentation works OK.

The problem happens when you have the macro inside the block

@miguel9554
Copy link
Author

The same if I do

`uvm_analysis_imp_decl(_w)

  class xxx;
  endclass

I've copied that into an empty file and could not reproduce, it worked OK

@ThunderMikey
Copy link

Oops, sorry. My bad, it turns about there is a ifndef which caused the indentation. I guess this is feature, not a bug (TM).

`ifndef XXX
  `define XXX
  `uvm_analysis_imp_decl(_w)

@vhda
Copy link
Owner

vhda commented Jul 4, 2023

It's always a good day when what we thought was a bug in fact isn't!
Shall I close this issue then?

@miguel9554
Copy link
Author

No, don't close, what I reported initially is a bug. What isn't, is what @ThunderMikey reported.

@puliget
Copy link

puliget commented Aug 23, 2023

Using macro inside constraints, is working fine. You code is working. Check this link and run the code https://edaplayground.com/x/MHuL

Read this document:
02-19.4.pdf

@miguel9554
Copy link
Author

@puliget Of course macros work inside constraints, who said they didn't? I'm reporting that this particular VIM indentation file does not handle well indentation for those cases.

The document you linked is part of the verilog 2001 standard, which has no constraints in it... I don't get your point

@puliget
Copy link

puliget commented Aug 25, 2023

class my_class;

rand int my_var;

constraint reg_addr_c {
    `ifndef MY_MACRO
        my_var == 2;
    `else
        my_var == 3;
    `endif
}

    function new();
    endfunction

endclass

module tb;
my_class cls;

initial begin
cls=new();
cls.randomize();
$display("my_var=%d",cls.my_var);
end
endmodule

@puliget
Copy link

puliget commented Aug 25, 2023

It is working, check once link :https://edaplayground.com/x/MHuL
and run code in eda playground

@miguel9554
Copy link
Author

@puliget again, I agree on macros inside constraints being valid systemverilog constructs, I never said contrary. In fact, I opened this issue because I was making use of the feature.

The bug is reported for a VIM syntax file, you are not getting the point. How can the problem be reproduced in eda playground if it is specific to the VIM editor?

@puliget
Copy link

puliget commented Aug 26, 2023

Eda playground for code editing and runing.many tools are available in eda playground for run codes . I use the mentor questa to run my code in eda playground and i shared that link to you. Vim editor is used for coding editing.on which tool,you are running the code ..

@puliget
Copy link

puliget commented Aug 26, 2023

Never learn , based on tools. Learn based on the syntax only.

@miguel9554
Copy link
Author

@puliget you really are not understanding the issue here

@vhda
Copy link
Owner

vhda commented Jan 23, 2024

@miguel9554 could I kindly ask you to take a test run of indent/skip_bracket_blocks branch?

@vhda
Copy link
Owner

vhda commented Oct 13, 2024

@miguel9554 Any updates?

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

No branches or pull requests

4 participants