@@ -5,7 +5,7 @@ struct NodePrinter: Sendable {
55    var  specializationPrefixPrinted :  Bool 
66    var  options :  DemangleOptions 
77    var  hidingCurrentModule :  String  =  " " 
8-      
8+ 
99    init ( options:  DemangleOptions  =  . default)  { 
1010        self . target =  . init( ) 
1111        self . specializationPrefixPrinted =  false 
@@ -16,7 +16,7 @@ struct NodePrinter: Sendable {
1616        guard  options. contains ( . qualifyEntities)  else  { 
1717            return  false 
1818        } 
19-         if  !options. contains ( . showModuleInDependentMemberType) ,  let  dependentMemberType =  context. parent? . parent? . parent? . parent,  dependentMemberType. kind ==  . dependentMemberType   { 
19+         if  !options. contains ( . showModuleInDependentMemberType) ,  let  dependentMemberType =  context. parent? . parent? . parent? . parent,  dependentMemberType. kind ==  . dependentMemberType { 
2020            return  false 
2121        } 
2222        if  context. kind ==  . module,  let  text =  context. text,  !text. isEmpty { 
@@ -35,13 +35,9 @@ struct NodePrinter: Sendable {
3535
3636    mutating  func  printOptional( _ optional:  Node ? ,  prefix:  String ? =  nil ,  suffix:  String ? =  nil ,  asPrefixContext:  Bool  =  false )  ->  Node ? { 
3737        guard  let  o =  optional else  {  return  nil  } 
38-         if  options. contains ( . showPrefixAndSuffix)  { 
39-             prefix. map  {  target. write ( $0)  } 
40-         } 
38+         prefix. map  {  target. write ( $0)  } 
4139        let  r  =  printName ( o) 
42-         if  options. contains ( . showPrefixAndSuffix)  { 
43-             suffix. map  {  target. write ( $0)  } 
44-         } 
40+         suffix. map  {  target. write ( $0)  } 
4541        return  r
4642    } 
4743
@@ -105,7 +101,7 @@ struct NodePrinter: Sendable {
105101
106102    mutating  func  printModule( _ name:  Node )  { 
107103        if  options. contains ( . displayModuleNames)  { 
108-             target. write ( name. text ??  " " ) 
104+             target. write ( name. text ??  " " ,  type :   . other ) 
109105        } 
110106    } 
111107
@@ -848,7 +844,7 @@ struct NodePrinter: Sendable {
848844
849845    mutating  func  printImplDifferentiabilityKind( _ name:  Node )  { 
850846        target. write ( " @differentiable " ) 
851-         if  case let   . index( value)  =  name. contents,  let  differentiability =  Differentiability ( value)  { 
847+         if  case . index( let   value)  =  name. contents,  let  differentiability =  Differentiability ( value)  { 
852848            switch  differentiability { 
853849            case  . normal:  break 
854850            case  . linear:  target. write ( " (_linear) " ) 
@@ -859,7 +855,7 @@ struct NodePrinter: Sendable {
859855    } 
860856
861857    mutating  func  printImplCoroutineKind( _ name:  Node )  { 
862-         guard  case let   . name( value)  =  name. contents,  !value. isEmpty else  {  return  } 
858+         guard  case . name( let   value)  =  name. contents,  !value. isEmpty else  {  return  } 
863859        target. write ( " @ \( value) " ) 
864860    } 
865861
@@ -876,7 +872,7 @@ struct NodePrinter: Sendable {
876872    } 
877873
878874    mutating  func  printImplParameterName( _ name:  Node )  { 
879-         guard  case let   . name( value)  =  name. contents,  !value. isEmpty else  {  return  } 
875+         guard  case . name( let   value)  =  name. contents,  !value. isEmpty else  {  return  } 
880876        target. write ( " \( value)   " ) 
881877    } 
882878
@@ -1183,7 +1179,7 @@ struct NodePrinter: Sendable {
11831179        case  . globalVariableOnceFunction, 
11841180             . globalVariableOnceToken:  printGlobalVariableOnceFunction ( name) 
11851181        case  . hasSymbolQuery:  target. write ( " #_hasSymbol query for  " ) 
1186-         case  . identifier:  target . write ( name. text  ??   " " ,  type :   ( name . parent ? . kind  ==   . function || name . parent ? . kind  ==   . variable )   ?   . functionDeclaration  :   . typeName ) 
1182+         case  . identifier:  printIdentifier ( name,  asPrefixContext :  asPrefixContext ) 
11871183        case  . implConvention:  target. write ( name. text ??  " " ) 
11881184        case  . implCoroutineKind:  printImplCoroutineKind ( name) 
11891185        case  . implDifferentiabilityKind:  printImplDifferentiabilityKind ( name) 
@@ -1396,13 +1392,36 @@ struct NodePrinter: Sendable {
13961392        case  . variadicMarker:  target. write ( "  variadic-marker  " ) 
13971393        case  . vTableAttribute:  target. write ( " override  " ) 
13981394        case  . vTableThunk:  printVTableThunk ( name) 
1399-         case  . weak:  printFirstChild ( name,  prefix:  " weak  " ) 
1395+         case  . weak:  printFirstChild ( name,  prefix:  options . contains ( . removeWeakPrefix )   ?   " "   :   " weak  " ) 
14001396        case  . willSet:  return  printAbstractStorage ( name. children. first,  asPrefixContext:  asPrefixContext,  extraName:  " willset " ) 
14011397        } 
14021398
14031399        return  nil 
14041400    } 
14051401
1402+     mutating  func  printIdentifier( _ name:  Node ,  asPrefixContext:  Bool  =  false )  { 
1403+         let  semanticType :  SemanticType 
1404+ 
1405+         switch  name. parent? . kind { 
1406+         case  . function: 
1407+             semanticType =  . function( . declaration) 
1408+         case  . variable: 
1409+             semanticType =  . variable
1410+         case  . enum: 
1411+             semanticType =  . type( . enum,  . name) 
1412+         case  . structure: 
1413+             semanticType =  . type( . struct,  . name) 
1414+         case  . class: 
1415+             semanticType =  . type( . class,  . name) 
1416+         case  . protocol: 
1417+             semanticType =  . type( . protocol,  . name) 
1418+         default : 
1419+             semanticType =  . standard
1420+         } 
1421+ 
1422+         target. write ( name. text ??  " " ,  type:  semanticType) 
1423+     } 
1424+ 
14061425    mutating  func  printAbstractStorage( _ name:  Node ? ,  asPrefixContext:  Bool ,  extraName:  String )  ->  Node ? { 
14071426        guard  let  n =  name else  {  return  nil  } 
14081427        switch  n. kind { 
@@ -1609,17 +1628,17 @@ struct NodePrinter: Sendable {
16091628        target. write ( " ( " ) 
16101629        for  tuple  in  parameters. children. enumerated ( )  { 
16111630            if  let  label =  labelList? . children. at ( tuple. offset)  { 
1612-                 target. write ( label. kind ==  . identifier ?  ( label. text ??  " " )  :  " _ " ,  type:  . functionDeclaration ) 
1631+                 target. write ( label. kind ==  . identifier ?  ( label. text ??  " " )  :  " _ " ,  type:  . function ( . declaration ) ) 
16131632                target. write ( " : " ) 
16141633                if  showTypes { 
16151634                    target. write ( "   " ) 
16161635                } 
16171636            }  else  if  !showTypes { 
16181637                if  let  label =  tuple. element. children. first ( where:  {  $0. kind ==  . tupleElementName } )  { 
1619-                     target. write ( label. text ??  " " ,  type:  . functionDeclaration ) 
1638+                     target. write ( label. text ??  " " ,  type:  . function ( . declaration ) ) 
16201639                    target. write ( " : " ) 
16211640                }  else  { 
1622-                     target. write ( " _ " ,  type:  . functionDeclaration ) 
1641+                     target. write ( " _ " ,  type:  . function ( . declaration ) ) 
16231642                    target. write ( " : " ) 
16241643                } 
16251644            } 
0 commit comments