function.carbon 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/namespace/function.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/function.carbon
  10. namespace Foo;
  11. // Never called, just here to help catch bugs in name lookup.
  12. fn Baz() {
  13. }
  14. fn Foo.Baz() {
  15. }
  16. fn Bar() {
  17. Foo.Baz();
  18. }
  19. // CHECK:STDOUT: --- function.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %Baz.type.1: type = fn_type @Baz.1 [template]
  23. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  24. // CHECK:STDOUT: %Baz.1: %Baz.type.1 = struct_value () [template]
  25. // CHECK:STDOUT: %Baz.type.2: type = fn_type @Baz.2 [template]
  26. // CHECK:STDOUT: %Baz.2: %Baz.type.2 = struct_value () [template]
  27. // CHECK:STDOUT: %Bar.type: type = fn_type @Bar [template]
  28. // CHECK:STDOUT: %Bar: %Bar.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: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/operators
  35. // CHECK:STDOUT: import Core//prelude/types
  36. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  37. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  38. // CHECK:STDOUT: import Core//prelude/operators/comparison
  39. // CHECK:STDOUT: import Core//prelude/types/bool
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .Foo = %Foo
  47. // CHECK:STDOUT: .Baz = %Baz.decl.loc14
  48. // CHECK:STDOUT: .Bar = %Bar.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %Foo: <namespace> = namespace [template] {
  52. // CHECK:STDOUT: .Baz = %Baz.decl.loc17
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Baz.decl.loc14: %Baz.type.1 = fn_decl @Baz.1 [template = constants.%Baz.1] {}
  55. // CHECK:STDOUT: %Baz.decl.loc17: %Baz.type.2 = fn_decl @Baz.2 [template = constants.%Baz.2] {}
  56. // CHECK:STDOUT: %Bar.decl: %Bar.type = fn_decl @Bar [template = constants.%Bar] {}
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @Baz.1() {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: return
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @Baz.2() {
  65. // CHECK:STDOUT: !entry:
  66. // CHECK:STDOUT: return
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @Bar() {
  70. // CHECK:STDOUT: !entry:
  71. // CHECK:STDOUT: %Foo.ref: <namespace> = name_ref Foo, file.%Foo [template = file.%Foo]
  72. // CHECK:STDOUT: %Baz.ref: %Baz.type.2 = name_ref Baz, file.%Baz.decl.loc17 [template = constants.%Baz.2]
  73. // CHECK:STDOUT: %Baz.call: init %.1 = call %Baz.ref()
  74. // CHECK:STDOUT: return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: