base_method_shadow.carbon 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. base class A {
  7. fn F[addr self: Self*]();
  8. }
  9. base class B {
  10. extend base: A;
  11. fn F[addr self: Self*]();
  12. }
  13. class C {
  14. extend base: B;
  15. fn F[addr self: Self*]();
  16. }
  17. class D {
  18. extend base: B;
  19. }
  20. fn Call(a: A*, b: B*, c: C*, d: D*) {
  21. (*a).F();
  22. (*b).F();
  23. (*c).F();
  24. (*d).F();
  25. }
  26. // CHECK:STDOUT: --- base_method_shadow.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %A: type = class_type @A [template]
  30. // CHECK:STDOUT: %.1: type = ptr_type A [template]
  31. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  32. // CHECK:STDOUT: %B: type = class_type @B [template]
  33. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  34. // CHECK:STDOUT: %.4: type = ptr_type {} [template]
  35. // CHECK:STDOUT: %.5: type = unbound_element_type B, A [template]
  36. // CHECK:STDOUT: %.6: type = ptr_type B [template]
  37. // CHECK:STDOUT: %.7: type = struct_type {.base: A} [template]
  38. // CHECK:STDOUT: %C: type = class_type @C [template]
  39. // CHECK:STDOUT: %.8: type = struct_type {.base: {}*} [template]
  40. // CHECK:STDOUT: %.9: type = ptr_type {.base: A} [template]
  41. // CHECK:STDOUT: %.10: type = unbound_element_type C, B [template]
  42. // CHECK:STDOUT: %.11: type = ptr_type C [template]
  43. // CHECK:STDOUT: %.12: type = struct_type {.base: B} [template]
  44. // CHECK:STDOUT: %D: type = class_type @D [template]
  45. // CHECK:STDOUT: %.13: type = unbound_element_type D, B [template]
  46. // CHECK:STDOUT: %.14: type = ptr_type D [template]
  47. // CHECK:STDOUT: %.15: type = struct_type {.base: {.base: A}*} [template]
  48. // CHECK:STDOUT: %.16: type = ptr_type {.base: B} [template]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace {.A = %A.decl, .B = %B.decl, .C = %C.decl, .D = %D.decl, .Call = %Call} [template]
  53. // CHECK:STDOUT: %A.decl = class_decl @A, () [template = constants.%A]
  54. // CHECK:STDOUT: %B.decl = class_decl @B, () [template = constants.%B]
  55. // CHECK:STDOUT: %C.decl = class_decl @C, () [template = constants.%C]
  56. // CHECK:STDOUT: %D.decl = class_decl @D, () [template = constants.%D]
  57. // CHECK:STDOUT: %Call: <function> = fn_decl @Call [template]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: class @A {
  61. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template]
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: !members:
  64. // CHECK:STDOUT: .F = %F
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: class @B {
  68. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  69. // CHECK:STDOUT: %.loc12: <unbound element of class B> = base_decl A, element0 [template]
  70. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template]
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !members:
  73. // CHECK:STDOUT: .base = %.loc12
  74. // CHECK:STDOUT: .F = %F
  75. // CHECK:STDOUT: extend name_scope1
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: class @C {
  79. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  80. // CHECK:STDOUT: %.loc17: <unbound element of class C> = base_decl B, element0 [template]
  81. // CHECK:STDOUT: %F: <function> = fn_decl @F.3 [template]
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !members:
  84. // CHECK:STDOUT: .base = %.loc17
  85. // CHECK:STDOUT: .F = %F
  86. // CHECK:STDOUT: extend name_scope2
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: class @D {
  90. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  91. // CHECK:STDOUT: %.loc22: <unbound element of class D> = base_decl B, element0 [template]
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: !members:
  94. // CHECK:STDOUT: .base = %.loc22
  95. // CHECK:STDOUT: extend name_scope2
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @F.1[addr %self: A*]();
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn @F.2[addr %self: B*]();
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @F.3[addr %self: C*]();
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @Call(%a: A*, %b: B*, %c: C*, %d: D*) {
  105. // CHECK:STDOUT: !entry:
  106. // CHECK:STDOUT: %a.ref: A* = name_ref a, %a
  107. // CHECK:STDOUT: %.loc26_4.1: ref A = deref %a.ref
  108. // CHECK:STDOUT: %.loc26_7: <bound method> = bound_method %.loc26_4.1, @A.%F
  109. // CHECK:STDOUT: %.loc26_4.2: A* = addr_of %.loc26_4.1
  110. // CHECK:STDOUT: %.loc26_9: init () = call %.loc26_7(%.loc26_4.2)
  111. // CHECK:STDOUT: %b.ref: B* = name_ref b, %b
  112. // CHECK:STDOUT: %.loc27_4.1: ref B = deref %b.ref
  113. // CHECK:STDOUT: %.loc27_7: <bound method> = bound_method %.loc27_4.1, @B.%F
  114. // CHECK:STDOUT: %.loc27_4.2: B* = addr_of %.loc27_4.1
  115. // CHECK:STDOUT: %.loc27_9: init () = call %.loc27_7(%.loc27_4.2)
  116. // CHECK:STDOUT: %c.ref: C* = name_ref c, %c
  117. // CHECK:STDOUT: %.loc28_4.1: ref C = deref %c.ref
  118. // CHECK:STDOUT: %.loc28_7: <bound method> = bound_method %.loc28_4.1, @C.%F
  119. // CHECK:STDOUT: %.loc28_4.2: C* = addr_of %.loc28_4.1
  120. // CHECK:STDOUT: %.loc28_9: init () = call %.loc28_7(%.loc28_4.2)
  121. // CHECK:STDOUT: %d.ref: D* = name_ref d, %d
  122. // CHECK:STDOUT: %.loc29_4.1: ref D = deref %d.ref
  123. // CHECK:STDOUT: %.loc29_7: <bound method> = bound_method %.loc29_4.1, @B.%F
  124. // CHECK:STDOUT: %.loc29_4.2: D* = addr_of %.loc29_4.1
  125. // CHECK:STDOUT: %.loc29_9.1: ref D = deref %.loc29_4.2
  126. // CHECK:STDOUT: %.loc29_9.2: ref B = class_element_access %.loc29_9.1, element0
  127. // CHECK:STDOUT: %.loc29_9.3: B* = addr_of %.loc29_9.2
  128. // CHECK:STDOUT: %.loc29_4.3: B* = converted %.loc29_4.2, %.loc29_9.3
  129. // CHECK:STDOUT: %.loc29_9.4: init () = call %.loc29_7(%.loc29_4.3)
  130. // CHECK:STDOUT: return
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: