arrow.carbon 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. class C {
  7. fn Member[self: Self]();
  8. var field: C*;
  9. }
  10. fn Foo(ptr: C*) {
  11. (*ptr).Member();
  12. ptr->Member();
  13. (*ptr).field;
  14. ptr->field;
  15. ptr->field->field;
  16. }
  17. // CHECK:STDOUT: --- arrow.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %C: type = class_type @C [template]
  21. // CHECK:STDOUT: %.1: type = ptr_type C [template]
  22. // CHECK:STDOUT: %.2: type = unbound_element_type C, C* [template]
  23. // CHECK:STDOUT: %.3: type = struct_type {.field: C*} [template]
  24. // CHECK:STDOUT: %.4: type = ptr_type {.field: C*} [template]
  25. // CHECK:STDOUT: %.5: type = tuple_type () [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: file {
  29. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  30. // CHECK:STDOUT: .C = %C.decl
  31. // CHECK:STDOUT: .Foo = %Foo
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  34. // CHECK:STDOUT: %Foo: <function> = fn_decl @Foo [template] {
  35. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  36. // CHECK:STDOUT: %.loc12: type = ptr_type C [template = constants.%.1]
  37. // CHECK:STDOUT: %ptr.loc12_8.1: C* = param ptr
  38. // CHECK:STDOUT: @Foo.%ptr: C* = bind_name ptr, %ptr.loc12_8.1
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: class @C {
  43. // CHECK:STDOUT: %Member: <function> = fn_decl @Member [template] {
  44. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  45. // CHECK:STDOUT: %self.loc8_13.1: C = param self
  46. // CHECK:STDOUT: %self.loc8_13.2: C = bind_name self, %self.loc8_13.1
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  49. // CHECK:STDOUT: %.loc9_15: type = ptr_type C [template = constants.%.1]
  50. // CHECK:STDOUT: %.loc9_12: <unbound element of class C> = field_decl field, element0 [template]
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: !members:
  53. // CHECK:STDOUT: .Self = constants.%C
  54. // CHECK:STDOUT: .Member = %Member
  55. // CHECK:STDOUT: .field = %.loc9_12
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @Member[@C.%self.loc8_13.2: C]();
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @Foo(%ptr: C*) {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: %ptr.ref.loc13: C* = name_ref ptr, %ptr
  63. // CHECK:STDOUT: %.loc13_4.1: ref C = deref %ptr.ref.loc13
  64. // CHECK:STDOUT: %Member.ref.loc13: <function> = name_ref Member, @C.%Member [template = @C.%Member]
  65. // CHECK:STDOUT: %.loc13_9: <bound method> = bound_method %.loc13_4.1, %Member.ref.loc13
  66. // CHECK:STDOUT: %.loc13_4.2: C = bind_value %.loc13_4.1
  67. // CHECK:STDOUT: %.loc13_16: init () = call %.loc13_9(%.loc13_4.2)
  68. // CHECK:STDOUT: %ptr.ref.loc14: C* = name_ref ptr, %ptr
  69. // CHECK:STDOUT: %.loc14_6.1: ref C = deref %ptr.ref.loc14
  70. // CHECK:STDOUT: %Member.ref.loc14: <function> = name_ref Member, @C.%Member [template = @C.%Member]
  71. // CHECK:STDOUT: %.loc14_6.2: <bound method> = bound_method %.loc14_6.1, %Member.ref.loc14
  72. // CHECK:STDOUT: %.loc14_6.3: C = bind_value %.loc14_6.1
  73. // CHECK:STDOUT: %.loc14_14: init () = call %.loc14_6.2(%.loc14_6.3)
  74. // CHECK:STDOUT: %ptr.ref.loc16: C* = name_ref ptr, %ptr
  75. // CHECK:STDOUT: %.loc16_4: ref C = deref %ptr.ref.loc16
  76. // CHECK:STDOUT: %field.ref.loc16: <unbound element of class C> = name_ref field, @C.%.loc9_12 [template = @C.%.loc9_12]
  77. // CHECK:STDOUT: %.loc16_9: ref C* = class_element_access %.loc16_4, element0
  78. // CHECK:STDOUT: %ptr.ref.loc17: C* = name_ref ptr, %ptr
  79. // CHECK:STDOUT: %.loc17_6.1: ref C = deref %ptr.ref.loc17
  80. // CHECK:STDOUT: %field.ref.loc17: <unbound element of class C> = name_ref field, @C.%.loc9_12 [template = @C.%.loc9_12]
  81. // CHECK:STDOUT: %.loc17_6.2: ref C* = class_element_access %.loc17_6.1, element0
  82. // CHECK:STDOUT: %ptr.ref.loc19: C* = name_ref ptr, %ptr
  83. // CHECK:STDOUT: %.loc19_6.1: ref C = deref %ptr.ref.loc19
  84. // CHECK:STDOUT: %field.ref.loc19_6: <unbound element of class C> = name_ref field, @C.%.loc9_12 [template = @C.%.loc9_12]
  85. // CHECK:STDOUT: %.loc19_6.2: ref C* = class_element_access %.loc19_6.1, element0
  86. // CHECK:STDOUT: %.loc19_6.3: C* = bind_value %.loc19_6.2
  87. // CHECK:STDOUT: %.loc19_13.1: ref C = deref %.loc19_6.3
  88. // CHECK:STDOUT: %field.ref.loc19_13: <unbound element of class C> = name_ref field, @C.%.loc9_12 [template = @C.%.loc9_12]
  89. // CHECK:STDOUT: %.loc19_13.2: ref C* = class_element_access %.loc19_13.1, element0
  90. // CHECK:STDOUT: return
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: