Mantis 1566-macros
P1800-2008/D4
Add variable number arguments to text macros
The proposal is based on Mantis 1571
In
Section 21.5.1
CHANGE
Change the syntax in Syntax 21-2 from (FROM MANTIS 1571)
list_of_formal_arguments ::=
formal_argument { , formal_argument
}
formal_argument ::=
simple_identifier [ = default_text ]
TO
list_of_formal_arguments ::=
formal_argument
{ , formal_argument } [ , last_format_argument ]
formal_argument ::=
simple_identifier [ = default_text ]
last_format_argument ::=
simple_identifier ... [ = default_text ]
CHANGE
(TEXT FROM
MANTIS 1571)
If formal arguments are
used, the list of formal argument names shall be enclosed in parentheses
following
the name of the macro. The
formal argument names shall be simple_identifiers,
separated by commas and
optionally whitespace. The left parenthesis shall follow the text macro name immediately, with no space in between.
A formal macro argument may have a default. A default is
specified by appending an = token after the formal argument name, followed by
the default text. The default text is substituted for the formal argument if no
corresponding actual argument is specified.
The
default text may be explicitly specified to be empty by adding an = token after
the formal argument name, followed by a comma (or a right parenthesis if it is
the last argument in the argument list.)
TO
If formal arguments are
used, the list of formal argument names shall be enclosed in parentheses
following
the name of the macro. The
formal argument names shall be simple_identifiers,
separated by commas and
optionally whitespace. The left parenthesis shall follow the text macro name immediately, with no space in between.
A formal macro argument may have a default. A default
is specified by appending an = token after the formal argument name, followed
by the default text. The default text is substituted for the formal argument if
no corresponding actual argument is specified.
The
default text may be explicitly specified to be empty by adding an = token after
the formal argument name, followed by a comma (or a right parenthesis if it is
the last argument in the argument list.)
The last argument in the list of formal argument names may be
followed by an ellipsis (...)
and is then called a multiple
argument. In that case, a list of actual arguments, separated by commas,
may be specified in the argument list in the text macro call. The list of
actual arguments, including the commas, shall be subsituted for the formal multiple
argument in the macro text. A default may be specified for a formal multiple
argument as well, after the ellipsis. Such a default may itself be a multiple
argument list.
Within the scope of the macro text, the predefined macro `__ARGC__
designates the number of arguments specified in the multiple argument list (or
of the default if the default was used). A particular member of the multiple argument
list may be specified by appending a simple non-negative integer constant index
within square brackets to the multiple argument list name. The arguments in the
multiple argument list are numbered from 0 to `__ARGC__ -1 . It shall be an
error to specify a number beyond the end of the list.
CHANGE
It shall be an error to
specify more actual arguments than the number of formal arguments. (FROM Mantis 1571)
TO
It
shall be an error to specify more actual arguments than the number of formal
arguments unless
the last formal argument is a multiple argument.
CHANGE (TEXT FROM Mantis 1571)
Example without defaults:
...
Example with defaults:
...
TO (ADD NEW EXAMPLES AFTER OTHER
EXAMPLES)
Example without defaults:
...
`define MUTEX(name, V...) name:
assert($onehot0{V})
`MUTEX (one_driver, a,b,c);
// expands to "one_driver:
assert($onehot0{a,b,c});
`define HEAD(Q...) Q[0]
`HEAD(3,1,4,15) // evaluates to 3
Example
with defaults:
`define MUTEX(name,
V...=a,b) name: assert($onehot0{V})
`MUTEX (one_driver);
// expands to "one_driver:
assert($onehot0{a,b});