self.carbon 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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[self: Class]() -> i32;
  8. fn G[addr self: Class*]() -> i32;
  9. var n: i32;
  10. }
  11. fn Class.F[self: Class]() -> i32 {
  12. return self.n;
  13. }
  14. fn Class.G[addr self: Class*]() -> i32 {
  15. return (*self).n;
  16. }
  17. // CHECK:STDOUT: --- 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 = unbound_element_type Class, i32 [template]
  23. // CHECK:STDOUT: %.3: type = struct_type {.n: i32} [template]
  24. // CHECK:STDOUT: %.4: type = ptr_type {.n: i32} [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: file {
  28. // CHECK:STDOUT: package: <namespace> = namespace package, {.Class = %Class.decl} [template]
  29. // CHECK:STDOUT: %Class.decl = class_decl @Class, ()
  30. // CHECK:STDOUT: %F: <function> = fn_decl @F [template]
  31. // CHECK:STDOUT: %G: <function> = fn_decl @G [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: class @Class {
  35. // CHECK:STDOUT: %F: <function> = fn_decl @F [template]
  36. // CHECK:STDOUT: %G: <function> = fn_decl @G [template]
  37. // CHECK:STDOUT: %.loc11: <unbound element of class Class> = field_decl n, element0 [template]
  38. // CHECK:STDOUT: %n: <unbound element of class Class> = bind_name n, %.loc11 [template = %.loc11]
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: !members:
  41. // CHECK:STDOUT: .F = %F
  42. // CHECK:STDOUT: .G = %G
  43. // CHECK:STDOUT: .n = %n
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: fn @F[%self: Class]() -> i32 {
  47. // CHECK:STDOUT: !entry:
  48. // CHECK:STDOUT: %self.ref: Class = name_ref self, %self
  49. // CHECK:STDOUT: %.loc15_14.1: ref i32 = class_element_access %self.ref, element0
  50. // CHECK:STDOUT: %.loc15_14.2: i32 = bind_value %.loc15_14.1
  51. // CHECK:STDOUT: return %.loc15_14.2
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: fn @G[addr %self: Class*]() -> i32 {
  55. // CHECK:STDOUT: !entry:
  56. // CHECK:STDOUT: %self.ref: Class* = name_ref self, %self
  57. // CHECK:STDOUT: %.loc19_11: ref Class = deref %self.ref
  58. // CHECK:STDOUT: %.loc19_17.1: ref i32 = class_element_access %.loc19_11, element0
  59. // CHECK:STDOUT: %.loc19_17.2: i32 = bind_value %.loc19_17.1
  60. // CHECK:STDOUT: return %.loc19_17.2
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: