method.carbon 779 B

123456789101112131415161718192021222324252627282930
  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 C {
  7. var a: i32;
  8. fn Get[self: C]() -> i32;
  9. fn Set[addr self: C*](n: i32);
  10. }
  11. fn F(p: C*) {
  12. let n: i32 = (*p).Get();
  13. (*p).Set(n);
  14. }
  15. // CHECK:STDOUT: ; ModuleID = 'method.carbon'
  16. // CHECK:STDOUT: source_filename = "method.carbon"
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: declare i32 @Get(ptr)
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: declare void @Set(ptr, i32)
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: define void @F(ptr %p) {
  23. // CHECK:STDOUT: %Get = call i32 @Get(ptr %p)
  24. // CHECK:STDOUT: call void @Set(ptr %p, i32 %Get)
  25. // CHECK:STDOUT: ret void
  26. // CHECK:STDOUT: }