|
1 | | -//===--- Availability.h - Swift Availability Structures ---------*- C++ -*-===// |
| 1 | +//===--- AvailabilityRange.h - Swift Availability Range ---------*- C++ -*-===// |
2 | 2 | // |
3 | 3 | // This source file is part of the Swift.org open source project |
4 | 4 | // |
5 | | -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception |
7 | 7 | // |
8 | 8 | // See https://swift.org/LICENSE.txt for license information |
9 | 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
10 | 10 | // |
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 | // |
13 | | -// This file defines data structures for API availability. |
| 13 | +// This file defines the AvailabilityRange utility. |
14 | 14 | // |
15 | 15 | //===----------------------------------------------------------------------===// |
16 | 16 |
|
17 | | -#ifndef SWIFT_AST_AVAILABILITY_H |
18 | | -#define SWIFT_AST_AVAILABILITY_H |
| 17 | +#ifndef SWIFT_AST_AVAILABILITY_RANGE_H |
| 18 | +#define SWIFT_AST_AVAILABILITY_RANGE_H |
19 | 19 |
|
20 | | -#include "swift/AST/PlatformKind.h" |
21 | | -#include "swift/AST/Type.h" |
22 | 20 | #include "swift/Basic/LLVM.h" |
23 | 21 | #include "llvm/ADT/FoldingSet.h" |
24 | 22 | #include "llvm/Support/VersionTuple.h" |
25 | 23 | #include <optional> |
26 | 24 |
|
27 | 25 | namespace swift { |
28 | 26 | class ASTContext; |
29 | | -class AvailableAttr; |
30 | | -class BackDeployedAttr; |
31 | | -class Decl; |
32 | 27 |
|
33 | 28 | /// A lattice of version ranges of the form [x.y.z, +Inf). |
34 | 29 | class VersionRange { |
@@ -335,95 +330,6 @@ class AvailabilityRange { |
335 | 330 | } |
336 | 331 | }; |
337 | 332 |
|
338 | | -class AvailabilityInference { |
339 | | -public: |
340 | | - /// Returns the decl that should be considered the parent decl of the given |
341 | | - /// decl when looking for inherited availability annotations. |
342 | | - static const Decl *parentDeclForInferredAvailability(const Decl *D); |
343 | | - |
344 | | - /// Infers the common availability required to access an array of |
345 | | - /// declarations and adds attributes reflecting that availability |
346 | | - /// to ToDecl. |
347 | | - static void |
348 | | - applyInferredAvailableAttrs(Decl *ToDecl, |
349 | | - ArrayRef<const Decl *> InferredFromDecls); |
350 | | - |
351 | | - static AvailabilityRange inferForType(Type t); |
352 | | - |
353 | | - /// Returns the range of platform versions in which the decl is available. |
354 | | - static AvailabilityRange availableRange(const Decl *D); |
355 | | - |
356 | | - /// Returns the range of platform versions in which the decl is available and |
357 | | - /// the attribute which determined this range (which may be `nullptr` if the |
358 | | - /// declaration is always available. |
359 | | - static std::pair<AvailabilityRange, const AvailableAttr *> |
360 | | - availableRangeAndAttr(const Decl *D); |
361 | | - |
362 | | - /// Returns true is the declaration is `@_spi_available`. |
363 | | - static bool isAvailableAsSPI(const Decl *D); |
364 | | - |
365 | | - /// Returns the range of platform versions in which a declaration with the |
366 | | - /// given `@available` attribute is available. |
367 | | - /// |
368 | | - /// NOTE: The attribute must be active on the current platform. |
369 | | - static AvailabilityRange availableRange(const AvailableAttr *attr, |
370 | | - ASTContext &C); |
371 | | - |
372 | | - /// Returns the attribute that should be used to determine the availability |
373 | | - /// range of the given declaration, or nullptr if there is none. |
374 | | - static const AvailableAttr *attrForAnnotatedAvailableRange(const Decl *D); |
375 | | - |
376 | | - /// Returns the context for which the declaration |
377 | | - /// is annotated as available, or None if the declaration |
378 | | - /// has no availability annotation. |
379 | | - static std::optional<AvailabilityRange> |
380 | | - annotatedAvailableRange(const Decl *D); |
381 | | - |
382 | | - static AvailabilityRange |
383 | | - annotatedAvailableRangeForAttr(const Decl *D, const SpecializeAttr *attr, |
384 | | - ASTContext &ctx); |
385 | | - |
386 | | - /// For the attribute's introduction version, update the platform and version |
387 | | - /// values to the re-mapped platform's, if using a fallback platform. |
388 | | - /// Returns `true` if a remap occured. |
389 | | - static bool updateIntroducedPlatformForFallback( |
390 | | - const AvailableAttr *attr, const ASTContext &Ctx, |
391 | | - llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer); |
392 | | - |
393 | | - /// For the attribute's deprecation version, update the platform and version |
394 | | - /// values to the re-mapped platform's, if using a fallback platform. |
395 | | - /// Returns `true` if a remap occured. |
396 | | - static bool updateDeprecatedPlatformForFallback( |
397 | | - const AvailableAttr *attr, const ASTContext &Ctx, |
398 | | - llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer); |
399 | | - |
400 | | - /// For the attribute's obsoletion version, update the platform and version |
401 | | - /// values to the re-mapped platform's, if using a fallback platform. |
402 | | - /// Returns `true` if a remap occured. |
403 | | - static bool updateObsoletedPlatformForFallback( |
404 | | - const AvailableAttr *attr, const ASTContext &Ctx, |
405 | | - llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer); |
406 | | - |
407 | | - static void updatePlatformStringForFallback( |
408 | | - const AvailableAttr *attr, const ASTContext &Ctx, |
409 | | - llvm::StringRef &Platform); |
410 | | - |
411 | | - /// For the attribute's before version, update the platform and version |
412 | | - /// values to the re-mapped platform's, if using a fallback platform. |
413 | | - /// Returns `true` if a remap occured. |
414 | | - static bool updateBeforePlatformForFallback(const BackDeployedAttr *attr, |
415 | | - const ASTContext &Ctx, |
416 | | - llvm::StringRef &Platform, |
417 | | - llvm::VersionTuple &PlatformVer); |
418 | | -}; |
419 | | - |
420 | | -/// Given a declaration upon which an availability attribute would appear in |
421 | | -/// concrete syntax, return a declaration to which the parser |
422 | | -/// actually attaches the attribute in the abstract syntax tree. We use this |
423 | | -/// function to determine whether the concrete syntax already has an |
424 | | -/// availability attribute. |
425 | | -const Decl *abstractSyntaxDeclForAvailableAttribute(const Decl *D); |
426 | | - |
427 | 333 | } // end namespace swift |
428 | 334 |
|
429 | 335 | #endif |
0 commit comments