nested_name.carbon 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/nested_name.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/nested_name.carbon
  10. class Outer {
  11. class Inner {
  12. var n: i32;
  13. }
  14. }
  15. fn F(oi: Outer.Inner) -> i32 {
  16. return oi.n;
  17. }
  18. fn G(o: Outer) {
  19. var i: o.Inner;
  20. }
  21. // CHECK:STDOUT: --- nested_name.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Outer: type = class_type @Outer [template]
  25. // CHECK:STDOUT: %Inner: type = class_type @Inner [template]
  26. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  27. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  28. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  29. // CHECK:STDOUT: %.2: type = unbound_element_type %Inner, i32 [template]
  30. // CHECK:STDOUT: %.3: type = struct_type {.n: i32} [template]
  31. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  32. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  33. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  34. // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
  35. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  36. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  37. // CHECK:STDOUT: %.6: type = ptr_type %.4 [template]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: file {
  41. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  42. // CHECK:STDOUT: .Core = %Core
  43. // CHECK:STDOUT: .Outer = %Outer.decl
  44. // CHECK:STDOUT: .F = %F.decl
  45. // CHECK:STDOUT: .G = %G.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  48. // CHECK:STDOUT: %Outer.decl: type = class_decl @Outer [template = constants.%Outer] {}
  49. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  51. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  52. // CHECK:STDOUT: %Outer.ref.loc17: type = name_ref Outer, %Outer.decl [template = constants.%Outer]
  53. // CHECK:STDOUT: %Inner.ref: type = name_ref Inner, @Outer.%Inner.decl [template = constants.%Inner]
  54. // CHECK:STDOUT: %oi.loc17_6.1: %Inner = param oi
  55. // CHECK:STDOUT: @F.%oi: %Inner = bind_name oi, %oi.loc17_6.1
  56. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  57. // CHECK:STDOUT: %.loc17_26.1: type = value_of_initializer %int.make_type_32 [template = i32]
  58. // CHECK:STDOUT: %.loc17_26.2: type = converted %int.make_type_32, %.loc17_26.1 [template = i32]
  59. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  62. // CHECK:STDOUT: %Outer.ref.loc21: type = name_ref Outer, %Outer.decl [template = constants.%Outer]
  63. // CHECK:STDOUT: %o.loc21_6.1: %Outer = param o
  64. // CHECK:STDOUT: @G.%o: %Outer = bind_name o, %o.loc21_6.1
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: class @Outer {
  69. // CHECK:STDOUT: %Inner.decl: type = class_decl @Inner [template = constants.%Inner] {}
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = constants.%Outer
  73. // CHECK:STDOUT: .Inner = %Inner.decl
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: class @Inner {
  77. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  78. // CHECK:STDOUT: %.loc13_12.1: type = value_of_initializer %int.make_type_32 [template = i32]
  79. // CHECK:STDOUT: %.loc13_12.2: type = converted %int.make_type_32, %.loc13_12.1 [template = i32]
  80. // CHECK:STDOUT: %.loc13_10: %.2 = field_decl n, element0 [template]
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: !members:
  83. // CHECK:STDOUT: .Self = constants.%Inner
  84. // CHECK:STDOUT: .n = %.loc13_10
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @F(%oi: %Inner) -> i32 {
  90. // CHECK:STDOUT: !entry:
  91. // CHECK:STDOUT: %oi.ref: %Inner = name_ref oi, %oi
  92. // CHECK:STDOUT: %n.ref: %.2 = name_ref n, @Inner.%.loc13_10 [template = @Inner.%.loc13_10]
  93. // CHECK:STDOUT: %.loc18_12.1: ref i32 = class_element_access %oi.ref, element0
  94. // CHECK:STDOUT: %.loc18_12.2: i32 = bind_value %.loc18_12.1
  95. // CHECK:STDOUT: return %.loc18_12.2
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @G(%o: %Outer) {
  99. // CHECK:STDOUT: !entry:
  100. // CHECK:STDOUT: %o.ref: %Outer = name_ref o, %o
  101. // CHECK:STDOUT: %Inner.ref: type = name_ref Inner, @Outer.%Inner.decl [template = constants.%Inner]
  102. // CHECK:STDOUT: %i.var: ref %Inner = var i
  103. // CHECK:STDOUT: %i: ref %Inner = bind_name i, %i.var
  104. // CHECK:STDOUT: return
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: