raw_self.carbon 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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[addr self: Class*](r#self: i32);
  8. fn G[self: Class](r#self: i32) -> (i32, i32);
  9. var n: i32;
  10. }
  11. fn Class.F[addr self: Class*](r#self: i32) {
  12. (*self).n = r#self;
  13. }
  14. fn Class.G[self: Class](r#self: i32) -> (i32, i32) {
  15. return (self.n, r#self);
  16. }
  17. // CHECK:STDOUT: --- raw_self.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  21. // CHECK:STDOUT: %.1: type = ptr_type Class [template]
  22. // CHECK:STDOUT: %.2: type = tuple_type (type, type) [template]
  23. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32) [template]
  24. // CHECK:STDOUT: %.4: type = ptr_type (i32, i32) [template]
  25. // CHECK:STDOUT: %.5: type = unbound_element_type Class, i32 [template]
  26. // CHECK:STDOUT: %.6: type = struct_type {.n: i32} [template]
  27. // CHECK:STDOUT: %.7: type = ptr_type {.n: i32} [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: file {
  31. // CHECK:STDOUT: package: <namespace> = namespace package, {.Class = %Class.decl} [template]
  32. // CHECK:STDOUT: %Class.decl = class_decl @Class, ()
  33. // CHECK:STDOUT: %F: <function> = fn_decl @F [template]
  34. // CHECK:STDOUT: %G: <function> = fn_decl @G [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: class @Class {
  38. // CHECK:STDOUT: %F: <function> = fn_decl @F [template]
  39. // CHECK:STDOUT: %G: <function> = fn_decl @G [template]
  40. // CHECK:STDOUT: %.loc10: <unbound element of class Class> = field_decl n, element0 [template]
  41. // CHECK:STDOUT: %n: <unbound element of class Class> = bind_name n, %.loc10 [template = %.loc10]
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: !members:
  44. // CHECK:STDOUT: .F = %F
  45. // CHECK:STDOUT: .G = %G
  46. // CHECK:STDOUT: .n = %n
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @F[addr %self.loc13_17: Class*](%self.loc13_31: i32) {
  50. // CHECK:STDOUT: !entry:
  51. // CHECK:STDOUT: %self.ref.loc14_5: Class* = name_ref self, %self.loc13_17
  52. // CHECK:STDOUT: %.loc14_4: ref Class = deref %self.ref.loc14_5
  53. // CHECK:STDOUT: %.loc14_10: ref i32 = class_element_access %.loc14_4, element0
  54. // CHECK:STDOUT: %self.ref.loc14_15: i32 = name_ref r#self, %self.loc13_31
  55. // CHECK:STDOUT: assign %.loc14_10, %self.ref.loc14_15
  56. // CHECK:STDOUT: return
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @G[%self.loc17_12: Class](%self.loc17_25: i32) -> %return: (i32, i32) {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: %self.ref.loc18_11: Class = name_ref self, %self.loc17_12
  62. // CHECK:STDOUT: %.loc18_15.1: ref i32 = class_element_access %self.ref.loc18_11, element0
  63. // CHECK:STDOUT: %.loc18_15.2: i32 = bind_value %.loc18_15.1
  64. // CHECK:STDOUT: %self.ref.loc18_19: i32 = name_ref r#self, %self.loc17_25
  65. // CHECK:STDOUT: %.loc18_25.1: (i32, i32) = tuple_literal (%.loc18_15.2, %self.ref.loc18_19)
  66. // CHECK:STDOUT: %.loc18_25.2: ref i32 = tuple_access %return, element0
  67. // CHECK:STDOUT: %.loc18_25.3: init i32 = initialize_from %.loc18_15.2 to %.loc18_25.2
  68. // CHECK:STDOUT: %.loc18_25.4: ref i32 = tuple_access %return, element1
  69. // CHECK:STDOUT: %.loc18_25.5: init i32 = initialize_from %self.ref.loc18_19 to %.loc18_25.4
  70. // CHECK:STDOUT: %.loc18_25.6: init (i32, i32) = tuple_init (%.loc18_25.3, %.loc18_25.5) to %return
  71. // CHECK:STDOUT: %.loc18_25.7: init (i32, i32) = converted %.loc18_25.1, %.loc18_25.6
  72. // CHECK:STDOUT: return %.loc18_25.7
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: