base.carbon 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Base {
  7. var b: i32;
  8. }
  9. class Derived {
  10. extend base: Base;
  11. var d: i32;
  12. }
  13. fn Make() -> Derived {
  14. return {.base = {.b = 4}, .d = 7};
  15. }
  16. fn Access(d: Derived) -> (i32, i32) {
  17. return (d.d, d.base.b);
  18. }
  19. // CHECK:STDOUT: --- base.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  23. // CHECK:STDOUT: %.1: type = unbound_element_type Base, i32 [template]
  24. // CHECK:STDOUT: %.2: type = struct_type {.b: i32} [template]
  25. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  26. // CHECK:STDOUT: %.3: type = ptr_type {.b: i32} [template]
  27. // CHECK:STDOUT: %.4: type = unbound_element_type Derived, Base [template]
  28. // CHECK:STDOUT: %.5: type = unbound_element_type Derived, i32 [template]
  29. // CHECK:STDOUT: %.6: type = struct_type {.base: Base, .d: i32} [template]
  30. // CHECK:STDOUT: %.7: type = struct_type {.base: {.b: i32}*, .d: i32} [template]
  31. // CHECK:STDOUT: %.8: type = ptr_type {.base: {.b: i32}*, .d: i32} [template]
  32. // CHECK:STDOUT: %.9: type = ptr_type {.base: Base, .d: i32} [template]
  33. // CHECK:STDOUT: %.10: i32 = int_literal 4 [template]
  34. // CHECK:STDOUT: %.11: i32 = int_literal 7 [template]
  35. // CHECK:STDOUT: %.12: type = struct_type {.base: {.b: i32}, .d: i32} [template]
  36. // CHECK:STDOUT: %.13: Base = struct_value (%.10) [template]
  37. // CHECK:STDOUT: %.14: Derived = struct_value (%.13, %.11) [template]
  38. // CHECK:STDOUT: %.15: type = tuple_type (type, type) [template]
  39. // CHECK:STDOUT: %.16: type = tuple_type (i32, i32) [template]
  40. // CHECK:STDOUT: %.17: type = ptr_type (i32, i32) [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .Core = %Core
  46. // CHECK:STDOUT: .Base = %Base.decl
  47. // CHECK:STDOUT: .Derived = %Derived.decl
  48. // CHECK:STDOUT: .Make = %Make
  49. // CHECK:STDOUT: .Access = %Access
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  52. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {}
  53. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {}
  54. // CHECK:STDOUT: %Make: <function> = fn_decl @Make [template] {
  55. // CHECK:STDOUT: %Derived.ref.loc17: type = name_ref Derived, %Derived.decl [template = constants.%Derived]
  56. // CHECK:STDOUT: @Make.%return: ref Derived = var <return slot>
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Access: <function> = fn_decl @Access [template] {
  59. // CHECK:STDOUT: %Derived.ref.loc21: type = name_ref Derived, %Derived.decl [template = constants.%Derived]
  60. // CHECK:STDOUT: %d.loc21_11.1: Derived = param d
  61. // CHECK:STDOUT: @Access.%d: Derived = bind_name d, %d.loc21_11.1
  62. // CHECK:STDOUT: %.loc21_35.1: (type, type) = tuple_literal (i32, i32)
  63. // CHECK:STDOUT: %.loc21_35.2: type = converted %.loc21_35.1, constants.%.16 [template = constants.%.16]
  64. // CHECK:STDOUT: @Access.%return: ref (i32, i32) = var <return slot>
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: class @Base {
  69. // CHECK:STDOUT: %.loc8: <unbound element of class Base> = field_decl b, element0 [template]
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = constants.%Base
  73. // CHECK:STDOUT: .b = %.loc8
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: class @Derived {
  77. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  78. // CHECK:STDOUT: %.loc12: <unbound element of class Derived> = base_decl Base, element0 [template]
  79. // CHECK:STDOUT: %.loc14: <unbound element of class Derived> = field_decl d, element1 [template]
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !members:
  82. // CHECK:STDOUT: .Self = constants.%Derived
  83. // CHECK:STDOUT: .base = %.loc12
  84. // CHECK:STDOUT: .d = %.loc14
  85. // CHECK:STDOUT: extend name_scope2
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @Make() -> %return: Derived {
  89. // CHECK:STDOUT: !entry:
  90. // CHECK:STDOUT: %.loc18_25: i32 = int_literal 4 [template = constants.%.10]
  91. // CHECK:STDOUT: %.loc18_26.1: {.b: i32} = struct_literal (%.loc18_25)
  92. // CHECK:STDOUT: %.loc18_34: i32 = int_literal 7 [template = constants.%.11]
  93. // CHECK:STDOUT: %.loc18_35.1: {.base: {.b: i32}, .d: i32} = struct_literal (%.loc18_26.1, %.loc18_34)
  94. // CHECK:STDOUT: %.loc18_35.2: ref Base = class_element_access %return, element0
  95. // CHECK:STDOUT: %.loc18_26.2: ref i32 = class_element_access %.loc18_35.2, element0
  96. // CHECK:STDOUT: %.loc18_26.3: init i32 = initialize_from %.loc18_25 to %.loc18_26.2 [template = constants.%.10]
  97. // CHECK:STDOUT: %.loc18_26.4: init Base = class_init (%.loc18_26.3), %.loc18_35.2 [template = constants.%.13]
  98. // CHECK:STDOUT: %.loc18_26.5: init Base = converted %.loc18_26.1, %.loc18_26.4 [template = constants.%.13]
  99. // CHECK:STDOUT: %.loc18_35.3: ref i32 = class_element_access %return, element1
  100. // CHECK:STDOUT: %.loc18_35.4: init i32 = initialize_from %.loc18_34 to %.loc18_35.3 [template = constants.%.11]
  101. // CHECK:STDOUT: %.loc18_35.5: init Derived = class_init (%.loc18_26.5, %.loc18_35.4), %return [template = constants.%.14]
  102. // CHECK:STDOUT: %.loc18_35.6: init Derived = converted %.loc18_35.1, %.loc18_35.5 [template = constants.%.14]
  103. // CHECK:STDOUT: return %.loc18_35.6
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: fn @Access(%d: Derived) -> %return: (i32, i32) {
  107. // CHECK:STDOUT: !entry:
  108. // CHECK:STDOUT: %d.ref.loc22_11: Derived = name_ref d, %d
  109. // CHECK:STDOUT: %d.ref.loc22_12: <unbound element of class Derived> = name_ref d, @Derived.%.loc14 [template = @Derived.%.loc14]
  110. // CHECK:STDOUT: %.loc22_12.1: ref i32 = class_element_access %d.ref.loc22_11, element1
  111. // CHECK:STDOUT: %.loc22_12.2: i32 = bind_value %.loc22_12.1
  112. // CHECK:STDOUT: %d.ref.loc22_16: Derived = name_ref d, %d
  113. // CHECK:STDOUT: %base.ref: <unbound element of class Derived> = name_ref base, @Derived.%.loc12 [template = @Derived.%.loc12]
  114. // CHECK:STDOUT: %.loc22_17.1: ref Base = class_element_access %d.ref.loc22_16, element0
  115. // CHECK:STDOUT: %.loc22_17.2: Base = bind_value %.loc22_17.1
  116. // CHECK:STDOUT: %b.ref: <unbound element of class Base> = name_ref b, @Base.%.loc8 [template = @Base.%.loc8]
  117. // CHECK:STDOUT: %.loc22_22.1: ref i32 = class_element_access %.loc22_17.2, element0
  118. // CHECK:STDOUT: %.loc22_22.2: i32 = bind_value %.loc22_22.1
  119. // CHECK:STDOUT: %.loc22_24.1: (i32, i32) = tuple_literal (%.loc22_12.2, %.loc22_22.2)
  120. // CHECK:STDOUT: %.loc22_24.2: ref i32 = tuple_access %return, element0
  121. // CHECK:STDOUT: %.loc22_24.3: init i32 = initialize_from %.loc22_12.2 to %.loc22_24.2
  122. // CHECK:STDOUT: %.loc22_24.4: ref i32 = tuple_access %return, element1
  123. // CHECK:STDOUT: %.loc22_24.5: init i32 = initialize_from %.loc22_22.2 to %.loc22_24.4
  124. // CHECK:STDOUT: %.loc22_24.6: init (i32, i32) = tuple_init (%.loc22_24.3, %.loc22_24.5) to %return
  125. // CHECK:STDOUT: %.loc22_24.7: init (i32, i32) = converted %.loc22_24.1, %.loc22_24.6
  126. // CHECK:STDOUT: return %.loc22_24.7
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: