|
22 | 22 | #include "swift/AST/DeclNameLoc.h" |
23 | 23 | #include "swift/AST/FunctionRefKind.h" |
24 | 24 | #include "swift/AST/ProtocolConformanceRef.h" |
| 25 | +#include "swift/AST/TrailingCallArguments.h" |
25 | 26 | #include "swift/AST/TypeAlignments.h" |
26 | 27 | #include "swift/AST/TypeLoc.h" |
27 | 28 | #include "swift/AST/TypeRepr.h" |
@@ -570,105 +571,6 @@ class alignas(8) Expr { |
570 | 571 | } |
571 | 572 | }; |
572 | 573 |
|
573 | | -/// Helper class to capture trailing call argument labels and related |
574 | | -/// information, for expression nodes that involve argument labels, trailing |
575 | | -/// closures, etc. |
576 | | -template<typename Derived> |
577 | | -class TrailingCallArguments |
578 | | - : private llvm::TrailingObjects<Derived, Identifier, SourceLoc> { |
579 | | - // We need to friend TrailingObjects twice here to work around an MSVC bug. |
580 | | - // If we have two functions of the same name with the parameter |
581 | | - // typename TrailingObjectsIdentifier::template OverloadToken<T> where T is |
582 | | - // different for each function, then MSVC reports a "member function already |
583 | | - // defined or declared" error, which is incorrect. |
584 | | - using TrailingObjectsIdentifier = llvm::TrailingObjects<Derived, Identifier>; |
585 | | - friend TrailingObjectsIdentifier; |
586 | | - |
587 | | - using TrailingObjects = llvm::TrailingObjects<Derived, Identifier, SourceLoc>; |
588 | | - friend TrailingObjects; |
589 | | - |
590 | | - Derived &asDerived() { |
591 | | - return *static_cast<Derived *>(this); |
592 | | - } |
593 | | - |
594 | | - const Derived &asDerived() const { |
595 | | - return *static_cast<const Derived *>(this); |
596 | | - } |
597 | | - |
598 | | - size_t numTrailingObjects( |
599 | | - typename TrailingObjectsIdentifier::template OverloadToken<Identifier>) |
600 | | - const { |
601 | | - return asDerived().getNumArguments(); |
602 | | - } |
603 | | - |
604 | | - size_t numTrailingObjects( |
605 | | - typename TrailingObjectsIdentifier::template OverloadToken<SourceLoc>) |
606 | | - const { |
607 | | - return asDerived().hasArgumentLabelLocs() ? asDerived().getNumArguments() |
608 | | - : 0; |
609 | | - } |
610 | | - |
611 | | - /// Retrieve the buffer containing the argument labels. |
612 | | - MutableArrayRef<Identifier> getArgumentLabelsBuffer() { |
613 | | - return { this->template getTrailingObjects<Identifier>(), |
614 | | - asDerived().getNumArguments() }; |
615 | | - } |
616 | | - |
617 | | - /// Retrieve the buffer containing the argument label locations. |
618 | | - MutableArrayRef<SourceLoc> getArgumentLabelLocsBuffer() { |
619 | | - if (!asDerived().hasArgumentLabelLocs()) |
620 | | - return { }; |
621 | | - |
622 | | - return { this->template getTrailingObjects<SourceLoc>(), |
623 | | - asDerived().getNumArguments() }; |
624 | | - } |
625 | | - |
626 | | -protected: |
627 | | - /// Determine the total size to allocate. |
628 | | - static size_t totalSizeToAlloc(ArrayRef<Identifier> argLabels, |
629 | | - ArrayRef<SourceLoc> argLabelLocs, |
630 | | - bool hasTrailingClosure) { |
631 | | - return TrailingObjects::template totalSizeToAlloc<Identifier, SourceLoc>( |
632 | | - argLabels.size(), argLabelLocs.size()); |
633 | | - } |
634 | | - |
635 | | - /// Initialize the actual call arguments. |
636 | | - void initializeCallArguments(ArrayRef<Identifier> argLabels, |
637 | | - ArrayRef<SourceLoc> argLabelLocs, |
638 | | - bool hasTrailingClosure) { |
639 | | - if (!argLabels.empty()) { |
640 | | - std::uninitialized_copy(argLabels.begin(), argLabels.end(), |
641 | | - this->template getTrailingObjects<Identifier>()); |
642 | | - } |
643 | | - |
644 | | - if (!argLabelLocs.empty()) |
645 | | - std::uninitialized_copy(argLabelLocs.begin(), argLabelLocs.end(), |
646 | | - this->template getTrailingObjects<SourceLoc>()); |
647 | | - } |
648 | | - |
649 | | -public: |
650 | | - /// Retrieve the argument labels provided at the call site. |
651 | | - ArrayRef<Identifier> getArgumentLabels() const { |
652 | | - return { this->template getTrailingObjects<Identifier>(), |
653 | | - asDerived().getNumArguments() }; |
654 | | - } |
655 | | - |
656 | | - /// Retrieve the buffer containing the argument label locations. |
657 | | - ArrayRef<SourceLoc> getArgumentLabelLocs() const { |
658 | | - if (!asDerived().hasArgumentLabelLocs()) |
659 | | - return { }; |
660 | | - |
661 | | - return { this->template getTrailingObjects<SourceLoc>(), |
662 | | - asDerived().getNumArguments() }; |
663 | | - } |
664 | | - |
665 | | - /// Retrieve the location of the ith argument label. |
666 | | - SourceLoc getArgumentLabelLoc(unsigned i) const { |
667 | | - auto locs = getArgumentLabelLocs(); |
668 | | - return i < locs.size() ? locs[i] : SourceLoc(); |
669 | | - } |
670 | | -}; |
671 | | - |
672 | 574 | /// ErrorExpr - Represents a semantically erroneous subexpression in the AST, |
673 | 575 | /// typically this will have an ErrorType. |
674 | 576 | class ErrorExpr : public Expr { |
@@ -5448,7 +5350,27 @@ inline const SourceLoc *CollectionExpr::getTrailingSourceLocs() const { |
5448 | 5350 | } |
5449 | 5351 |
|
5450 | 5352 | #undef SWIFT_FORWARD_SOURCE_LOCS_TO |
5451 | | - |
| 5353 | + |
| 5354 | +/// Pack the argument information into a single argument, to match the |
| 5355 | +/// representation expected by the AST. |
| 5356 | +/// |
| 5357 | +/// \param argLabels The argument labels, which might be updated by this |
| 5358 | +/// function. |
| 5359 | +/// |
| 5360 | +/// \param argLabelLocs The argument label locations, which might be updated by |
| 5361 | +/// this function. |
| 5362 | +Expr *packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc, |
| 5363 | + ArrayRef<Expr *> args, |
| 5364 | + ArrayRef<Identifier> &argLabels, |
| 5365 | + ArrayRef<SourceLoc> &argLabelLocs, |
| 5366 | + SourceLoc rParenLoc, |
| 5367 | + Expr *trailingClosure, bool implicit, |
| 5368 | + SmallVectorImpl<Identifier> &argLabelsScratch, |
| 5369 | + SmallVectorImpl<SourceLoc> &argLabelLocsScratch, |
| 5370 | + llvm::function_ref<Type(const Expr *)> getType = |
| 5371 | + [](const Expr *E) -> Type { |
| 5372 | + return E->getType(); |
| 5373 | + }); |
5452 | 5374 | } // end namespace swift |
5453 | 5375 |
|
5454 | 5376 | #endif |
0 commit comments