scope.carbon 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. class Class {
  7. fn F() -> i32 {
  8. return 1;
  9. }
  10. fn G() -> i32 {
  11. return F();
  12. }
  13. }
  14. fn F() -> i32 {
  15. return 2;
  16. }
  17. fn Run() {
  18. var a: i32 = F();
  19. var b: i32 = Class.F();
  20. }
  21. // CHECK:STDOUT: --- scope.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  25. // CHECK:STDOUT: %F.1: type = fn_type @F.1 [template]
  26. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  27. // CHECK:STDOUT: %struct.1: F = struct_value () [template]
  28. // CHECK:STDOUT: %G: type = fn_type @G [template]
  29. // CHECK:STDOUT: %struct.2: G = struct_value () [template]
  30. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  31. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  32. // CHECK:STDOUT: %F.2: type = fn_type @F.2 [template]
  33. // CHECK:STDOUT: %struct.3: F = struct_value () [template]
  34. // CHECK:STDOUT: %.4: i32 = int_literal 2 [template]
  35. // CHECK:STDOUT: %Run: type = fn_type @Run [template]
  36. // CHECK:STDOUT: %struct.4: Run = struct_value () [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .Core = %Core
  42. // CHECK:STDOUT: .Class = %Class.decl
  43. // CHECK:STDOUT: .F = %F.decl
  44. // CHECK:STDOUT: .Run = %Run.decl
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  47. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  48. // CHECK:STDOUT: %F.decl: F = fn_decl @F.2 [template = constants.%struct.3] {
  49. // CHECK:STDOUT: @F.2.%return: ref i32 = var <return slot>
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Run.decl: Run = fn_decl @Run [template = constants.%struct.4] {}
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: class @Class {
  55. // CHECK:STDOUT: %F.decl: F = fn_decl @F.1 [template = constants.%struct.1] {
  56. // CHECK:STDOUT: %return.var.loc8: ref i32 = var <return slot>
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.2] {
  59. // CHECK:STDOUT: %return.var.loc12: ref i32 = var <return slot>
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !members:
  63. // CHECK:STDOUT: .Self = constants.%Class
  64. // CHECK:STDOUT: .F = %F.decl
  65. // CHECK:STDOUT: .G = %G.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @F.1() -> i32 {
  69. // CHECK:STDOUT: !entry:
  70. // CHECK:STDOUT: %.loc9: i32 = int_literal 1 [template = constants.%.3]
  71. // CHECK:STDOUT: return %.loc9
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @G() -> i32 {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: %F.ref: F = name_ref F, @Class.%F.decl [template = constants.%struct.1]
  77. // CHECK:STDOUT: %F.call: init i32 = call %F.ref()
  78. // CHECK:STDOUT: %.loc13_15.1: i32 = value_of_initializer %F.call
  79. // CHECK:STDOUT: %.loc13_15.2: i32 = converted %F.call, %.loc13_15.1
  80. // CHECK:STDOUT: return %.loc13_15.2
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @F.2() -> i32 {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: %.loc18: i32 = int_literal 2 [template = constants.%.4]
  86. // CHECK:STDOUT: return %.loc18
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @Run() {
  90. // CHECK:STDOUT: !entry:
  91. // CHECK:STDOUT: %a.var: ref i32 = var a
  92. // CHECK:STDOUT: %a: ref i32 = bind_name a, %a.var
  93. // CHECK:STDOUT: %F.ref.loc22: F = name_ref F, file.%F.decl [template = constants.%struct.3]
  94. // CHECK:STDOUT: %F.call.loc22: init i32 = call %F.ref.loc22()
  95. // CHECK:STDOUT: assign %a.var, %F.call.loc22
  96. // CHECK:STDOUT: %b.var: ref i32 = var b
  97. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  98. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  99. // CHECK:STDOUT: %F.ref.loc23: F = name_ref F, @Class.%F.decl [template = constants.%struct.1]
  100. // CHECK:STDOUT: %F.call.loc23: init i32 = call %F.ref.loc23()
  101. // CHECK:STDOUT: assign %b.var, %F.call.loc23
  102. // CHECK:STDOUT: return
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: