mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC] Factor out DiagnosticArgument into a new file
This commit is contained in:
208
include/swift/AST/DiagnosticArgument.h
Normal file
208
include/swift/AST/DiagnosticArgument.h
Normal file
@@ -0,0 +1,208 @@
|
||||
//===--- DiagnosticArgument.h -----------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2025 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_DIAGNOSTIC_ARGUMENT_H
|
||||
#define SWIFT_AST_DIAGNOSTIC_ARGUMENT_H
|
||||
|
||||
#include "swift/AST/ActorIsolation.h"
|
||||
#include "swift/AST/AvailabilityDomain.h"
|
||||
#include "swift/AST/DiagnosticConsumer.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/AST/LayoutConstraint.h"
|
||||
#include "swift/AST/TypeLoc.h"
|
||||
#include "swift/Basic/Version.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
|
||||
namespace clang {
|
||||
class NamedDecl;
|
||||
class Type;
|
||||
} // namespace clang
|
||||
|
||||
namespace swift {
|
||||
|
||||
class Decl;
|
||||
class DeclAttribute;
|
||||
class TypeRepr;
|
||||
|
||||
enum class DescriptivePatternKind : uint8_t;
|
||||
enum class DescriptiveDeclKind : uint8_t;
|
||||
enum class ReferenceOwnership : uint8_t;
|
||||
enum class SelfAccessKind : uint8_t;
|
||||
enum class StaticSpellingKind : uint8_t;
|
||||
enum class StmtKind;
|
||||
|
||||
/// A family of wrapper types for compiler data types that forces its
|
||||
/// underlying data to be formatted with full qualification.
|
||||
///
|
||||
/// So far, this is only useful for \c Type, hence the SFINAE'ing.
|
||||
template <typename T, typename = void>
|
||||
struct FullyQualified {};
|
||||
|
||||
template <typename T>
|
||||
struct FullyQualified<
|
||||
T, typename std::enable_if<std::is_convertible<T, Type>::value>::type> {
|
||||
Type t;
|
||||
|
||||
public:
|
||||
FullyQualified(T t) : t(t) {};
|
||||
|
||||
Type getType() const { return t; }
|
||||
};
|
||||
|
||||
struct WitnessType {
|
||||
Type t;
|
||||
|
||||
WitnessType(Type t) : t(t) {}
|
||||
|
||||
Type getType() { return t; }
|
||||
};
|
||||
|
||||
/// Describes the kind of diagnostic argument we're storing.
|
||||
enum class DiagnosticArgumentKind {
|
||||
String,
|
||||
Integer,
|
||||
Unsigned,
|
||||
Identifier,
|
||||
ObjCSelector,
|
||||
Decl,
|
||||
Type,
|
||||
TypeRepr,
|
||||
FullyQualifiedType,
|
||||
WitnessType,
|
||||
DescriptivePatternKind,
|
||||
SelfAccessKind,
|
||||
ReferenceOwnership,
|
||||
StaticSpellingKind,
|
||||
DescriptiveDeclKind,
|
||||
DescriptiveStmtKind,
|
||||
DeclAttribute,
|
||||
AvailabilityDomain,
|
||||
AvailabilityRange,
|
||||
VersionTuple,
|
||||
LayoutConstraint,
|
||||
ActorIsolation,
|
||||
IsolationSource,
|
||||
Diagnostic,
|
||||
ClangDecl,
|
||||
ClangType,
|
||||
};
|
||||
|
||||
/// Variant type that holds a single diagnostic argument of a known
|
||||
/// type.
|
||||
///
|
||||
/// All diagnostic arguments are converted to an instance of this class.
|
||||
class DiagnosticArgument {
|
||||
DiagnosticArgumentKind Kind;
|
||||
union {
|
||||
int IntegerVal;
|
||||
unsigned UnsignedVal;
|
||||
StringRef StringVal;
|
||||
DeclNameRef IdentifierVal;
|
||||
ObjCSelector ObjCSelectorVal;
|
||||
const Decl *TheDecl;
|
||||
Type TypeVal;
|
||||
TypeRepr *TyR;
|
||||
FullyQualified<Type> FullyQualifiedTypeVal;
|
||||
WitnessType WitnessTypeVal;
|
||||
DescriptivePatternKind DescriptivePatternKindVal;
|
||||
SelfAccessKind SelfAccessKindVal;
|
||||
ReferenceOwnership ReferenceOwnershipVal;
|
||||
StaticSpellingKind StaticSpellingKindVal;
|
||||
DescriptiveDeclKind DescriptiveDeclKindVal;
|
||||
StmtKind DescriptiveStmtKindVal;
|
||||
const DeclAttribute *DeclAttributeVal;
|
||||
AvailabilityDomain AvailabilityDomainVal;
|
||||
AvailabilityRange AvailabilityRangeVal;
|
||||
llvm::VersionTuple VersionVal;
|
||||
LayoutConstraint LayoutConstraintVal;
|
||||
ActorIsolation ActorIsolationVal;
|
||||
IsolationSource IsolationSourceVal;
|
||||
DiagnosticInfo *DiagnosticVal;
|
||||
const clang::NamedDecl *ClangDecl;
|
||||
const clang::Type *ClangType;
|
||||
};
|
||||
|
||||
public:
|
||||
DiagnosticArgument(StringRef S);
|
||||
DiagnosticArgument(int I);
|
||||
DiagnosticArgument(unsigned I);
|
||||
DiagnosticArgument(DeclNameRef R);
|
||||
DiagnosticArgument(DeclName D);
|
||||
DiagnosticArgument(DeclBaseName D);
|
||||
DiagnosticArgument(Identifier I);
|
||||
DiagnosticArgument(ObjCSelector S);
|
||||
DiagnosticArgument(const Decl *VD);
|
||||
DiagnosticArgument(Type T);
|
||||
DiagnosticArgument(TypeRepr *T);
|
||||
DiagnosticArgument(FullyQualified<Type> FQT);
|
||||
DiagnosticArgument(WitnessType WT);
|
||||
DiagnosticArgument(const TypeLoc &TL);
|
||||
DiagnosticArgument(DescriptivePatternKind DPK);
|
||||
DiagnosticArgument(ReferenceOwnership RO);
|
||||
DiagnosticArgument(SelfAccessKind SAK);
|
||||
DiagnosticArgument(StaticSpellingKind SSK);
|
||||
DiagnosticArgument(DescriptiveDeclKind DDK);
|
||||
DiagnosticArgument(StmtKind SK);
|
||||
DiagnosticArgument(const DeclAttribute *attr);
|
||||
DiagnosticArgument(const AvailabilityDomain domain);
|
||||
DiagnosticArgument(const AvailabilityRange &range);
|
||||
DiagnosticArgument(llvm::VersionTuple version);
|
||||
DiagnosticArgument(LayoutConstraint L);
|
||||
DiagnosticArgument(ActorIsolation AI);
|
||||
DiagnosticArgument(IsolationSource IS);
|
||||
DiagnosticArgument(DiagnosticInfo *D);
|
||||
DiagnosticArgument(const clang::NamedDecl *ND);
|
||||
DiagnosticArgument(const clang::Type *Ty);
|
||||
|
||||
/// Initializes a diagnostic argument using the underlying type of the
|
||||
/// given enum.
|
||||
template <
|
||||
typename EnumType,
|
||||
typename std::enable_if<std::is_enum<EnumType>::value>::type * = nullptr>
|
||||
DiagnosticArgument(EnumType value)
|
||||
: DiagnosticArgument(
|
||||
static_cast<typename std::underlying_type<EnumType>::type>(value)) {
|
||||
}
|
||||
|
||||
DiagnosticArgumentKind getKind() const;
|
||||
|
||||
StringRef getAsString() const;
|
||||
int getAsInteger() const;
|
||||
unsigned getAsUnsigned() const;
|
||||
DeclNameRef getAsIdentifier() const;
|
||||
ObjCSelector getAsObjCSelector() const;
|
||||
const Decl *getAsDecl() const;
|
||||
Type getAsType() const;
|
||||
TypeRepr *getAsTypeRepr() const;
|
||||
FullyQualified<Type> getAsFullyQualifiedType() const;
|
||||
WitnessType getAsWitnessType() const;
|
||||
DescriptivePatternKind getAsDescriptivePatternKind() const;
|
||||
ReferenceOwnership getAsReferenceOwnership() const;
|
||||
SelfAccessKind getAsSelfAccessKind() const;
|
||||
StaticSpellingKind getAsStaticSpellingKind() const;
|
||||
DescriptiveDeclKind getAsDescriptiveDeclKind() const;
|
||||
StmtKind getAsDescriptiveStmtKind() const;
|
||||
const DeclAttribute *getAsDeclAttribute() const;
|
||||
const AvailabilityDomain getAsAvailabilityDomain() const;
|
||||
const AvailabilityRange getAsAvailabilityRange() const;
|
||||
llvm::VersionTuple getAsVersionTuple() const;
|
||||
LayoutConstraint getAsLayoutConstraint() const;
|
||||
ActorIsolation getAsActorIsolation() const;
|
||||
IsolationSource getAsIsolationSource() const;
|
||||
DiagnosticInfo *getAsDiagnostic() const;
|
||||
const clang::NamedDecl *getAsClangDecl() const;
|
||||
const clang::Type *getAsClangType() const;
|
||||
};
|
||||
|
||||
} // namespace swift
|
||||
|
||||
#endif /* SWIFT_AST_DIAGNOSTIC_ARGUMENT_H */
|
||||
@@ -18,9 +18,8 @@
|
||||
#ifndef SWIFT_BASIC_DIAGNOSTICENGINE_H
|
||||
#define SWIFT_BASIC_DIAGNOSTICENGINE_H
|
||||
|
||||
#include "swift/AST/ActorIsolation.h"
|
||||
#include "swift/AST/AvailabilityDomain.h"
|
||||
#include "swift/AST/DeclNameLoc.h"
|
||||
#include "swift/AST/DiagnosticArgument.h"
|
||||
#include "swift/AST/DiagnosticConsumer.h"
|
||||
#include "swift/AST/TypeLoc.h"
|
||||
#include "swift/Basic/PrintDiagnosticNamesMode.h"
|
||||
@@ -35,7 +34,6 @@
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/SaveAndRestore.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
|
||||
namespace clang {
|
||||
class NamedDecl;
|
||||
@@ -43,28 +41,14 @@ class Type;
|
||||
}
|
||||
|
||||
namespace swift {
|
||||
class ConstructorDecl;
|
||||
class ClosureExpr;
|
||||
class Decl;
|
||||
class DeclAttribute;
|
||||
class DiagnosticEngine;
|
||||
class FuncDecl;
|
||||
class GeneratedSourceInfo;
|
||||
class SourceManager;
|
||||
class TypeAliasDecl;
|
||||
class ValueDecl;
|
||||
class SourceFile;
|
||||
|
||||
enum class CXXStdlibKind : uint8_t;
|
||||
enum class DescriptivePatternKind : uint8_t;
|
||||
enum class DiagGroupID : uint16_t;
|
||||
enum class SelfAccessKind : uint8_t;
|
||||
enum class ReferenceOwnership : uint8_t;
|
||||
enum class StaticSpellingKind : uint8_t;
|
||||
enum class DescriptiveDeclKind : uint8_t;
|
||||
enum class DeclAttrKind : unsigned;
|
||||
enum class StmtKind;
|
||||
|
||||
/// Enumeration describing all of possible diagnostics.
|
||||
///
|
||||
/// Each of the diagnostics described in Diagnostics.def has an entry in
|
||||
@@ -101,371 +85,10 @@ namespace swift {
|
||||
using DiagArgTuple =
|
||||
std::tuple<typename detail::PassArgument<ArgTypes>::type...>;
|
||||
|
||||
/// A family of wrapper types for compiler data types that forces its
|
||||
/// underlying data to be formatted with full qualification.
|
||||
///
|
||||
/// So far, this is only useful for \c Type, hence the SFINAE'ing.
|
||||
template <typename T, typename = void> struct FullyQualified {};
|
||||
|
||||
template <typename T>
|
||||
struct FullyQualified<
|
||||
T, typename std::enable_if<std::is_convertible<T, Type>::value>::type> {
|
||||
Type t;
|
||||
|
||||
public:
|
||||
FullyQualified(T t) : t(t){};
|
||||
|
||||
Type getType() const { return t; }
|
||||
};
|
||||
|
||||
struct WitnessType {
|
||||
Type t;
|
||||
|
||||
WitnessType(Type t) : t(t) {}
|
||||
|
||||
Type getType() { return t; }
|
||||
};
|
||||
|
||||
/// Describes the kind of diagnostic argument we're storing.
|
||||
///
|
||||
enum class DiagnosticArgumentKind {
|
||||
String,
|
||||
Integer,
|
||||
Unsigned,
|
||||
Identifier,
|
||||
ObjCSelector,
|
||||
Decl,
|
||||
Type,
|
||||
TypeRepr,
|
||||
FullyQualifiedType,
|
||||
WitnessType,
|
||||
DescriptivePatternKind,
|
||||
SelfAccessKind,
|
||||
ReferenceOwnership,
|
||||
StaticSpellingKind,
|
||||
DescriptiveDeclKind,
|
||||
DescriptiveStmtKind,
|
||||
DeclAttribute,
|
||||
AvailabilityDomain,
|
||||
AvailabilityRange,
|
||||
VersionTuple,
|
||||
LayoutConstraint,
|
||||
ActorIsolation,
|
||||
IsolationSource,
|
||||
Diagnostic,
|
||||
ClangDecl,
|
||||
ClangType,
|
||||
};
|
||||
|
||||
namespace diag {
|
||||
enum class RequirementKind : uint8_t;
|
||||
}
|
||||
|
||||
/// Variant type that holds a single diagnostic argument of a known
|
||||
/// type.
|
||||
///
|
||||
/// All diagnostic arguments are converted to an instance of this class.
|
||||
class DiagnosticArgument {
|
||||
DiagnosticArgumentKind Kind;
|
||||
union {
|
||||
int IntegerVal;
|
||||
unsigned UnsignedVal;
|
||||
StringRef StringVal;
|
||||
DeclNameRef IdentifierVal;
|
||||
ObjCSelector ObjCSelectorVal;
|
||||
const Decl *TheDecl;
|
||||
Type TypeVal;
|
||||
TypeRepr *TyR;
|
||||
FullyQualified<Type> FullyQualifiedTypeVal;
|
||||
WitnessType WitnessTypeVal;
|
||||
DescriptivePatternKind DescriptivePatternKindVal;
|
||||
SelfAccessKind SelfAccessKindVal;
|
||||
ReferenceOwnership ReferenceOwnershipVal;
|
||||
StaticSpellingKind StaticSpellingKindVal;
|
||||
DescriptiveDeclKind DescriptiveDeclKindVal;
|
||||
StmtKind DescriptiveStmtKindVal;
|
||||
const DeclAttribute *DeclAttributeVal;
|
||||
AvailabilityDomain AvailabilityDomainVal;
|
||||
AvailabilityRange AvailabilityRangeVal;
|
||||
llvm::VersionTuple VersionVal;
|
||||
LayoutConstraint LayoutConstraintVal;
|
||||
ActorIsolation ActorIsolationVal;
|
||||
IsolationSource IsolationSourceVal;
|
||||
DiagnosticInfo *DiagnosticVal;
|
||||
const clang::NamedDecl *ClangDecl;
|
||||
const clang::Type *ClangType;
|
||||
};
|
||||
|
||||
public:
|
||||
DiagnosticArgument(StringRef S)
|
||||
: Kind(DiagnosticArgumentKind::String), StringVal(S) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(int I)
|
||||
: Kind(DiagnosticArgumentKind::Integer), IntegerVal(I) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(unsigned I)
|
||||
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(DeclNameRef R)
|
||||
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(R) {}
|
||||
|
||||
DiagnosticArgument(DeclName D)
|
||||
: Kind(DiagnosticArgumentKind::Identifier),
|
||||
IdentifierVal(DeclNameRef(D)) {}
|
||||
|
||||
DiagnosticArgument(DeclBaseName D)
|
||||
: Kind(DiagnosticArgumentKind::Identifier),
|
||||
IdentifierVal(DeclNameRef(D)) {}
|
||||
|
||||
DiagnosticArgument(Identifier I)
|
||||
: Kind(DiagnosticArgumentKind::Identifier),
|
||||
IdentifierVal(DeclNameRef(I)) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(ObjCSelector S)
|
||||
: Kind(DiagnosticArgumentKind::ObjCSelector), ObjCSelectorVal(S) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(const Decl *VD)
|
||||
: Kind(DiagnosticArgumentKind::Decl), TheDecl(VD) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(Type T)
|
||||
: Kind(DiagnosticArgumentKind::Type), TypeVal(T) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(TypeRepr *T)
|
||||
: Kind(DiagnosticArgumentKind::TypeRepr), TyR(T) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(FullyQualified<Type> FQT)
|
||||
: Kind(DiagnosticArgumentKind::FullyQualifiedType),
|
||||
FullyQualifiedTypeVal(FQT) {}
|
||||
|
||||
DiagnosticArgument(WitnessType WT)
|
||||
: Kind(DiagnosticArgumentKind::WitnessType),
|
||||
WitnessTypeVal(WT) {}
|
||||
|
||||
DiagnosticArgument(const TypeLoc &TL) {
|
||||
if (TypeRepr *tyR = TL.getTypeRepr()) {
|
||||
Kind = DiagnosticArgumentKind::TypeRepr;
|
||||
TyR = tyR;
|
||||
} else {
|
||||
Kind = DiagnosticArgumentKind::Type;
|
||||
TypeVal = TL.getType();
|
||||
}
|
||||
}
|
||||
|
||||
DiagnosticArgument(DescriptivePatternKind DPK)
|
||||
: Kind(DiagnosticArgumentKind::DescriptivePatternKind),
|
||||
DescriptivePatternKindVal(DPK) {}
|
||||
|
||||
DiagnosticArgument(ReferenceOwnership RO)
|
||||
: Kind(DiagnosticArgumentKind::ReferenceOwnership),
|
||||
ReferenceOwnershipVal(RO) {}
|
||||
|
||||
DiagnosticArgument(SelfAccessKind SAK)
|
||||
: Kind(DiagnosticArgumentKind::SelfAccessKind),
|
||||
SelfAccessKindVal(SAK) {}
|
||||
|
||||
DiagnosticArgument(StaticSpellingKind SSK)
|
||||
: Kind(DiagnosticArgumentKind::StaticSpellingKind),
|
||||
StaticSpellingKindVal(SSK) {}
|
||||
|
||||
DiagnosticArgument(DescriptiveDeclKind DDK)
|
||||
: Kind(DiagnosticArgumentKind::DescriptiveDeclKind),
|
||||
DescriptiveDeclKindVal(DDK) {}
|
||||
|
||||
DiagnosticArgument(StmtKind SK)
|
||||
: Kind(DiagnosticArgumentKind::DescriptiveStmtKind),
|
||||
DescriptiveStmtKindVal(SK) {}
|
||||
|
||||
DiagnosticArgument(const DeclAttribute *attr)
|
||||
: Kind(DiagnosticArgumentKind::DeclAttribute),
|
||||
DeclAttributeVal(attr) {}
|
||||
|
||||
DiagnosticArgument(const AvailabilityDomain domain)
|
||||
: Kind(DiagnosticArgumentKind::AvailabilityDomain),
|
||||
AvailabilityDomainVal(domain) {}
|
||||
|
||||
DiagnosticArgument(const AvailabilityRange &range)
|
||||
: Kind(DiagnosticArgumentKind::AvailabilityRange),
|
||||
AvailabilityRangeVal(range) {}
|
||||
|
||||
DiagnosticArgument(llvm::VersionTuple version)
|
||||
: Kind(DiagnosticArgumentKind::VersionTuple),
|
||||
VersionVal(version) { }
|
||||
|
||||
DiagnosticArgument(LayoutConstraint L)
|
||||
: Kind(DiagnosticArgumentKind::LayoutConstraint), LayoutConstraintVal(L) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(ActorIsolation AI)
|
||||
: Kind(DiagnosticArgumentKind::ActorIsolation),
|
||||
ActorIsolationVal(AI) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(IsolationSource IS)
|
||||
: Kind(DiagnosticArgumentKind::IsolationSource),
|
||||
IsolationSourceVal(IS){
|
||||
}
|
||||
|
||||
DiagnosticArgument(DiagnosticInfo *D)
|
||||
: Kind(DiagnosticArgumentKind::Diagnostic),
|
||||
DiagnosticVal(D) {
|
||||
}
|
||||
|
||||
DiagnosticArgument(const clang::NamedDecl *ND)
|
||||
: Kind(DiagnosticArgumentKind::ClangDecl), ClangDecl(ND) {}
|
||||
|
||||
DiagnosticArgument(const clang::Type *Ty)
|
||||
: Kind(DiagnosticArgumentKind::ClangType), ClangType(Ty) {}
|
||||
|
||||
/// Initializes a diagnostic argument using the underlying type of the
|
||||
/// given enum.
|
||||
template<
|
||||
typename EnumType,
|
||||
typename std::enable_if<std::is_enum<EnumType>::value>::type* = nullptr>
|
||||
DiagnosticArgument(EnumType value)
|
||||
: DiagnosticArgument(
|
||||
static_cast<typename std::underlying_type<EnumType>::type>(value)) {}
|
||||
|
||||
DiagnosticArgumentKind getKind() const { return Kind; }
|
||||
|
||||
StringRef getAsString() const {
|
||||
assert(Kind == DiagnosticArgumentKind::String);
|
||||
return StringVal;
|
||||
}
|
||||
|
||||
int getAsInteger() const {
|
||||
assert(Kind == DiagnosticArgumentKind::Integer);
|
||||
return IntegerVal;
|
||||
}
|
||||
|
||||
unsigned getAsUnsigned() const {
|
||||
assert(Kind == DiagnosticArgumentKind::Unsigned);
|
||||
return UnsignedVal;
|
||||
}
|
||||
|
||||
DeclNameRef getAsIdentifier() const {
|
||||
assert(Kind == DiagnosticArgumentKind::Identifier);
|
||||
return IdentifierVal;
|
||||
}
|
||||
|
||||
ObjCSelector getAsObjCSelector() const {
|
||||
assert(Kind == DiagnosticArgumentKind::ObjCSelector);
|
||||
return ObjCSelectorVal;
|
||||
}
|
||||
|
||||
const Decl *getAsDecl() const {
|
||||
assert(Kind == DiagnosticArgumentKind::Decl);
|
||||
return TheDecl;
|
||||
}
|
||||
|
||||
Type getAsType() const {
|
||||
assert(Kind == DiagnosticArgumentKind::Type);
|
||||
return TypeVal;
|
||||
}
|
||||
|
||||
TypeRepr *getAsTypeRepr() const {
|
||||
assert(Kind == DiagnosticArgumentKind::TypeRepr);
|
||||
return TyR;
|
||||
}
|
||||
|
||||
FullyQualified<Type> getAsFullyQualifiedType() const {
|
||||
assert(Kind == DiagnosticArgumentKind::FullyQualifiedType);
|
||||
return FullyQualifiedTypeVal;
|
||||
}
|
||||
|
||||
WitnessType getAsWitnessType() const {
|
||||
assert(Kind == DiagnosticArgumentKind::WitnessType);
|
||||
return WitnessTypeVal;
|
||||
}
|
||||
|
||||
DescriptivePatternKind getAsDescriptivePatternKind() const {
|
||||
assert(Kind == DiagnosticArgumentKind::DescriptivePatternKind);
|
||||
return DescriptivePatternKindVal;
|
||||
}
|
||||
|
||||
ReferenceOwnership getAsReferenceOwnership() const {
|
||||
assert(Kind == DiagnosticArgumentKind::ReferenceOwnership);
|
||||
return ReferenceOwnershipVal;
|
||||
}
|
||||
|
||||
SelfAccessKind getAsSelfAccessKind() const {
|
||||
assert(Kind == DiagnosticArgumentKind::SelfAccessKind);
|
||||
return SelfAccessKindVal;
|
||||
}
|
||||
|
||||
StaticSpellingKind getAsStaticSpellingKind() const {
|
||||
assert(Kind == DiagnosticArgumentKind::StaticSpellingKind);
|
||||
return StaticSpellingKindVal;
|
||||
}
|
||||
|
||||
DescriptiveDeclKind getAsDescriptiveDeclKind() const {
|
||||
assert(Kind == DiagnosticArgumentKind::DescriptiveDeclKind);
|
||||
return DescriptiveDeclKindVal;
|
||||
}
|
||||
|
||||
StmtKind getAsDescriptiveStmtKind() const {
|
||||
assert(Kind == DiagnosticArgumentKind::DescriptiveStmtKind);
|
||||
return DescriptiveStmtKindVal;
|
||||
}
|
||||
|
||||
const DeclAttribute *getAsDeclAttribute() const {
|
||||
assert(Kind == DiagnosticArgumentKind::DeclAttribute);
|
||||
return DeclAttributeVal;
|
||||
}
|
||||
|
||||
const AvailabilityDomain getAsAvailabilityDomain() const {
|
||||
assert(Kind == DiagnosticArgumentKind::AvailabilityDomain);
|
||||
return AvailabilityDomainVal;
|
||||
}
|
||||
|
||||
const AvailabilityRange getAsAvailabilityRange() const {
|
||||
assert(Kind == DiagnosticArgumentKind::AvailabilityRange);
|
||||
return AvailabilityRangeVal;
|
||||
}
|
||||
|
||||
llvm::VersionTuple getAsVersionTuple() const {
|
||||
assert(Kind == DiagnosticArgumentKind::VersionTuple);
|
||||
return VersionVal;
|
||||
}
|
||||
|
||||
LayoutConstraint getAsLayoutConstraint() const {
|
||||
assert(Kind == DiagnosticArgumentKind::LayoutConstraint);
|
||||
return LayoutConstraintVal;
|
||||
}
|
||||
|
||||
ActorIsolation getAsActorIsolation() const {
|
||||
assert(Kind == DiagnosticArgumentKind::ActorIsolation);
|
||||
return ActorIsolationVal;
|
||||
}
|
||||
|
||||
IsolationSource getAsIsolationSource() const {
|
||||
assert(Kind == DiagnosticArgumentKind::IsolationSource);
|
||||
return IsolationSourceVal;
|
||||
}
|
||||
|
||||
DiagnosticInfo *getAsDiagnostic() const {
|
||||
assert(Kind == DiagnosticArgumentKind::Diagnostic);
|
||||
return DiagnosticVal;
|
||||
}
|
||||
|
||||
const clang::NamedDecl *getAsClangDecl() const {
|
||||
assert(Kind == DiagnosticArgumentKind::ClangDecl);
|
||||
return ClangDecl;
|
||||
}
|
||||
|
||||
const clang::Type *getAsClangType() const {
|
||||
assert(Kind == DiagnosticArgumentKind::ClangType);
|
||||
return ClangType;
|
||||
}
|
||||
};
|
||||
|
||||
/// Describes the current behavior to take with a diagnostic.
|
||||
/// Ordered from most severe to least.
|
||||
struct DiagnosticBehavior {
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
#include "swift/Config.h"
|
||||
|
||||
namespace swift {
|
||||
class ConstructorDecl;
|
||||
class SwitchStmt;
|
||||
class TypeAliasDecl;
|
||||
|
||||
template<typename ...ArgTypes>
|
||||
struct Diag;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "swift/AST/DiagnosticsCommon.h"
|
||||
|
||||
namespace swift {
|
||||
class SwitchStmt;
|
||||
namespace diag {
|
||||
|
||||
/// Describes the kind of requirement in a protocol.
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
namespace swift {
|
||||
class ASTScope;
|
||||
class AvailabilityScope;
|
||||
class GeneratedSourceInfo;
|
||||
class PersistentParserState;
|
||||
struct SourceFileExtras;
|
||||
class Token;
|
||||
|
||||
@@ -45,6 +45,7 @@ add_swift_host_library(swiftAST STATIC
|
||||
DeclContext.cpp
|
||||
DeclContextDumper.cpp
|
||||
DeclNameLoc.cpp
|
||||
DiagnosticArgument.cpp
|
||||
DiagnosticBridge.cpp
|
||||
DiagnosticConsumer.cpp
|
||||
DiagnosticEngine.cpp
|
||||
|
||||
253
lib/AST/DiagnosticArgument.cpp
Normal file
253
lib/AST/DiagnosticArgument.cpp
Normal file
@@ -0,0 +1,253 @@
|
||||
//===--- DiagnosticArgument.cpp ---------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2025 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/DiagnosticArgument.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(StringRef S)
|
||||
: Kind(DiagnosticArgumentKind::String), StringVal(S) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(int I)
|
||||
: Kind(DiagnosticArgumentKind::Integer), IntegerVal(I) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(unsigned I)
|
||||
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(DeclNameRef R)
|
||||
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(R) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(DeclName D)
|
||||
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(DeclNameRef(D)) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(DeclBaseName D)
|
||||
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(DeclNameRef(D)) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(Identifier I)
|
||||
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(DeclNameRef(I)) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(ObjCSelector S)
|
||||
: Kind(DiagnosticArgumentKind::ObjCSelector), ObjCSelectorVal(S) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(const Decl *VD)
|
||||
: Kind(DiagnosticArgumentKind::Decl), TheDecl(VD) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(Type T)
|
||||
: Kind(DiagnosticArgumentKind::Type), TypeVal(T) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(TypeRepr *T)
|
||||
: Kind(DiagnosticArgumentKind::TypeRepr), TyR(T) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(FullyQualified<Type> FQT)
|
||||
: Kind(DiagnosticArgumentKind::FullyQualifiedType),
|
||||
FullyQualifiedTypeVal(FQT) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(WitnessType WT)
|
||||
: Kind(DiagnosticArgumentKind::WitnessType), WitnessTypeVal(WT) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(const TypeLoc &TL) {
|
||||
if (TypeRepr *tyR = TL.getTypeRepr()) {
|
||||
Kind = DiagnosticArgumentKind::TypeRepr;
|
||||
TyR = tyR;
|
||||
} else {
|
||||
Kind = DiagnosticArgumentKind::Type;
|
||||
TypeVal = TL.getType();
|
||||
}
|
||||
}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(DescriptivePatternKind DPK)
|
||||
: Kind(DiagnosticArgumentKind::DescriptivePatternKind),
|
||||
DescriptivePatternKindVal(DPK) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(ReferenceOwnership RO)
|
||||
: Kind(DiagnosticArgumentKind::ReferenceOwnership),
|
||||
ReferenceOwnershipVal(RO) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(SelfAccessKind SAK)
|
||||
: Kind(DiagnosticArgumentKind::SelfAccessKind), SelfAccessKindVal(SAK) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(StaticSpellingKind SSK)
|
||||
: Kind(DiagnosticArgumentKind::StaticSpellingKind),
|
||||
StaticSpellingKindVal(SSK) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(DescriptiveDeclKind DDK)
|
||||
: Kind(DiagnosticArgumentKind::DescriptiveDeclKind),
|
||||
DescriptiveDeclKindVal(DDK) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(StmtKind SK)
|
||||
: Kind(DiagnosticArgumentKind::DescriptiveStmtKind),
|
||||
DescriptiveStmtKindVal(SK) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(const DeclAttribute *attr)
|
||||
: Kind(DiagnosticArgumentKind::DeclAttribute), DeclAttributeVal(attr) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(const AvailabilityDomain domain)
|
||||
: Kind(DiagnosticArgumentKind::AvailabilityDomain),
|
||||
AvailabilityDomainVal(domain) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(const AvailabilityRange &range)
|
||||
: Kind(DiagnosticArgumentKind::AvailabilityRange),
|
||||
AvailabilityRangeVal(range) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(llvm::VersionTuple version)
|
||||
: Kind(DiagnosticArgumentKind::VersionTuple), VersionVal(version) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(LayoutConstraint L)
|
||||
: Kind(DiagnosticArgumentKind::LayoutConstraint), LayoutConstraintVal(L) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(ActorIsolation AI)
|
||||
: Kind(DiagnosticArgumentKind::ActorIsolation), ActorIsolationVal(AI) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(IsolationSource IS)
|
||||
: Kind(DiagnosticArgumentKind::IsolationSource), IsolationSourceVal(IS) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(DiagnosticInfo *D)
|
||||
: Kind(DiagnosticArgumentKind::Diagnostic), DiagnosticVal(D) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(const clang::NamedDecl *ND)
|
||||
: Kind(DiagnosticArgumentKind::ClangDecl), ClangDecl(ND) {}
|
||||
|
||||
DiagnosticArgument::DiagnosticArgument(const clang::Type *Ty)
|
||||
: Kind(DiagnosticArgumentKind::ClangType), ClangType(Ty) {}
|
||||
|
||||
DiagnosticArgumentKind DiagnosticArgument::getKind() const { return Kind; }
|
||||
|
||||
StringRef DiagnosticArgument::getAsString() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::String);
|
||||
return StringVal;
|
||||
}
|
||||
|
||||
int DiagnosticArgument::getAsInteger() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::Integer);
|
||||
return IntegerVal;
|
||||
}
|
||||
|
||||
unsigned DiagnosticArgument::getAsUnsigned() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::Unsigned);
|
||||
return UnsignedVal;
|
||||
}
|
||||
|
||||
DeclNameRef DiagnosticArgument::getAsIdentifier() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::Identifier);
|
||||
return IdentifierVal;
|
||||
}
|
||||
|
||||
ObjCSelector DiagnosticArgument::getAsObjCSelector() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::ObjCSelector);
|
||||
return ObjCSelectorVal;
|
||||
}
|
||||
|
||||
const Decl *DiagnosticArgument::getAsDecl() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::Decl);
|
||||
return TheDecl;
|
||||
}
|
||||
|
||||
Type DiagnosticArgument::getAsType() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::Type);
|
||||
return TypeVal;
|
||||
}
|
||||
|
||||
TypeRepr *DiagnosticArgument::getAsTypeRepr() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::TypeRepr);
|
||||
return TyR;
|
||||
}
|
||||
|
||||
FullyQualified<Type> DiagnosticArgument::getAsFullyQualifiedType() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::FullyQualifiedType);
|
||||
return FullyQualifiedTypeVal;
|
||||
}
|
||||
|
||||
WitnessType DiagnosticArgument::getAsWitnessType() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::WitnessType);
|
||||
return WitnessTypeVal;
|
||||
}
|
||||
|
||||
DescriptivePatternKind DiagnosticArgument::getAsDescriptivePatternKind() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::DescriptivePatternKind);
|
||||
return DescriptivePatternKindVal;
|
||||
}
|
||||
|
||||
ReferenceOwnership DiagnosticArgument::getAsReferenceOwnership() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::ReferenceOwnership);
|
||||
return ReferenceOwnershipVal;
|
||||
}
|
||||
|
||||
SelfAccessKind DiagnosticArgument::getAsSelfAccessKind() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::SelfAccessKind);
|
||||
return SelfAccessKindVal;
|
||||
}
|
||||
|
||||
StaticSpellingKind DiagnosticArgument::getAsStaticSpellingKind() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::StaticSpellingKind);
|
||||
return StaticSpellingKindVal;
|
||||
}
|
||||
|
||||
DescriptiveDeclKind DiagnosticArgument::getAsDescriptiveDeclKind() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::DescriptiveDeclKind);
|
||||
return DescriptiveDeclKindVal;
|
||||
}
|
||||
|
||||
StmtKind DiagnosticArgument::getAsDescriptiveStmtKind() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::DescriptiveStmtKind);
|
||||
return DescriptiveStmtKindVal;
|
||||
}
|
||||
|
||||
const DeclAttribute *DiagnosticArgument::getAsDeclAttribute() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::DeclAttribute);
|
||||
return DeclAttributeVal;
|
||||
}
|
||||
|
||||
const AvailabilityDomain DiagnosticArgument::getAsAvailabilityDomain() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::AvailabilityDomain);
|
||||
return AvailabilityDomainVal;
|
||||
}
|
||||
|
||||
const AvailabilityRange DiagnosticArgument::getAsAvailabilityRange() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::AvailabilityRange);
|
||||
return AvailabilityRangeVal;
|
||||
}
|
||||
|
||||
llvm::VersionTuple DiagnosticArgument::getAsVersionTuple() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::VersionTuple);
|
||||
return VersionVal;
|
||||
}
|
||||
|
||||
LayoutConstraint DiagnosticArgument::getAsLayoutConstraint() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::LayoutConstraint);
|
||||
return LayoutConstraintVal;
|
||||
}
|
||||
|
||||
ActorIsolation DiagnosticArgument::getAsActorIsolation() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::ActorIsolation);
|
||||
return ActorIsolationVal;
|
||||
}
|
||||
|
||||
IsolationSource DiagnosticArgument::getAsIsolationSource() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::IsolationSource);
|
||||
return IsolationSourceVal;
|
||||
}
|
||||
|
||||
DiagnosticInfo *DiagnosticArgument::getAsDiagnostic() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::Diagnostic);
|
||||
return DiagnosticVal;
|
||||
}
|
||||
|
||||
const clang::NamedDecl *DiagnosticArgument::getAsClangDecl() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::ClangDecl);
|
||||
return ClangDecl;
|
||||
}
|
||||
|
||||
const clang::Type *DiagnosticArgument::getAsClangType() const {
|
||||
ASSERT(Kind == DiagnosticArgumentKind::ClangType);
|
||||
return ClangType;
|
||||
}
|
||||
Reference in New Issue
Block a user