mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-next
This commit is contained in:
@@ -140,7 +140,24 @@ class alignas(8) Expr {
|
||||
Implicit : 1
|
||||
);
|
||||
|
||||
SWIFT_INLINE_BITFIELD_FULL(CollectionExpr, Expr, 64-NumExprBits,
|
||||
/// True if the type of this collection expr was inferred by the collection
|
||||
/// fallback type, like [Any].
|
||||
IsTypeDefaulted : 1,
|
||||
/// Number of comma source locations.
|
||||
NumCommas : 32 - 1 - NumExprBits,
|
||||
/// Number of entries in the collection. If this is a DictionaryLiteral,
|
||||
/// each entry is a Tuple with the key and value pair.
|
||||
NumSubExprs : 32
|
||||
);
|
||||
|
||||
SWIFT_INLINE_BITFIELD_EMPTY(LiteralExpr, Expr);
|
||||
SWIFT_INLINE_BITFIELD_EMPTY(IdentityExpr, Expr);
|
||||
|
||||
SWIFT_INLINE_BITFIELD(ParenExpr, IdentityExpr, 1,
|
||||
/// \brief Whether we're wrapping a trailing closure expression.
|
||||
HasTrailingClosure : 1
|
||||
);
|
||||
|
||||
SWIFT_INLINE_BITFIELD(NumberLiteralExpr, LiteralExpr, 1,
|
||||
IsNegative : 1
|
||||
@@ -167,7 +184,12 @@ class alignas(8) Expr {
|
||||
IsSuper : 1
|
||||
);
|
||||
|
||||
SWIFT_INLINE_BITFIELD(TupleExpr, Expr, 1+1+1,
|
||||
SWIFT_INLINE_BITFIELD_FULL(TupleElementExpr, Expr, 32,
|
||||
: NumPadBits,
|
||||
FieldNo : 32
|
||||
);
|
||||
|
||||
SWIFT_INLINE_BITFIELD_FULL(TupleExpr, Expr, 1+1+1+32,
|
||||
/// Whether this tuple has a trailing closure.
|
||||
HasTrailingClosure : 1,
|
||||
|
||||
@@ -175,7 +197,10 @@ class alignas(8) Expr {
|
||||
HasElementNames : 1,
|
||||
|
||||
/// Whether this tuple has label locations.
|
||||
HasElementNameLocations : 1
|
||||
HasElementNameLocations : 1,
|
||||
|
||||
: NumPadBits,
|
||||
NumElements : 32
|
||||
);
|
||||
|
||||
SWIFT_INLINE_BITFIELD(UnresolvedDotExpr, Expr, 2,
|
||||
@@ -309,6 +334,11 @@ class alignas(8) Expr {
|
||||
IsObjC : 1
|
||||
);
|
||||
|
||||
SWIFT_INLINE_BITFIELD_FULL(SequenceExpr, Expr, 32,
|
||||
: NumPadBits,
|
||||
NumElements : 32
|
||||
);
|
||||
|
||||
protected:
|
||||
union {
|
||||
SWIFT_INLINE_BITS(Expr);
|
||||
@@ -317,6 +347,7 @@ protected:
|
||||
SWIFT_INLINE_BITS(DeclRefExpr);
|
||||
SWIFT_INLINE_BITS(UnresolvedDeclRefExpr);
|
||||
SWIFT_INLINE_BITS(TupleExpr);
|
||||
SWIFT_INLINE_BITS(TupleElementExpr);
|
||||
SWIFT_INLINE_BITS(MemberRefExpr);
|
||||
SWIFT_INLINE_BITS(UnresolvedDotExpr);
|
||||
SWIFT_INLINE_BITS(SubscriptExpr);
|
||||
@@ -337,6 +368,9 @@ protected:
|
||||
SWIFT_INLINE_BITS(ArrayToPointerExpr);
|
||||
SWIFT_INLINE_BITS(ObjCSelectorExpr);
|
||||
SWIFT_INLINE_BITS(KeyPathExpr);
|
||||
SWIFT_INLINE_BITS(ParenExpr);
|
||||
SWIFT_INLINE_BITS(SequenceExpr);
|
||||
SWIFT_INLINE_BITS(CollectionExpr);
|
||||
} Bits;
|
||||
|
||||
private:
|
||||
@@ -1863,17 +1897,13 @@ public:
|
||||
class ParenExpr : public IdentityExpr {
|
||||
SourceLoc LParenLoc, RParenLoc;
|
||||
|
||||
/// \brief Whether we're wrapping a trailing closure expression.
|
||||
/// FIXME: Pack bit into superclass.
|
||||
bool HasTrailingClosure;
|
||||
|
||||
public:
|
||||
ParenExpr(SourceLoc lploc, Expr *subExpr, SourceLoc rploc,
|
||||
bool hasTrailingClosure,
|
||||
Type ty = Type())
|
||||
: IdentityExpr(ExprKind::Paren, subExpr, ty),
|
||||
LParenLoc(lploc), RParenLoc(rploc),
|
||||
HasTrailingClosure(hasTrailingClosure) {
|
||||
LParenLoc(lploc), RParenLoc(rploc) {
|
||||
Bits.ParenExpr.HasTrailingClosure = hasTrailingClosure;
|
||||
assert(lploc.isValid() == rploc.isValid() &&
|
||||
"Mismatched source location information");
|
||||
}
|
||||
@@ -1891,13 +1921,13 @@ public:
|
||||
SourceLoc getEndLoc() const {
|
||||
// If we have a trailing closure, our end point is the end of the
|
||||
// trailing closure.
|
||||
if (RParenLoc.isInvalid() || HasTrailingClosure)
|
||||
if (RParenLoc.isInvalid() || Bits.ParenExpr.HasTrailingClosure)
|
||||
return getSubExpr()->getEndLoc();
|
||||
return RParenLoc;
|
||||
}
|
||||
|
||||
/// \brief Whether this expression has a trailing closure as its argument.
|
||||
bool hasTrailingClosure() const { return HasTrailingClosure; }
|
||||
bool hasTrailingClosure() const { return Bits.ParenExpr.HasTrailingClosure; }
|
||||
|
||||
static bool classof(const Expr *E) { return E->getKind() == ExprKind::Paren; }
|
||||
};
|
||||
@@ -1911,7 +1941,6 @@ class TupleExpr final : public Expr,
|
||||
|
||||
SourceLoc LParenLoc;
|
||||
SourceLoc RParenLoc;
|
||||
unsigned NumElements;
|
||||
|
||||
size_t numTrailingObjects(OverloadToken<Expr *>) const {
|
||||
return getNumElements();
|
||||
@@ -1981,7 +2010,7 @@ public:
|
||||
return { getTrailingObjects<Expr *>(), getNumElements() };
|
||||
}
|
||||
|
||||
unsigned getNumElements() const { return NumElements; }
|
||||
unsigned getNumElements() const { return Bits.TupleExpr.NumElements; }
|
||||
|
||||
Expr *getElement(unsigned i) const {
|
||||
return getElements()[i];
|
||||
@@ -2035,36 +2064,66 @@ class CollectionExpr : public Expr {
|
||||
SourceLoc LBracketLoc;
|
||||
SourceLoc RBracketLoc;
|
||||
|
||||
/// ASTContext allocated element lists. Each entry is one entry of the
|
||||
/// collection. If this is a DictionaryLiteral, each entry is a Tuple with
|
||||
/// the key and value pair.
|
||||
MutableArrayRef<Expr*> Elements;
|
||||
|
||||
Expr *SemanticExpr = nullptr;
|
||||
|
||||
/// True if the type of this collection expr was inferred by the collection
|
||||
/// fallback type, like [Any].
|
||||
bool IsTypeDefaulted = false;
|
||||
/// Retrieve the intrusive pointer storage from the subtype
|
||||
Expr *const *getTrailingObjectsPointer() const;
|
||||
Expr **getTrailingObjectsPointer() {
|
||||
const CollectionExpr *temp = this;
|
||||
return const_cast<Expr**>(temp->getTrailingObjectsPointer());
|
||||
}
|
||||
|
||||
/// Retrieve the intrusive pointer storage from the subtype
|
||||
const SourceLoc *getTrailingSourceLocs() const;
|
||||
SourceLoc *getTrailingSourceLocs() {
|
||||
const CollectionExpr *temp = this;
|
||||
return const_cast<SourceLoc*>(temp->getTrailingSourceLocs());
|
||||
}
|
||||
|
||||
protected:
|
||||
CollectionExpr(ExprKind Kind, SourceLoc LBracketLoc,
|
||||
MutableArrayRef<Expr*> Elements,
|
||||
ArrayRef<Expr*> Elements, ArrayRef<SourceLoc> CommaLocs,
|
||||
SourceLoc RBracketLoc, Type Ty)
|
||||
: Expr(Kind, /*Implicit=*/false, Ty),
|
||||
LBracketLoc(LBracketLoc), RBracketLoc(RBracketLoc),
|
||||
Elements(Elements) { }
|
||||
LBracketLoc(LBracketLoc), RBracketLoc(RBracketLoc) {
|
||||
Bits.CollectionExpr.IsTypeDefaulted = false;
|
||||
Bits.CollectionExpr.NumSubExprs = Elements.size();
|
||||
Bits.CollectionExpr.NumCommas = CommaLocs.size();
|
||||
assert(Bits.CollectionExpr.NumCommas == CommaLocs.size() && "Truncation");
|
||||
std::uninitialized_copy(Elements.begin(), Elements.end(),
|
||||
getTrailingObjectsPointer());
|
||||
std::uninitialized_copy(CommaLocs.begin(), CommaLocs.end(),
|
||||
getTrailingSourceLocs());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/// Retrieve the elements stored in the collection.
|
||||
ArrayRef<Expr *> getElements() const { return Elements; }
|
||||
MutableArrayRef<Expr *> getElements() { return Elements; }
|
||||
Expr *getElement(unsigned i) const { return Elements[i]; }
|
||||
void setElement(unsigned i, Expr *E) { Elements[i] = E; }
|
||||
unsigned getNumElements() const { return Elements.size(); }
|
||||
ArrayRef<Expr *> getElements() const {
|
||||
return {getTrailingObjectsPointer(), Bits.CollectionExpr.NumSubExprs};
|
||||
}
|
||||
MutableArrayRef<Expr *> getElements() {
|
||||
return {getTrailingObjectsPointer(), Bits.CollectionExpr.NumSubExprs};
|
||||
}
|
||||
Expr *getElement(unsigned i) const { return getElements()[i]; }
|
||||
void setElement(unsigned i, Expr *E) { getElements()[i] = E; }
|
||||
unsigned getNumElements() const { return Bits.CollectionExpr.NumSubExprs; }
|
||||
|
||||
bool isTypeDefaulted() const { return IsTypeDefaulted; }
|
||||
void setIsTypeDefaulted(bool value = true) { IsTypeDefaulted = value; }
|
||||
/// Retrieve the comma source locations stored in the collection. Please note
|
||||
/// that trailing commas are currently allowed, and that invalid code may have
|
||||
/// stray or missing commas.
|
||||
MutableArrayRef<SourceLoc> getCommaLocs() {
|
||||
return {getTrailingSourceLocs(), Bits.CollectionExpr.NumCommas};
|
||||
}
|
||||
ArrayRef<SourceLoc> getCommaLocs() const {
|
||||
return {getTrailingSourceLocs(), Bits.CollectionExpr.NumCommas};
|
||||
}
|
||||
unsigned getNumCommas() const { return Bits.CollectionExpr.NumCommas; }
|
||||
|
||||
bool isTypeDefaulted() const { return Bits.CollectionExpr.IsTypeDefaulted; }
|
||||
void setIsTypeDefaulted(bool value = true) {
|
||||
Bits.CollectionExpr.IsTypeDefaulted = value;
|
||||
}
|
||||
|
||||
SourceLoc getLBracketLoc() const { return LBracketLoc; }
|
||||
SourceLoc getRBracketLoc() const { return RBracketLoc; }
|
||||
@@ -2083,16 +2142,23 @@ public:
|
||||
};
|
||||
|
||||
/// \brief An array literal expression [a, b, c].
|
||||
class ArrayExpr : public CollectionExpr {
|
||||
/// ASTContext allocated list of comma locations, there is one less entry here
|
||||
/// than the number of elements.
|
||||
MutableArrayRef<SourceLoc> CommaLocs;
|
||||
class ArrayExpr final : public CollectionExpr,
|
||||
private llvm::TrailingObjects<ArrayExpr, Expr*, SourceLoc> {
|
||||
friend TrailingObjects;
|
||||
friend CollectionExpr;
|
||||
|
||||
ArrayExpr(SourceLoc LBracketLoc, MutableArrayRef<Expr*> Elements,
|
||||
MutableArrayRef<SourceLoc> CommaLocs,
|
||||
size_t numTrailingObjects(OverloadToken<Expr *>) const {
|
||||
return getNumElements();
|
||||
}
|
||||
size_t numTrailingObjects(OverloadToken<SourceLoc>) const {
|
||||
return getNumCommas();
|
||||
}
|
||||
|
||||
ArrayExpr(SourceLoc LBracketLoc, ArrayRef<Expr*> Elements,
|
||||
ArrayRef<SourceLoc> CommaLocs,
|
||||
SourceLoc RBracketLoc, Type Ty)
|
||||
: CollectionExpr(ExprKind::Array, LBracketLoc, Elements, RBracketLoc, Ty),
|
||||
CommaLocs(CommaLocs) {}
|
||||
: CollectionExpr(ExprKind::Array, LBracketLoc, Elements, CommaLocs,
|
||||
RBracketLoc, Ty) { }
|
||||
public:
|
||||
static ArrayExpr *create(ASTContext &C, SourceLoc LBracketLoc,
|
||||
ArrayRef<Expr*> Elements,
|
||||
@@ -2100,29 +2166,37 @@ public:
|
||||
SourceLoc RBracketLoc,
|
||||
Type Ty = Type());
|
||||
|
||||
/// ASTContext allocated list of comma locations, there is one less entry here
|
||||
/// than the number of elements.
|
||||
MutableArrayRef<SourceLoc> getCommaLocs() { return CommaLocs; }
|
||||
ArrayRef<SourceLoc> getCommaLocs() const { return CommaLocs; }
|
||||
|
||||
static bool classof(const Expr *e) {
|
||||
return e->getKind() == ExprKind::Array;
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief A dictionary literal expression [a : x, b : y, c : z].
|
||||
class DictionaryExpr : public CollectionExpr {
|
||||
DictionaryExpr(SourceLoc LBracketLoc, MutableArrayRef<Expr*> Elements,
|
||||
class DictionaryExpr final : public CollectionExpr,
|
||||
private llvm::TrailingObjects<DictionaryExpr, Expr*, SourceLoc> {
|
||||
friend TrailingObjects;
|
||||
friend CollectionExpr;
|
||||
|
||||
size_t numTrailingObjects(OverloadToken<Expr *>) const {
|
||||
return getNumElements();
|
||||
}
|
||||
size_t numTrailingObjects(OverloadToken<SourceLoc>) const {
|
||||
return getNumCommas();
|
||||
}
|
||||
|
||||
DictionaryExpr(SourceLoc LBracketLoc, ArrayRef<Expr*> Elements,
|
||||
ArrayRef<SourceLoc> CommaLocs,
|
||||
SourceLoc RBracketLoc, Type Ty)
|
||||
: CollectionExpr(ExprKind::Dictionary, LBracketLoc, Elements, RBracketLoc,
|
||||
Ty) { }
|
||||
: CollectionExpr(ExprKind::Dictionary, LBracketLoc, Elements, CommaLocs,
|
||||
RBracketLoc, Ty) { }
|
||||
public:
|
||||
|
||||
static DictionaryExpr *create(ASTContext &C, SourceLoc LBracketLoc,
|
||||
ArrayRef<Expr*> Elements, SourceLoc RBracketLoc,
|
||||
ArrayRef<Expr*> Elements,
|
||||
ArrayRef<SourceLoc> CommaLocs,
|
||||
SourceLoc RBracketLoc,
|
||||
Type Ty = Type());
|
||||
|
||||
|
||||
static bool classof(const Expr *e) {
|
||||
return e->getKind() == ExprKind::Dictionary;
|
||||
}
|
||||
@@ -2312,20 +2386,21 @@ public:
|
||||
class TupleElementExpr : public Expr {
|
||||
Expr *SubExpr;
|
||||
SourceLoc NameLoc;
|
||||
unsigned FieldNo;
|
||||
SourceLoc DotLoc;
|
||||
|
||||
public:
|
||||
TupleElementExpr(Expr *SubExpr, SourceLoc DotLoc, unsigned FieldNo,
|
||||
SourceLoc NameLoc, Type Ty)
|
||||
: Expr(ExprKind::TupleElement, /*Implicit=*/false, Ty), SubExpr(SubExpr),
|
||||
NameLoc(NameLoc), FieldNo(FieldNo), DotLoc(DotLoc) {}
|
||||
NameLoc(NameLoc), DotLoc(DotLoc) {
|
||||
Bits.TupleElementExpr.FieldNo = FieldNo;
|
||||
}
|
||||
|
||||
SourceLoc getLoc() const { return NameLoc; }
|
||||
Expr *getBase() const { return SubExpr; }
|
||||
void setBase(Expr *e) { SubExpr = e; }
|
||||
|
||||
unsigned getFieldNumber() const { return FieldNo; }
|
||||
unsigned getFieldNumber() const { return Bits.TupleElementExpr.FieldNo; }
|
||||
SourceLoc getNameLoc() const { return NameLoc; }
|
||||
SourceLoc getDotLoc() const { return DotLoc; }
|
||||
|
||||
@@ -3203,12 +3278,10 @@ class SequenceExpr final : public Expr,
|
||||
private llvm::TrailingObjects<SequenceExpr, Expr *> {
|
||||
friend TrailingObjects;
|
||||
|
||||
unsigned NumElements;
|
||||
|
||||
SequenceExpr(ArrayRef<Expr*> elements)
|
||||
: Expr(ExprKind::Sequence, /*Implicit=*/false),
|
||||
NumElements(elements.size()) {
|
||||
assert(NumElements > 0 && "zero-length sequence!");
|
||||
: Expr(ExprKind::Sequence, /*Implicit=*/false) {
|
||||
Bits.SequenceExpr.NumElements = elements.size();
|
||||
assert(Bits.SequenceExpr.NumElements > 0 && "zero-length sequence!");
|
||||
std::uninitialized_copy(elements.begin(), elements.end(),
|
||||
getTrailingObjects<Expr*>());
|
||||
}
|
||||
@@ -3223,14 +3296,14 @@ public:
|
||||
return getElement(getNumElements() - 1)->getEndLoc();
|
||||
}
|
||||
|
||||
unsigned getNumElements() const { return NumElements; }
|
||||
unsigned getNumElements() const { return Bits.SequenceExpr.NumElements; }
|
||||
|
||||
MutableArrayRef<Expr*> getElements() {
|
||||
return {getTrailingObjects<Expr*>(), NumElements};
|
||||
return {getTrailingObjects<Expr*>(), Bits.SequenceExpr.NumElements};
|
||||
}
|
||||
|
||||
ArrayRef<Expr*> getElements() const {
|
||||
return {getTrailingObjects<Expr*>(), NumElements};
|
||||
return {getTrailingObjects<Expr*>(), Bits.SequenceExpr.NumElements};
|
||||
}
|
||||
|
||||
Expr *getElement(unsigned i) const {
|
||||
@@ -4918,6 +4991,22 @@ inline bool Expr::isInfixOperator() const {
|
||||
isa<AssignExpr>(this) || isa<ExplicitCastExpr>(this);
|
||||
}
|
||||
|
||||
inline Expr *const *CollectionExpr::getTrailingObjectsPointer() const {
|
||||
if (auto ty = dyn_cast<ArrayExpr>(this))
|
||||
return ty->getTrailingObjects<Expr*>();
|
||||
if (auto ty = dyn_cast<DictionaryExpr>(this))
|
||||
return ty->getTrailingObjects<Expr*>();
|
||||
llvm_unreachable("Unhandled CollectionExpr!");
|
||||
}
|
||||
|
||||
inline const SourceLoc *CollectionExpr::getTrailingSourceLocs() const {
|
||||
if (auto ty = dyn_cast<ArrayExpr>(this))
|
||||
return ty->getTrailingObjects<SourceLoc>();
|
||||
if (auto ty = dyn_cast<DictionaryExpr>(this))
|
||||
return ty->getTrailingObjects<SourceLoc>();
|
||||
llvm_unreachable("Unhandled CollectionExpr!");
|
||||
}
|
||||
|
||||
#undef SWIFT_FORWARD_SOURCE_LOCS_TO
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
Reference in New Issue
Block a user