|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2024 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 | +import SwiftSyntax |
| 14 | + |
| 15 | +/// Instances of a conforming type should provide an identifier to be used in code generation. |
| 16 | +public protocol IdentifierConvertible { |
| 17 | + /// The name of the instance as an identifer. |
| 18 | + var identifier: TokenSyntax { |
| 19 | + get |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +public extension IdentifierConvertible { |
| 24 | + /// ``identifier`` escaped as a base name suitable for call sites. |
| 25 | + var baseCallName: TokenSyntax { |
| 26 | + identifier.declNameOrVarCallName |
| 27 | + } |
| 28 | + |
| 29 | + /// ``identifier`` escaped as an enum case name suitable for call sites. |
| 30 | + var enumCaseCallName: TokenSyntax { |
| 31 | + memberCallName |
| 32 | + } |
| 33 | + |
| 34 | + /// ``identifier`` escaped as a member name suitable for call sites. |
| 35 | + var memberCallName: TokenSyntax { |
| 36 | + identifier.nonVarCallNameOrLabelDeclName |
| 37 | + } |
| 38 | + |
| 39 | + /// ``identifier`` escaped as an enum case name suitable for declaration sites. |
| 40 | + var enumCaseDeclName: TokenSyntax { |
| 41 | + identifier.declNameOrVarCallName |
| 42 | + } |
| 43 | + |
| 44 | + /// ``identifier`` escaped as a function name suitable for declaration sites. |
| 45 | + var funcDeclName: TokenSyntax { |
| 46 | + identifier.declNameOrVarCallName |
| 47 | + } |
| 48 | + |
| 49 | + /// ``identifier`` escaped as an argument label name suitable for declaration sites. |
| 50 | + var labelDeclName: TokenSyntax { |
| 51 | + identifier.nonVarCallNameOrLabelDeclName |
| 52 | + } |
| 53 | + |
| 54 | + /// ``identifier`` escaped as a variable name suitable for declaration sites. |
| 55 | + var varDeclName: TokenSyntax { |
| 56 | + identifier.declNameOrVarCallName |
| 57 | + } |
| 58 | +} |
0 commit comments