[libc][NFC] Use STL case for functional
authorGuillaume Chatelet <gchatelet@google.com>
Fri, 29 Jul 2022 12:11:35 +0000 (12:11 +0000)
committerGuillaume Chatelet <gchatelet@google.com>
Mon, 1 Aug 2022 09:10:59 +0000 (09:10 +0000)
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion.

Differential Revision: https://reviews.llvm.org/D130760

libc/src/__support/CPP/CMakeLists.txt
libc/src/__support/CPP/functional.h [moved from libc/src/__support/CPP/Functional.h with 65% similarity]
libc/test/src/__support/OSUtil/linux/x86_64/syscall_test.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel

index d9126b1..7172dae 100644 (file)
@@ -41,7 +41,7 @@ add_header_library(
 add_header_library(
   functional
   HDRS
-    Functional.h
+    functional.h
 )
 
 add_header_library(
similarity index 65%
rename from libc/src/__support/CPP/Functional.h
rename to libc/src/__support/CPP/functional.h
index 51f6331..5919306 100644 (file)
 namespace __llvm_libc {
 namespace cpp {
 
-template <typename Func> class Function;
+template <typename F> class function;
 
-template <typename Ret, typename... Params> class Function<Ret(Params...)> {
-  Ret (*func)(Params...) = nullptr;
+template <typename R, typename... Args> class function<R(Args...)> {
+  R (*func)(Args...) = nullptr;
 
 public:
-  constexpr Function() = default;
-  template <typename Func> constexpr Function(Func &&f) : func(f) {}
+  constexpr function() = default;
+  template <typename F> constexpr function(F &&f) : func(f) {}
 
-  constexpr Ret operator()(Params... params) { return func(params...); }
+  constexpr R operator()(Args... params) { return func(params...); }
 };
 
 } // namespace cpp
index 2f9816e..4869e00 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/Functional.h"
+#include "src/__support/CPP/functional.h"
 #include "src/__support/OSUtil/syscall.h"
 #include "utils/UnitTest/Test.h"
 
@@ -14,30 +14,30 @@ TEST(LlvmLibcX86_64_SyscallTest, APITest) {
   // We only do a signature test here. Actual functionality tests are
   // done by the unit tests of the syscall wrappers like mmap.
 
-  using __llvm_libc::cpp::Function;
+  using __llvm_libc::cpp::function;
 
-  Function<long(long)> f([](long n) { return __llvm_libc::syscall(n); });
-  Function<long(long, long)> f1(
+  function<long(long)> f([](long n) { return __llvm_libc::syscall(n); });
+  function<long(long, long)> f1(
       [](long n, long a1) { return __llvm_libc::syscall(n, a1); });
-  Function<long(long, long, long)> f2(
+  function<long(long, long, long)> f2(
       [](long n, long a1, long a2) { return __llvm_libc::syscall(n, a1, a2); });
-  Function<long(long, long, long, long)> f3(
+  function<long(long, long, long, long)> f3(
       [](long n, long a1, long a2, long a3) {
         return __llvm_libc::syscall(n, a1, a2, a3);
       });
-  Function<long(long, long, long, long, long)> f4(
+  function<long(long, long, long, long, long)> f4(
       [](long n, long a1, long a2, long a3, long a4) {
         return __llvm_libc::syscall(n, a1, a2, a3, a4);
       });
-  Function<long(long, long, long, long, long, long)> f5(
+  function<long(long, long, long, long, long, long)> f5(
       [](long n, long a1, long a2, long a3, long a4, long a5) {
         return __llvm_libc::syscall(n, a1, a2, a3, a4, a5);
       });
-  Function<long(long, long, long, long, long, long, long)> f6(
+  function<long(long, long, long, long, long, long, long)> f6(
       [](long n, long a1, long a2, long a3, long a4, long a5, long a6) {
         return __llvm_libc::syscall(n, a1, a2, a3, a4, a5, a6);
       });
 
-  Function<long(long, void *)> not_long_type(
+  function<long(long, void *)> not_long_type(
       [](long n, void *a1) { return __llvm_libc::syscall(n, a1); });
 }
index e4fec95..6ee055f 100644 (file)
@@ -65,7 +65,7 @@ cc_library(
 
 cc_library(
     name = "__support_cpp_functional",
-    hdrs = ["src/__support/CPP/Functional.h"],
+    hdrs = ["src/__support/CPP/functional.h"],
     deps = [":libc_root"],
 )