Skip to content

Commit 2a48efe

Browse files
committed
[AST] Add simple LifetimeAnnotation enum.
The enum just provides a convenience around mutually exclusive attributes which may be applied to decls and to SILFunctionArguments. This way we can switch over the flavor of annotation that a decl enjoys rather than having to remember the list of which might affect it, a list which is likely to grow.
1 parent 31b2d81 commit 2a48efe

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===--- LifetimeAnnotation.h - Lifetime-affecting attributes ---*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 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+
// Defines a simple type-safe wrapper around the annotations that affect value
14+
// lifetimes. Used for both Decls and SILFunctionArguments.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_AST_LIFETIMEANNOTATION_H
19+
#define SWIFT_AST_LIFETIMEANNOTATION_H
20+
21+
#include <cstdint>
22+
23+
namespace swift {
24+
25+
/// The annotation on a value (or type) explicitly indicating the lifetime that
26+
/// it (or its instances) should have.
27+
///
28+
/// A LifetimeAnnotation is one of the following three values:
29+
///
30+
/// 1) None: No annotation has been applied.
31+
/// 2) EagerMove: The @_eagerMove attribute has been applied.
32+
/// 3) Lexical: The @_lexical attribute has been applied.
33+
struct LifetimeAnnotation {
34+
enum Case : uint8_t {
35+
None,
36+
EagerMove,
37+
Lexical,
38+
} value;
39+
40+
LifetimeAnnotation(Case newValue) : value(newValue) {}
41+
42+
operator Case() const { return value; }
43+
44+
bool isSome() { return value != None; }
45+
};
46+
47+
} // namespace swift
48+
49+
#endif

0 commit comments

Comments
 (0)