@@ -1463,6 +1463,37 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
14631463 diagnostic.isChildNote ());
14641464}
14651465
1466+ static DeclName
1467+ getGeneratedSourceInfoMacroName (const GeneratedSourceInfo &info) {
1468+ ASTNode expansionNode = ASTNode::getFromOpaqueValue (info.astNode );
1469+ switch (info.kind ) {
1470+ #define MACRO_ROLE (Name, Description ) \
1471+ case GeneratedSourceInfo::Name##MacroExpansion:
1472+ #include " swift/Basic/MacroRoles.def"
1473+ {
1474+ if (auto customAttr = info.attachedMacroCustomAttr ) {
1475+ // FIXME: How will we handle deserialized custom attributes like this?
1476+ auto declRefType = cast<DeclRefTypeRepr>(customAttr->getTypeRepr ());
1477+ return declRefType->getNameRef ().getFullName ();
1478+ }
1479+
1480+ if (auto expansionExpr = dyn_cast_or_null<MacroExpansionExpr>(
1481+ expansionNode.dyn_cast <Expr *>())) {
1482+ return expansionExpr->getMacroName ().getFullName ();
1483+ }
1484+
1485+ auto expansionDecl =
1486+ cast<MacroExpansionDecl>(expansionNode.get <Decl *>());
1487+ return expansionDecl->getMacroName ().getFullName ();
1488+ }
1489+
1490+ case GeneratedSourceInfo::PrettyPrinted:
1491+ case GeneratedSourceInfo::ReplacedFunctionBody:
1492+ case GeneratedSourceInfo::DefaultArgument:
1493+ return DeclName ();
1494+ }
1495+ }
1496+
14661497std::vector<Diagnostic>
14671498DiagnosticEngine::getGeneratedSourceBufferNotes (SourceLoc loc) {
14681499 // The set of child notes we're building up.
@@ -1674,35 +1705,3 @@ EncodedDiagnosticMessage::EncodedDiagnosticMessage(StringRef S)
16741705 : Message(Lexer::getEncodedStringSegment(S, Buf, /* IsFirstSegment=*/ true ,
16751706 /* IsLastSegment=*/ true ,
16761707 /* IndentToStrip=*/ ~0U )) {}
1677-
1678- DeclName
1679- swift::getGeneratedSourceInfoMacroName (const GeneratedSourceInfo &info) {
1680- ASTNode expansionNode = ASTNode::getFromOpaqueValue (info.astNode );
1681- switch (info.kind ) {
1682- #define MACRO_ROLE (Name, Description ) \
1683- case GeneratedSourceInfo::Name##MacroExpansion:
1684- #include " swift/Basic/MacroRoles.def"
1685- {
1686- DeclName macroName;
1687- if (auto customAttr = info.attachedMacroCustomAttr ) {
1688- // FIXME: How will we handle deserialized custom attributes like this?
1689- auto declRefType = cast<DeclRefTypeRepr>(customAttr->getTypeRepr ());
1690- return declRefType->getNameRef ().getFullName ();
1691- }
1692-
1693- if (auto expansionExpr = dyn_cast_or_null<MacroExpansionExpr>(
1694- expansionNode.dyn_cast <Expr *>())) {
1695- return expansionExpr->getMacroName ().getFullName ();
1696- }
1697-
1698- auto expansionDecl =
1699- cast<MacroExpansionDecl>(expansionNode.get <Decl *>());
1700- return expansionDecl->getMacroName ().getFullName ();
1701- }
1702-
1703- case GeneratedSourceInfo::PrettyPrinted:
1704- case GeneratedSourceInfo::ReplacedFunctionBody:
1705- case GeneratedSourceInfo::DefaultArgument:
1706- return DeclName ();
1707- }
1708- }
0 commit comments