Merge pull request #79614 from DougGregor/conformance-attributes

Factor conformance attributes into their own separate structure.
This commit is contained in:
Doug Gregor
2025-02-25 17:07:59 -08:00
committed by GitHub
5 changed files with 83 additions and 80 deletions

View File

@@ -0,0 +1,46 @@
//===--- ConformanceLookup.h - Global conformance lookup --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_CONFORMANCEATTRIBUTES_H
#define SWIFT_AST_CONFORMANCEATTRIBUTES_H
#include "swift/Basic/SourceLoc.h"
namespace swift {
/// Describes all of the attributes that can occur on a conformance.
struct ConformanceAttributes {
/// The location of the "unchecked" attribute, if present.
SourceLoc uncheckedLoc;
/// The location of the "preconcurrency" attribute if present.
SourceLoc preconcurrencyLoc;
/// The location of the "unsafe" attribute if present.
SourceLoc unsafeLoc;
/// Merge other conformance attributes into this set.
ConformanceAttributes &
operator |=(const ConformanceAttributes &other) {
if (other.uncheckedLoc.isValid())
uncheckedLoc = other.uncheckedLoc;
if (other.preconcurrencyLoc.isValid())
preconcurrencyLoc = other.preconcurrencyLoc;
if (other.unsafeLoc.isValid())
unsafeLoc = other.unsafeLoc;
return *this;
}
};
}
#endif

View File

@@ -19,6 +19,7 @@
#include "swift/AST/ASTVisitor.h"
#include "swift/AST/CatchNode.h"
#include "swift/AST/ConformanceAttributes.h"
#include "swift/AST/GenericSignature.h"
#include "swift/AST/Identifier.h"
#include "swift/AST/Module.h"
@@ -603,14 +604,7 @@ void forEachPotentialAttachedMacro(
/// Describes an inherited nominal entry.
struct InheritedNominalEntry : Located<NominalTypeDecl *> {
/// The location of the "unchecked" attribute, if present.
SourceLoc uncheckedLoc;
/// The location of the "preconcurrency" attribute if present.
SourceLoc preconcurrencyLoc;
/// The location of the "unsafe" attribute if present.
SourceLoc unsafeLoc;
ConformanceAttributes attributes;
/// Whether this inherited entry was suppressed via "~".
bool isSuppressed;
@@ -618,10 +612,9 @@ struct InheritedNominalEntry : Located<NominalTypeDecl *> {
InheritedNominalEntry() { }
InheritedNominalEntry(NominalTypeDecl *item, SourceLoc loc,
SourceLoc uncheckedLoc, SourceLoc preconcurrencyLoc,
SourceLoc unsafeLoc, bool isSuppressed)
: Located(item, loc), uncheckedLoc(uncheckedLoc),
preconcurrencyLoc(preconcurrencyLoc), unsafeLoc(unsafeLoc),
ConformanceAttributes attributes,
bool isSuppressed)
: Located(item, loc), attributes(attributes),
isSuppressed(isSuppressed) {}
};