Dimb-amb-expr/tyname
Disambiguate an ambiguous expression or type name.
- Signature
(dimb-amb-expr/tyname expr/tyname add-parens-p table)
→
(mv erp expr-or-tyname new-table)
- Arguments
- expr/tyname — Guard (amb-expr/tyname-p expr/tyname).
- add-parens-p — Guard (booleanp add-parens-p).
- table — Guard (dimb-tablep table).
- Returns
- erp — Type (maybe-msgp erp).
- expr-or-tyname — Type (expr/tyname-p expr-or-tyname).
- new-table — Type (dimb-tablep new-table).
An ambiguous expression or type name is represented as
a pair of an expression and a type name
(with the same concrete syntax appearance).
We attempt to disambiguate both the expression and the type name,
independently from each other.
In valid code, one of them must succeed and the other one must fail:
then we disambiguate in favor of the one that succeeded.
If none or both succeed, the code must be invalid.
If the ambiguous expression or type name
is disambiguated to an expression,
if the add-parens-p flag is t
we parenthesize the expression.
This is needed because, for instance,
in a sizeof(A) expression where A is
a possibly ambiguous expression or type name,
the actual expression would be (A), not just A,
because sizeof can be applied to
an unparenthesized unary expression (e.g. sizeof x).
In this case, the add-parens-p is set to t
by the caller of this disambiguation function.
On the other hand, in a construct like _Alignas(A),
where A is a possibly ambiguous expression or type name,
the expression is just A,
because the parentheses are always required:
they are part of the syntax of _Alignas,
not part of the expression as in the case of
sizeof applied to an expression.
In this case, the add-parens-p flag is set to nil
by the caller of this disambiguation function.