static_method.carbon 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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: %int_32: Core.IntLiteral = int_value 32 [template]
  22. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  23. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  24. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  25. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  26. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  27. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  28. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: imports {
  32. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  33. // CHECK:STDOUT: .Int = %Core.Int
  34. // CHECK:STDOUT: import Core//prelude
  35. // CHECK:STDOUT: import Core//prelude/...
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .Core = imports.%Core
  42. // CHECK:STDOUT: .Class = %Class.decl
  43. // CHECK:STDOUT: .Run = %Run.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core.import = import Core
  46. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  47. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {
  48. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  49. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  50. // CHECK:STDOUT: } {
  51. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  52. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  53. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  54. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  57. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: class @Class {
  61. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  62. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  63. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  66. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  67. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  68. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  71. // CHECK:STDOUT: complete_type_witness = %complete_type
  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 @F() -> %i32;
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @Run() -> %i32 {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: name_binding_decl {
  83. // CHECK:STDOUT: %c.patt: %Class = binding_pattern c
  84. // CHECK:STDOUT: %.loc16: %Class = var_pattern %c.patt
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %c.var: ref %Class = var c
  87. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  88. // CHECK:STDOUT: %c: ref %Class = bind_name c, %c.var
  89. // CHECK:STDOUT: %c.ref: ref %Class = name_ref c, %c
  90. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  91. // CHECK:STDOUT: %F.call: init %i32 = call %F.ref()
  92. // CHECK:STDOUT: %.loc17_15.1: %i32 = value_of_initializer %F.call
  93. // CHECK:STDOUT: %.loc17_15.2: %i32 = converted %F.call, %.loc17_15.1
  94. // CHECK:STDOUT: return %.loc17_15.2
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: