pascalkuthe / OpenVAF

An innovative Verilog-A compiler
https://openvaf.semimod.de/
GNU General Public License v3.0
123 stars 20 forks source link

macro call parsing issue #140

Open gjcoram opened 2 months ago

gjcoram commented 2 months ago

If I have `define myexp exp and then call it with y = `myexp(5.0); OpenVAF complains error: argument mismatch expected 0 but found 1!

If I do y = `myexp (5.0); then it works fine -- note the space before the open-parenthesis.

The parser properly looks for an open-parenthesis when parsing the define: if it finds a parenthesis before any whitespace, then there are arguments for that macro. But when parsing the call, this is not the proper way to determine whether there are arguments.

Interestingly, it seems that the parser can support a macro call in the formal arguments: `define myadd(arg1,arg2) (arg1) + (arg2) which seems a little weird. parse_define calls parse_macro_token, which can get macros.

gjcoram commented 2 months ago

I have a way to fix this, but it's inefficient, because it clones the AHashMap for the macros, in order to be able to look up the number of arguments for the macro, to know if the macro call should have any.

gjcoram commented 2 months ago

I found a better way to fix this and have added it to my fork.