class_with_fun.carbon 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 [template]
  19. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  20. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  21. // CHECK:STDOUT: %ret_a.type: type = fn_type @ret_a [template]
  22. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  23. // CHECK:STDOUT: %ret_a: %ret_a.type = struct_value () [template]
  24. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  25. // CHECK:STDOUT: %struct: %A = struct_value () [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: imports {
  29. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  30. // CHECK:STDOUT: import Core//prelude
  31. // CHECK:STDOUT: import Core//prelude/operators
  32. // CHECK:STDOUT: import Core//prelude/types
  33. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  34. // CHECK:STDOUT: import Core//prelude/operators/as
  35. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  36. // CHECK:STDOUT: import Core//prelude/operators/comparison
  37. // CHECK:STDOUT: import Core//prelude/types/bool
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .A = %A.decl
  45. // CHECK:STDOUT: .ret_a = %ret_a.decl
  46. // CHECK:STDOUT: .a = %a
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  50. // CHECK:STDOUT: %ret_a.decl: %ret_a.type = fn_decl @ret_a [template = constants.%ret_a] {} {
  51. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  52. // CHECK:STDOUT: %return: ref %A = var <return slot>
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [template = constants.%A]
  55. // CHECK:STDOUT: %a.var: ref %A = var a
  56. // CHECK:STDOUT: %a: ref %A = bind_name a, %a.var
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: class @A {
  60. // CHECK:STDOUT: %.loc10: <witness> = complete_type_witness %.1 [template = constants.%.2]
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !members:
  63. // CHECK:STDOUT: .Self = constants.%A
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @ret_a() -> %return: %A {
  67. // CHECK:STDOUT: !entry:
  68. // CHECK:STDOUT: %.loc13_11.1: %.1 = struct_literal ()
  69. // CHECK:STDOUT: %.loc13_11.2: init %A = class_init (), %return [template = constants.%struct]
  70. // CHECK:STDOUT: %.loc13_12: init %A = converted %.loc13_11.1, %.loc13_11.2 [template = constants.%struct]
  71. // CHECK:STDOUT: return %.loc13_12 to %return
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @__global_init() {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: %.loc16_13.1: %.1 = struct_literal ()
  77. // CHECK:STDOUT: %.loc16_13.2: init %A = class_init (), file.%a.var [template = constants.%struct]
  78. // CHECK:STDOUT: %.loc16_14: init %A = converted %.loc16_13.1, %.loc16_13.2 [template = constants.%struct]
  79. // CHECK:STDOUT: assign file.%a.var, %.loc16_14
  80. // CHECK:STDOUT: return
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: