Re: [sv-bc] Mantis 1338 - Clarificaion on String literal behavior in macros

From: Coffin, Eric <eric_coffin_at_.....>
Date: Tue Nov 20 2007 - 13:55:48 PST
Hi Thomas,

Thanks for writing the 1338 proposal.  I've found this area of the language a bit problematic myself, and I agree with you in that it needs clarification.

My take on the three macro-operator character sequences `", `` and `\`" is that they do not have any special meaning within a string literal.  If they did have special meaning why would the `" macro-operator be needed at all?

The 1338 proposal defines two macros.  They are:

`define msg(x,y) `"x: `\`"y`\`"`"
`define nosubx(x,y) "x: `\`"y`\`"`"

And the examples of their use are:

$display(`msg(left side,right side));
$display(`nosubx(left side,right side));

I agree with mantis 1338's interpretation of the first macro's expansion:

$display("left side: \"right side\"");

I disagree with mantis 1338's interpretation of the second macro.  The second macro should be expanded to:
"x: `\`"right side`\`"`"  which is an ill-formed argument to the display systask.  The first double-quote starts a string literal.  The `\` are just characters within the string literal, and have no special meaning.  The string literal is terminated with the second double-quote forming the literal:  "x:`\`".  The next two preprocessor tokens are the identifiers 'right' and 'side'.  These two idents are followed by the special macro-operators  `\`" and `".

As an aside, P1800/D4 table 5.9.1 does not explicitly state how to interpret characters within string literals that are prefixed with the back slash character but that are not in the table.  Take, for example, the string literal "\`"-- is it two characters long (a backslash followed by a tick) or one character (a tick)?  ModelSim

-Eric



Alsop, Thomas R wrote:

I have updated mantis item 1338 with a proposal on what I believe is the intended behavior of string literals inside of macros WRT to argument substitution.

 

I am slightly hesitant on adding this wording simply because some vendor tools do not distinguish on this behavior.  Shalom is asking for clarification about how we treat macro argument substitution WRT string literals.  I agree about the ambiguity of the current wording.  The fact that we have `” in macros that allow us keep the string character after substitution means that string literals without the back tick have an alternative meaning.  I would interpret that meaning as a string literal, not a replacement on the string token.  

 

This does collide with current implementation.  For example I ran VCS on the following code snippets:

 

`define msg(x,y) `"x: `\`"y`\`"`"

`define msg_nobacktick(x,y) "x: \"y\""

`define msg_nosubsitute(x) "x"

`define msg_subsitute(x) `"x`"

 

module foo();

 

initial begin

  //$fsdbDumpvars(0,foo,"+all");

 

  $display(`msg(left side,right side));

  $display(`msg_nobacktick(left side,right side));

  $display(`msg_nosubsitute(left side));

  $display(`msg_subsitute(left side));

 

end

endmodule

 

 

This produced the following results:

 

left side: "right side"

left side: "right side"

left side

left side

 

The conclusion being that “ is treated exactly the same way as `”.

 

With the change in the proposal this would have the following results instead:

 

left side: "right side"

x: "y"

x

left side

 

I am happy to shoot down the proposal.  The intent is to come up with one and discuss it.  I don’t see a strong need for this change.  The alternative proposal is to clarify that “ and `” behave the same.

 

 


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean. Received on Tue Nov 20 13:56:32 2007

This archive was generated by hypermail 2.1.8 : Tue Nov 20 2007 - 13:56:55 PST