diff --git a/lib/Demangling/NodePrinter.cpp b/lib/Demangling/NodePrinter.cpp index 3a7fc824699b2..5287239caffc5 100644 --- a/lib/Demangling/NodePrinter.cpp +++ b/lib/Demangling/NodePrinter.cpp @@ -18,6 +18,7 @@ #include "swift/Demangling/Demangle.h" #include "swift/AST/Ownership.h" #include "swift/Strings.h" +#include #include #include @@ -753,6 +754,35 @@ class NodePrinter { setInvalid(); return; } + + switch (node->getKind()) { + case Node::Kind::FunctionType: + case Node::Kind::UncurriedFunctionType: + case Node::Kind::NoEscapeFunctionType: + break; + case Node::Kind::AutoClosureType: + case Node::Kind::EscapingAutoClosureType: + Printer << "@autoclosure "; break; + case Node::Kind::ThinFunctionType: + Printer << "@convention(thin) "; break; + case Node::Kind::CFunctionPointer: + Printer << "@convention(c) "; break; + case Node::Kind::ObjCBlock: + Printer << "@convention(block) "; break; + case Node::Kind::EscapingObjCBlock: + Printer << "@escaping @convention(block) "; break; + case Node::Kind::DifferentiableFunctionType: + Printer << "@differentiable "; break; + case Node::Kind::EscapingDifferentiableFunctionType: + Printer << "@escaping @differentiable "; break; + case Node::Kind::LinearFunctionType: + Printer << "@differentiable(linear) "; break; + case Node::Kind::EscapingLinearFunctionType: + Printer << "@escaping @differentiable(linear) "; break; + default: + assert(false && "Unhandled function type in printFunctionType!"); + } + unsigned startIndex = 0; bool isAsync = false, isThrows = false; if (node->getChild(startIndex)->getKind() == Node::Kind::ThrowsAnnotation) { @@ -1256,39 +1286,19 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) { case Node::Kind::UnknownIndex: Printer << "unknown index"; return nullptr; + case Node::Kind::FunctionType: + case Node::Kind::UncurriedFunctionType: case Node::Kind::NoEscapeFunctionType: - printFunctionType(nullptr, Node); - return nullptr; - case Node::Kind::EscapingAutoClosureType: - Printer << "@autoclosure "; - printFunctionType(nullptr, Node); - return nullptr; case Node::Kind::AutoClosureType: - Printer << "@autoclosure "; - printFunctionType(nullptr, Node); - return nullptr; + case Node::Kind::EscapingAutoClosureType: case Node::Kind::ThinFunctionType: - Printer << "@convention(thin) "; - printFunctionType(nullptr, Node); - return nullptr; + case Node::Kind::CFunctionPointer: + case Node::Kind::ObjCBlock: + case Node::Kind::EscapingObjCBlock: case Node::Kind::DifferentiableFunctionType: - Printer << "@differentiable "; - printFunctionType(nullptr, Node); - return nullptr; case Node::Kind::EscapingDifferentiableFunctionType: - Printer << "@escaping @differentiable "; - printFunctionType(nullptr, Node); - return nullptr; case Node::Kind::LinearFunctionType: - Printer << "@differentiable(linear) "; - printFunctionType(nullptr, Node); - return nullptr; case Node::Kind::EscapingLinearFunctionType: - Printer << "@escaping @differentiable(linear) "; - printFunctionType(nullptr, Node); - return nullptr; - case Node::Kind::FunctionType: - case Node::Kind::UncurriedFunctionType: printFunctionType(nullptr, Node); return nullptr; case Node::Kind::ArgumentTuple: @@ -1881,21 +1891,6 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) { case Node::Kind::DynamicSelf: Printer << "Self"; return nullptr; - case Node::Kind::CFunctionPointer: { - Printer << "@convention(c) "; - printFunctionType(nullptr, Node); - return nullptr; - } - case Node::Kind::ObjCBlock: { - Printer << "@convention(block) "; - printFunctionType(nullptr, Node); - return nullptr; - } - case Node::Kind::EscapingObjCBlock: { - Printer << "@escaping @convention(block) "; - printFunctionType(nullptr, Node); - return nullptr; - } case Node::Kind::SILBoxType: { Printer << "@box "; NodePointer type = Node->getChild(0); @@ -2648,14 +2643,6 @@ void NodePrinter::printEntityType(NodePointer Entity, NodePointer type, Printer << ' '; type = dependentType->getFirstChild(); } - if (type->getKind() == Node::Kind::DifferentiableFunctionType) - Printer << "@differentiable "; - else if (type->getKind() == Node::Kind::EscapingDifferentiableFunctionType) - Printer << "@escaping @differentiable "; - else if (type->getKind() == Node::Kind::LinearFunctionType) - Printer << "@differentiable(linear) "; - else if (type->getKind() == Node::Kind::EscapingLinearFunctionType) - Printer << "@escaping @differentiable(linear) "; printFunctionType(labelList, type); } else { print(type); diff --git a/test/Demangle/Inputs/manglings.txt b/test/Demangle/Inputs/manglings.txt index 7f410eec10faa..294e7a08a34c2 100644 --- a/test/Demangle/Inputs/manglings.txt +++ b/test/Demangle/Inputs/manglings.txt @@ -357,6 +357,8 @@ $s3red4testyAA3ResOyxSayq_GAEs5ErrorAAq_sAFHD1__HCg_GADyxq_GsAFR_r0_lF ---> red. $s3red4testyAA7OurTypeOy4them05TheirD0Vy5AssocQzGAjE0F8ProtocolAAxAA0c7DerivedH0HD1_AA0c4BaseH0HI1_AieKHA2__HCg_GxmAaLRzlF ---> red.test(A.Type) -> red.OurType> $s17property_wrappers10WithTuplesV9fractionsSd_S2dtvpfP ---> property wrapper backing initializer of property_wrappers.WithTuples.fractions : (Swift.Double, Swift.Double, Swift.Double) $sSo17OS_dispatch_queueC4sync7executeyyyXE_tFTOTA ---> {T:$sSo17OS_dispatch_queueC4sync7executeyyyXE_tFTO} partial apply forwarder for @nonobjc __C.OS_dispatch_queue.sync(execute: () -> ()) -> () +$s4main1gyySiXCvp ---> main.g : @convention(c) (Swift.Int) -> () +$s4main1gyySiXBvp ---> main.g : @convention(block) (Swift.Int) -> () $sxq_Idgnr_D ---> @differentiable @callee_guaranteed (@in_guaranteed A) -> (@out B) $sxq_Ilgnr_D ---> @differentiable(linear) @callee_guaranteed (@in_guaranteed A) -> (@out B) $sS3fIedgyywd_D ---> @escaping @differentiable @callee_guaranteed (@unowned Swift.Float, @unowned @noDerivative Swift.Float) -> (@unowned Swift.Float)