加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift VTables

发布时间:2020-12-14 05:11:51 所属栏目:百科 来源:网络整理
导读:VTables https://github.com/apple/swift/blob/master/docs/SIL.rst#vtables decl ::= sil-vtable sil-vtable ::= ‘sil_vtable‘ identifier ‘{‘ sil-vtable-entry* ‘}‘ ? sil-vtable-entry ::= sil-decl-ref ‘:‘ sil-linkage? sil-function-name SIL

VTables

https://github.com/apple/swift/blob/master/docs/SIL.rst#vtables

decl ::= sil-vtable

sil-vtable ::= ‘sil_vtable‘ identifier ‘{‘ sil-vtable-entry* ‘}‘

?

sil-vtable-entry ::= sil-decl-ref ‘:‘ sil-linkage? sil-function-name

SIL represents dynamic dispatch for class methods using the class_method,super_method,objc_method,and objc_super_method instructions.

The potential destinations for class_method and super_method are tracked in sil_vtable declarations for every class type. The declaration contains a mapping from every method of the class (including those inherited from its base class) to the SIL function that implements the method for that class:

class A {

? func foo()

? func bar()

? func bas()

}

?

sil @A_foo : [email?protected](thin) (@owned A) -> ()

sil @A_bar : [email?protected](thin) (@owned A) -> ()

sil @A_bas : [email?protected](thin) (@owned A) -> ()

?

sil_vtable A {

? #A.foo!1: @A_foo

? #A.bar!1: @A_bar

? #A.bas!1: @A_bas

}

?

class B : A {

? func bar()

}

?

sil @B_bar : [email?protected](thin) (@owned B) -> ()

?

sil_vtable B {

? #A.foo!1: @A_foo

? #A.bar!1: @B_bar

? #A.bas!1: @A_bas

}

?

class C : B {

? func bas()

}

?

sil @C_bas : [email?protected](thin) (@owned C) -> ()

?

sil_vtable C {

? #A.foo!1: @A_foo

? #A.bar!1: @B_bar

? #A.bas!1: @C_bas

}

Note that the declaration reference in the vtable is to the least-derived method visible through that class (in the example above,B‘s vtable references A.bar and not B.bar,and C‘s vtable references A.bas and not C.bas). The Swift AST maintains override relationships between declarations that can be used to look up overridden methods in the SIL vtable for a derived class (such as C.bas in C‘s vtable).

In case the SIL function is a thunk,the function name is preceded with the linkage of the original implementing function.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读