Skip to content

Commit f8e10bb

Browse files
committed
[CodeCompletion] Add static_assert to limit the max values of enums
1 parent 94a372e commit f8e10bb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ enum class SemanticContextKind : uint8_t {
452452

453453
/// A declaration imported from other module.
454454
OtherModule,
455+
456+
MAX_VALUE = OtherModule
455457
};
456458

457459
enum class CodeCompletionFlairBit: uint8_t {
@@ -564,6 +566,8 @@ enum class CodeCompletionOperatorKind : uint8_t {
564566
PipeEq, // |=
565567
PipePipe, // ||
566568
TildeEq, // ~=
569+
570+
MAX_VALUE = TildeEq
567571
};
568572

569573
enum class CodeCompletionKeywordKind : uint8_t {
@@ -612,12 +616,14 @@ enum class CompletionKind : uint8_t {
612616
TypeAttrBeginning,
613617
};
614618

615-
enum class CodeCompletionDiagnosticSeverity: uint8_t {
619+
enum class CodeCompletionDiagnosticSeverity : uint8_t {
616620
None,
617621
Error,
618622
Warning,
619623
Remark,
620624
Note,
625+
626+
MAX_VALUE = Note
621627
};
622628

623629
/// A single code completion result.
@@ -631,6 +637,8 @@ class CodeCompletionResult {
631637
Pattern,
632638
Literal,
633639
BuiltinOperator,
640+
641+
MAX_VALUE = BuiltinOperator
634642
};
635643

636644
/// Describes the relationship between the type of the completion results and
@@ -654,6 +662,8 @@ class CodeCompletionResult {
654662

655663
/// The result's type is identical to the type of the expected.
656664
Identical,
665+
666+
MAX_VALUE = Identical
657667
};
658668

659669
enum class NotRecommendedReason : uint8_t {
@@ -665,6 +675,8 @@ class CodeCompletionResult {
665675
InvalidAsyncContext,
666676
CrossActorReference,
667677
VariableUsedInOwnDefinition,
678+
679+
MAX_VALUE = VariableUsedInOwnDefinition
668680
};
669681

670682
private:
@@ -693,6 +705,14 @@ class CodeCompletionResult {
693705
CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3;
694706
StringRef DiagnosticMessage;
695707

708+
// Assertions for limiting max values of enums.
709+
static_assert(int(ResultKind::MAX_VALUE) < 1 << 3, "");
710+
static_assert(int(CodeCompletionOperatorKind::MAX_VALUE) < 1 << 6, "");
711+
static_assert(int(SemanticContextKind::MAX_VALUE) < 1 << 3, "");
712+
static_assert(int(NotRecommendedReason::MAX_VALUE) < 1 << 4, "");
713+
static_assert(int(ExpectedTypeRelation::MAX_VALUE) < 1 << 3, "");
714+
static_assert(int(CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3, "");
715+
696716
public:
697717
/// Constructs a \c Pattern, \c Keyword or \c BuiltinOperator result.
698718
///

0 commit comments

Comments
 (0)