set(TARGET_LIBC_ENTRYPOINTS
+ # ctype.h entrypoints
+ libc.src.ctype.isalpha
+
# errno.h entrypoints
libc.src.errno.__errno_location
];
}
+def CTypeAPI : PublicAPI<"ctype.h"> {
+ let Functions = [
+ "isalpha",
+ ];
+}
+
def MathErrHandlingMacro : MacroDef<"math_errhandling"> {
let Defn = [{
#ifndef math_errhandling
set(TARGET_LIBC_ENTRYPOINTS
# assert.h entrypoints
libc.src.assert.__assert_fail
+
+ # ctype.h entrypoints
+ libc.src.ctype.isalpha
# errno.h entrypoints
libc.src.errno.__errno_location
__llvm-libc-stdc-types.h
)
-add_header(
+add_gen_header(
ctype
- HDR
- ctype.h
+ DEF_FILE ctype.h.def
+ GEN_HDR ctype.h
DEPENDS
.llvm_libc_common_h
)
--- /dev/null
+//===-- C standard library header ctype.h --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_CTYPE_H
+#define LLVM_LIBC_CTYPE_H
+
+#include <__llvm-libc-common.h>
+
+%%public_api()
+
+#endif // LLVM_LIBC_CTYPE_H
[], // Enumerations
[]
>;
-
+
+ HeaderSpec CType = HeaderSpec<
+ "ctype.h",
+ [], // Macros
+ [], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "isalpha",
+ RetValSpec<IntType>,
+ [ArgSpec<IntType>]
+ >,
+ ]
+ >;
+
HeaderSpec String = HeaderSpec<
"string.h",
[
let Headers = [
Assert,
+ CType,
Errno,
Math,
String,
add_subdirectory(assert)
+add_subdirectory(ctype)
add_subdirectory(errno)
add_subdirectory(math)
add_subdirectory(signal)
--- /dev/null
+add_entrypoint_object(
+ isalpha
+ SRCS
+ isalpha.cpp
+ HDRS
+ isalpha.h
+)
--- /dev/null
+//===-- Implementation of isalpha------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/ctype/isalpha.h"
+
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+// TODO: Currently restricted to default locale.
+// These should be extended using locale information.
+int LLVM_LIBC_ENTRYPOINT(isalpha)(int c) {
+ const unsigned ch = c;
+ return (ch | 32) - 'a' < 26;
+}
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation header for isalpha -------------------------*-C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_CTYPE_ISALPHA_H
+#define LLVM_LIBC_SRC_CTYPE_ISALPHA_H
+
+namespace __llvm_libc {
+
+int isalpha(int c);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_CTYPE_ISALPHA_H
add_subdirectory(assert)
+add_subdirectory(ctype)
add_subdirectory(errno)
add_subdirectory(math)
add_subdirectory(signal)
target_link_libraries(libc-integration-test
PRIVATE
${library_files}
-)
\ No newline at end of file
+)
--- /dev/null
+add_libc_testsuite(libc_ctype_unittests)
+
+add_libc_unittest(
+ isalpha
+ SUITE
+ libc_ctype_unittests
+ SRCS
+ isalpha_test.cpp
+ DEPENDS
+ libc.src.ctype.isalpha
+)
--- /dev/null
+//===-- Unittests for isalpha----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/ctype/isalpha.h"
+#include "utils/UnitTest/Test.h"
+
+// Helper function that makes a call to isalpha a bit cleaner
+// for use with testing utilities, since it explicitly requires
+// a boolean value for EXPECT_TRUE and EXPECT_FALSE.
+bool call_isalpha(int c) { return __llvm_libc::isalpha(c); }
+
+TEST(IsAlpha, DefaultLocale) {
+ // Loops through all characters, verifying that letters return true
+ // and everything else returns false.
+ for (int ch = 0; ch < 255; ++ch) {
+ if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
+ EXPECT_TRUE(call_isalpha(ch));
+ else
+ EXPECT_FALSE(call_isalpha(ch));
+ }
+}