Factor parsing of pattern-tuple-element into its own routine.

This simple refactor makes pattern-tuple-element available for re-use
in closure expressions. As a drive-by, diagnose non-final ellipses via
diagnose() rather than via assert(), the latter being considered
rather unfriendly. Also, take pains to restore AST invariants after
such an error.


Swift SVN r5163
This commit is contained in:
Doug Gregor
2013-05-13 21:32:33 +00:00
parent 656892b30d
commit 8372f46fb4
6 changed files with 110 additions and 53 deletions

View File

@@ -139,6 +139,8 @@ public:
/// An element of a tuple pattern.
class TuplePatternElt {
Pattern *ThePattern;
// FIXME: Init and VarargBaseType can be collapsed into one field.
ExprHandle *Init;
Type VarargBaseType;
@@ -153,6 +155,13 @@ public:
bool isVararg() const { return !VarargBaseType.isNull(); }
Type getVarargBaseType() const { return VarargBaseType; }
void setVarargBaseType(Type ty) { VarargBaseType = ty; }
/// \brief Revert this variadic tuple pattern element to a
/// non-variadic version.
///
/// Used for error recovery, when we've detected that the element
/// is not the last one.
void revertToNonVariadic();
};
/// A pattern consisting of a tuple of patterns.