inline.carbon 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/inline.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/inline.carbon
  12. // --- use_inline_function_decl.carbon
  13. library "[[@TEST_NAME]]";
  14. import Cpp inline '''
  15. // A C++ function.
  16. inline void func() {}
  17. ''';
  18. fn Run() {
  19. //@dump-sem-ir-begin
  20. Cpp.func();
  21. //@dump-sem-ir-end
  22. }
  23. // --- with_language_marker.carbon
  24. library "[[@TEST_NAME]]";
  25. import Cpp inline '''c++
  26. // A C++ function.
  27. inline void another_func() {}
  28. ''';
  29. fn Run() {
  30. //@dump-sem-ir-begin
  31. Cpp.another_func();
  32. //@dump-sem-ir-end
  33. }
  34. // CHECK:STDOUT: --- use_inline_function_decl.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  38. // CHECK:STDOUT: %func.type: type = fn_type @func [concrete]
  39. // CHECK:STDOUT: %func: %func.type = struct_value () [concrete]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  44. // CHECK:STDOUT: .func = %func.decl
  45. // CHECK:STDOUT: import Cpp//...
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %func.decl: %func.type = fn_decl @func [concrete = constants.%func] {} {}
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: fn @Run() {
  51. // CHECK:STDOUT: !entry:
  52. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  53. // CHECK:STDOUT: %func.ref: %func.type = name_ref func, imports.%func.decl [concrete = constants.%func]
  54. // CHECK:STDOUT: %func.call: init %empty_tuple.type = call %func.ref()
  55. // CHECK:STDOUT: <elided>
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: --- with_language_marker.carbon
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: constants {
  61. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  62. // CHECK:STDOUT: %another_func.type: type = fn_type @another_func [concrete]
  63. // CHECK:STDOUT: %another_func: %another_func.type = struct_value () [concrete]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: imports {
  67. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  68. // CHECK:STDOUT: .another_func = %another_func.decl
  69. // CHECK:STDOUT: import Cpp//...
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %another_func.decl: %another_func.type = fn_decl @another_func [concrete = constants.%another_func] {} {}
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @Run() {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  77. // CHECK:STDOUT: %another_func.ref: %another_func.type = name_ref another_func, imports.%another_func.decl [concrete = constants.%another_func]
  78. // CHECK:STDOUT: %another_func.call: init %empty_tuple.type = call %another_func.ref()
  79. // CHECK:STDOUT: <elided>
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: