Eric, I believe I agree with you. Note that Mantis 1119 explicitly clarifies that macro argument substitution does NOT agree within a string literal (using ", not `"). Mantis 1507 is open on clarifying the behavior of a backslash followed by a general character (i.e., one not in the table) within a string literal. The C precedent is that the backslash has no special meaning, and that these are two characters. Note that when used as a display format, the backslash disappears, though, see Mantis 1101. Yulik once commented that the phrase "usual lexical meaning" is not clear. The LRM also does not specify what happens if `\ appears in the macro text NOT followed by `". Does it become just backslash, or does it stay as quote+backslash? The email thread starting at http://www.eda-stds.org/sv-bc/hm/4201.html clarifies the behavior and the clarifications should enter the LRM text. Regards, Shalom ________________________________ From: owner-sv-bc@server.eda.org [mailto:owner-sv-bc@server.eda.org] On Behalf Of Coffin, Eric Sent: Tuesday, November 20, 2007 4:56 PM To: Alsop, Thomas R Cc: sv-bc@server.eda.org Subject: Re: [sv-bc] Mantis 1338 - Clarificaion on String literal behavior in macros 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 <http://www.mailscanner.info/> , and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner <http://www.mailscanner.info/> , and is believed to be clean. --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Thu Nov 22 09:27:34 2007
This archive was generated by hypermail 2.1.8 : Thu Nov 22 2007 - 09:28:11 PST