mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Introduce a proper TypeAttribute class hierarchy.
The old TypeAttributes reprsentation wasn't too bad for a small number of simple attributes. Unfortunately, the number of attributes has grown over the years by quite a bit, which makes TypeAttributes fairly bulky even at just a single SourceLoc per attribute. The bigger problem is that we want to carry more information than that on some of these attributes, which is all super ad hoc and awkward. And given that we want to do some things for each attribute we see, like diagnosing unapplied attributes, the linear data structure does require a fair amount of extra work. I switched around the checking logic quite a bit in order to try to fit in with the new representation better. The most significant change here is the change to how we handle implicit noescape, where now we're passing the escaping attribute's presence down in the context instead of resetting the context anytime we see any attributes at all. This should be cleaner overall. The source range changes around some of the @escaping checking is really a sort of bugfix --- the existing code was really jumping from the @ sign all the way past the autoclosure keyword in a way that I'm not sure always works and is definitely a little unintentional-feeling. I tried to make the parser logic more consistent around recognizing these parameter specifiers; it seems better now, at least.
This commit is contained in:
@@ -707,18 +707,19 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
|
||||
|
||||
case KeyKind::KK_typeAttributes: {
|
||||
auto *Seq = cast<llvm::yaml::SequenceNode>(Pair.getValue());
|
||||
std::transform(Seq->begin(), Seq->end(),
|
||||
std::back_inserter(Info.TypeAttrs),
|
||||
[&](llvm::yaml::Node &N) {
|
||||
auto Result = llvm::StringSwitch<TypeAttrKind>(GetScalarString(&N))
|
||||
#define TYPE_ATTR(X) .Case(#X, TypeAttrKind::TAK_##X)
|
||||
for (auto &N : *Seq) {
|
||||
auto Result =
|
||||
llvm::StringSwitch<llvm::Optional<TypeAttrKind>>(GetScalarString(&N))
|
||||
#define TYPE_ATTR(X, C) .Case(#X, TAK_##X)
|
||||
#include "swift/AST/Attr.def"
|
||||
.Default(TypeAttrKind::TAK_Count);
|
||||
if (Result == TAK_Count)
|
||||
Ctx.diagnose(&N, diag::sdk_node_unrecognized_type_attr_kind,
|
||||
GetScalarString(&N));
|
||||
return Result;
|
||||
});
|
||||
.Default(llvm::Optional<TypeAttrKind>());
|
||||
|
||||
if (!Result)
|
||||
Ctx.diagnose(&N, diag::sdk_node_unrecognized_type_attr_kind,
|
||||
GetScalarString(&N));
|
||||
else
|
||||
Info.TypeAttrs.push_back(*Result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyKind::KK_declAttributes: {
|
||||
@@ -2225,7 +2226,7 @@ namespace json {
|
||||
template<>
|
||||
struct ScalarEnumerationTraits<TypeAttrKind> {
|
||||
static void enumeration(Output &out, TypeAttrKind &value) {
|
||||
#define TYPE_ATTR(X) out.enumCase(value, #X, TypeAttrKind::TAK_##X);
|
||||
#define TYPE_ATTR(X, C) out.enumCase(value, #X, TypeAttrKind::TAK_##X);
|
||||
#include "swift/AST/Attr.def"
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user