|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2022 - 2023 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef SWIFT_IDE_IDEBRIDGING |
| 14 | +#define SWIFT_IDE_IDEBRIDGING |
| 15 | + |
| 16 | +#include "swift/Basic/BasicBridging.h" |
| 17 | +#include "swift/Basic/SourceLoc.h" |
| 18 | +#include "llvm/ADT/Optional.h" |
| 19 | +#include "llvm/CAS/CASReference.h" |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +enum class LabelRangeType { |
| 23 | + None, |
| 24 | + |
| 25 | + /// `foo([a: ]2) or .foo([a: ]String)` |
| 26 | + CallArg, |
| 27 | + |
| 28 | + /// `func([a b]: Int)` |
| 29 | + Param, |
| 30 | + |
| 31 | + /// `subscript([a a]: Int)` |
| 32 | + NoncollapsibleParam, |
| 33 | + |
| 34 | + /// `#selector(foo.func([a]:))` |
| 35 | + Selector, |
| 36 | +}; |
| 37 | + |
| 38 | +enum class ResolvedLocContext { Default, Selector, Comment, StringLiteral }; |
| 39 | + |
| 40 | +struct ResolvedLoc { |
| 41 | + /// The range of the call's base name. |
| 42 | + swift::CharSourceRange range; |
| 43 | + |
| 44 | + // FIXME: (NameMatcher) We should agree on whether `labelRanges` contains the |
| 45 | + // colon or not |
| 46 | + /// The range of the labels. |
| 47 | + /// |
| 48 | + /// What the label range contains depends on the `labelRangeType`: |
| 49 | + /// - Labels of calls span from the label name (excluding trivia) to the end |
| 50 | + /// of the colon's trivia. |
| 51 | + /// - Declaration labels contain the first name and the second name, excluding |
| 52 | + /// the trivia on their sides |
| 53 | + /// - For function arguments that don't have a label, this is an empty range |
| 54 | + /// that points to the start of the argument (exculding trivia). |
| 55 | + std::vector<swift::CharSourceRange> labelRanges; |
| 56 | + |
| 57 | + /// The in index in `labelRanges` that belongs to the first trailing closure |
| 58 | + /// or `llvm::None` if there is no trailing closure. |
| 59 | + llvm::Optional<unsigned> firstTrailingLabel; |
| 60 | + |
| 61 | + LabelRangeType labelType; |
| 62 | + |
| 63 | + /// Whether the location is in an active `#if` region or not. |
| 64 | + bool isActive; |
| 65 | + |
| 66 | + ResolvedLocContext context; |
| 67 | + |
| 68 | + SWIFT_NAME( |
| 69 | + "init(range:labelRanges:firstTrailingLabel:labelType:isActive:context:)") |
| 70 | + ResolvedLoc(BridgedCharSourceRange range, CharSourceRangeVector labelRanges, |
| 71 | + unsigned firstTrailingLabel, LabelRangeType labelType, |
| 72 | + bool isActive, ResolvedLocContext context); |
| 73 | + |
| 74 | + ResolvedLoc(swift::CharSourceRange range, |
| 75 | + std::vector<swift::CharSourceRange> labelRanges, |
| 76 | + llvm::Optional<unsigned> firstTrailingLabel, |
| 77 | + LabelRangeType labelType, bool isActive, |
| 78 | + ResolvedLocContext context); |
| 79 | + |
| 80 | + ResolvedLoc(); |
| 81 | +}; |
| 82 | + |
| 83 | +typedef std::vector<ResolvedLoc> ResolvedLocVector; |
| 84 | + |
| 85 | +/// Create an empty `std::vector<ResolvedLoc>`. |
| 86 | +/// |
| 87 | +/// - Note: This can't be imported as an initializer on |
| 88 | +/// `BridgedResolvedLocVector` |
| 89 | +/// because initializers without any arguments aren't imported to Swift |
| 90 | +SWIFT_NAME("ResolvedLocVector.empty()") |
| 91 | +ResolvedLocVector ResolvedLocVector_createEmpty(); |
| 92 | + |
| 93 | +typedef std::vector<BridgedSourceLoc> SourceLocVector; |
| 94 | + |
| 95 | +/// Needed so that we can manually conform `SourceLocVectorIterator` to |
| 96 | +/// `UnsafeCxxInputIterator` on the Swift side because the conformance is not |
| 97 | +/// automatically generated by C++ interop by a Swift 5.8 compiler. |
| 98 | +typedef std::vector<BridgedSourceLoc>::const_iterator SourceLocVectorIterator; |
| 99 | + |
| 100 | +SWIFT_NAME("SourceLocVectorIterator.equals(_:_:)") |
| 101 | +inline bool SourceLocVectorIterator_equal(const SourceLocVectorIterator &lhs, |
| 102 | + const SourceLocVectorIterator &rhs) { |
| 103 | + return lhs == rhs; |
| 104 | +} |
| 105 | + |
| 106 | +#endif |
0 commit comments