Qucs / ADMS

ADMS is a code generator for the Verilog-AMS language
GNU General Public License v3.0
94 stars 31 forks source link

Make conditional if parse/output consistent, reduce clang warnings. #5

Closed guitorri closed 9 years ago

guitorri commented 10 years ago

Clang warns about multiple parentheses on if conditionals (the compiler output is too noisy to be of any use).

The enhancement is to make the returned conditions consistent, they should return already with parentheses. The if (condition) ... currently returns just condition. It should return (condition) instead. Test case below.

This is the sort warning that repeats for each and every if condition (using Qucs XML files here).

hicumL2V2p23.core.cpp:23564:9: warning: equality comparison with extraneous
      parentheses [-Wparentheses-equality]
((tunode==1.0))
  ~~~~~~^~~~~
hicumL2V2p23.core.cpp:23564:9: note: remove extraneous parentheses around the
      comparison to silence this warning
((tunode==1.0))
 ~      ^    ~
hicumL2V2p23.core.cpp:23564:9: note: use '=' to turn this equality comparison
      into an assignment
((tunode==1.0))
        ^~
        =

The user's XML scripts are forced to wrap the conditional once again, because the returned condition is not consistent. See below.

For the following Verilog-A code

if (index) result1 = 1+1;
if (index != 0 ) result2 = 1+2;
...
if ((index > 0) && (i != 0)) j=1+i;

The conditional if/tree stack is dumped (in reverse) as:

conditional : ((index>0)&&(i!=0))
...
conditional : (index!=0)
conditional : index

The first/last should be wrapped in ( ).

Test case:

Run: admsXml test_if.va -e dump_if.xml

guitorri commented 10 years ago

As a workaround, one can test for the datatypename of the condition and add parenthesis for number or variable types.

    <!-- print conditional (if) expressions -->
    <admst:for-each select="conditional">
      <admst:value-of select="./if/tree"/>
      <admst:variable name="COND" select="%s"/> <!-- store -->
      <admst:value-of select="./if/tree/adms/datatypename"/>
      <admst:variable name="TYPE" select="%s"/> <!-- store -->
      <admst:text format=" condition: $(COND) | type: $(TYPE) \n"/>
    </admst:for-each>