Apple Swift杂乱无章的反复背景规则
在带有Swift 5.6的MacOS上,给定从这里具有以下快速代码:
class Car //AB
{
class Foo //AD
{
func Foo() -> Void //AD
{
}
}
}
foo
is _ $ s4test3carc3foocadyyf
(目标名称name test ),我无法理解为什么<为什么<代码> foo 给出了索引代码 ad
,我期望分配 ac
:
AA AB AC
TEST.Car.Foo.Foo
在其他示例中:
class TEST //AA
{
class Car //AC
{
class Foo //AE
{
class Car //AC
{
func Foo() -> Void //AE
{
}
}
}
}
}
杂交名称为 _ $ S4TESTAAC3CARC3FOOCACCAEYYF
,同样是我要分配的值:
AA AB AC
TEST.TEST.Car.Foo.Car.Foo
为什么 foo
分配给 ae> ae
之后,第一个长期编码 3foo
?为什么 AB
和 AD
被跳过且未使用?请注意,这仅在字符串中的复发项目中,如果我可以愉快地编码所有经常性项目,则只有。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一种情况下,替换指数分配如下:
您可以通过使用这个问题。将方法的被弄糊糊的名称删除,而没有
f
后缀 - 这是为了允许我们添加任何a
替换我们选择的替代。 (我还删除了yy
以减少输出中的噪声),因此事实证明,当Mangling Algorithm Mangles
CAR CAR
时,它也会“记住”替换test.car
(因为它是标称类型),而不仅仅是car
自己。无论是否以后使用替换,都会发生这种情况,可能会使脱孔更容易(?),时,您也可以看到这一点。
当您将代码更改为:现在:现在方法
foo
名称为$ s6output3carc3foocadcyf
,使用ac
。作为一种心理模型,您可以将其视为与字母
c
相关联的替代指数,以及&lt; number&gt;&gt;&gt;&lt; didentifier&gt;
零件,像这样:在第二种情况下发生了类似的事情。
ab
是test.test
和ad
istest.test.car
。In the first case, the substitution indices are assigned as follows:
You can get these results by using the demangling code from this question. Demangle the mangled name of the method, just without the
F
suffix - this is to allow us to add anyA
substitution of our choice to the end. (I've also removed theyy
to reduce noise in the output)So it turns out that, when the mangling algorithm mangles
Car
, it also "remembers" a substitution forTEST.Car
(because it is a nominal type, perhaps), not justCar
on its own. This happens regardless of whether the substitution is used later on or not, probably to make demangling easier (?)You can also see this in effect when you change the code to:
Now the method
Foo
's mangled name is$s6output3CarC3FooCAdCyF
, making use ofAC
.As a mental model, you can think of it as the substitution indices being associated with the letter
C
in the mangled name as well as the<number><identifier>
parts, like this:A similar thing happens in the second case.
AB
isTEST.TEST
andAD
isTEST.TEST.Car
.