static_method.carbon 4.5 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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/static_method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/static_method.carbon
  10. class Class {
  11. fn F() -> i32;
  12. }
  13. fn Run() -> i32 {
  14. var c: Class;
  15. return c.F();
  16. }
  17. // CHECK:STDOUT: --- static_method.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  21. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  22. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  23. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  26. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  27. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  28. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  29. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  30. // CHECK:STDOUT: %.4: type = ptr_type %.2 [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  35. // CHECK:STDOUT: .Int32 = %import_ref
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/operators
  38. // CHECK:STDOUT: import Core//prelude/types
  39. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  40. // CHECK:STDOUT: import Core//prelude/operators/as
  41. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  42. // CHECK:STDOUT: import Core//prelude/operators/comparison
  43. // CHECK:STDOUT: import Core//prelude/types/bool
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+9, loaded [template = constants.%Int32]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = imports.%Core
  51. // CHECK:STDOUT: .Class = %Class.decl
  52. // CHECK:STDOUT: .Run = %Run.decl
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.import = import Core
  55. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  56. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {
  57. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  58. // CHECK:STDOUT: %.loc15_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  59. // CHECK:STDOUT: %.loc15_13.2: type = converted %int.make_type_32, %.loc15_13.1 [template = i32]
  60. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class @Class {
  65. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {
  66. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc12_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  68. // CHECK:STDOUT: %.loc12_13.2: type = converted %int.make_type_32, %.loc12_13.1 [template = i32]
  69. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %.loc13: <witness> = complete_type_witness %.2 [template = constants.%.3]
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: !members:
  74. // CHECK:STDOUT: .Self = constants.%Class
  75. // CHECK:STDOUT: .F = %F.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @F() -> i32;
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @Run() -> i32 {
  83. // CHECK:STDOUT: !entry:
  84. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  85. // CHECK:STDOUT: %c.var: ref %Class = var c
  86. // CHECK:STDOUT: %c: ref %Class = bind_name c, %c.var
  87. // CHECK:STDOUT: %c.ref: ref %Class = name_ref c, %c
  88. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  89. // CHECK:STDOUT: %F.call: init i32 = call %F.ref()
  90. // CHECK:STDOUT: %.loc17_15.1: i32 = value_of_initializer %F.call
  91. // CHECK:STDOUT: %.loc17_15.2: i32 = converted %F.call, %.loc17_15.1
  92. // CHECK:STDOUT: return %.loc17_15.2
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: