class_with_fun.carbon 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/global/class_with_fun.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/global/class_with_fun.carbon
  10. class A {}
  11. fn ret_a() -> A {
  12. return {};
  13. }
  14. var a: A = {};
  15. // CHECK:STDOUT: --- class_with_fun.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  19. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  20. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  21. // CHECK:STDOUT: %pattern_type: type = pattern_type %A [concrete]
  22. // CHECK:STDOUT: %ret_a.type: type = fn_type @ret_a [concrete]
  23. // CHECK:STDOUT: %ret_a: %ret_a.type = struct_value () [concrete]
  24. // CHECK:STDOUT: %A.val: %A = struct_value () [concrete]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  29. // CHECK:STDOUT: import Core//prelude
  30. // CHECK:STDOUT: import Core//prelude/...
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: file {
  35. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  36. // CHECK:STDOUT: .Core = imports.%Core
  37. // CHECK:STDOUT: .A = %A.decl
  38. // CHECK:STDOUT: .ret_a = %ret_a.decl
  39. // CHECK:STDOUT: .a = %a
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core.import = import Core
  42. // CHECK:STDOUT: %A.decl: type = class_decl @A [concrete = constants.%A] {} {}
  43. // CHECK:STDOUT: %ret_a.decl: %ret_a.type = fn_decl @ret_a [concrete = constants.%ret_a] {
  44. // CHECK:STDOUT: %return.patt: %pattern_type = return_slot_pattern [concrete]
  45. // CHECK:STDOUT: %return.param_patt: %pattern_type = out_param_pattern %return.patt, call_param0 [concrete]
  46. // CHECK:STDOUT: } {
  47. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  48. // CHECK:STDOUT: %return.param: ref %A = out_param call_param0
  49. // CHECK:STDOUT: %return: ref %A = return_slot %return.param
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: name_binding_decl {
  52. // CHECK:STDOUT: %a.patt: %pattern_type = binding_pattern a [concrete]
  53. // CHECK:STDOUT: %.loc16: %pattern_type = var_pattern %a.patt [concrete]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %a.var: ref %A = var a
  56. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [concrete = constants.%A]
  57. // CHECK:STDOUT: %a: ref %A = bind_name a, %a.var
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: class @A {
  61. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  62. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  63. // CHECK:STDOUT: complete_type_witness = %complete_type
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .Self = constants.%A
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @ret_a() -> %return.param: %A {
  70. // CHECK:STDOUT: !entry:
  71. // CHECK:STDOUT: %.loc13_11.1: %empty_struct_type = struct_literal ()
  72. // CHECK:STDOUT: %.loc13_11.2: init %A = class_init (), %return [concrete = constants.%A.val]
  73. // CHECK:STDOUT: %.loc13_12: init %A = converted %.loc13_11.1, %.loc13_11.2 [concrete = constants.%A.val]
  74. // CHECK:STDOUT: return %.loc13_12 to %return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @__global_init() {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: %.loc16_13.1: %empty_struct_type = struct_literal ()
  80. // CHECK:STDOUT: %.loc16_13.2: init %A = class_init (), file.%a.var [concrete = constants.%A.val]
  81. // CHECK:STDOUT: %.loc16_1: init %A = converted %.loc16_13.1, %.loc16_13.2 [concrete = constants.%A.val]
  82. // CHECK:STDOUT: assign file.%a.var, %.loc16_1
  83. // CHECK:STDOUT: return
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: